[ncl-talk] Fwd: Regridding from fine to coarse resolution by aggregating not interpolating

Dennis Shea shea at ucar.edu
Mon Sep 29 22:25:19 MDT 2014


I see the issue (I think). There must a latitude value and a longitude
value for each input 'z' value. I speculate that zlat and zlon are
one-dimensional while z is two-dimensional. Thus the zlat/zlon must be
replicated (broadcast) to the same dimensionality as z.  Try


; Get data
     z_in = addfile(infile,"r")
     zlat  = z_in->lat
     zlon = z_in->lon
     z      = z_in->pop

     nzlat= dimsizes(zlat)
     nzlon= dimsizes(zlon)

     zlat2d = conform_dims( (/nzlat,nzlon/), zlat, 0)
     zlon2d = conform_dims( (/nzlat,nzlon/), zlon, 1)

[snip]

     bin_sum(gbin,gknt,glon,glat,ndtooned(zlon2d),
ndtooned(zlat2d),ndtooned(z) )


On Mon, Sep 29, 2014 at 9:31 PM, Silva, Raquel <rasilva at live.unc.edu> wrote:

>  Dennis,
>
>
>  Thanks for the references. I was able to run Example 2 and I also looked
> at Example 1 and compared it to my script.
>
>
>  If I understand it correctly, the error I get ('bin_sum: zlat must be
> the same size as zlon') is related with the dimensions of lon and lat in
> the original data not nlat and mlon:
>
>
>  *(...)*
>
>
>  *;******************************************************************
> *; Get new grid and data to regrid*
> *;******************************************************************
>
> *; Get new grid*
> *  g_in = addfile(gfile,"r")*
> *  glat = g_in->lat*
> *  glon = g_in->lon*
>
> *  nlat = dimsizes(glat)*
> *  mlon = dimsizes(glon)*
>
> *  print("New grid = "+mlon+"x"+nlat)*
>
> *; Get data*
> *  z_in = addfile(infile,"r")*
> *  zlat = z_in->lat*
> *  zlon = z_in->lon*
> *  z = z_in->pop*
>
> *  nlat_in = dimsizes(zlat)*
> *  nlon_in = dimsizes(zlon)*
>
> *  print("Original grid = "+nlon_in+"x"+nlat_in)*
> *  print(" ")*
>
> *  z_sum = sum(z)*
>
> *  print("Sum z:")*
> *  print(z_sum)*
> *  print(" ")*
>
>
>  *;******************************************************************
> *; Variables to hold binned quantities*
> *;******************************************************************
> *  gbin  = new ( (/nlat,mlon/), float )*
> *  gknt  = new ( (/nlat,mlon/), integer)*
>
> *  gbin  = 0.0                      ; initialization*
> *  gknt  = 0*
>
> *;******************************************************************
>
>
> *; Regrid data *
>
> *;******************************************************************
> *  bin_sum(gbin,gknt,glon,glat,ndtooned(zlon), ndtooned(zlat),ndtooned(z)
> )*
>
> *  z_out_sum = sum(gbin)*
>
>   *print("Sum z_out:")*
> *  print(z_out_sum)*
>
>
>  *(...)*
>
>
>  Is there anything else I should check/change?
>
>
>  Thanks,
> Raquel
>  ------------------------------
> *From:* ncl-talk-bounces at ucar.edu <ncl-talk-bounces at ucar.edu> on behalf
> of Dennis Shea <shea at ucar.edu>
> *Sent:* Monday, September 29, 2014 7:30 PM
> *To:* ncl-talk at ucar.edu
> *Subject:* [ncl-talk] Fwd: Regridding from fine to coarse resolution by
> aggregating not interpolating
>
>  This response was inadvertently not sent to ncl-talk at ucar.edu
>
>  ---------- Forwarded message ----------
> From: Dennis Shea <shea at ucar.edu>
> Date: Mon, Sep 29, 2014 at 2:40 PM
> Subject: Re: [ncl-talk] Regridding from fine to coarse resolution by
> aggregating not interpolating
> To: "Silva, Raquel" <rasilva at live.unc.edu>
> Cc: Carl Schreck <cjschrec at ncsu.edu>
>
>
>   You should be able to bin.  nlat and mlon *can* be different sizes.
>
>  I just ran: Example 2  (random data):
>
> *http://www.ncl.ucar.edu/Applications/binning.shtml
> <http://www.ncl.ucar.edu/Applications/binning.shtml>*
>
>  You can download the script and run it. Here nlat=36 and mlon=61
>
> ===
>
>
>
>
> On Mon, Sep 29, 2014 at 2:11 PM, Silva, Raquel <rasilva at live.unc.edu>
> wrote:
>
>>  Hi Carl and Dennis,
>>
>>
>>  Thanks for your quick responses.
>>
>>
>>  I'm getting the following error:
>>
>> fatal:bin_sum: zlat must be the same size as zlon
>>
>>
>>  where
>>
>>   zlat = z_in->lat
>>   zlon = z_in->lon
>>
>>  I thought that I could have different sizes for longitude and latitude.
>>
>>
>>  Thanks,
>>
>> Raquel
>>  ------------------------------
>> *From:* Dennis Shea <shea at ucar.edu>
>> *Sent:* Monday, September 29, 2014 4:05 PM
>> *To:* Carl Schreck
>> *Cc:* Silva, Raquel; ncl-talk at ucar.edu
>> *Subject:* Re: [ncl-talk] Regridding from fine to coarse resolution by
>> aggregating not interpolating
>>
>>       Also, see:
>>
>> http://www.ncl.ucar.edu/Applications/
>>
>>  on the right under "Data Analysis", Click "Binning"
>>
>>  There are a few examples.
>>
>> ===
>>  If you are new to NCL, pleasesee
>>
>> http://www.ncl.ucar.edu/Document/Manuals/
>>
>>  [1] Mini-Language Manual    (concise but detailed language overview)
>>
>>  [2] the DKRZ tutorials. This is a rather large pdf.
>>      The 1st contains a subset of the Mini-Language Manual plu many
>> examples.
>>       The 2nd has a lot of exercises. Unfortunately, not all the data
>> sets are available
>>       for general use.
>>
>>  Cheers
>>
>>
>> On Mon, Sep 29, 2014 at 1:00 PM, Carl Schreck <cjschrec at ncsu.edu> wrote:
>>
>>> Hi Raquel,
>>>
>>>  I believe bin_sum will do what you're looking for:
>>> http://www.ncl.ucar.edu/Document/Functions/Built-in/bin_sum.shtml
>>>
>>>      Carl
>>>
>>>  On Mon, Sep 29, 2014 at 2:25 PM, Silva, Raquel <rasilva at live.unc.edu>
>>> wrote:
>>>
>>>>   Hi all,
>>>>
>>>>
>>>>  I need to regrid global data from a fine (30"x30") to a
>>>> coarser (0.7x0.5 deg) resolution so that each output cell contains the sum
>>>> of the input cells that are encompassed by the extent of that cell. Could
>>>> you please let me know if there is an ncl function I could use?
>>>>
>>>>
>>>>  Thanks,
>>>> Raquel
>>>>
>>>>  _______________________________________________
>>>> ncl-talk mailing list
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>>
>>>
>>>
>>>  --
>>>
>>>   <http://www.cicsnc.org/>
>>>  <http://www.researcherid.com/rid/B-8711-2011>
>>> * Cyclone <http://www.cyclonecenter.org/>*Center.org
>>> <http://www.cyclonecenter.org/>   *Carl J. Schreck III, PhD*
>>> *Research Associate*
>>> Cooperative Institute for Climate and Satellites NC
>>> <http://www.cicsnc.org/>
>>> North Carolina State University <http://ncsu.edu/>
>>> NOAA's National Climatic Data Center <http://ncdc.noaa.gov/>
>>> 151 Patton Ave, Asheville, NC 28801
>>> e: cjschrec at ncsu.edu
>>> o: +1 828 257 3140
>>> Publications
>>> <http://scholar.google.com/citations?hl=en&user=th8ONEcAAAAJ&view_op=list_works&sortby=pubdate>
>>> monitor.cicsnc.org/mjo
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140929/3237e685/attachment.html 


More information about the ncl-talk mailing list