pyrokinetics.dataset_wrapper.DatasetWrapper#

class pyrokinetics.dataset_wrapper.DatasetWrapper(data_vars=None, coords=None, attrs=None, title=None)[source]#

Bases: object

Base class for classes that store their data in an Xarray Dataset. Defines a number of useful functions, such as __getitem__ that redirects to the underlying Dataset, and methods to read or write to disk. Ensures that the underlying Dataset contains metadata about the current session. The user may access the underlying Dataset via self.data.

Parameters:
  • data_vars (Optional[Dict[str, Any]]) – Variables to be passed to the underlying Dataset.

  • coords (Optional[Dict[str, Any]]) – Coordinates to be passed to the underlying Dataset.

  • attrs (Optional[Dict[str,Any]]) – Attributes to be passed to the underlying Dataset. An associated read-only property is created for each attr.

  • title (Optional[str]) – Sets the ‘title’ attribute in the underlying Dataset. Uses the derived class name by default.

__init__(data_vars=None, coords=None, attrs=None, title=None)[source]#
Parameters:
Return type:

None

Methods

__init__([data_vars, coords, attrs, title])

from_netcdf(path, *args[, ...])

Initialise self.data from a netCDF file.

to_netcdf(*args, **kwargs)

Writes self.data to disk.

Attributes

attrs

Redirects to underlying Xarray Dataset attrs.

coords

Redirects to underlying Xarray Dataset coords.

data

Property for managing the underlying Xarray Dataset.

data_vars

Redirects to underlying Xarray Dataset data_vars.

dims

Redirects to underlying Xarray Dataset dims.

property attrs: Dict[str, Any]#

Redirects to underlying Xarray Dataset attrs.

property coords: Mapping[str, DataArray]#

Redirects to underlying Xarray Dataset coords.

property data: Dataset#

Property for managing the underlying Xarray Dataset. The ‘getter’ returns the Dataset without changes, while the ‘setter’ uses the pint-array ‘quantify’ function to ensure units attributes are integrated properly.

property data_vars: Mapping[str, DataArray]#

Redirects to underlying Xarray Dataset data_vars.

property dims: Mapping[str, int]#

Redirects to underlying Xarray Dataset dims.

classmethod from_netcdf(path, *args, overwrite_metadata=False, overwrite_title=None, **kwargs)[source]#

Initialise self.data from a netCDF file.

Parameters:
  • path (PathLike) – Path to the netCDF file on disk.

  • *args – Positional arguments forwarded to xarray.open_dataset.

  • overwrite_metadata (bool, default False) – Take ownership of the netCDF data, overwriting attributes such as ‘title’, ‘software_name’, ‘date_created’, etc.

  • overwrite_title (Optional[str]) – If overwrite_metadata is True, this is used to set the title attribute in self.data. If unset, the derived class name is used.

  • **kwargs – Keyword arguments forwarded to xarray.open_dataset.

Returns:

Instance of a derived class with self.data initialised. Derived classes which need to do more than this should override this method with their own implementation.

Return type:

Derived

Raises:

RuntimeError – If the netcdf is for the wrong type of object.

to_netcdf(*args, **kwargs)[source]#

Writes self.data to disk. Forwards all args to xarray.Dataset.to_netcdf. Complex data is expanded out into float arrays of shape [dims..., 2].

Return type:

None