[Thread Prev][Thread Next][Index]

Re: [ferret_users] inconsistent data grids: File needs axis attributes on coordinate variables indicating correct direction



Hi Patrick, and others on this thread,

Maybe there needs to be an FAQ about this. It's good to have this example.

PyFerret creates grids for variables as it initializes a dataset.  It decides which dimensions have which direction, and as it works it requires that the directions are the same for all of the variables in the dataset. If there is any doubt about the directions of dimensions, it starts with the variables with the most dimensions, assigning the directions for their dimensions, and then works to create the grids for variables with fewer dimensions.
If a dimension has a coordinate variable associated with it, the attributes are used to determine directions, and this is the most direct and preferred method. 

If there is a coordinate variable, then direction is determined by looking at the coordinate variable's attributes. Once the direction is determined, the search stops, so for instance if we had a coordinate variable with an attribute :axis = "x" and :units="days" would be marked as an x axis.This is the order for checking direction information.

1- An axis attribute, with value x, y, z, t.  If there is no axis attribute, then

2 - A cartesian_axis attribute.

3- A cf_role attribute. This attribute is used in the discrete sampling geometries form for netCDF datasets.

4- A _CoordinateAxisType attribute.

5- If the direction is still undetermined, pyferret looks for a units attribute of the coordinate variable and checks whether those correspond to directions of longitude, latitude, depth/height (or pressure), or time. 

6- A positive attribute.  positive=down or positive=up indicate a Z axis.

7- A standard_name attribute where the standard name value indicates longitude, latitude, height/depth, time.

8- If the direction is still undetermined, or if the dimension does not correspond to a coordinate variable then a few obvious dimension names can indicate the direction:

     o Dimension names that are simple one-letter names X","Y", "Z", "T", "I", "J", "K", "L"

     o Dimension names that start with "XAX","YAX","ZAX","TAX"

     o Dimension names that start with "LON","LAT","TIME","DATE","DEP","ALT,"ELEV","HEI","LAYER","LEVEL" are assigned the appropriate direction. This last group is not applied if there is a units string that indicates something that is not a direction, in case there might be for example dimension that is say, "depletion", with units of "percent".

9- If the axis direction is still undermined, then they will be assigned, starting with the largest grid, working right to left with the first axis an x axis, then a y axis, and so on.  So the file here would look at bounds_lat(jmax, imax, nv)  and put nv in the x direction, imax in the y direction, and jmax in the z direction.  Then it cannot reconcile that with the 2-D grid (jmax, imax).


In much older versions of Ferret, even more guessing was used to determine directions, so that any dimension name starting with T was put in the time direction and so forth. Probably jmax and imax would have been Y and X axes.  However this led to confusion and inconsistencies. For instance an axis called TSTATION was put in the T direction but should have been a simple axis in the X direction, for instance.


Ansley


On 9/29/2021 5:00 AM, Patrick Brockmann wrote:
Hi all,

I have investigated a little bit more on the internal ferret mechanism that leads to produce this error. 

**ERROR: inconsistent data grids: File needs axis attributes on coordinate variables indicating correct directions

Starting from an example given by the CF convention description from the folowing paragraph
https://cfconventions.org/Data/cf-conventions/cf-conventions-1.9/cf-conventions.html#cell-boundaries
I have reproduced the error from a very simple exemple.

$ cat notok.cdl
netcdf notok {
dimensions:
       jmax = 1 ;
       imax = 1 ;
       nv = 4 ;
variables:
       double lat(jmax, imax) ;
               lat:long_name = "latitude" ;
               lat:units = "degrees_north" ;
               lat:bounds = "bounds_lat" ;
       double lon(jmax, imax) ;
               lon:long_name = "longitude" ;
               lon:units = "degrees_east" ;
               lon:bounds = "bounds_lon" ;
       double bounds_lat(jmax, imax, nv) ;
       double bounds_lon(jmax, imax, nv) ;
       double sample(jmax, imax) ;
               sample:coordinates = "lon lat" ;
data:
lat = -28;
lon = 157;
bounds_lat = -29, -29, -27, -27;
bounds_lon = 156, 158, 158, 156;
sample = 1 ;
}
$ ncgen -o notok.nc notok.cdl
$ ferret
yes? use notok.nc
          *** NOTE:
          *** NOTE: Could not adjust grid for variable lat
**ERROR: inconsistent data grids: File needs axis attributes on coordinate variables indicating correct directions

The same file with modified dimension names (jmax, imax replaced by y, x) can be openned.

