[Thread Prev][Thread Next][Index]

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



Hi,

There is another detail about these file examples which is important.  PyFerret does not have an implementation of bounds variables for 2-D coordinates. It does fully implement bounds for 1-dimensional coordinate axes, using them to determine the location of the cell edges along an axis. It writes a bounds variable when writing data that has an irregular axis.

For 2-dimensional coordinate variables, bounds such as bounds_lat(jmax, imax, nv) are not recognized, and it iss that nv dimension that is making it hard for PyFerret to initialize the file. A dimension to the right of the x dimension is not part of PyFerret's data model. If a file had only the 2-D lon(jmax, imax) and lat(imax,jmax)  and the data variable, it would be able to use the file even with the original naming and no axis attributes.

Some capability for 2-D coordinates is available in PyFerret; the coordinate variables can be specified for graphics commands and there is some functionality for regridding and sampling; see "curvilinear coordinates" in the documentation.  The implementation of curvilinear coordinates for graphics also allows for 2-D coordinate variables that describe the vertices of the grid cells.  Those would have nvx = ncx+1 and nvy = ncy+1 values. Those are expected to be in the files as 2-D variables not 3-D variables. So an ncdump -h of a file might look like this to contain both grid cell centers and grid cell vertices:


netcdf curvi_coord {
dimensions:
       ncx = 180 ;
       ncy = 90 ;
       nvx = 181 ;
       nvy = 91 ;
variables:
    int ncx;
       ncx:axis = "x" ;
    int ncy;
       ncy:axis = "y" ;
    int nvx;
       nvx:axis = "x" ;
    int nvy;
       nvy:axis = "y" ;
    double lonc(jmax, imax) ;
       latc:long_name = "geographic longitude of cell centers" ;
       lonc:units = "degrees_east" ;
    double latc(ncy, ncx) ;
       latc:long_name = "geographic latitude of cell centers" ;
       latc:units = "degrees_north" ;
    double lon_vert(jmax, imax, nv) ;
       lon_vert:long_name = "geographic latitude of cell vertices" ;
       lon_vert:units = "degrees_north" ;
    double lat_vert(jmax, imax, nv) ;
       lat_vert:long_name = "geographic latitude of cell vertices" ;
       lat_vert:units = "degrees_north" ;
    double u(ncx, ncy) ;
       u:lont_name = "zonal current" ;
       u:units = "m/sec" ;
       u:coordinates = "lonc latc" ;
    double v(ncx, ncy) ;
       v:lont_name = "meridional current" ;
       v:units = "m/sec" ;
       v:coordinates = "lonc latc" ;
}


PyFerret would be able to open this file, and we could do plots such as:

yes? fill u, lonc, latc
yes? vector u, v, lonc, latc

Or,  PtFerret will see that the dimensions of the vertex coordinates is one larger than the size of the coordinates of the data variables, and will treat that data as the edges of the grid cells:

yes? shade u, lon_vert, lat_vert   ! Which would look a bit different from "shade lon_c, lat_c"


( I am just typing things, here.  Typos are possible!)


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