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.

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