$ cat ok.cdl
netcdf ok {
dimensions:
       y = 1 ;
       x = 1 ;
       nv = 4 ;
variables:
       double lat(y, x) ;
               lat:long_name = "latitude" ;
               lat:units = "degrees_north" ;
               lat:bounds = "bounds_lat" ;
       double lon(y, x) ;
               lon:long_name = "longitude" ;
               lon:units = "degrees_east" ;
               lon:bounds = "bounds_lon" ;
       double bounds_lat(y, x, nv) ;
       double bounds_lon(y, x, nv) ;
       double sample(y, x) ;
               sample:coordinates = "lon lat" ;
data:
lat = -28;
lon = 157;
bounds_lat = -29, -29, -27, -27;
bounds_lon = 156, 158, 158, 156;
sample = 1 ;
}
$ ncgen -o ok.nc ok.cdl
$ ferret
yes? use ok.nc

I would like to understand why ?

Best regards
Patrick

--
Data Analytics and Visualization Engineer / Project Manager
LSCE/IPSL, CEA-CNRS-UVSQ laboratory
LSCE - Climate and Environment Sciences Laboratory
IPSL - Institut Pierre Simon Laplace
--


De: "Patrick Brockmann" <patrick.brockmann@xxxxxxxxxxxx>
À: "ferret users" <ferret_users@xxxxxxxx>
Cc: "Thanh-Lam Nguyen" <sebastien.nguyen@xxxxxxxxxxxx>
Envoyé: Lundi 27 Septembre 2021 16:48:27
Objet: [ferret_users] inconsistent data grids: File needs axis attributes on coordinate variables indicating correct direction

Hi ferreters,

A colleague has encountered a strange problem as he was trying to
nicely respect the netCDF CF conventions to describe a curvilinear grid (NEMO configuration).

ferret complains about some inconsistent data grid and missing axis attributes.
use notok.nc 
          *** NOTE: 
          *** NOTE: Could not adjust grid for variable mask_T 
**ERROR: inconsistent data grids: File needs axis attributes on coordinate variables indicating correct directions

Stranger, if I change the name of the dimension, then the file
is read. I have not been able to fix this by adding a direction attribute as requested.

The file is simple as:
$ ncdump notok.nc
netcdf notok { 
dimensions: 
       y_grid_T = 1 ; 
       x_grid_T = 1 ; 
       nvertex_grid_T = 4 ; 
variables: 
       double bounds_lat_grid_T(y_grid_T, x_grid_T, nvertex_grid_T) ; 
       double bounds_lon_grid_T(y_grid_T, x_grid_T, nvertex_grid_T) ; 
       byte mask_T(y_grid_T, x_grid_T) ; 
               mask_T:cell_measures = "area: area_grid_T" ; 
               mask_T:coordinates = "nav_lat_grid_T nav_lon_grid_T" ; 
       double nav_lat_grid_T(y_grid_T, x_grid_T) ; 
               nav_lat_grid_T:standard_name = "latitude" ; 
               nav_lat_grid_T:long_name = "Latitude" ; 
               nav_lat_grid_T:units = "degrees_north" ; 
               nav_lat_grid_T:bounds = "bounds_lat_grid_T" ; 
       double nav_lon_grid_T(y_grid_T, x_grid_T) ; 
               nav_lon_grid_T:standard_name = "longitude" ; 
               nav_lon_grid_T:long_name = "Longitude" ; 
               nav_lon_grid_T:units = "degrees_east" ; 
               nav_lon_grid_T:bounds = "bounds_lon_grid_T" ; 
data: 
bounds_lat_grid_T = 
 -29.5895932339965, -29.5895932339965, -27.835621888657, -27.835621888657 ; 
bounds_lon_grid_T = 
 156.999148343641, 158.999201071309, 158.999201071309, 156.999148343641 ; 
mask_T = 
 1 ; 
nav_lat_grid_T = 
 -28.7162844516478 ; 
nav_lon_grid_T = 
 157.999608915878 ; 
}

If I remove _grid_T suffix then the file is read correctly.
$ ncgen -o notok.nc notok.cdl
$ sed -e 's/_grid_T//g' notok.cdl > ok.cdl
$ ncgen -o ok.nc ok.cdl


Any idea on why there is the unexpected behaviour (test on names of dimensions) ?
Patrick

--
Data Analytics and Visualization Engineer / Project Manager
LSCE/IPSL, CEA-CNRS-UVSQ laboratory
LSCE - Climate and Environment Sciences Laboratory
IPSL - Institut Pierre Simon Laplace
--sed -e 's/_grid_T//g' tyty.cdl > tyty1.cdl


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement