weldx.util.xr_check_coords#

weldx.util.xr_check_coords(coords, ref)#

Validate the coordinates of the DataArray against a reference dictionary.

The reference dictionary should have the dimensions as keys and those contain dictionaries with the following keywords (all optional):

values

Specify exact coordinate values to match.

dtypestr or type

Ensure coordinate dtype matches at least one of the given dtypes.

optionalboolean

default False - if True, the dimension has to be in the DataArray dax

dimensionalitystr or pint.Unit

Check if .attrs["units"] is the requested dimensionality

unitsstr or pint.Unit

Check if .attrs["units"] matches the requested unit

Parameters:
  • coords (DataArray | Mapping[str, Any]) – xarray object or coordinate mapping that should be validated

  • ref (dict) – reference dictionary

Returns:

True, if the test was a success, else an exception is raised

Return type:

bool

Examples

>>> import numpy as np
>>> import pandas as pd
>>> import xarray as xr
>>> import weldx as wx
>>> dax = xr.DataArray(
...     data=np.ones((3, 2, 3)),
...     dims=["d1", "d2", "d3"],
...     coords={
...         "d1": np.array([-1, 0, 2], dtype=int),
...         "d2": pd.DatetimeIndex(["2020-05-01", "2020-05-03"]),
...         "d3": ["x", "y", "z"],
...     }
... )
>>> ref = dict(
...     d1={"optional": True, "values": np.array([-1, 0, 2], dtype=int)},
...     d2={
...         "values": pd.DatetimeIndex(["2020-05-01", "2020-05-03"]),
...         "dtype": ["datetime64[ns]", "timedelta64[ns]"],
...     },
...     d3={"values": ["x", "y", "z"], "dtype": "<U1"},
... )
>>> wx.util.xr_check_coords(dax, ref)
True