[ncl-talk] grid_area_avg

Mary Haley haley at ucar.edu
Fri Oct 13 12:54:16 MDT 2017


Kunal,

Please include the code where you are actually taking the average of your
data using the information returned from getind_latlon2d.

It's important to note that getind_latlon2d simply returns the individual
index values that are closest to each of the lat/lon pairs that you gave
it. It doesn't work in such a way that you give it a lat/lon box and it
returns all the values in that box.

That's what I was trying to illustrate with the wrf_gsn_10.ncl I created.
I gave the function two corners of the box, and then using the two pairs of
index values I got back, I was able to get all the values inside the box
area of interest:

  lats = (/ min_lat, max_lat /)
  lons = (/ min_lon, max_lon /)
  nm   = getind_latlon2d (lat2d, lon2d, lats, lons)
  ilt1 = nm(0,0)  ; start lat index
  ilt2 = nm(1,0)  ; start lon index
  iln1 = nm(0,1)  ; end lat index
  iln2 = nm(1,1)  ; end lon index
  var_subset = var(ilt1:ilt2,iln1:iln2)
  var_subset_avg = avg(var_subset)

--Mary


On Thu, Oct 12, 2017 at 1:19 PM, Kunal Bali <kunal.bali9 at gmail.com> wrote:

> Dear Haley Ma'am,
>
> Thanks for providing the information and example.
> But if I follow the getind_latlon2d function as I did, then it seems like
> I followed the same procedure as given in the example
> http://www.ncl.ucar.edu/Document/Functions/Contributed/getind_latlon2d.
> shtml
>
> But still I am not getting the mean of the grid box on every time step or
> am I reading incorrectly the result ?
>
>
> regards
> Kunal Bali
>
>
>
>
>
>
> On Fri, Oct 13, 2017 at 12:11 AM, Mary Haley <haley at ucar.edu> wrote:
>
>> Kunal,
>>
>> I created an example for you, showing three ways you can subset a WRF
>> grid (since I already had a similar example).  It shows how to use the
>> getind_latlon2d function.
>>
>> You have to be careful with subsetting curvilinear data, because
>> specifying a lat/lon box to take an average over can mean two different
>> things. You will be able to see the difference when you look at the graphic.
>>
>> See example wrf_gsn_10.ncl at:
>>
>> http://www.ncl.ucar.edu/Applications/wrfgsn.shtml#ex10
>>
>> --Mary
>>
>>
>>
>> On Wed, Oct 11, 2017 at 12:03 PM, Kunal Bali <kunal.bali9 at gmail.com>
>> wrote:
>>
>>> Dear NCL users,
>>>
>>> Single point coordinates values of 23.0 N and 77.0 E is extracted or
>>> print by using the script below
>>>
>>> ----------------------------------------------------------------------
>>> ; Main code
>>> ;----------------------------------------------------------------------
>>>   dir    = "./"
>>>   fnames = systemfunc("ls " + dir + "maiactaot*.nc")
>>> print(fnames)
>>>   a      = addfile(fnames,"r")
>>>   data   = short2flt(a->Optical_Depth_055_grid1km)
>>>   nFill  = num(ismissing(data))
>>>   lat2d  = a->GridLat_grid1km
>>>   lon2d  = a->GridLon_grid1km
>>>
>>> ;---grid points of interest
>>>   latv = (/23.0/)
>>>   lonv = (/77.0 /)
>>>
>>>   nm = getind_latlon2d (lat2d,lon2d, latv, lonv)
>>>
>>>   do k=0,dimsizes(latv)-1
>>>      n = nm(k,0)
>>>      m = nm(k,1)
>>>      print(lat2d(n,m)+"   "+lon2d(n,m))   ; grid point location
>>>      print("     "+data(:,n,m))                   ; nearest grid point
>>> at all time steps
>>>      print("-----")
>>>   end do
>>>
>>>
>>> NOW, I want to extract the square grid box of 100 km around the
>>> coordinates (23N,77E) such as
>>>    latv = (/22, 24.0, 24.0, 22.0, 22.0/)
>>>    lonv = (/76, 76.0, 78.0, 78.0, 76.0 /)
>>>
>>>
>>> after that I want to do the area mean of the grid box. So that I can
>>> get one single point value of that grid box.
>>> So when I replacing
>>>   latv = (/23.0/)
>>>   lonv = (/77.0/)
>>>
>>> with
>>>
>>>    latv = (/22, 24.0, 24.0, 22.0, 22.0/)
>>>    lonv = (/76, 76.0, 78.0, 78.0, 76.0 /)
>>>
>>> then It's not giving mean of the square grid box.
>>>
>>> It shows the something like that (given below), which is incorrect. So
>>> please let me know how can I get the square grid box mean and then extract
>>> as asciiwrite or print?
>>>
>>> (0)    23.76603307545667   75.53995171540016
>>> (0)         0.179
>>> (1)         0.142
>>> (2)         -28672
>>> (3)         0.169
>>> (4)         -28672
>>> (5)         -28672
>>> (6)         -28672
>>> (0)    -----
>>> (0)    24.00322458681621   75.99551564353467
>>> (0)         0.171
>>> (1)         0.16
>>> (2)         -28672
>>> (3)         0.17
>>> (4)         -28672
>>> (5)         -28672
>>> (6)         -28672
>>>
>>> etc..etc..
>>>
>>>
>>>
>>> regards
>>> Kunal Bali
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> 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/20171013/b9e5ba3b/attachment.html>


More information about the ncl-talk mailing list