Iris helper functions#
Auxiliary functions for iris.
Functions:
|
Add new leading dimension to cube. |
|
Convert datetime object into numeric value with requested dtype. |
|
Check if a cube has an irregular grid. |
|
Check if a cube has a regular grid. |
|
Check if a cube has an unstructured grid. |
|
Merge attributes of all given cubes in-place. |
|
Rechunk cube so that it is not chunked along given dimensions. |
|
Safe unit conversion (change of standard_name not allowed; 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)wherewis 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:
iris.exceptions.CoordinateMultiDimError –
dim_coordis 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.datetimeorcftime.datetime)unit (
cf_units.Unit)dtype (a numpy dtype)
- Returns:
The return value of
unit.date2numwith the requested dtype.- Return type:
numpy.ndarrayof type dtype
- esmvalcore.iris_helpers.has_irregular_grid(cube: Cube) bool[source]#
Check if a cube has an irregular grid.
“Irregular” refers to a general curvilinear grid with 2D latitude and 2D longitude coordinates with common dimensions.
- esmvalcore.iris_helpers.has_regular_grid(cube: Cube) bool[source]#
Check if a cube has a regular grid.
“Regular” refers to a rectilinear grid with 1D latitude and 1D longitude coordinates orthogonal to each other.
- esmvalcore.iris_helpers.has_unstructured_grid(cube: Cube) bool[source]#
Check if a cube has an unstructured grid.
“Unstructured” refers to a grid with 1D latitude and 1D longitude coordinates with common dimensions (i.e., a simple list of points).
- 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: historicalandexp: ssp585end up asexp: historical ssp585using the defaultdelimiter = ' '.
- esmvalcore.iris_helpers.rechunk_cube(cube: Cube, complete_coords: Iterable[Coord | str], remaining_dims: int | Literal['auto'] = 'auto') Cube[source]#
Rechunk cube so that it is not chunked along given dimensions.
This will rechunk the cube’s data, but also all non-dimensional coordinates, cell measures, and ancillary variables that span at least one of the given dimensions.
Note
This will only rechunk dask arrays. numpy arrays are not changed.
- Parameters:
- Returns:
Rechunked cube. This will always be a copy of the input cube.
- Return type:
- esmvalcore.iris_helpers.safe_convert_units(cube: Cube, units: str | Unit) Cube[source]#
Safe unit conversion (change of standard_name not allowed; in-place).
This is a safe version of
esmvalcore.preprocessor.convert_units()that will raise an error if the input cube’sstandard_namehas been changed.- Parameters:
- Returns:
Converted cube. Just returned for convenience; input cube is modified in place.
- Return type:
- Raises:
iris.exceptions.UnitConversionError – Old units are unknown.
ValueError – Old units are not convertible to new units or unit conversion required change of standard_name.