[Thread Prev][Thread Next][Index]

Re: sorting in a multi-dimensional dataset



Hi Sim Larkin, 

                If I understand your question properly, you have a dataset
(ascii ??) in which the data is defined over all the four dimensions but is
not arranged in the increasing/decreasing order of Z-values. Since all other
dimensions are ok, you want to arrange the data in the increasing/decreasing
order of Z values using SORTK and SAMPLEK functions in Ferret..am I right ??

   Now according to usermanual, with SAMPLEK function, the dimensions X, Y 
& T of the resultant variable should be inherited from the source variable.
I used this function several times and all the time it worked fine for me.
Please have a look at the attachment (example_sortk.jnl) and still you
have any doubt, please let me know (with all the neccessary details)

Hope This Helps

With Regards

Jaison

On Fri, 7 Jan 2005, Sim Larkin wrote:

> 
> 
> 
> 
> I'm sorting along a dimension using the SORT* and SAMPLE* functions (in
> this case in the K dimension).
> 
> However, I can only make it work if I pare down the region to a single
> point in all the other dimension (I,J,L) using SET REGION or some other
> equivalent code.
> If I don't do this I get the
> 
> SAMPLE* only takes a 1D index
> 
> error.
> 
> Is there a way around this?
> 
> What I want is:
> 
> Original Data -> Sorted Data
> dimensions I, J, L simply inherted through
> dimension K contains sorted values
> 
> This is exactly what the SORT* function gives me for the indices, but the
> SAMPLE* function can't seem to handle it.
> 
> Any suggestions to avoid having to loop through all the I,J,L combinations?
> 
> - Sim
> 
> -------------------------------------------------------------------------------------------------
> 
> Sim Larkin
> Research Physical Climatologist, AirFIRE Team
> USDA Forest Service Pacific Wildland Fire Sciences Laboratory
> 400 N. 34th St Suite#201, Seattle, WA 98103
> Email: larkin@fs.fed.us
> 206.732.7849
> -------------------------------------------------------------------------------------------------
> 

-- 
___________________________________________________

    Jaison Kurian                           
    Centre for Atmospheric and Oceanic Sciences
    Indian Institute of Science
    B A N G A L O R E   560 012
    Ph: +91-80-3942505
        +91-80-3600450
    Fax:+91-80-3600865
___________________________________________________
\ cancel mode verify
!
! ref : http://ferret.pmel.noaa.gov/Ferret/Mail_Archives/fu_2005/msg00024.html
!

! create a variable defined over all the four dimensions. Exact values of 
!   'Z' will be random (not monotonic with respect to 'K' indices) and is
!   available in another variable say 'dep_pts'. Then the procedure is 

     define axis/x=30:120:1/units=longitudes xlon    
     define axis/y=-30:30:1/units=latitudes  ylat    
     define axis/z=1:15:1  zindex               ! just 1,2,3... indices
     define axis/t=01-JAN-2001:31-JAN-2001:1/units=days/t0=31-DEC-2000 time

     let v4d = sin (x[gx=xlon] + y[gy=ylat] + z[gz=zindex] + t[gt=time] )

     show grid v4d

! let the actual values of depth be like this
!    ie default "k" values ==> 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
     let dep_pts = ZSEQUENCE({30,20,50,10,40,70,60,55,45,15, 5,65, 0,25,35})

! now sort the depth values in the increasing order

     let dep_incr_k = SORTK(dep_pts)
     let dep_incr   = SAMPLEK(dep_pts,dep_incr_k) 
     list dep_incr, dep_incr_k

! now we know the sapling indices to sort along Z for the variable v4d
!     then do the sampling

     let v4d_z_incr = SAMPLEK(v4d, dep_incr_k)

! do a cross checking : for v4d         k=1 corresponds to Z=30
!                       for v4d_z_incr  k=7 corresponds to Z=30

     fill/l=1 v4d[k=1]-v4d_z_incr[k=7]  ! a blank plot

     message

! it is fine...then assign a new depth axis to the original variable so that
!     the Z-values are in the increasing order     

     define axis/z/DEPTH/units=meters/from_data depth=dep_incr

! now v4d_z_incr is in proper order, just need to assign the new depth axis
!    @ASN regridding can be used for this purpose

     let v4d_z = v4d_z_incr[GZ=depth@ASN]  

     fill/l=1 v4d[k=1]-v4d_z[k=7]      ! a blank plot

! now put proper title and units (and save to a NetCDF file if needed)

     set var/title="My Variable in ascending order of Depth"/units="^oC" v4d_z
 
     ! sp rm -f myncfile.nc
     ! save/file=myncfile.nc/append v4d_z

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement