Iris helper functions

Auxiliary functions for iris.

Functions:

add_leading_dim_to_cube(cube, dim_coord)

Add new leading dimension to cube.

date2num(date, unit[, dtype])

Convert datetime object into numeric value with requested dtype.

var_name_constraint(var_name)

iris.Constraint using var_name.

esmvalcore.iris_helpers.add_leading_dim_to_cube(cube, dim_coord)[source]

Add new leading dimension to cube.

An input cube with shape (x, ..., z) will be transformed to a cube with shape (w, x, ..., z) where w is the length of dim_coord. Note that the data is broadcasted to the new shape.

Parameters
Returns

Transformed input cube with new leading dimension.

Return type

iris.cube.Cube

Raises

CoordinateMultiDimErrordim_coord is not 1D.

esmvalcore.iris_helpers.date2num(date, unit, dtype=<class 'numpy.float64'>)[source]

Convert datetime object into numeric value with requested dtype.

This is a custom version of cf_units.Unit.date2num() that guarantees the correct dtype for the return value.

Parameters
Returns

The return value of unit.date2num with the requested dtype.

Return type

numpy.ndarray of type dtype

esmvalcore.iris_helpers.var_name_constraint(var_name)[source]

iris.Constraint using var_name.

Warning

Deprecated since version 2.6.0: This function has been deprecated in ESMValCore version 2.6.0 and is scheduled for removal in version 2.8.0. Please use the function iris.NameConstraint with the argument var_name instead: this is an exact replacement.

Parameters

var_name (str) – var_name used for the constraint.

Returns

Constraint.

Return type

iris.Constraint