[ncl-talk] grid_area_avg

Kunal Bali kunal.bali9 at gmail.com
Tue Oct 17 03:25:21 MDT 2017


I did the following changes but still getting an error of *aot_subset*
which is undefined.
please let me know that how to fix or defined the *aot_subset *this problem.



  latv = (/ 18, 24/)     ; for extracting grid box data
  lonv = (/ 74, 78 /)
  nm   = getind_latlon2d (lat2d, lon2d, latv, lonv)
  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
  lat_subset  := lat2d(ilt1:ilt2,iln1:iln2)
  lon_subset := lon2d(ilt1:ilt2,iln1:iln2)
  aot_subset := data
 * aot_subset(ilt1:ilt2,iln1:iln2) := data(ilt1:ilt2, iln1:iln2)*

  ;printVarSummary(aot_subset)
  aot_avg = avg(data)
  aot_subset_avg = avg(*aot_subset*)

  ;print(nm)
  print("-----")

  do k=0,dimsizes(latv)-1
     n = nm(k,0)
     m = nm(k,1)
     print(lat2d(n,m)+"   "+lon2d(n,m))
     print("     "+data(:,n,m))                   ; nearest grid point at
all time steps
     print("-----")
  end do




regards
Kunal Bali






On Tue, Oct 17, 2017 at 12:41 PM, Kunal Bali <kunal.bali9 at gmail.com> wrote:

