"""Wrappers for the Xarray ``Variable`` class to represent data and dimensionalcoordinates when creating a data log."""from__future__importannotationsfromcollections.abcimportSequencefromnumpy.typingimportArrayLikeimportxarrayasxrclass_Variable:"""Wrapper for an Xarray ``Variable``."""# pylint: disable-next=too-many-argumentsdef__init__(self,name:str,dims:str|Sequence[str],data:ArrayLike,long_name:str|None=None,units:str|None=None,)->None:self._name=nameattrs={}iflong_nameisnotNone:attrs["long_name"]=long_nameifunitsisnotNone:attrs["units"]=unitsself._variable=xr.Variable(dims,data,attrs)@propertydefname(self)->str:"""Name of this coordinate or data."""returnself._name@propertydefvariable(self)->xr.Variable:""" Underlying Xarray ``Variable`` object. See https://docs.xarray.dev/en/stable/generated/xarray.Variable.html. """returnself._variable
[docs]classCoord(_Variable):""" Wrapper for an Xarray ``Variable`` representing a dimensional coordinate. - ``name`` is used as the coordinate and dimension name. - ``data`` should be a 1D array labeling points along the dimension. - ``long_name`` and ``units`` are stored in the underlying variable's attribute dictionary. See https://docs.xarray.dev/en/stable/user-guide/data-structures.html#coordinates for more information on coordinates in Xarray. """def__init__(self,name:str,data:ArrayLike,long_name:str|None=None,units:str|None=None,)->None:super().__init__(name,name,data,long_name,units)
[docs]classDataVar(_Variable):""" Wrapper for an Xarray ``Variable`` representing a data variable along particular dimensions. - ``data`` should be an array that aligns with the named dimensions. - ``long_name`` and ``units`` are stored in the underlying variable's attribute dictionary. """