[ncl-talk] How to pick out the grids in a chosen area from a polar stereographic projection dataset?
Guido Cioni
guidocioni at gmail.com
Tue Aug 23 00:48:46 MDT 2016
You can use ind_resolve to reshape the indices of the box and then use them to subset. I guess something like this would work (untested)
dims_lat = dimsizes(latitude)
dims_lon = dimsizes(longitude)
lon1d = ndtooned(longitude)
lat1d = ndtooned(latitude)
box_lon = ind(lon1d.ge.min_lon .AND. lon1d.le.max_lon )
box_lat = ind(lat1d.ge.min_lat .AND. lat1d.le.max_lat)
inds_lon = ind_resolve(box_lon, dims_lon)
inds_lat = ind_resolve(box_lat, dims_lat)
xbox=x(:,inds_lat,inds_lon)
Guido Cioni
http://guidocioni.altervista.org <http://guidocioni.altervista.org/>
> Il giorno 23 ago 2016, alle ore 04:53, 林祥 <xianglin72 at icloud.com> ha scritto:
>
> Hey Cioni,
>
> Thanks for your reply. The longitude and latitude array is 2-dimensional, so I rewrite the following scripts
>
> lon1d = ndtooned(longitude)
> lat1d = ndtooned(latitude)
> x1d = ndtooned(x)
>
> box_id = ind(lon1d.ge.min_lon .AND. lon1d.le.max_lon .AND. lat1d.ge.min_lat .AND. lat1d.le.max_lat)
> ;box_id = ind(lat1d.ge.min_lat .AND. lat1d.le.max_lat) ; the result is same as the above line
>
> xlat = lat1d(box_id)
> xlon = lon1d(box_id)
> xbox = x1d(box_id)
>
> No I have picked out the data in the chosen area. But I am puzzled by plotting the contouring map for xbox.
> Should I have to deal with the array of xbox like the separated station datas?
>
> Thanks
>
>
> Lin
>
>
>
>
>> 在 2016年8月23日,00:12,Guido Cioni <guidocioni at gmail.com <mailto:guidocioni at gmail.com>> 写道:
>>
>> Hey Lin,
>> when dealing with non-monotonic arrays I usually employ the ind function, so I don’t understand why is not working for you…
>>
>> If you have, say, lon and lat arrays (this assume to have them 1-Dimensional, otherwise it gets fishy…).
>>
>> min_lon= -50.
>> max_lon= -70.
>> min_lat= -180.
>> max_lat= -180.
>> box_lon= ind(lon.ge.min_lon .AND. lon.le.max_lon)
>> box_lat= ind(lat.ge.min_lat .AND. lat.le.max_lat)
>>
>> should give you exactly all the indices inside the user-prescribed area. Then you can subset using
>>
>> var_box=var(:,box_lat,box_lon)
>>
>> Please be reminded that box_values will have different dimensions, since it is a subset of the original variable.
>> Cheers,
>>
>> Guido Cioni
>> http://guidocioni.altervista.org <http://guidocioni.altervista.org/>
>>
>>> On 22 Aug 2016, at 01:13, 林祥 <xianglin72 at icloud.com <mailto:xianglin72 at icloud.com>> wrote:
>>>
>>> <latitude.csv>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160823/2d00142a/attachment.html
More information about the ncl-talk
mailing list