Iris helper functions#
Auxiliary functions for iris
.
Functions:
|
Add new leading dimension to cube. |
|
Convert datetime object into numeric value with requested dtype. |
|
Merge attributes of all given cubes in-place. |
- 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)
wherew
is the length ofdim_coord
. Note that the data is broadcasted to the new shape.- Parameters:
cube (iris.cube.Cube) – Input cube.
dim_coord (iris.coords.DimCoord) – Dimensional coordinate that is used to describe the new leading dimension. Needs to be 1D.
- Returns:
Transformed input cube with new leading dimension.
- Return type:
- Raises:
CoordinateMultiDimError –
dim_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:
date (
datetime.datetime
orcftime.datetime
) –unit (
cf_units.Unit
) –dtype (a numpy dtype) –
- Returns:
The return value of
unit.date2num
with the requested dtype.- Return type:
numpy.ndarray
of type dtype
- esmvalcore.iris_helpers.merge_cube_attributes(cubes: Sequence[Cube], delimiter: str = ' ') None [source]#
Merge attributes of all given cubes in-place.
After this operation, the attributes of all given cubes are equal. This is useful for operations that combine cubes, such as
iris.cube.CubeList.merge_cube()
oriris.cube.CubeList.concatenate_cube()
.Note
This function differs from
iris.util.equalise_attributes()
in this respect that it does not delete attributes that are not identical but rather concatenates them (sorted) using the givendelimiter
. E.g., the attributesexp: historical
andexp: ssp585
end up asexp: historical ssp585
using the defaultdelimiter = ' '
.