validate_dims_coords#

movement.validators.arrays.validate_dims_coords(data, required_dim_coords, exact_coords=False)[source]#

Validate dimensions and coordinates in a data array.

This function raises a ValueError if the specified dimensions and coordinates are not present in the input data array. By default, each dimension must contain at least the specified coordinates. Pass exact_coords=True to require that each dimension contains exactly the specified coordinates (and no others).

Parameters:
  • data (xarray.DataArray) – The input data array to validate.

  • required_dim_coords (dict of {str: list of str}) – A dictionary mapping required dimensions to a list of required coordinate values along each dimension.

  • exact_coords (bool, optional) – If False (default), checks only that the listed coordinates exist in each dimension. If True, checks that each dimension has exactly the specified coordinates and no more. The exactness check is completely skipped for dimensions with no required coordinates.

Return type:

None

Examples

Validate that a data array contains the dimension ‘time’. No specific coordinates are required.

>>> validate_dims_coords(data, {"time": []})

Validate that a data array contains the dimensions ‘time’ and ‘space’, and that the ‘space’ dimension contains the coordinates ‘x’ and ‘y’.

>>> validate_dims_coords(data, {"time": [], "space": ["x", "y"]})

Enforce that ‘space’ has only ‘x’ and ‘y’, and no other coordinates:

>>> validate_dims_coords(data, {"space": ["x", "y"]}, exact_coords=True)
Raises:

ValueError – If the input data does not contain the required dimension(s) and/or the required coordinate(s).