xarray_dataclasses package#

Submodules#

Module contents#

class AsDataArray[source]#

Bases: object

Mix-in class that provides shorthand methods.

classmethod empty(shape: Sequence[int] | int | Dict[str, int], order: Literal['C', 'F'] = 'C', **kwargs: Any) TDataArray[source]#
classmethod empty(shape: Sequence[int] | int | Dict[str, int], order: Literal['C', 'F'] = 'C', **kwargs: Any) 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: Sequence[int] | int | Dict[str, int], fill_value: Any, order: Literal['C', 'F'] = 'C', **kwargs: Any) TDataArray[source]#
classmethod full(shape: Sequence[int] | int | Dict[str, int], fill_value: Any, order: Literal['C', 'F'] = 'C', **kwargs: Any) 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: Sequence[int] | int | Dict[str, int], order: Literal['C', 'F'] = 'C', **kwargs: Any) TDataArray[source]#
classmethod ones(shape: Sequence[int] | int | Dict[str, int], order: Literal['C', 'F'] = 'C', **kwargs: Any) 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[[Sequence[int] | int], ndarray[Any, Any]], shape: Sequence[int] | int | Dict[str, int], **kwargs: Any) TDataArray[source]#
classmethod shaped(func: Callable[[Sequence[int] | int], ndarray[Any, Any]], shape: Sequence[int] | int | Dict[str, int], **kwargs: Any) 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: Sequence[int] | int | Dict[str, int], order: Literal['C', 'F'] = 'C', **kwargs: Any) TDataArray[source]#
classmethod zeros(shape: Sequence[int] | int | Dict[str, int], order: Literal['C', 'F'] = 'C', **kwargs: Any) 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: Dict[str, int], order: Literal['C', 'F'] = 'C', **kwargs: Any) TDataset[source]#
classmethod empty(sizes: Dict[str, int], order: Literal['C', 'F'] = 'C', **kwargs: Any) 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: Dict[str, int], fill_value: Any, order: Literal['C', 'F'] = 'C', **kwargs: Any) TDataset[source]#
classmethod full(sizes: Dict[str, int], fill_value: Any, order: Literal['C', 'F'] = 'C', **kwargs: Any) 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: Dict[str, int], order: Literal['C', 'F'] = 'C', **kwargs: Any) TDataset[source]#
classmethod ones(sizes: Dict[str, int], order: Literal['C', 'F'] = 'C', **kwargs: Any) 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[[Sequence[int] | int], ndarray[Any, Any]], sizes: Dict[str, int], **kwargs: Any) TDataset[source]#
classmethod shaped(func: Callable[[Sequence[int] | int], ndarray[Any, Any]], sizes: Dict[str, int], **kwargs: Any) 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: Dict[str, int], order: Literal['C', 'F'] = 'C', **kwargs: Any) TDataset[source]#
classmethod zeros(sizes: Dict[str, int], order: Literal['C', 'F'] = 'C', **kwargs: Any) 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