[ncl-talk] grid_area_avg

Kunal Bali kunal.bali9 at gmail.com
Wed Oct 25 01:51:51 MDT 2017


Dear NCL users,

I am able to get the avg value of the grid box now.
by changing some code as

aot_subset(ilt1:ilt2,iln1:iln2) = data(ilt1:ilt2,iln1:iln2) *TO* aot_subset(
:,ilt1:ilt2,iln1:iln2) = data(:,ilt1:ilt2,iln1:iln2)
and
aot_subset_avg = avg(*data*) *TO* aot_subset_avg = avg(*aot_subset)*
print(*aot_subset_avg*)

But Now I am not able to print data with time.
I am trying

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


So could anyone please let me know how to get the avg value with each time
steps.

thank you

regards
Kunal Bali






On Wed, Oct 25, 2017 at 12:37 PM, Kunal Bali <kunal.bali9 at gmail.com> wrote:

> Thanks for the information. I did not include the time variable. So
>
> I changed aot_subset(ilt1:ilt2,iln1:iln2) = data(ilt1:ilt2,iln1:iln2) to
> aot_subset(*:,*ilt1:ilt2,iln1:iln2) = data(*:,*ilt1:ilt2,iln1:iln2)
>
> AND it worked.
>
>
> But from the given script, I am not getting the mean value of the grid
> box. It producing the values of every grid separately. As given below
>
> (0)    22.17971308103524   69.17124237598317
> (0)         -28672
> (1)         0.208
> (0)    -----
> (0)    24.55800304046942   79.47472902537179
> (0)         -28672
> (1)         -28672
> (0)    -----
>
>
> I need to extract the data of square box and mean it. so that I can get
> the values with every time steps.
>
>   latv = (/ 13, 25/)     ; for extracting grid box data
>   lonv = (/ 72, 85 /)
>
> The script is
>
>
> ;----------------------------------------------------------------------
> ; 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/getind_latlon2d.shtml
>  ; latv = (/22, 24.0, 24.0, 22.0, 22.0/)
>  ; lonv = (/76, 76.0, 78.0, 78.0, 76.0/)
>
>   latv = (/ 13, 25/)     ; for extracting grid box data
>   lonv = (/ 72, 85 /)
>   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 = aot_subset at _FillValue
>   aot_subset(:,ilt1:ilt2,iln1:iln2) = data(:,ilt1:ilt2,iln1:iln2)
>
>
>
>   printVarSummary(aot_subset)
>   print("ilt1 = " + ilt1)
>   print("ilt2 = " + ilt2)
>   print("iln1 = " + iln1)
>   print("iln2 = " + iln2)
>
>  ; aot_avg = avg(data)
>   aot_subset_avg = avg(data)
>
>   ;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
>
>
>
>
>
>
> Kunal Bali
>
>
>
>
>
> On Wed, Oct 25, 2017 at 12:25 PM, Barry Lynn <barry.h.lynn at gmail.com>
> wrote:
>
>> Kunal:
>>
>> The error message says that you have used three subscripts on a variables
>> with only two dimensions.
>>
>> You need to fix this error for your script to proceed to the next step.
>>
>> Barry
>>
>> On Wed, Oct 25, 2017 at 8:59 AM, Kunal Bali <kunal.bali9 at gmail.com>
>> wrote:
>>
>>> It also shows an error if I replaced := with = in 38 line of the given
>>> script (attached earlier), even though variable is in 2D array.
>>>
>>> fatal:["Execute.c":7950]:Number of subscripts on right-hand-side do not
>>> match
>>>             number of dimensions of variable: (2), Subscripts used: (3)
>>>
>>> fatal:["Execute.c":8640]:Execute: Error occurred at or near line 38 in
>>> file extract1.ncl
>>>
>>>
>>>
>>> Kunal Bali
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Tue, Oct 24, 2017 at 4:46 PM, Helen Macintyre <
>>> Helen.Macintyre at phe.gov.uk> wrote:
>>>
>>>> You are trying to delete a variable that has not been assigned.
>>>>
>>>>
>>>>
>>>> Using “:=” tries to delete aot_subset when it doesn’t exist yet.
>>>>
>>>>
>>>>
>>>> More info here:
>>>>
>>>> http://www.ncl.ucar.edu/Document/Language/varb_assign.shtml
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> *From:* ncl-talk [mailto:ncl-talk-bounces at ucar.edu] *On Behalf Of *Kunal
>>>> Bali
>>>> *Sent:* 24 October 2017 06:28
>>>> *To:* ncl-talk at ucar.edu
>>>> *Subject:* Re: [ncl-talk] grid_area_avg
>>>>
>>>>
>>>>
>>>> I am not able to sort out the query regarding
>>>>
>>>> fatal:Variable (aot_subset) is undefined
>>>> fatal:["Execute.c":8640]:Execute: Error occurred at or near line 38 in
>>>> file extract1.ncl
>>>>
>>>> I have attached my script. please let me know how to solve it (the file
>>>> regarding this script is attached in the previous mail).
>>>>
>>>>
>>>>
>>>> sorry for the inconvenience*. *
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> regards
>>>>
>>>> Kunal Bali
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Sat, Oct 21, 2017 at 1:53 PM, Kunal Bali <kunal.bali9 at gmail.com>
>>>> wrote:
>>>>
>>>> thanks for providing this information. I am positive that the given
>>>> variable in the data is a 2D array and the error is coming on 38 line as I
>>>> mentioned earlier.
>>>>
>>>> I am trying to debug this problem accordingly as you mentioned.
>>>>
>>>> However, I have attached the data (size =30mb, tried via ftp but facing
>>>> some error while uploading) and the full script for extracting the grid box
>>>> mean value.
>>>>
>>>>
>>>>
>>>> Thank You for all the support.
>>>>
>>>>>>>>
>>>> * maiactaot.h00v02.20010040635-20011550640.nc.bz2
>>>> <https://drive.google.com/file/d/0B6MS-JLMHECwaVh3QVVHUU1Wazg/view?usp=drive_web>*
>>>>
>>>>>>>>
>>>>
>>>> Kunal Bali
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Fri, Oct 20, 2017 at 9:14 PM, Mary Haley <haley at ucar.edu> wrote:
>>>>
>>>> Kunal,
>>>>
>>>>
>>>>
>>>> Multiple people have tried to help you, but you continue to post error
>>>> messages without trying to debug them yourself. If you don't make an
>>>> effort, people are likely to stop trying to help. You are including code
>>>> snippets, but this is not always enough for us to help you debug the
>>>> problem. You need to include full scripts, output from
>>>> print/printVarSummary commands, AND all error messages.
>>>>
>>>>
>>>>
>>>> For example, you originally included this code:
>>>>
>>>>
>>>>
>>>>   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)
>>>>
>>>>
>>>>
>>>> and then said that you were getting an error about aot_subset being
>>>> undefined. From the perspective of somebody who is just looking at the code
>>>> snippet above and doesn't have access to your full script, we are going to
>>>> wonder about this line:
>>>>
>>>>
>>>>
>>>>   aot_subset := data
>>>>
>>>>
>>>>
>>>> Since this appears to be the first time aot_subset is set, our next
>>>> question is going to be "is data defined"? In the code snippet you
>>>> included, we don't see where "data" is defined, so we have no way to help.
>>>> This is where a "printVarSummary(data)" line would have helped.
>>>>
>>>>
>>>>
>>>> In your last email, in which you did include some information about
>>>> "data", things are still not making any sense. You said you were subsetting
>>>> data as a 2D array with:
>>>>
>>>>
>>>>
>>>> aot_subset(ilt1:ilt2,iln1:iln2) = data(ilt1:ilt2,iln1:iln2)
>>>>
>>>>
>>>>
>>>> which you said was causing this error:
>>>>
>>>>
>>>>
>>>> fatal:["Execute.c":7950]:Number of subscripts on right-hand-side do
>>>> not match
>>>>
>>>>             number of dimensions of variable: (2), Subscripts used: (3)
>>>>
>>>>
>>>>
>>>> This error doesn't seem possible, because it's saying that you are
>>>> using 3 subscripts, but the line only has 2 subscripts being used in both
>>>> arrays. Are you positive that this error is coming from this line?
>>>>
>>>>
>>>>
>>>> I have to ask you again to please include your *full script* next time
>>>> and *all error messages* and *all printed output*, so people can see
>>>> exactly what line numbers in your script the errors correspond with and
>>>> what your data looks like. But don't do this until you have shown that you
>>>> tried to debug the problem yourself. Use "print" and "printVarSummary"
>>>> *before* the locations where the error messages are occurring, so you can
>>>> see what might be causing the error.
>>>>
>>>>
>>>>
>>>> For example, if the error says
>>>>
>>>>
>>>>
>>>>  number of dimensions of variable: (2), Subscripts used: (3)
>>>>
>>>>
>>>>
>>>> then this means you are subscripting a variable as if it were a 2D
>>>> array, when it is actually a 3D array. Add *printVarSummary*
>>>> statements on ALL subscripted variables that occur in that line, so you can
>>>> be sure you are doing things correctly.  For example, if the error occurs
>>>> on this line:
>>>>
>>>>
>>>>
>>>>   aot_subset(ilt1:ilt2,iln1:iln2) := data(ilt1:ilt2, iln1:iln2)
>>>>
>>>>
>>>>
>>>> then do this:
>>>>
>>>>
>>>>   printVarSummary(data)
>>>>
>>>>   printVarSummary(aot_subset)
>>>>
>>>>   aot_subset(ilt1:ilt2,iln1:iln2) := data(ilt1:ilt2, iln1:iln2)
>>>>
>>>>
>>>>
>>>> It may also help to print the il* variables:
>>>>
>>>>
>>>>
>>>>   printVarSummary(data)
>>>>
>>>>   printVarSummary(aot_subset)
>>>>
>>>>   print("ilt1 = " + ilt1)
>>>>
>>>>   print("ilt2 = " + ilt2)
>>>>
>>>>   print("iln1 = " + iln1)
>>>>
>>>>   print("iln2 = " + iln2)
>>>>
>>>>   aot_subset(ilt1:ilt2,iln1:iln2) := data(ilt1:ilt2, iln1:iln2)
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Moving forward, you *must* show that you are making some effort to
>>>> debug your problem.
>>>>
>>>>
>>>>
>>>> Thank you for your consideration.
>>>>
>>>>
>>>>
>>>> --Mary
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Wed, Oct 18, 2017 at 12:23 AM, Kunal Bali <kunal.bali9 at gmail.com>
>>>> wrote:
>>>>
>>>> printVarSummary(aot_subset), shows that aot_subset is undefined, which
>>>> I am unable to fix this problem yet.
>>>>
>>>> If I used aot_subset(ilt1:ilt2,iln1:iln2) *=*
>>>> data(ilt1:ilt2,iln1:iln2) *instead of *aot_subset(ilt1:ilt2,iln1:iln2)
>>>> *:=* data(ilt1:ilt2,iln1:iln2)
>>>>
>>>>
>>>> then the error appeared as
>>>>
>>>>
>>>> *fatal:["Execute.c":7950]:Number of subscripts on right-hand-side do
>>>> not match             number of dimensions of variable: (2), Subscripts
>>>> used: (3)*
>>>>
>>>> basically, the data summary is
>>>>
>>>> Variable: fnames
>>>> Type: string
>>>> Total Size: 8 bytes
>>>>             1 values
>>>> Number of Dimensions: 1
>>>> Dimensions and sizes:    [1]
>>>> Coordinates:
>>>> (0)    ./maiactaotE.h00v03.20000550525-20003660700.nc
>>>>
>>>> Variable: data
>>>> Type: float
>>>> Total Size: 2545920000 <(254)%20592-0000> bytes
>>>>             636480000 values
>>>> Number of Dimensions: 3
>>>> Dimensions and sizes:    *[time | 442] x [YDim_grid1km | 1200] x
>>>> [XDim_grid1km | 1200]*
>>>> Coordinates:
>>>>             time: [1301.416666666686..8767]
>>>> 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)    latitude (degrees_north) : min=11.2940312768897
>>>> max=24.54921980985786
>>>> (0)    longitude (degrees_east) : min=68.08003670367275
>>>> max=81.63171349927691
>>>>
>>>> *fatal:["Execute.c":7776]:aot_subset is undefined, can not subscript an
>>>> undefined variable fatal:["Execute.c":8640]:Execute: Error occurred at or
>>>> near line 38 in file test_extract.ncl*
>>>>
>>>> *38 line is *
>>>> *aot_subset(ilt1:ilt2,iln1:iln2) = data(ilt1:ilt2,iln1:iln2)*
>>>>
>>>> *fatal:Variable (aot_subset) is undefined*
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> regards
>>>>
>>>> Kunal Bali
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Tue, Oct 17, 2017 at 3:05 PM, Guido Cioni <guidocioni at gmail.com>
>>>> wrote:
>>>>
>>>> Why did you comment this line ?
>>>>
>>>>
>>>>
>>>>   ;printVarSummary(aot_subset)
>>>>
>>>>
>>>>
>>>> That would have helped you in debugging the error on your own.
>>>>
>>>>
>>>>
>>>> You are using the re-assignment operator ":=". This means that every
>>>> time you make an assignment the variable is created again. Thus, you cannot
>>>> make this assignment
>>>>
>>>>
>>>>
>>>>  * aot_subset(ilt1:ilt2,iln1:iln2) := data(ilt1:ilt2, iln1:iln2)*
>>>>
>>>>
>>>>
>>>> as NCL has no way to know the shape of aot_subset beforehand.
>>>>
>>>>
>>>>
>>>> The following should be used instead (notice the assignment with "=" in
>>>> the second line).
>>>>
>>>>
>>>>
>>>>   aot_subset := data
>>>>
>>>>   aot_subset = aot_subset at _FillValue
>>>>   aot_subset(ilt1:ilt2,iln1:iln2) *=* data(ilt1:ilt2, iln1:iln2)
>>>>
>>>>
>>>>
>>>> Notice that this will (1) create an array which is shaped like data (2)
>>>> fill it with fill values as you only want to compute the average over the
>>>> subset (3) populate the array only in the lat-lon box provided. However I
>>>> don't see why you would want to use such a complicated syntax when the
>>>> following code would produce the same result
>>>>
>>>>
>>>>
>>>> aot_subset_avg=avg(data(ilt1:ilt2, iln1:iln2))
>>>>
>>>>
>>>>
>>>> If you have the right coordinate attributes you can even jump the first
>>>> 7 lines and do
>>>>
>>>>
>>>>
>>>> aot_subset_avg=avg(data({18:24},{74:78})
>>>>
>>>>
>>>>
>>>> but I don't know your data.
>>>>
>>>>
>>>>
>>>> As it was already suggested by Mary and others, PLEASE take time to
>>>> debug the errors on your own.
>>>>
>>>>
>>>>
>>>> Regards,
>>>>
>>>>
>>>>
>>>> On 17. Oct 2017, at 11:25, Kunal Bali <kunal.bali9 at gmail.com> wrote:
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> 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.sht
>>>> ml#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
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> ncl-talk at ucar.edu
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>>
>>>>
>>>>
>>>> Guido Cioni
>>>>
>>>> http://guidocioni.altervista.org
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> ncl-talk at ucar.edu
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> ************************************************************
>>>> **************
>>>> The information contained in the EMail and any attachments is
>>>> confidential and intended solely and for the attention and use of the named
>>>> addressee(s). It may not be disclosed to any other person without the
>>>> express authority of Public Health England, or the intended recipient, or
>>>> both. If you are not the intended recipient, you must not disclose, copy,
>>>> distribute or retain this message or any part of it. This footnote also
>>>> confirms that this EMail has been swept for computer viruses by
>>>> Symantec.Cloud, but please re-sweep any attachments before opening or
>>>> saving. http://www.gov.uk/PHE
>>>> ************************************************************
>>>> **************
>>>>
>>>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>>
>> --
>> Barry H. Lynn, Ph.D
>> Senior 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
>> Jerusalem, Israel
>> Local: 02 930 9525
>> Cell: 054 7 231 170
>> Int-IS: x972 2 930 9525
>> US 914 432 3108 <091443%2023108>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171025/e87e93ad/attachment.html>


More information about the ncl-talk mailing list