Re: Unusual ind()/ind_resolve() behaviour

From: Will Hobbs <Will.Hobbs_at_nyahnyahspammersnyahnyah>
Date: Thu Feb 27 2014 - 22:15:59 MST

I think can see where the problem is; as usual it's with me!

If I make a 1-d array of the transect coords from the resolved indices,
from the example we've used:

>npts = dimsizes(jj(:,0))
>transx = new(npts,typeof(lat))
>transy = transx

>do i = 0, npts-1
> transx(i) = lon(jj(i,0),jj(i,1))
> transy(i) = lat(jj(i,0),jj(i,1))
end do

>printMinMax(transy, True) ;min=39.5062 max=40.4737, success!

As you said, the POP grid 'curves' and because the index
lat(jj(:,0),(:,1))) is a rectangular array of indices rather than an
approximately west-east line of coords, it's picking up grid points
outside my original spec.

Sorry to have wasted your time.

Will

On 28/02/14 4:05 PM, "Dennis Shea" <shea@ucar.edu> wrote:

>Hi Will
>
>Yes. It looks like a bug with ind_resolve.
>The 'TEMP.nc' file is a POP grid
>
>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> f = addfile("TEMP.nc", "r")
> x = f->TEMP
>
> lat = f->TLAT
> lon = f->TLONG
>
> print("lat: min="+min(lat)+" max="+max(lat))
> print("lon: min="+min(lon)+" max="+max(lon))
>
> lat1d = ndtooned(lat)
> lon1d = ndtooned(lon)
>
>;find all coords in a band across the mid-lat N. Atlantic
>
> ii = ind(lon1d.ge.270..and.lon1d.le.360. .and. \
> lat1d.gt.39.5.and.lat1d.lt.40.5)
> jj = ind_resolve(ii, dimsizes(lat))
>
> print(ii+" "+lat1d(ii)+" "+lon1d(ii)) ; the ii are 'good'
>
> printMinMax(lon(jj(:,0),jj(:,1)), True) ;returns range of 270.296
>to 359.746 ; so far so good
> printMinMax(lat(jj(:,0),jj(:,1)), True) ; not so good
>
>=======================
>I'm not sure of the workings of ind_resolve.
>
>I wonder if the fact that the POP grid 'curves back on itself'
>is an issue?
>
> https://www.ncl.ucar.edu/Applications/Images/popgrid_1_lg.png
>
>
>
>
>On 2/27/14, 8:34 PM, Will Hobbs wrote:
>> I've noticed some strange results using the ind() and ind_resolve()
>>functions, that I can't explain. I'm using the functions to find all
>>indices on the POP ocean grid within a certain domain, viz:
>>
>>> f = addfile(filename,"r") ;file could be any CCSM4 or CESM ocean data
>>
>> ;read lat/lon coords
>>> lat = f->lat
>>> lon = f->lon
>>
>> ;convert to 1d arrays
>>> lat1d = ndtooned(lat)
>>> lon1d = ndtooned(lon)
>>
>> ;find all coords in a band across the mid-lat N. Atlantic
>>> ii =
>>>ind(lon1d.ge.270..and.lon1d.le.360..and.lat1d.gt.39.5.and.lat1d.lt.40.5)
>>
>>> jj = ind_resolve(ii, dimsizes(lat)) ; find array elements on the 2-d
>>>grid
>>
>>> printMinMax(lon(jj(:,0),jj(:,1)), True) ;returns range of 270.296 to
>>>359.746 ; so far so good
>>
>>> printMinMax(lat(jj(:,0),jj(:,1)), True)
>> ;returns range of 38.0728 to 41.8587, which is outside the initial
>>query of 39.5 to 40.5
>>
>> Any thoughts?
>>
>> Will
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>_______________________________________________
>ncl-talk mailing list
>List instructions, subscriber options, unsubscribe:
>http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Feb 27 22:16:17 2014

This archive was generated by hypermail 2.1.8 : Mon Mar 03 2014 - 14:26:18 MST