What passes as a valid standard_name?

342 views
Skip to first unread message

Damien Irving

unread,
May 9, 2016, 2:27:46 AM5/9/16
to Iris
Ive got a netCDF file that looks as follows:

$ ncdump my_file.nc

dimensions
:
    time
= UNLIMITED ; // (144 currently)
    lat
= 130 ;
    lon
= 360 ;
    bnds
= 2 ;
variables
:
   
double ohc_2D(time, lat) ;
        ohc_2D
:_FillValue = 1.e+20 ;
        ohc_2D
:standard_name = "ocean_heat_content_2D" ;
        ohc_2D
:long_name = "ocean heat content 2D" ;
        ohc_2D
:units = "10^12 J m-2" ;
   
float time(time) ;
        time
:axis = "T" ;
        time
:units = "days since 2004-01-01 00:00:00" ;
        time
:standard_name = "time" ;
        time
:long_name = "time" ;
        time
:calendar = "gregorian" ;
        time
:time_origin = "01-JAN-2004 00:00:00" ;
   
float lat(lat) ;
        lat
:axis = "Y" ;
        lat
:units = "degrees" ;
        lat
:standard_name = "latitude" ;
        lat
:long_name = "latitude" ;
        lat
:point_spacing = "even" ;
   
double ohc_3D(time, lat, lon) ;
        ohc_3D
:_FillValue = 1.e+20 ;
        ohc_3D
:standard_name = "ocean_heat_content_3D" ;
        ohc_3D
:long_name = "ocean heat content 3D" ;
        ohc_3D
:units = "10^12 J m-2" ;
   
float lon(lon) ;
        lon
:axis = "X" ;
        lon
:bounds = "lon_bnds" ;
        lon
:units = "degrees" ;
        lon
:standard_name = "longitude" ;
        lon
:long_name = "longitude" ;
        lon
:modulo = 360. ;
        lon
:point_spacing = "even" ;
   
float lon_bnds(lon, bnds) ;

When I try and load one of the variables using the standard_name, I get a constraint error:

with iris.FUTURE.context(cell_datetime_objects=True):
    cube1
= iris.load_cube('my_file.nc', 'ocean_heat_content_3D')

ConstraintMismatchError                   Traceback (most recent call last)
<ipython-input-19-f8f3a453fedb> in <module>()
     
1 with iris.FUTURE.context(cell_datetime_objects=True):
----> 2     cube1 = iris.load_cube(fname, 'ocean_heat_content_3D')

/g/data/r87/dbi599/miniconda2/envs/default/lib/python2.7/site-packages/iris/__init__.pyc in load_cube(uris, constraint, callback)
   
341         raise iris.exceptions.ConstraintMismatchError(str(e))
   
342     except ValueError:
--> 343         raise iris.exceptions.ConstraintMismatchError('no cubes found')
   
344
   
345     return cube

ConstraintMismatchError: no cubes found

but everything works fine using the long_name.

This is the first time using the standard_name has failed for me, so I'm wondering if the problem is the number in the standard_name? Otherwise, I can't think of any reason for this error?

Andrew Dawson

unread,
May 9, 2016, 4:22:10 AM5/9/16
to Iris
Valid standard names are those specified by the CF conventions. See http://cfconventions.org/Data/cf-standard-names/32/build/cf-standard-name-table.html. The name in the file "ocean_heat_content_3D" is not a vlaid CF standard name.

The constraint you applied is a text match against the value of cube.name(). This value returned by this method depends what is available in the file, the first preference is standard_name, the second is long_name. However, iris has correctly realised that the name "ocean_heat_content_3D" is not a valid CF standard name. Therefore when iris loads your file the resulting cube will **not** have a "standard_name = ocean_heat_content_3D" attribute. The loaded cubes will instead have an attribute "invalid_standard_name = ocean_heat_content_3D". This means that the name() method will choose the second choice long_name (since there is no standard name) as the cube's name and matching against it will work.

Damien Irving

unread,
May 9, 2016, 7:38:31 PM5/9/16
to Iris
Thanks, Andrew. That is exactly the information I needed :-)
Reply all
Reply to author
Forward
0 new messages