Re: Unusual ind()/ind_resolve() behaviour

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu Feb 27 2014 - 22:05:02 MST

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
Received on Thu Feb 27 22:05:05 2014

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