[ncl-talk] accumulate data on grid

Paimazumder, Debasish Debasish.Paimazumder at aig.com
Mon Oct 19 15:56:33 MDT 2020


Hi Dennis,
Thanks for your response. Nice to hear from you and hope you are doing well and safe from recent wildfire in north boulder.

I’m not sure that I understand the bin_sum function specially the second part (‘user must perform averaging’).

For my case, dlon, dlat and d are from csv file and lat/lon from netcdf file. See blow their dimension. I would like create new variable at lat/lon grid by summing all d based on number of dlon, dlat within each of lat/lon grid.

For example – if we have 50 dlat/dlon in one latXlon grid, then  new variable in lat/lon grid = sum of d from all 50 dlat/dlon.

With regards
-Dave

Variable: dlat
Type: float
Total Size: 1392092 bytes
            348023 values
Number of Dimensions: 1
Dimensions and sizes:   [348023]
Coordinates:
Number Of Attributes: 1
  _FillValue :  9.96921e+36

Variable: dlon
Type: float
Total Size: 1392092 bytes
            348023 values
Number of Dimensions: 1
Dimensions and sizes:   [348023]
Coordinates:
Number Of Attributes: 1
  _FillValue :  9.96921e+36

Variable: d
Type: float
Total Size: 1392092 bytes
            348023 values
Number of Dimensions: 1
Dimensions and sizes:   [348023]
Coordinates:
Number Of Attributes: 1
  _FillValue :  9.96921e+36

Output grid –
Variable: lat
Type: float
Total Size: 744 bytes
            186 values
Number of Dimensions: 1
Dimensions and sizes:   [lat | 186]
Coordinates:
            lat: [-46.375..-0.125]
Number Of Attributes: 4
  units :       degree_north
  standard_name :       latitude
  long_name :   latitude
  bounds :      lat_bnds

Variable: lon
Type: float
Total Size: 964 bytes
            241 values
Number of Dimensions: 1
Dimensions and sizes:   [lon | 241]
Coordinates:
            lon: [100.125..160.125]
Number Of Attributes: 4
  units :       degree_east
  standard_name :       longitude
  long_name :   longitude
  bounds :      lon_bnds
From: Dennis Shea <shea at ucar.edu>
Sent: Sunday, October 18, 2020 2:25 PM
To: Paimazumder, Debasish <Debasish.Paimazumder at aig.com>
Cc: Barry Lynn <barry.h.lynn at gmail.com>; ncl-talk <ncl-talk at ucar.edu>
Subject: [EXTERNAL] Re: [ncl-talk] accumulate data on grid

This message is from an external sender; be cautious with links and attachments.
Maybe the "bin"  examples<https://urldefense.proofpoint.com/v2/url?u=https-3A__www.ncl.ucar.edu_Applications_binning.shtml&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=6F7M48QNHan0cjDH_KWLNBKvEM8Z4MLy0AVrfi5jQo8&s=esBoEZ_hYSHMOH9ETaF6M17fqzbclWD-fQGCOTkzhL0&e=> / functions:  bin_sum<https://urldefense.proofpoint.com/v2/url?u=https-3A__www.ncl.ucar.edu_Document_Functions_Built-2Din_bin-5Fsum.shtml&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=6F7M48QNHan0cjDH_KWLNBKvEM8Z4MLy0AVrfi5jQo8&s=xnFvaC2e9cElHG3_pafK084oquAu_2dJsejynvv5C-k&e=> , bin_avg<https://urldefense.proofpoint.com/v2/url?u=https-3A__www.ncl.ucar.edu_Document_Functions_Built-2Din_bin-5Favg.shtml&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=6F7M48QNHan0cjDH_KWLNBKvEM8Z4MLy0AVrfi5jQo8&s=9NeB2QchXaY0pnTSSuyn5Qmj-7oUsC6EfwD4EXGQNYA&e=>

Assuming the data are randomly located: d(npts), dlat(npts), dlon(npts)
**AND**
the target grid is RECTILINEAR with grid locations/sizes: glon[mlon], glat[nlat]


  gbin  = new<https://urldefense.proofpoint.com/v2/url?u=https-3A__www.ncl.ucar.edu_Document_Functions_Built-2Din_new.shtml&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=6F7M48QNHan0cjDH_KWLNBKvEM8Z4MLy0AVrfi5jQo8&s=R3wqMSXgnUywYdf9AP9u9NrETGphvJvVf7GItjprpxI&e=> ( (/nlat,mlon/), float )

  gknt  = new<https://urldefense.proofpoint.com/v2/url?u=https-3A__www.ncl.ucar.edu_Document_Functions_Built-2Din_new.shtml&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=6F7M48QNHan0cjDH_KWLNBKvEM8Z4MLy0AVrfi5jQo8&s=R3wqMSXgnUywYdf9AP9u9NrETGphvJvVf7GItjprpxI&e=> ( (/nlat,mlon/), integer)



  gbin  = 0.0                      ; initialization

  gknt  = 0

  bin_sum(gbin,gknt,glon,glat,dlon,dlat,d)