> I have sent the ncl script and data to the incoming dir with the given
> names as
>
> data = maiactaotE.h00v03.20003660525-20003660700.nc.bz2
> ncl_script = extract_iiserb.ncl
>
> I am not able to define the var_subset in the given script.
> please let me know if you have received the data and script?
>
>
>
>
>
> Kunal Bali
>
>
>
>
>
>
> On Mon, Oct 16, 2017 at 11:07 PM, Mary Haley <haley at ucar.edu> wrote:
>
>> Kunal,
>>
>> You must make an effort to debug some of these problems on your own. The
>> error is telling you that something is wrong around line 34 and it is
>> telling you exactly what the problem is. Please try to fix this error.
>>
>> If you continue to have problems after fixing this error, then I need to
>> ask you to provide the full script and data via ftp:
>>
>> http://www.ncl.ucar.edu/ftp_files.shtml
>>
>> However, make sure you debug any other new problems that come up, instead
>> of just emailing them to ncl-talk.  We have a page to help you understand
>> some of NCL's errors, and what causes them:
>>
>> http://www.ncl.ucar.edu/Document/Language/error_messages.shtml
>>
>> The particular error you're seeing can be found here:
>>
>> http://www.ncl.ucar.edu/Document/Language/error_messages.shtml#NumSubRHS
>>
>> As a side note, you are running a 3-year old version of NCL. I suggest
>> that you upgrade to NCL V6.4.0.
>>
>> --Mary
>>
>>
>>
>> On Mon, Oct 16, 2017 at 12:52 AM, Kunal Bali <kunal.bali9 at gmail.com>
>> wrote:
>>
>>> I simply include the code (which you mentioned) were I was taking the
>>> avg of the data as given below (please correct me if I did wrong)
>>>
>>>
>>> ;----------------------------------------------------------------------
>>> ; Main code
>>> ;----------------------------------------------------------------------
>>>   dir    = "./"
>>>   fnames = systemfunc("ls " + dir + "maiactaot*.nc")
>>> print(fnames)
>>>   a      = addfile(fnames,"r")
>>>   data   = short2flt(a->Optical_Depth_055_grid1km)
>>> printVarSummary (data)
>>> printMinMax (data, 0)
>>> print("-----")
>>>   nFill  = num(ismissing(data))
>>> print("nFill="+nFill)
>>> print("-----")
>>>
>>>   lat2d  = a->GridLat_grid1km
>>>   lon2d  = a->GridLon_grid1km
>>> printMinMax (lat2d, 0)
>>> printMinMax (lon2d, 0)
>>> print("-----")
>>>
>>> ;---grid points of interest
>>> ;---http://www.ncl.ucar.edu/Document/Functions/Contributed/g
>>> etind_latlon2d.shtml
>>>  ; latv = (/22, 24.0, 24.0, 22.0, 22.0/)
>>>  ; lonv = (/76, 76.0, 78.0, 78.0, 76.0/)
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *latv = (/ 22, 24/)  lonv = (/ 76, 78 /)  nm   = getind_latlon2d (lat2d,
>>> lon2d, latv, lonv)  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)*
>>>
>>>   print(nm)
>>>   print("-----")
>>>
>>>   do k=0,dimsizes(latv)-1
>>>      n = nm(k,0)
>>>      m = nm(k,1)
>>>      print(lat2d(n,m)+"   "+lon2d(n,m))
>>>      print("     "+data(:,n,m))                   ; nearest grid point
>>> at all time steps
>>>      print("-----")
>>>   end do
>>>
>>>
>>>
>>>
>>>
>>> *But still not getting the desired output as a single square box mean
>>> value . It is showing the errors as*
>>>
>>> kunal at kunal-Vostro-1015:/media/Local Disk_/IIT_DELHI/2001/MAIACTAOT_TIME$
>>> ncl extract1.ncl
>>>  Copyright (C) 1995-2014 - All Rights Reserved
>>>  University Corporation for Atmospheric Research
>>>  NCAR Command Language Version 6.2.1
>>>  The use of this software is governed by a License Agreement.
>>>  See http://www.ncl.ucar.edu/ for more details.
>>>
>>>
>>> Variable: fnames
>>> Type: string
>>> Total Size: 4 bytes
>>>             1 values
>>> Number of Dimensions: 1
>>> Dimensions and sizes:    [1]
>>> Coordinates:
>>> (0)    ./maiactaot.h00v02.20010040635-20011550640.nc
>>>
>>> Variable: data
>>> Type: float
>>> Total Size: 40320000 bytes
>>>             10080000 values
>>> Number of Dimensions: 3
>>> Dimensions and sizes:    [time | 7] x [YDim_grid1km | 1200] x
>>> [XDim_grid1km | 1200]
>>> Coordinates:
>>>             time: [8862.583333333314..12486.66666666669]
>>> Number Of Attributes: 8
>>>   coordinates :    GridLat_grid1km, GridLon_grid1km
>>>   hdfeos_name :    Optical_Depth_055
>>>   projection :    Albers Conical Equal_Area
>>>   unit :    None
>>>   long_name :    AOT at 0.55 micron
>>>   _FillValue_original :    -28672
>>>   _FillValue :    -28672
>>>   valid_range :    ( -0.1,  5 )
>>> (0)    AOT at 0.55 micron: min=0   max=3.924
>>> (0)    -----
>>> (0)    nFill=6285271
>>> (0)    -----
>>> (0)    latitude: min=21.86737357453027   max=34.99855492029426
>>> (0)    longitude: min=64.23634233372005   max=79.4747290253718
>>> (0)    -----
>>> fatal:["Execute.c":7863]:Number of subscripts on right-hand-side do not
>>> match
>>>             number of dimensions of variable: (2), Subscripts used: (3)
>>>
>>> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 34 in
>>> file extract1.ncl
>>>
>>> fatal:Variable (var_subset) is undefined
>>> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 35 in
>>> file extract1.ncl
>>>
>>>
>>>
>>>
>>> Variable: nm
>>> Type: integer
>>> Total Size: 16 bytes
>>>             4 values
>>> Number of Dimensions: 2
>>> Dimensions and sizes:    [2] x [2]
>>> Coordinates:
>>> Number Of Attributes: 1
>>>   long_name :    indices closest to specified LAT/LON coordinate pairs
>>> (0,0)    1199
>>> (0,1)    792
>>> (1,0)    1199
>>> (1,1)    1041
>>> (0)    -----
>>> (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.26559325846936   77.93996773594735
>>> (0)         -28672
>>> (1)         0.393
>>> (2)         -28672
>>> (3)         0.156
>>> (4)         0.313
>>> (5)         -28672
>>> (6)         -28672
>>> (0)    -----
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Kunal Bali
>>>
>>>
>>>
>>>
>>>
>>> On Sat, Oct 14, 2017 at 12:24 AM, Mary Haley <haley at ucar.edu> wrote:
>>>
>>>> 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/getin
>>>>> d_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
>>>>>
>>>>>
>>>>
>>>
>>> _______________________________________________
>>> 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/20171017/939893ff/attachment.html>


More information about the ncl-talk mailing list