Skip to content

Bounds of derived variable are not read correctly #3678

Open
@schlunma

Description

@schlunma

Hi,

in ESMValTool we found the following issue concerning files with derived variables (in particular atmosphere_hybrid_sigma_pressure_coordinate, see ESMValGroup/ESMValCore#543):

The bounds of the derived variable of model output that is consistent with the CF conventions cannot be read correctly with iris. Here is a minimal example using the nc file that is used on the CF convention webpage (without the optional attributes and the units of A replaced by 1):

netcdf a_new_file {
dimensions:
        eta = 1 ;
        lat = 1 ;
        lon = 1 ;
        bnds = 2 ;
variables:
        double eta(eta) ;
                eta:long_name = "eta at full levels" ;
                eta:positive = "down" ;
                eta:standard_name = "atmosphere_hybrid_sigma_pressure_coordinate" ;
                eta:formula_terms = "a: A b: B ps: PS p0: P0" ;
                eta:bounds = "eta_bnds" ;
        double eta_bnds(eta, bnds) ;
                eta_bnds:formula_terms = "a: A_bnds b: B_bnds ps: PS p0: P0" ;
        double A(eta) ;
                A:long_name = "a coefficient for vertical coordinate at full levels" ;
                A:units = "1" ;
        double A_bnds(eta, bnds) ;
        double B(eta) ;
                B:long_name = "b coefficient for vertical coordinate at full levels" ;
                B:units = "1" ;
        double B_bnds(eta, bnds) ;
        double PS(lat, lon) ;
                PS:units = "Pa" ;
        double P0 ;
                P0:units = "Pa" ;
        float temp(eta, lat, lon) ;
                temp:standard_name = "air_temperature" ;
                temp:units = "K" ;

Reading this file with iris

import iris
print(iris.__version__)
print("")

path = os.path.expanduser('~/a_new_file.nc')
cubes = iris.load(path)
print(cubes)
print("")

cube = cubes.extract_strict(iris.Constraint('air_temperature'))
air_pressure_coord = cube.coord('air_pressure')
print(air_pressure_coord)

gives

2.4.0

/miniconda3/envs/test/lib/python3.7/site-packages/iris/fileformats/cf.py:1074: UserWarning: Ignoring formula terms variable 'PS' referenced by data variable 'A_bnds' via variable 'eta': Dimensions ('lat', 'lon') do not span ('eta', 'bnds')
  warnings.warn(msg)
/miniconda3/envs/test/lib/python3.7/site-packages/iris/fileformats/cf.py:1074: UserWarning: Ignoring formula terms variable 'PS' referenced by data variable 'B_bnds' via variable 'eta': Dimensions ('lat', 'lon') do not span ('eta', 'bnds')
  warnings.warn(msg)
/miniconda3/envs/test/lib/python3.7/site-packages/iris/fileformats/netcdf.py:601: UserWarning: Unable to find coordinate for variable 'PS'
  '{!r}'.format(name))
/miniconda3/envs/test/lib/python3.7/site-packages/iris/fileformats/netcdf.py:601: UserWarning: Unable to find coordinate for variable 'PS'
  '{!r}'.format(name))
0: A_bnds / (1)                        (atmosphere_hybrid_sigma_pressure_coordinate: 1; -- : 2)
1: B_bnds / (1)                        (atmosphere_hybrid_sigma_pressure_coordinate: 1; -- : 2)
2: PS / (Pa)                           (-- : 1; -- : 1)
3: air_temperature / (K)               (atmosphere_hybrid_sigma_pressure_coordinate: 1; -- : 1; -- : 1)

AuxCoord(masked_array(data=[[[3004000.]]],
             mask=False,
       fill_value=1e+20), standard_name='air_pressure', units=Unit('Pa'))

As you can see, the air_pressure coordinate does not have bounds. When the optional attributes A:bounds = "A_bnds" and B:bounds = "B_bnds" are added to the file, iris is able to read the bounds correctly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    In Progress

    Status

    🏗 In progress

    Status

    🚧 Blocked

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions