iris.coords#
Definitions of coordinates and other dimensional metadata.
- class iris.coords.AncillaryVariable(data, standard_name=None, long_name=None, var_name=None, units=None, attributes=None)[source]#
Bases:
_DimensionalMetadata
Constructs a single ancillary variable.
Args:
- data:
The values of the ancillary variable.
Kwargs:
- standard_name:
CF standard name of the ancillary variable.
- long_name:
Descriptive name of the ancillary variable.
- var_name:
The netCDF variable name for the ancillary variable.
- units
The
Unit
of the ancillary variable’s values. Can be a string, which will be converted to a Unit object.
- attributes
A dictionary containing other cf and user-defined attributes.
- core_data()[source]#
The data array at the core of this ancillary variable, which may be a NumPy array or a dask array.
- cube_dims(cube)[source]#
Return the cube dimensions of this AncillaryVariable.
Equivalent to “cube.ancillary_variable_dims(self)”.
- property data#
- has_lazy_data()[source]#
Return a boolean indicating whether the ancillary variable’s data array is a lazy dask array or not.
- lazy_data()[source]#
Return a lazy array representing the ancillary variable’s data.
Accessing this method will never cause the data values to be loaded. Similarly, calling methods on, or indexing, the returned Array will not cause the ancillary variable to have loaded data.
If the data have already been loaded for the ancillary variable, the returned Array will be a new lazy array wrapper.
- Returns:
A lazy array, representing the ancillary variable data array.
- class iris.coords.AuxCoord(*args, **kwargs)[source]#
Bases:
Coord
A CF auxiliary coordinate.
Create a coordinate with mutable points and bounds.
Args:
- points:
The values (or value in the case of a scalar coordinate) for each cell of the coordinate.
Kwargs:
- standard_name:
CF standard name of the coordinate.
- long_name:
Descriptive name of the coordinate.
- var_name:
The netCDF variable name for the coordinate.
- units
The
Unit
of the coordinate’s values. Can be a string, which will be converted to a Unit object.
- bounds
An array of values describing the bounds of each cell. Given n bounds for each cell, the shape of the bounds array should be points.shape + (n,). For example, a 1D coordinate with 100 points and two bounds per cell would have a bounds array of shape (100, 2) Note if the data is a climatology, climatological should be set.
- attributes
A dictionary containing other CF and user-defined attributes.
- coord_system
A
CoordSystem
representing the coordinate system of the coordinate, e.g., aGeogCS
for a longitude coordinate.
- climatological (bool):
When True: the coordinate is a NetCDF climatological time axis. When True: saving in NetCDF will give the coordinate variable a ‘climatology’ attribute and will create a boundary variable called ‘<coordinate-name>_climatology’ in place of a standard bounds attribute and bounds variable. Will set to True when a climatological time axis is loaded from NetCDF. Always False if no bounds exist.
- class iris.coords.Cell(point=None, bound=None)[source]#
Bases:
Cell
An immutable representation of a single cell of a coordinate, including the sample point and/or boundary position.
Notes on cell comparison:
Cells are compared in two ways, depending on whether they are compared to another Cell, or to a number/string.
Cell-Cell comparison is defined to produce a strict ordering. If two cells are not exactly equal (i.e. including whether they both define bounds or not) then they will have a consistent relative order.
Cell-number and Cell-string comparison is defined to support Constraint matching. The number/string will equal the Cell if, and only if, it is within the Cell (including on the boundary). The relative comparisons (lt, le, ..) are defined to be consistent with this interpretation. So for a given value n and Cell cell, only one of the following can be true:
n < celln == celln > cellSimilarly, n <= cell implies either n < cell or n == cell. And n >= cell implies either n > cell or n == cell.
Construct a Cell from point or point-and-bound information.
- __common_cmp__(other, operator_method)[source]#
Common method called by the rich comparison operators. The method of checking equality depends on the type of the object to be compared.
Cell vs Cell comparison is used to define a strict order. Non-Cell vs Cell comparison is used to define Constraint matching.
- class iris.coords.CellMeasure(data, standard_name=None, long_name=None, var_name=None, units=None, attributes=None, measure=None)[source]#
Bases:
AncillaryVariable
A CF Cell Measure, providing area or volume properties of a cell where these cannot be inferred from the Coordinates and Coordinate Reference System.
Constructs a single cell measure.
Args:
- data:
The values of the measure for each cell. Either a ‘real’ array (
numpy.ndarray
) or a ‘lazy’ array (dask.array.Array
).
Kwargs:
- standard_name:
CF standard name of the coordinate.
- long_name:
Descriptive name of the coordinate.
- var_name:
The netCDF variable name for the coordinate.
- units
The
Unit
of the coordinate’s values. Can be a string, which will be converted to a Unit object.
- attributes
A dictionary containing other CF and user-defined attributes.
- measure
A string describing the type of measure. Supported values are ‘area’ and ‘volume’. The default is ‘area’.
- cube_dims(cube)[source]#
Return the cube dimensions of this CellMeasure.
Equivalent to “cube.cell_measure_dims(self)”.
- property measure#
String naming the measure type.
- xml_element(doc)[source]#
Create the
xml.dom.minidom.Element
that describes thisCellMeasure
.Args:
- doc:
The parent
xml.dom.minidom.Document
.
- Returns:
The
xml.dom.minidom.Element
that describes thisCellMeasure
.
- class iris.coords.CellMethod(method, coords=None, intervals=None, comments=None)[source]#
Bases:
_OrderedHashable
Represents a sub-cell pre-processing operation.
Args:
- method:
The name of the operation.
Kwargs:
- coords:
A single instance or sequence of
Coord
instances or coordinate names.
- intervals:
A single string, or a sequence strings, describing the intervals within the cell method.
- comments:
A single string, or a sequence strings, containing any additional comments.
- comments = None#
Additional comments.
- coord_names = None#
The tuple of coordinate names over which the operation was applied.
- intervals = None#
A description of the original intervals over which the operation was applied.
- method = None#
The name of the operation that was applied. e.g. “mean”, “max”, etc.
- xml_element(doc)[source]#
Create the
xml.dom.minidom.Element
that describes thisCellMethod
.Args:
- doc:
The parent
xml.dom.minidom.Document
.
- Returns:
The
xml.dom.minidom.Element
that describes thisCellMethod
.
- class iris.coords.Coord(points, standard_name=None, long_name=None, var_name=None, units=None, bounds=None, attributes=None, coord_system=None, climatological=False)[source]#
Bases:
_DimensionalMetadata
Abstract base class for coordinates.
Coordinate abstract base class. As of
v3.0.0
you cannot create an instance ofCoord
.Args:
- points:
The values (or value in the case of a scalar coordinate) for each cell of the coordinate.
Kwargs:
- standard_name:
CF standard name of the coordinate.
- long_name:
Descriptive name of the coordinate.
- var_name:
The netCDF variable name for the coordinate.
- units
The
Unit
of the coordinate’s values. Can be a string, which will be converted to a Unit object.
- bounds
An array of values describing the bounds of each cell. Given n bounds for each cell, the shape of the bounds array should be points.shape + (n,). For example, a 1D coordinate with 100 points and two bounds per cell would have a bounds array of shape (100, 2) Note if the data is a climatology, climatological should be set.
- attributes
A dictionary containing other CF and user-defined attributes.
- coord_system
A
CoordSystem
representing the coordinate system of the coordinate, e.g., aGeogCS
for a longitude coordinate.
- climatological (bool):
When True: the coordinate is a NetCDF climatological time axis. When True: saving in NetCDF will give the coordinate variable a ‘climatology’ attribute and will create a boundary variable called ‘<coordinate-name>_climatology’ in place of a standard bounds attribute and bounds variable. Will set to True when a climatological time axis is loaded from NetCDF. Always False if no bounds exist.
- property bounds#
The coordinate bounds values, as a NumPy array, or None if no bound values are defined.
Note
The shape of the bound array should be:
points.shape + (n_bounds, )
.
- property bounds_dtype#
The NumPy dtype of the coord’s bounds. Will be None if the coord does not have bounds.
- cell(index)[source]#
Return the single
Cell
instance which results from slicing the points/bounds with the given index.
- cells()[source]#
Returns an iterable of Cell instances for this Coord.
For example:
for cell in self.cells(): ...
- property climatological#
A boolean that controls whether the coordinate is a climatological time axis, in which case the bounds represent a climatological period rather than a normal period.
Always reads as False if there are no bounds. On set, the input value is cast to a boolean, exceptions raised if units are not time units or if there are no bounds.
- collapsed(dims_to_collapse=None)[source]#
Returns a copy of this coordinate, which has been collapsed along the specified dimensions.
Replaces the points & bounds with a simple bounded region.
- contiguous_bounds()[source]#
Returns the N+1 bound values for a contiguous bounded 1D coordinate of length N, or the (N+1, M+1) bound values for a contiguous bounded 2D coordinate of shape (N, M).
Only 1D or 2D coordinates are supported.
Note
If the coordinate has bounds, this method assumes they are contiguous.
If the coordinate is 1D and does not have bounds, this method will return bounds positioned halfway between the coordinate’s points.
If the coordinate is 2D and does not have bounds, an error will be raised.
- convert_units(unit)[source]#
Change the coordinate’s units, converting the values in its points and bounds arrays.
For example, if a coordinate’s
units
attribute is set to radians then:coord.convert_units('degrees')
will change the coordinate’s
units
attribute to degrees and multiply each value inpoints
andbounds
by 180.0/\(\pi\).Full list of supported units can be found in the UDUNITS-2 documentation https://docs.unidata.ucar.edu/udunits/current/#Database
- property coord_system#
Relevant coordinate system (if any).
- copy(points=None, bounds=None)[source]#
Returns a copy of this coordinate.
Kwargs:
- points: A points array for the new coordinate.
This may be a different shape to the points of the coordinate being copied.
- bounds: A bounds array for the new coordinate.
Given n bounds for each cell, the shape of the bounds array should be points.shape + (n,). For example, a 1d coordinate with 100 points and two bounds per cell would have a bounds array of shape (100, 2).
Note
If the points argument is specified and bounds are not, the resulting coordinate will have no bounds.
- core_bounds()[source]#
The points array at the core of this coord, which may be a NumPy array or a dask array.
- core_points()[source]#
The points array at the core of this coord, which may be a NumPy array or a dask array.
- cube_dims(cube)[source]#
Return the cube dimensions of this Coord.
Equivalent to “cube.coord_dims(self)”.
- guess_bounds(bound_position=0.5)[source]#
Add contiguous bounds to a coordinate, calculated from its points.
Puts a cell boundary at the specified fraction between each point and the next, plus extrapolated lowermost and uppermost bound points, so that each point lies within a cell.
With regularly spaced points, the resulting bounds will also be regular, and all points lie at the same position within their cell. With irregular points, the first and last cells are given the same widths as the ones next to them.
Kwargs:
- bound_position:
The desired position of the bounds relative to the position of the points.
Note
An error is raised if the coordinate already has bounds, is not one-dimensional, or is not monotonic.
Note
Unevenly spaced values, such from a wrapped longitude range, can produce unexpected results : In such cases you should assign suitable values directly to the bounds property, instead.
- has_lazy_bounds()[source]#
Return a boolean indicating whether the coord’s bounds array is a lazy dask array or not.
- has_lazy_points()[source]#
Return a boolean indicating whether the coord’s points array is a lazy dask array or not.
- property ignore_axis#
A boolean that controls whether guess_coord_axis acts on this coordinate.
Defaults to False, and when set to True it will be skipped by guess_coord_axis.
- intersect(other, return_indices=False)[source]#
Returns a new coordinate from the intersection of two coordinates.
Both coordinates must be compatible as defined by
is_compatible()
.Kwargs:
- return_indices:
If True, changes the return behaviour to return the intersection indices for the “self” coordinate.
- is_compatible(other, ignore=None)[source]#
Return whether the coordinate is compatible with another.
Compatibility is determined by comparing
iris.coords.Coord.name()
,iris.coords.Coord.units
,iris.coords.Coord.coord_system
andiris.coords.Coord.attributes
that are present in both objects.Args:
- other:
An instance of
iris.coords.Coord
,iris.common.CoordMetadata
oriris.common.DimCoordMetadata
.
- ignore:
A single attribute key or iterable of attribute keys to ignore when comparing the coordinates. Default is None. To ignore all attributes, set this to other.attributes.
- Returns:
Boolean.
- is_contiguous(rtol=1e-05, atol=1e-08)[source]#
Return True if, and only if, this Coord is bounded with contiguous bounds to within the specified relative and absolute tolerances.
1D coords are contiguous if the upper bound of a cell aligns, within a tolerance, to the lower bound of the next cell along.
2D coords, with 4 bounds, are contiguous if the lower right corner of each cell aligns with the lower left corner of the cell to the right of it, and the upper left corner of each cell aligns with the lower left corner of the cell above it.
Args:
- rtol:
The relative tolerance parameter (default is 1e-05).
- atol:
The absolute tolerance parameter (default is 1e-08).
- Returns:
Boolean.
- lazy_bounds()[source]#
Return a lazy array representing the coord bounds.
Accessing this method will never cause the bounds values to be loaded. Similarly, calling methods on, or indexing, the returned Array will not cause the coord to have loaded bounds.
If the data have already been loaded for the coord, the returned Array will be a new lazy array wrapper.
- Returns:
A lazy array representing the coord bounds array or None if the coord does not have bounds.
- lazy_points()[source]#
Return a lazy array representing the coord points.
Accessing this method will never cause the points values to be loaded. Similarly, calling methods on, or indexing, the returned Array will not cause the coord to have loaded points.
If the data have already been loaded for the coord, the returned Array will be a new lazy array wrapper.
- Returns:
A lazy array, representing the coord points array.
- property nbounds#
Return the number of bounds that this coordinate has (0 for no bounds).
- nearest_neighbour_index(point)[source]#
Returns the index of the cell nearest to the given point.
Only works for one-dimensional coordinates.
For example:
>>> cube = iris.load_cube(iris.sample_data_path('ostia_monthly.nc')) >>> cube.coord('latitude').nearest_neighbour_index(0) 9 >>> cube.coord('longitude').nearest_neighbour_index(10) 12
Note
If the coordinate contains bounds, these will be used to determine the nearest neighbour instead of the point values.
Note
For circular coordinates, the ‘nearest’ point can wrap around to the other end of the values.
- property points#
The coordinate points values as a NumPy array.
- class iris.coords.CoordExtent(name_or_coord, minimum, maximum, min_inclusive=True, max_inclusive=True)[source]#
Bases:
_CoordExtent
Defines a range of values for a coordinate.
Create a CoordExtent for the specified coordinate and range of values.
Args:
- name_or_coord
Either a coordinate name or a coordinate, as defined in
iris.cube.Cube.coords()
.
- minimum
The minimum value of the range to select.
- maximum
The maximum value of the range to select.
Kwargs:
- min_inclusive
If True, coordinate values equal to minimum will be included in the selection. Default is True.
- max_inclusive
If True, coordinate values equal to maximum will be included in the selection. Default is True.
- static __new__(cls, name_or_coord, minimum, maximum, min_inclusive=True, max_inclusive=True)[source]#
Create a CoordExtent for the specified coordinate and range of values.
Args:
- name_or_coord
Either a coordinate name or a coordinate, as defined in
iris.cube.Cube.coords()
.
- minimum
The minimum value of the range to select.
- maximum
The maximum value of the range to select.
Kwargs:
- min_inclusive
If True, coordinate values equal to minimum will be included in the selection. Default is True.
- max_inclusive
If True, coordinate values equal to maximum will be included in the selection. Default is True.
- iris.coords.DEFAULT_IGNORE_AXIS = False#
The default value for ignore_axis which controls guess_coord_axis’ behaviour
- class iris.coords.DimCoord(points, standard_name=None, long_name=None, var_name=None, units=None, bounds=None, attributes=None, coord_system=None, circular=False, climatological=False)[source]#
Bases:
Coord
A coordinate that is 1D, and numeric, with values that have a strict monotonic ordering. Missing values are not permitted in a
DimCoord
.Create a 1D, numeric, and strictly monotonic coordinate with immutable points and bounds.
Missing values are not permitted.
Args:
- points:
1D numpy array-like of values (or single value in the case of a scalar coordinate) for each cell of the coordinate. The values must be strictly monotonic and masked values are not allowed.
Kwargs:
- standard_name:
CF standard name of the coordinate.
- long_name:
Descriptive name of the coordinate.
- var_name:
The netCDF variable name for the coordinate.
- units:
The
Unit
of the coordinate’s values. Can be a string, which will be converted to a Unit object.
- bounds:
An array of values describing the bounds of each cell. Given n bounds and m cells, the shape of the bounds array should be (m, n). For each bound, the values must be strictly monotonic along the cells, and the direction of monotonicity must be consistent across the bounds. For example, a DimCoord with 100 points and two bounds per cell would have a bounds array of shape (100, 2), and the slices
bounds[:, 0]
andbounds[:, 1]
would be monotonic in the same direction. Masked values are not allowed. Note if the data is a climatology, climatological should be set.
- attributes:
A dictionary containing other CF and user-defined attributes.
- coord_system:
A
CoordSystem
representing the coordinate system of the coordinate, e.g., aGeogCS
for a longitude coordinate.
- circular (bool):
Whether the coordinate wraps by the
modulus
i.e., the longitude coordinate wraps around the full great circle.
- climatological (bool):
When True: the coordinate is a NetCDF climatological time axis. When True: saving in NetCDF will give the coordinate variable a ‘climatology’ attribute and will create a boundary variable called ‘<coordinate-name>_climatology’ in place of a standard bounds attribute and bounds variable. Will set to True when a climatological time axis is loaded from NetCDF. Always False if no bounds exist.
- property bounds#
The coordinate bounds values, as a NumPy array, or None if no bound values are defined.
Note
The shape of the bound array should be:
points.shape + (n_bounds, )
.
- property circular#
Whether the coordinate wraps by
coord.units.modulus
.
- collapsed(dims_to_collapse=None)[source]#
Returns a copy of this coordinate, which has been collapsed along the specified dimensions.
Replaces the points & bounds with a simple bounded region.
- copy(points=None, bounds=None)[source]#
Returns a copy of this coordinate.
Kwargs:
- points: A points array for the new coordinate.
This may be a different shape to the points of the coordinate being copied.
- bounds: A bounds array for the new coordinate.
Given n bounds for each cell, the shape of the bounds array should be points.shape + (n,). For example, a 1d coordinate with 100 points and two bounds per cell would have a bounds array of shape (100, 2).
Note
If the points argument is specified and bounds are not, the resulting coordinate will have no bounds.
- classmethod from_regular(zeroth, step, count, standard_name=None, long_name=None, var_name=None, units=None, attributes=None, coord_system=None, circular=False, climatological=False, with_bounds=False)[source]#
Create a
DimCoord
with regularly spaced points, and optionally bounds.The majority of the arguments are defined as for
Coord
, but those which differ are defined below.Args:
- zeroth:
The value prior to the first point value.
- step:
The numeric difference between successive point values.
- count:
The number of point values.
Kwargs:
- with_bounds:
If True, the resulting DimCoord will possess bound values which are equally spaced around the points. Otherwise no bounds values will be defined. Defaults to False.