[Thread Prev][Thread Next][Index]

Re: North to South Latitude (reversed) axis in ASCII data file

Hi everyone,

Mick gives a useful discussion of working with reversing North/South
ordering, and a good example using SAMPLEJ function to flip the
axis, essentially using.

I just want to mention another method -- write a NetCDF file, and
apply the USE/ORDER qualifer to read back the data and indicate the
reversed axis.  See "ORDER, for USE" in the Users Guide index.

In Mick's example, once the reversed data are read in, we could
SAVE the data to a NetCDF file, and then read it back in with
USE/ORDER=X-Y  to indicate that the Y axis is reversed.

! Read the reversed-data file specifying geographic units on the axes;
! the plot shows the data inverted.

     def axis/y=59.5:49.5:1/units=degrees_north yfer
     def axis/x=348.5:362.5/npoints=15/units=degrees_east xfer
     def grid/x=xfer/y=yfer gin
     file/form=(15f7.0)/col=15/ord=xy/g=gin/var=v test.file
     fill/lev=(0,1000,100) v

!  Save this as a NetCDF file.
     save/clobber/file=reverse_north.cdf v

     can data/all
     can var/all
     set win/new

!  Read it in; the -Y indicates that the Y axis is inverted.

     use/order=x-y reverse_north.cdf 
     fill/lev=(0,1000,100) v

Ansley Manke

Mick Spillane wrote:

Probably many of us have encountered data files where the ordering is
NORTH to SOUTH rather than ferret's preferred SOUTH to NORTH.  There
may be prior solutions in the archives for ways to get around this
but I missed them while searching.  So here is a response to a user.
Apologies if it is a wheel that you have already invented.
Mick Spillane
Hi Steve,
        Ferret has a preference for geographic axes that are ordered
from south to north, and east to west.  For example if you wanted to
define a grid from 10N to 10S and 10E to 10W you might try
        def axis/x=10E:10W/npoints=21 x21
        def axis/y=10N:10S/npoints=21 y21
        def grid/x=x21/y=y21 g21
but when you check it ...
        show grid/y g21
... you find that Ferret has imposed its preference to reorder your grid
       J     Y                   YBOX      YBOXLO
       1>  10S                   1         10.5S
       2>  9S                    1         9.5S
      20>  9N                    1         8.5N
      21>  10N                   1         9.5N
from south to north.
In the case of the x-axis it goes the other way around the earth
        show grid/x g21
       I     X                   XBOX      XBOXLO
       1>  10E                   17        1.5E
       2>  27E                   17        18.5E
      20>  27W                   17        35.5W
      21>  10W                   17        18.5W

In the case of data input via netCDF files this is not much of a problem.
The axis order can be defined in either direction and Ferret will read
it and convert axes and data consistently to its preferred order.

In your case you want to read in data ordered NORTH to SOUTH. Here is a
demo using the coarse etopo60 topography around GreatBritain and Ireland
of how SAMPLEJ can solve the problem. Cut and paste the steps below to
see how it works.

! make the test data file, ordered west to east but NORTH to SOUTH
use etopo60
fill/lev=(0,1000,100) rose ! shows the normally-oriented chart
list/nohead/form=(15f7.0)/j=150/ord=xy/file=test.file rose
repeat/j=149:138:-1 (list/nohead/form=(18f7.0)/ord=xy/app/file=test.file

! remove etopo60 and cancel region
can data 1 ; can region

! now make a grid to read back the NORTH to SOUTH data ...
def axis/x=1:15:1 xin ; def axis/y=1:13:1 yin
def grid/x=xin/y=yin gin
file/form=(15f7.0)/col=15/ord=xy/g=gin/var=v test.file
! ... and confirm that it is upside-down
fill/lev=(0,1000,100) v

! then define the sampling to rectify it ...
let yr=14-y[g=gin]
let vr=samplej(v,yr)
! ... and check it out
fill/lev=(0,1000,100) vr

! now we need to assign the rectified data to the geographic grid

! define the axes in ferret-preferred order
def axis/x=348.5:362.5/npoints=15/units=degrees_east xfer
def axis/y=47.5:59.5/npoints=13/units=degrees_north yfer
def grid/x=xfer/y=yfer gfer
let vfer=vr[g=gfer,gx=@asn,gy=@asn]
fill/lev=(0,1000,100) vfer

! finally access the etopo60 data again and confirm that all is well
use etopo60 ; contour/over/lev=(0,1000,100) rose

Using the SAMPLEI function one could handle an input ASCII file that
was ordered EAST to WEST, and probably SAMPLEIJ could serve to fix
data where both axes were non-ferret-preferred.


|-*__---*-----*--*-*--*--*-*--*-|_SCIENCE APPLICATIONS SUPPORT_|
|-----*-*-----*-*****-*----*----|__Room 2070 Bldg#3 NOAA/PMEL__|

Ansley Manke  Pacific Marine Environmental Laboratory  Seattle WA  (206)526-6246

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement