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.
dtype
str or typeEnsure coordinate dtype matches at least one of the given dtypes.
optional
booleandefault
False
- ifTrue
, the dimension has to be in the DataArray daxdimensionality
str or pint.UnitCheck if
.attrs["units"]
is the requested dimensionalityunits
str or pint.UnitCheck if
.attrs["units"]
matches the requested unit
- Parameters:
- Returns:
True, if the test was a success, else an exception is raised
- Return type:
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