cf.Field.compute_vertical_coordinates

Field.compute_vertical_coordinates(default_to_zero=True, strict=True, key=False, inplace=False, verbose=None)[source]

Compute non-parametric vertical coordinates.

When vertical coordinates are a function of horizontal location as well as parameters which depend on vertical location, they cannot be stored in a vertical dimension coordinate construct. In such cases a parametric vertical dimension coordinate construct is stored and a coordinate reference construct contains the formula for computing the required non-parametric vertical coordinates.

See CF section 4.3.3 “Parametric Vertical Coordinate” and CF

Appendix D “Parametric Vertical Coordinates” for details.

For example, multi-dimensional non-parametric parametric ocean altitude coordinates can be computed from one-dimensional parametric ocean sigma coordinates.

Coordinate reference systems based on parametric vertical coordinates are identified from the coordinate reference constructs and, if possible, the corresponding non-parametric vertical coordinates are computed and stored in a new auxiliary coordinate construct.

If there are no appropriate coordinate reference constructs then the field construct is unchanged.

Added in version 3.8.0.

Parameters:
default_to_zero: bool, optional

If False then do not assume that missing terms have a value of zero. By default a missing term is assumed to be zero.

strict: bool

If False then allow the computation to occur when:

  • A domain ancillary construct has no standard name, but the corresponding term has a standard name that is prescribed

  • When the computed standard name can not be found by inference from the standard names of the domain ancillary constructs, nor from the computed_standard_name parameter of the relevant coordinate reference construct.

By default an exception is raised in these cases.

If a domain ancillary construct does have a standard name, but one that is inconsistent with any prescribed standard names, then an exception is raised regardless of the value of strict.

key: bool

If True, return alongside the field construct the key identifying the auxiliary coordinate of the field with the newly-computed vertical coordinates, as a 2-tuple of field and then key. If False, the default, then only return the field construct.

If no coordinates were computed, None will be returned in the key (second) position of the 2-tuple.

Added in version 3.17.0.

inplace: bool, optional

If True then do the operation in-place and return None.

verbose: int or str or None, optional

If an integer from -1 to 3, or an equivalent string equal ignoring case to one of:

  • 'DISABLE' (0)

  • 'WARNING' (1)

  • 'INFO' (2)

  • 'DETAIL' (3)

  • 'DEBUG' (-1)

set for the duration of the method call only as the minimum cut-off for the verboseness level of displayed output (log) messages, regardless of the globally-configured cf.log_level. Note that increasing numerical value corresponds to increasing verbosity, with the exception of -1 as a special case of maximal and extreme verbosity.

Otherwise, if None (the default value), output messages will be shown according to the value of the cf.log_level setting.

Overall, the higher a non-negative integer or equivalent string that is set (up to a maximum of 3/'DETAIL') for increasing verbosity, the more description that is printed to convey information about the operation.

Returns:
Field, 2-tuple, or None

The field construct with the new non-parametric vertical coordinates, or a 2-tuple of this field construct along with the key of the new auxiliary coordinate with the computed vertical coordinates, or None if the operation was in-place.

Examples

>>> f = cf.example_field(1)
>>> print(f)
Field: air_temperature (ncvar%ta)
---------------------------------
Data            : air_temperature(atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) K
Cell methods    : grid_latitude(10): grid_longitude(9): mean where land (interval: 0.1 degrees) time(1): maximum
Field ancils    : air_temperature standard_error(grid_latitude(10), grid_longitude(9)) = [[0.76, ..., 0.32]] K
Dimension coords: atmosphere_hybrid_height_coordinate(1) = [1.5]
                : grid_latitude(10) = [2.2, ..., -1.76] degrees
                : grid_longitude(9) = [-4.7, ..., -1.18] degrees
                : time(1) = [2019-01-01 00:00:00]
Auxiliary coords: latitude(grid_latitude(10), grid_longitude(9)) = [[53.941, ..., 50.225]] degrees_N
                : longitude(grid_longitude(9), grid_latitude(10)) = [[2.004, ..., 8.156]] degrees_E
                : long_name=Grid latitude name(grid_latitude(10)) = [--, ..., kappa]
Cell measures   : measure:area(grid_longitude(9), grid_latitude(10)) = [[2391.9657, ..., 2392.6009]] km2
Coord references: grid_mapping_name:rotated_latitude_longitude
                : standard_name:atmosphere_hybrid_height_coordinate
Domain ancils   : ncvar%a(atmosphere_hybrid_height_coordinate(1)) = [10.0] m
                : ncvar%b(atmosphere_hybrid_height_coordinate(1)) = [20.0]
                : surface_altitude(grid_latitude(10), grid_longitude(9)) = [[0.0, ..., 270.0]] m
>>> print(f.auxiliary_coordinate('altitude', default=None))
None
>>> g = f.compute_vertical_coordinates()
>>> print(g.auxiliary_coordinates())
Constructs:
{'auxiliarycoordinate0': <CF AuxiliaryCoordinate: latitude(10, 9) degrees_N>,
 'auxiliarycoordinate1': <CF AuxiliaryCoordinate: longitude(9, 10) degrees_E>,
 'auxiliarycoordinate2': <CF AuxiliaryCoordinate: long_name=Grid latitude name(10) >,
 'auxiliarycoordinate3': <CF AuxiliaryCoordinate: altitude(1, 10, 9) m>}
>>> g.auxiliary_coordinate('altitude').dump()
Auxiliary coordinate: altitude
    long_name = 'Computed from parametric atmosphere_hybrid_height_coordinate
                 vertical coordinates'
    standard_name = 'altitude'
    units = 'm'
    Data(1, 10, 9) = [[[10.0, ..., 5410.0]]] m
    Bounds:units = 'm'
    Bounds:Data(1, 10, 9, 2) = [[[[5.0, ..., 5415.0]]]] m
>>> g, key = f.compute_vertical_coordinates(key=True)
>>> g
<CF Field: air_temperature(atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) K>
>>> key
'auxiliarycoordinate3'
>>> i = f.compute_vertical_coordinates(inplace=True)
>>> print(i)
None
>>> print(f.auxiliary_coordinates())
Constructs:
{'auxiliarycoordinate0': <CF AuxiliaryCoordinate: latitude(10, 9) degrees_N>,
'auxiliarycoordinate1': <CF AuxiliaryCoordinate: longitude(9, 10) degrees_E>,
'auxiliarycoordinate2': <CF AuxiliaryCoordinate: long_name=Grid latitude name(10) >,
'auxiliarycoordinate3': <CF AuxiliaryCoordinate: altitude(1, 10, 9) m>}