[ncl-talk] Sub: Region selection

Mary Haley haley at ucar.edu
Wed Nov 22 08:51:37 MST 2017


Please read your error messages carefully. It says:

fatal:Subscript out of range, error in subscript #1

This is telling you that there's something wrong with the way you are
trying to subscript the variable.

The issue is that you are subscripting the array using the index method,
but using lat/lon values instead. You can't do this.

To subscript using lat/lon values, you must use the curly braces as I
described in step 2:

   tmpp  = neb(:,{lat_min:lat_max},{lon_min:lon_max})






On Tue, Nov 21, 2017 at 9:07 AM, Mary Haley <haley at ucar.edu> wrote:

> There are two changes you need to make.
>
> [1] Your tmp1 longitude values go from -180 to 179.375, but you are trying
> to subscript it with 180 to 255.  To do this, you first need to "flip" your
> longitudes to go from 0 to 360:
>
> tmp1 = lonFlip(tmp1)
>
> [2] Your "tmp1" variable is on a rectilinear grid, which means you can use
> coordinate subscripting to subscript it. You need to use curly braces ({
> and }) to subscript based on lat/lon:
>
>    tmp1  = in1->SWNETTOA(:,{lat_min:lat_max},{lon_min:lon_max})
>    tmp  = in->TMP_P0_L103_GGA0(:,{lat_min:lat_max},{lon_min:lon_max})
>
> The way you can tell that tmp1 is on a rectilinear grid is from your
> printVarSummary output. Under the "Coordinates" section, it listed three
> arrays, and each one of these is a coordinate array.
>
> Variable: tmp1
> Type: float
> Total Size: 19961856 bytes
>             4990464 values
> Number of Dimensions: 3
> Dimensions and sizes:    [time | 24] x [lat | 361] x [lon | 576]
> Coordinates:
>             time: [0..1380]                <------ time is a coordinate
> array
>             lat: [ -90..  90]              <------ lat is a coordinate
> array
>             lon: [-180..179.375]           <------ lon is a coordinate
> array
>
> If you do not have any arrays listed under "Coordinates:", then you will
> not be able to use the {...} syntax.
>
> You didn't include the printVarSummary for your "tmp" variable.  If it is
> also rectilinear, then you can subscript it the same way.  If it is not,
> then there are other methods you can use.
>
> Please see this page which describes various methods for subsetting your
> data across lat/lon, given different kinds of grids:
>
> http://www.ncl.ucar.edu/Applications/latlon_subset.shtml
>
> --Mary
>
>
>
> On Tue, Nov 21, 2017 at 3:17 AM, dale zuri <dalezuri at gmail.com> wrote:
>
>> Hi,
>> Please help me to select the same region from the two different files.
>> I want to have the region1 selection for both the files. I am not able to
>> set the same region1 for Merra data.
>> Thanks
>>
>> begin
>> ;************************************************
>> ; create pointer to file and read in temperature
>> ;************************************************
>>    diri = "./"
>>    fili1 = "MERRA2_300.tavg1_2d_int_Nx.20040926.nc4"
>>    fili = "tmp2m.2012050218.time.nc"
>>    in  = addfile(diri+fili,"r")
>>    in1  = addfile(diri+fili1,"r")
>> print(in1)
>> lat_min =-180;;wrong region selection
>>   lat_max =180
>>   lon_min = 0
>>   lon_max = 138
>> ;;;;Region1;;;;;;;;;;;;
>> lat_min =15
>> lat_max =40
>>  lon_min = 180
>>  lon_max =  255
>>    tmp1  = in1->SWNETTOA(:,lat_min:lat_max,lon_min:lon_max)
>>    tmp  = in->TMP_P0_L103_GGA0(:,lat_min:lat_max,lon_min:lon_max)
>> printVarSummary(tmp1)
>> ;   ts   = tmp(time|0:0,lat|:,lon|:)               ; reorder variable
>> ;printVarSummary(ts)
>>  ts = dim_avg_n_Wrap(tmp, 0 )
>>  ts1 = dim_avg_n_Wrap(tmp1, 0 )
>>
>> Variable: tmp1
>> Type: float
>> Total Size: 19961856 bytes
>>             4990464 values
>> Number of Dimensions: 3
>> Dimensions and sizes:    [time | 24] x [lat | 361] x [lon | 576]
>> Coordinates:
>>             time: [0..1380]
>>             lat: [ -90..  90]
>>             lon: [-180..179.375]
>> Number Of Attributes: 11
>>   long_name :    toa_net_downward_shortwave_flux
>>   units :    W m-2
>>   _FillValue :    1e+15
>>   missing_value :    1e+15
>>   fmissing_value :    1e+15
>>   scale_factor :     1
>>   add_offset :     0
>>   standard_name :    toa_net_downward_shortwave_flux
>>   vmax :    1e+15
>>   vmin :    -1e+15
>>   valid_range :    ( -1e+15, 1e+15 )
>>
>> _______________________________________________
>> 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/20171122/7cf9c44e/attachment.html>


More information about the ncl-talk mailing list