Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Unsure of best way to access xr.Dataset methods #2

Closed
TomNicholas opened this issue Oct 8, 2018 · 1 comment
Closed

Unsure of best way to access xr.Dataset methods #2

TomNicholas opened this issue Oct 8, 2018 · 1 comment

Comments

@TomNicholas
Copy link
Owner

(described in more detail at pydata/xarray#2473)

I want to make a BoutDataset class which contains extra attributes to hold information about the run which doesn't naturally fit into the xarray data model, extra methods to perform analysis/plotting which only users of this code would require, but also be able to use xarray-specific methods and top-level functions:

bd = BoutDataset('/path/to/data')

ds = bd.data  # access the wrapped xarray dataset
extra_data = bd.extra_data  # access the BOUT-specific data

bd.isel(time=-1)  # use xarray dataset methods

bd2 = BoutDataset('/path/to/other/data')
concatenated_bd = xr.concat([bd, bd2])  # apply top-level xarray functions to the data

bd.plot_tokamak()  # methods implementing bout-specific functionality

I'm not sure what the best way to do this is. My current approach uses xr.register_dataset_accessor.

@TomNicholas
Copy link
Owner Author

This was closed by adding the ability to always keep attributes on operations in xarray (pydata/xarray#2482).

This means that as long as the desired data is stored either in the dataset variables or in the attrs dictionary it will be preserved across operations, and therefore we can just use xarray.Dataset to hold everything, and implement BOUT-specific methods using the xarray accessors.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant