xarray_dataclasses package#

Submodules#

Module contents#

class AsDataArray[source]#

Bases: object

Mix-in class that provides shorthand methods.

classmethod empty(shape: Shape | Sizes, order: Order = 'C', **kwargs: Any) TDataArray[source]#
classmethod empty(shape: Shape | Sizes, order: Order = 'C', **kwargs: Any) xr.DataArray

Create a DataArray object without initializing data.

Parameters:
  • shape – Shape or sizes of the new DataArray object.

  • order – Whether to store data in row-major (C-style) or column-major (Fortran-style) order in memory.

  • kwargs – Args of the DataArray class except for data.

Returns:

DataArray object without initializing data.

classmethod full(shape: Shape | Sizes, fill_value: Any, order: Order = 'C', **kwargs: Any) TDataArray[source]#
classmethod full(shape: Shape | Sizes, fill_value: Any, order: Order = 'C', **kwargs: Any) xr.DataArray

Create a DataArray object filled with given value.

Parameters:
  • shape – Shape or sizes of the new DataArray object.

  • fill_value – Value for the new DataArray object.

  • order – Whether to store data in row-major (C-style) or column-major (Fortran-style) order in memory.

  • kwargs – Args of the DataArray class except for data.

Returns:

DataArray object filled with given value.

new(*args: Any, **kwargs: Any) Any[source]#

Create a DataArray object from dataclass parameters.

Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

Any

classmethod ones(shape: Shape | Sizes, order: Order = 'C', **kwargs: Any) TDataArray[source]#
classmethod ones(shape: Shape | Sizes, order: Order = 'C', **kwargs: Any) xr.DataArray

Create a DataArray object filled with ones.

Parameters:
  • shape – Shape or sizes of the new DataArray object.

  • order – Whether to store data in row-major (C-style) or column-major (Fortran-style) order in memory.

  • kwargs – Args of the DataArray class except for data.

Returns:

DataArray object filled with ones.

classmethod shaped(func: Callable[[Shape], AnyArray], shape: Shape | Sizes, **kwargs: Any) TDataArray[source]#
classmethod shaped(func: Callable[[Shape], AnyArray], shape: Shape | Sizes, **kwargs: Any) xr.DataArray

Create a DataArray object from a shaped function.

Parameters:
  • func – Function to create an array with given shape.

  • shape – Shape or sizes of the new DataArray object.

  • kwargs – Args of the DataArray class except for data.

Returns:

DataArray object created from the shaped function.

classmethod zeros(shape: Shape | Sizes, order: Order = 'C', **kwargs: Any) TDataArray[source]#
classmethod zeros(shape: Shape | Sizes, order: Order = 'C', **kwargs: Any) xr.DataArray

Create a DataArray object filled with zeros.

Parameters:
  • shape – Shape or sizes of the new DataArray object.

  • order – Whether to store data in row-major (C-style) or column-major (Fortran-style) order in memory.

  • kwargs – Args of the DataArray class except for data.

Returns:

DataArray object filled with zeros.

class AsDataset[source]#

Bases: object

Mix-in class that provides shorthand methods.

classmethod empty(sizes: Sizes, order: Order = 'C', **kwargs: Any) TDataset[source]#
classmethod empty(sizes: Sizes, order: Order = 'C', **kwargs: Any) xr.Dataset

Create a Dataset object without initializing data vars.

Parameters:
  • sizes – Sizes of the new Dataset object.

  • order – Whether to store data in row-major (C-style) or column-major (Fortran-style) order in memory.

  • kwargs – Args of the Dataset class except for data vars.

Returns:

Dataset object without initializing data vars.

classmethod full(sizes: Sizes, fill_value: Any, order: Order = 'C', **kwargs: Any) TDataset[source]#
classmethod full(sizes: Sizes, fill_value: Any, order: Order = 'C', **kwargs: Any) xr.Dataset

Create a Dataset object whose data vars are filled with given value.

Parameters:
  • sizes – Sizes of the new Dataset object.

  • fill_value – Value for data vars of the new Dataset object.

  • order – Whether to store data in row-major (C-style) or column-major (Fortran-style) order in memory.

  • kwargs – Args of the Dataset class except for data vars.

Returns:

Dataset object whose data vars are filled with given value.

new(*args: Any, **kwargs: Any) Any[source]#

Create a Dataset object from dataclass parameters.

Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

Any

classmethod ones(sizes: Sizes, order: Order = 'C', **kwargs: Any) TDataset[source]#
classmethod ones(sizes: Sizes, order: Order = 'C', **kwargs: Any) xr.Dataset

Create a Dataset object whose data vars are filled with ones.

Parameters:
  • sizes – Sizes of the new Dataset object.

  • order – Whether to store data in row-major (C-style) or column-major (Fortran-style) order in memory.

  • kwargs – Args of the Dataset class except for data vars.

Returns:

Dataset object whose data vars are filled with ones.

classmethod shaped(func: Callable[[Shape], AnyArray], sizes: Sizes, **kwargs: Any) TDataset[source]#
classmethod shaped(func: Callable[[Shape], AnyArray], sizes: Sizes, **kwargs: Any) xr.Dataset

Create a Dataset object from a shaped function.

Parameters:
  • func – Function to create an array with given shape.

  • sizes – Sizes of the new Dataset object.

  • kwargs – Args of the Dataset class except for data vars.

Returns:

Dataset object created from the shaped function.

classmethod zeros(sizes: Sizes, order: Order = 'C', **kwargs: Any) TDataset[source]#
classmethod zeros(sizes: Sizes, order: Order = 'C', **kwargs: Any) xr.Dataset

Create a Dataset object whose data vars are filled with zeros.

Parameters:
  • sizes – Sizes of the new Dataset object.

  • order – Whether to store data in row-major (C-style) or column-major (Fortran-style) order in memory.

  • kwargs – Args of the Dataset class except for data vars.

Returns:

Dataset object whose data vars are filled with zeros.

class DataModel(entries: ~typing.Dict[str, ~xarray_dataclasses.datamodel.AttrEntry | ~xarray_dataclasses.datamodel.DataEntry] = <factory>)[source]#

Bases: object

Data representation (data model) inside the package.

Parameters:

entries (Dict[str, AttrEntry | DataEntry]) –

property attrs: List[AttrEntry]#

Return a list of attribute entries.

property coords: List[DataEntry]#

Return a list of coordinate entries.

property data_vars: List[DataEntry]#

Return a list of data variable entries.

property data_vars_items: List[Tuple[str, DataEntry]]#

Return a list of data variable entries with keys.

entries: Dict[str, AttrEntry | DataEntry]#

Entries of data variable(s) and attribute(s).

classmethod from_dataclass(dataclass: Type[DataClass[PInit]] | DataClass[PInit]) DataModel[source]#

Create a data model from a dataclass or its object.

Parameters:

dataclass (Type[DataClass[~PInit]] | DataClass[~PInit]) –

Return type:

DataModel

property names: List[AttrEntry]#

Return a list of name entries.

class DataOptions(factory: Callable[[...], TAnyXarray])[source]#

Bases: Generic[TAnyXarray]

Options for DataArray or Dataset creation.

Parameters:

factory (Callable[[...], TAnyXarray]) –

factory: Callable[[...], TAnyXarray]#

Factory function for DataArray or Dataset.

asdataarray(dataclass: Any, reference: DataArray | Dataset | None = None, dataoptions: Any = None) Any[source]#

Create a DataArray object from a dataclass object.

Parameters:
  • dataclass (Any) – Dataclass object that defines typed DataArray.

  • reference (DataArray | Dataset | None) – DataArray or Dataset object as a reference of shape.

  • dataoptions (Any) – Options for DataArray creation.

Returns:

DataArray object created from the dataclass object.

Return type:

Any

asdataset(dataclass: Any, reference: DataArray | Dataset | None = None, dataoptions: Any = None) Any[source]#

Create a Dataset object from a dataclass object.

Parameters:
  • dataclass (Any) – Dataclass object that defines typed Dataset.

  • reference (DataArray | Dataset | None) – DataArray or Dataset object as a reference of shape.

  • dataoptions (Any) – Options for Dataset creation.

Returns:

Dataset object created from the dataclass object.

Return type:

Any