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:
_DimensionalMetadataConstruct a single ancillary variable.
- Parameters:
data – The values of the ancillary variable.
standard_name (optional, default=None) – CF standard name of the ancillary variable.
long_name (optional, default=None) – Descriptive name of the ancillary variable.
var_name (optional, default=None) – The netCDF variable name for the ancillary variable.
units (optional, default=None) – The
Unitof the ancillary variable’s values. Can be a string, which will be converted to a Unit object.attributes (optional, default=None) – A dictionary containing other cf and user-defined attributes.
- core_data()[source]#
Return data array at the core of this ancillary variable.
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]#
Indicate 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.
- Return type:
A lazy array, representing the ancillary variable data array.
- class iris.coords.AuxCoord(*args, **kwargs)[source]#
Bases:
CoordA CF auxiliary coordinate.
Create a coordinate with mutable points and bounds.
- Parameters:
points – The values (or value in the case of a scalar coordinate) for each cell of the coordinate.
standard_name (optional) – CF standard name of the coordinate.
long_name (optional) – Descriptive name of the coordinate.
var_name (optional) – The netCDF variable name for the coordinate.
unit (
Unit, optional) – TheUnitof the coordinate’s values. Can be a string, which will be converted to a Unit object.bounds (optional) – 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 (optional) – A dictionary containing other CF and user-defined attributes.
coord_system (
CoordSystem, optional) – ACoordSystemrepresenting the coordinate system of the coordinate, e.g., aGeogCSfor a longitude coordinate.bool (climatological) – 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.
optional – 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:
CellA coordinate cell containing a single point, or point and bounds.
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 equality comparison.
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:
AncillaryVariableA CF Cell Measure, providing area or volume properties of a cell.
A CF Cell Measure, providing area or volume properties of a cell where these cannot be inferred from the Coordinates and Coordinate Reference System.
Construct a single cell measure.
- Parameters:
data – The values of the measure for each cell. Either a ‘real’ array (
numpy.ndarray) or a ‘lazy’ array (dask.array.Array).standard_name (optional, default=None) – CF standard name of the coordinate.
long_name (optional, default=None) – Descriptive name of the coordinate.
var_name (optional, default=None) – The netCDF variable name for the coordinate.
units (optional, default=None) – The
Unitof the coordinate’s values. Can be a string, which will be converted to a Unit object.attributes (optional, default=None) – A dictionary containing other CF and user-defined attributes.
measure (optional) – 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.Elementthat describes thisCellMeasure.- Parameters:
doc – The parent
xml.dom.minidom.Document.- Returns:
The
xml.dom.minidom.Elementthat describes thisCellMeasure.- Return type:
xml.dom.minidom.Element
- class iris.coords.CellMethod(method, coords=None, intervals=None, comments=None)[source]#
Bases:
_OrderedHashableRepresents a sub-cell pre-processing operation.
Call Method initialise.
- Parameters:
method – The name of the operation.
coords (
Coordinstances, optional) – A single instance or sequence ofCoordinstances or coordinate names.intervals (optional) – A single string, or a sequence strings, describing the intervals within the cell method.
comments (optional) – 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.Elementthat describes thisCellMethod.- Parameters:
doc – The parent
xml.dom.minidom.Document.- Returns:
The
xml.dom.minidom.Elementthat describes thisCellMethod.- Return type:
xml.dom.minidom.Element
- 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:
_DimensionalMetadataAbstract base class for coordinates.
Coordinate abstract base class.
As of
v3.0.0you cannot create an instance ofCoord.- Parameters:
points – The values (or value in the case of a scalar coordinate) for each cell of the coordinate.
standard_name (optional, default=None) – CF standard name of the coordinate.
long_name (optional, default=None) – Descriptive name of the coordinate.
var_name (optional, default=None) – The netCDF variable name for the coordinate.
units (optional, default=None) – The
Unitof the coordinate’s values. Can be a string, which will be converted to a Unit object.bounds (optional, default=None) – 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 (optional, default=None) – A dictionary containing other CF and user-defined attributes.
coord_system (optional, default=None) – A
CoordSystemrepresenting the coordinate system of the coordinate, e.g., aGeogCSfor a longitude coordinate.climatological (bool, optional, default=False) – 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#
Coordinate bounds values.
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 coordinates bounds.
The NumPy dtype of the coord’s bounds. Will be None if the coord does not have bounds.
- cell(index)[source]#
Point/bound cell at the given coordinate index.
Return the single
Cellinstance which results from slicing the points/bounds with the given index.
- cells()[source]#
Return an iterable of Cell instances for this Coord.
For example:
for cell in self.cells(): ...
- property climatological#
Flag for representing a climatological time axis.
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]#
Return 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]#
Contiguous bounds of 1D coordinate.
Return 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
unitsattribute is set to radians then:coord.convert_units('degrees')
will change the coordinate’s
unitsattribute to degrees and multiply each value inpointsandboundsby 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]#
Return a copy of this coordinate.
- 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).
Notes
Note
If the points argument is specified and bounds are not, the resulting coordinate will have no bounds.
- core_bounds()[source]#
Core bounds. The points array at the core of this coord, which may be a NumPy array or a dask array.
- core_points()[source]#
Core 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.
- Parameters:
bound_position (optional, default=0.5) – The desired position of the bounds relative to the position of the points.
Notes
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]#
Whether coordinate bounds are lazy.
Return a boolean indicating whether the coord’s bounds array is a lazy dask array or not.
- has_lazy_points()[source]#
Return a boolean 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]#
Return a new coordinate from the intersection of two coordinates.
Both coordinates must be compatible as defined by
is_compatible().- Parameters:
return_indices (optional, default=False) – 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_systemandiris.coords.Coord.attributesthat are present in both objects.- Parameters:
other – An instance of
iris.coords.Coord,iris.common.CoordMetadataoriris.common.DimCoordMetadata.ignore (optional) – 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.
- Return type:
- is_contiguous(rtol=1e-05, atol=1e-08)[source]#
Whether coordinate has contiguous bounds.
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.
- Parameters:
rtol (optional) – The relative tolerance parameter (default is 1e-05).
atol (optional) – The absolute tolerance parameter (default is 1e-08).
- Return type:
- 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.
- Return type:
lazy array
- 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.
- Return type:
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]#
Return 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:
_CoordExtentDefines a range of values for a coordinate.
Create a CoordExtent for the specified coordinate and range of values.
- Parameters:
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.
min_inclusive (optional) – If True, coordinate values equal to minimum will be included in the selection. Default is True.
max_inclusive (optional) – 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.
- Parameters:
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.
min_inclusive (optional) – If True, coordinate values equal to minimum will be included in the selection. Default is True.
max_inclusive (optional) – 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:
CoordA 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.
- Parameters:
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.
standard_name (optional, default=None) – CF standard name of the coordinate.
long_name (optional, default=None) – Descriptive name of the coordinate.
var_name (optional, default=None) – The netCDF variable name for the coordinate.
units (
Unit, optional, default=None) – TheUnitof the coordinate’s values. Can be a string, which will be converted to a Unit object.bounds (optional, default=None) – 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 (optional, default=None) – A dictionary containing other CF and user-defined attributes.
coord_system (
CoordSystem, optional, default=None) – ACoordSystemrepresenting the coordinate system of the coordinate, e.g., aGeogCSfor a longitude coordinate.circular (bool, optional, default=False) – Whether the coordinate wraps by the
modulusi.e., the longitude coordinate wraps around the full great circle.climatological (bool, optional, default=False) – 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#
Coordinate bounds values.
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]#
Return 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]#
Return a copy of this coordinate.
- 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).
Notes
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
DimCoordwith regularly spaced points, and optionally bounds.The majority of the arguments are defined as for
Coord, but those which differ are defined below.- Parameters:
zeroth – The value prior to the first point value.
step – The numeric difference between successive point values.
count – The number of point values.
with_bounds (optional) – 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.