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 viaself.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.
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
Redirects to underlying Xarray Dataset attrs.
Redirects to underlying Xarray Dataset coords.
Property for managing the underlying Xarray Dataset.
Redirects to underlying Xarray Dataset data_vars.
Redirects to underlying Xarray Dataset dims.
- 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.
- 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
, defaultFalse
) – Take ownership of the netCDF data, overwriting attributes such as ‘title’, ‘software_name’, ‘date_created’, etc.overwrite_title (
Optional[str]
) – Ifoverwrite_metadata
isTrue
, this is used to set thetitle
attribute inself.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.