xrdantic.Dataset#

pydantic model xrdantic.Dataset#

Base class for Dataset definitions.

A Dataset represents a collection of DataArrays with shared coordinates. It must have at least one DataArray field and can have coordinate and attribute fields.

Examples

>>> from xrdantic import Dataset, DataArray, Attr, Dim, Data
>>> 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"
>>> class Pressure(DataArray):
...     data: Data[(Time, Y, X), float]
...     time: TimeCoord
...     y: YCoord
...     x: XCoord
...     units: Attr[str] = "pascal"
>>> class WeatherData(Dataset):
...     temperature: Temperature
...     pressure: Pressure
...     x: XCoord
...     y: YCoord
...     station_name: Attr[str] = "Station Alpha"
>>> weather = WeatherData(temperature=temp_array, pressure=pressure_array, x=x_coord, y=y_coord)
>>> xr_weather = weather.to_xarray()
Raises:

ValidationError – If the model doesn’t have at least one DataArray field:

classmethod new(**dataarray_instances)#

Create a new Dataset instance with the given DataArray instances.

Return type:

Dataset

classmethod ones_like_fields(shapes, **coords_and_attrs)#

Create a Dataset with ones for each DataArray field.

Return type:

Dataset

classmethod zeros_like_fields(shapes, **coords_and_attrs)#

Create a Dataset with zeros for each DataArray field.

Return type:

Dataset

to_xarray()#

Convert this model to an xarray Dataset.

Return type:

Dataset