;*****************************************************************

; User must perform averaging

;*****************************************************************

                                    ; avoid division by 0

  gknt     = where<https://urldefense.proofpoint.com/v2/url?u=https-3A__www.ncl.ucar.edu_Document_Functions_Built-2Din_where.shtml&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=6F7M48QNHan0cjDH_KWLNBKvEM8Z4MLy0AVrfi5jQo8&s=4SbR5DjHbZc8obQVy_1-w-LH_brR9Bnv0Ixv8K46mA0&e=>(gknt.eq.0 , gknt at _FillValue, gknt)



  gbin     = gbin/gknt



  gbin!0   = "lat"

  gbin!1   = "lon"

  gbin&lat =  glat

  gbin&lon =  lon



  copy_VarCoords<https://urldefense.proofpoint.com/v2/url?u=https-3A__www.ncl.ucar.edu_Document_Functions_Contributed_copy-5FVarCoords.shtml&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=6F7M48QNHan0cjDH_KWLNBKvEM8Z4MLy0AVrfi5jQo8&s=H8H1S0QA3naQXQKhJSuJAT2QNQyKzwCTxbukEdlFtI8&e=>(gbin, gknt)        ; copy coords



  if (isfilevaratt<https://urldefense.proofpoint.com/v2/url?u=https-3A__www.ncl.ucar.edu_Document_Functions_Built-2Din_isfilevaratt.shtml&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=6F7M48QNHan0cjDH_KWLNBKvEM8Z4MLy0AVrfi5jQo8&s=pbnNxst9G_K0_R0bUV0jHQfBbWTAjBmkwShzIGuJjwE&e=>(f, vNam, "long_name")) then

      gbin at long_name = "BINNED: "+vNam

      gknt at long_name = "BINNED COUNT: "+vNam

  end if



  if (isfilevaratt<https://urldefense.proofpoint.com/v2/url?u=https-3A__www.ncl.ucar.edu_Document_Functions_Built-2Din_isfilevaratt.shtml&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=6F7M48QNHan0cjDH_KWLNBKvEM8Z4MLy0AVrfi5jQo8&s=pbnNxst9G_K0_R0bUV0jHQfBbWTAjBmkwShzIGuJjwE&e=>(f, vNam, "units")) then

      gbin at units     = f->$vNam$@units

  end if



  printVarSummary(gbin)
  printMinMax(gbin,1)
  print("=========")
  print("=========")
  printVarSummary(gknt)
  printMinMax(gbin,1)

====

Note: If the target grid is CURVILINEAR: [ glat(nlat,mlon), glon(nlat,mlon], there is no NCL function to accomplish the task.

On Sun, Oct 18, 2020 at 11:32 AM Paimazumder, Debasish via ncl-talk <ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>> wrote:
Dave- getind_latlon2d needs two-dimensional lat/lon while my output grid 1-d lat/lon.
Interpolation from location to 1-d grid could be an option but we won’t get the accumulation (sum) at the output grid.
Best regards,
Dave


On Oct 18, 2020, at 12:54 PM, Barry Lynn <barry.h.lynn at gmail.com<mailto:barry.h.lynn at gmail.com>> wrote:

This message is from an external sender; be cautious with links and attachments.
Right, that can be done.  Or, you can interpolate the data from the fine to coarse grid.

I am not sure if the latter will conserve the averages like doing the averaging in a loop.

On Sun, Oct 18, 2020 at 6:58 PM Dave Allured - NOAA Affiliate via ncl-talk <ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>> wrote:
Use the function getind_latlon2d to get the (i,j) grid point indices for the point data coordinates.  Then do a single loop over the point data to accumulate sums and counts on the output grid.


On Sun, Oct 18, 2020 at 9:09 AM Paimazumder, Debasish via ncl-talk <ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>> wrote:
Hi Barry,
Thanks for your response. Actually I don’t have time dimension. I have location level data (at high resolution).
For example, x(m) with lat(m) and lon (m) where m = 300k location

My output grid is 32x32 km and I would like to do following
1. Estimate the number of locations are in each 32x32 km grid
2. Accumulate (sum) the x at each output grid.
For example- if I have 100 locations at one of the 32x32km grid, I will sum all x from 100 locations and assign the sum to the output grid.
Best regards,
Dave


On Oct 18, 2020, at 3:50 AM, Barry Lynn <barry.h.lynn at gmail.com<mailto:barry.h.lynn at gmail.com>> wrote:
Hi:

If you have two grids of the same dimensions, but different times, you can simply add them together.

If you have grids of a different size, you can interpolate the data to this grid, one grid at a time.

See for example:

https://www.ncl.ucar.edu/Applications/regrid.shtml<https://urldefense.proofpoint.com/v2/url?u=https-3A__www.ncl.ucar.edu_Applications_regrid.shtml&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=IaFm8AuXStzIPZXMbIRmp6fjt5zy74eAUUQzoQb5pBc&s=tUIMDu-yehcnE2-mHTaX2NhZiAg5eBHJsqf3e1Bmbl8&e=>

This may also help.

https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_sum_n.shtml<https://urldefense.proofpoint.com/v2/url?u=https-3A__www.ncl.ucar.edu_Document_Functions_Built-2Din_dim-5Fsum-5Fn.shtml&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=IaFm8AuXStzIPZXMbIRmp6fjt5zy74eAUUQzoQb5pBc&s=4tdKFBxFBOUpMYFj95WyO8MUdUcYRniTWsJIvCCbhAE&e=>

On Sun, Oct 18, 2020 at 7:59 AM Paimazumder, Debasish via ncl-talk <ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>> wrote:
Hi NCL users
I have location level data and 2d lat, lon grid and I’m trying to accumulate the data on  2d lat, lon grid.

For example
Input - x (n) with lat(n), lon(n)
Output grid - lat(i)xlon(j)
I’m trying to estimate number of location within each grid and accumulate x at each grid.
Is there any function in NCL that will solve this problem?

With regards
-Debasish

Debasish PaiMazumder, PhD |Tel +1 215 255 6052<tel:%2B1%20215%20255%206371> | Cell +1 267 449 5226<tel:%2B1%20718%20913%206946> |Debasish.Paimazumder at aig.com<mailto:Debasish.Paimazumder at aig.com>
_______________________________________________
ncl-talk mailing list
ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>
List instructions, subscriber options, unsubscribe:
https://mailman.ucar.edu/mailman/listinfo/ncl-talk<https://urldefense.proofpoint.com/v2/url?u=https-3A__mailman.ucar.edu_mailman_listinfo_ncl-2Dtalk&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=MrHhJNEEUYaIu_m4tHYe3BagQB4y_F9zUKivzqyU6Qc&s=OAPVqMfiOsSTA-yHW1I4powc9uQpzwob8irpoxiBBy0&e=>


--
Barry H. Lynn, Ph.D
Senior Associate Scientist, Lecturer,
The Institute of the Earth Science,
The Hebrew University of Jerusalem,
Givat Ram, Jerusalem 91904, Israel
Tel: 972 547 231 170
Fax: (972)-25662581

C.E.O, Weather It Is, LTD
Weather and Climate Focus
http://weather-it-is.com<https://urldefense.proofpoint.com/v2/url?u=http-3A__weather-2Dit-2Dis.com&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=MrHhJNEEUYaIu_m4tHYe3BagQB4y_F9zUKivzqyU6Qc&s=wTDx59WcqkIpQWlxXtecOdqmP_2sM2GEo2mXT7ZAaPw&e=>
Jerusalem, Israel
Local: 02 930 9525
Cell: 054 7 231 170
Int-IS: x972 2 930 9525
_______________________________________________
ncl-talk mailing list
ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>
List instructions, subscriber options, unsubscribe:
https://mailman.ucar.edu/mailman/listinfo/ncl-talk<https://urldefense.proofpoint.com/v2/url?u=https-3A__mailman.ucar.edu_mailman_listinfo_ncl-2Dtalk&d=DwMFaQ&c=kn4_INW_mBCDHV_xJEVJkg&r=fpudUXThXLQwAKQPDCnmVaSzm2dwE9OxcWi7MuJ0jbo&m=6F7M48QNHan0cjDH_KWLNBKvEM8Z4MLy0AVrfi5jQo8&s=JHsKhKBBboyoxNbA9b8hgUBDyt3F_iBYSmaDbFnDfy0&e=>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20201019/54bee3b0/attachment.html>


More information about the ncl-talk mailing list