xrdantic.DataArray#
- pydantic model xrdantic.DataArray#
Base class for DataArray definitions.
A DataArray represents a labeled, multi-dimensional array with coordinates and attributes. It must have exactly one data field and can have multiple coordinate and attribute fields.
Examples
>>> from xrdantic import DataArray, Data, Attr, Dim >>> import numpy as np
>>> Time = Dim("time") >>> Y = Dim("y") >>> X = Dim("x") >>> class Temperature(DataArray): ... data: Data[(Time, Y, X), float] ... time: TimeCoord ... y: YCoord ... x: XCoord ... units: Attr[str] = "celsius"
>>> temp = Temperature(data=np.random.random((10, 5, 3)), time=time_coord, y=y_coord, x=x_coord) >>> xr_temp = temp.to_xarray()
- Raises:
ValidationError – If the model doesn’t have exactly one data field:
ValidationError – If coordinate dimensions don’t match data dimensions:
- classmethod empty(shape, **coords_and_attrs)#
Create an uninitialized DataArray.
- Return type:
- classmethod full(shape, fill_value, **coords_and_attrs)#
Create a DataArray filled with a constant value.
- Return type:
- classmethod new(**field_values)#
Create a new DataArray instance with the given field values.
- classmethod ones(shape, **coords_and_attrs)#
Create a DataArray filled with ones.
- Return type:
- classmethod random(size, **coords_and_attrs)#
Create a DataArray filled with random values.
- Return type:
- classmethod zeros(shape, **coords_and_attrs)#
Create a DataArray filled with zeros.
- Return type: