NOAA-PMEL / Ferret

The Ferret program from NOAA/PMEL
https://ferret.pmel.noaa.gov/Ferret/
The Unlicense
55 stars 20 forks source link

Handle grids where axis is reversed #1365

Open karlmsmith opened 7 years ago

karlmsmith commented 7 years ago

Reported by @AnsleyManke on 20 Sep 2013 18:23 UTC Our GFDL friends wrote us with the question quoted below, about Ferret's handling of axes with decreasing coordinates. We will be discussing how to resolve this in general.

An element of this which we can immediately address is to have Ferret WRITE data and axes in the same reversed order as in the dataset. Any variable defined on a grid which includes an axis that Ferret marked as reversed should be written with the coordinates and data reversed. In fact there is a NetCDF call to write data with a mapping vector for ordering the data, just as there is a call to read data in a permuted order.

I think we should do this by default, perhaps issuing a NOTE. This goes along with our efforts in recent Ferret releases to write netCDF files that conform to the original dataset as much as possible.


(from Matt, @AndrewWittenberg, Balaji, Keith, Alistair Adcroft 9/17/2013)

Hi Ansley,

We have identified an issue with Ferret's handling of vertical 
coordinates containing negative values.  The code below provides an 
example.

This issue came up in the development of  MOM6 diagnostics where we 
are now using height as opposed to depth as the vertical coordinate. 
According to the current CF documentation, this is allowed by the 
standard. Unfortunately, we hit on an oddity in ferret which, if we 
don't address, will cause all sorts of confusion for ferret users 
using our output.  Although plotting works, the data seems to be 
read in upside down into memory so that k=1 is at the bottom instead 
of the surface where z=0. Users get the expected result when 
referring to z=0 but not when referring to k=1. Is this a known 
issue and is there a workaround? or do we need to patch Ferret? 

Thanks,

Matt (and Alistair)

The following steps illustrate the problem:
cat <<EOFA >! test.cdl
netcdf test {
dimensions:
zl = 5 ;
variables:
double zl(zl) ;
zl:long_name = "Height Z" ;
zl:units = "m" ;
zl:positive = "up" ;
zl:cartesian_axis = "Z" ;
double temp(zl) ;
temp:long_name = "Temperature" ;
temp:units = "degrees C" ;
// global attributes:
:filename = "test.nc" ;
data:
zl = -5, -15, -25, -35, -45 ;
temp = 20, 16, 13, 9, 8 ;
}
EOFA
ncgen -b test.cdl
ferret
use test.nc
plot temp
list temp[k=1]
list temp[k=5]

You get a plot that IS correct but the data evidently has been inverted:
yes? list temp[k=1]
             VARIABLE : Temperature (degrees C)
             FILENAME : test.nc
             Z (m)    : -45
          8.000
yes? list temp[k=5]
             VARIABLE : Temperature (degrees C)
             FILENAME : test.nc
             Z (m)    : -5
          20.00

Migrated-From: http://dunkel.pmel.noaa.gov/trac/ferret/ticket/2093

karlmsmith commented 7 years ago

Modified by @AnsleyManke on 26 Sep 2013 17:57 UTC

karlmsmith commented 7 years ago

Comment by @AnsleyManke on 26 Sep 2013 18:03 UTC Here is a proposed set of changes to complete the work, changing the interpretation of indices on reverse-ordered axes. Continuing to support the reversed axes as in-memory, forward-ordered variables, but making this transparent to users: