home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 428152588

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/2473#issuecomment-428152588 https://api.github.com/repos/pydata/xarray/issues/2473 428152588 MDEyOklzc3VlQ29tbWVudDQyODE1MjU4OA== 35968931 2018-10-09T11:10:46Z 2018-10-09T11:10:46Z MEMBER

Accessors should only accept one argument, which is an xarray.Dataset.

Ah - I misunderstood how they work, if I do this:

```python @xr.register_dataset_accessor('bout') class BoutDataset(object): def init(self, ds_object): self.data = ds_object

def plot_tokamak():
    plot_in_bout_specific_way(self.data, self.extra_data)

then I can successfully use it like this:python ds = collect_data(path)

ds.bout.plot_tokamak() print(ds.bout.data) ``` Thanks!

What does your extra_data look like? Would it be possible to put it into xarray in the form of coordinates or attributes?

My extra_data is a nested-dictionary-like object containing everything in the simulation input file. This I can store in the attributes dictionary (that's what I'm doing at the moment), but I'm still interested in the problem of attaching arbitrary objects because because losing the attributes on operations is annoying and I envisage either myself or other users of the code wanting to store more complicated structures in the future. (For example an xgcm grid object)

Also the philosophy of the BOUT framework encourages each group of users to add their own functionality depending on what exactly they are solving. Some kind of base BoutDataset class which could then be further subclassed to add more specific functionality would fit best with this system. Would it be a terrible idea to subclass xr.Dataset into a BoutDataset, then decorate every inherited method by looping over them so that my extra attached objects are dealt with appropriately (maybe like this)? Would that not in theory give me the whole API of xarray while allowing me to attach arbitrary objects and methods to my class, and allowing further subclassing if desired?

(Sorry if this is too far off the topic of xarray, feel free to close it if you think this is not going to be relevant to any of the rest of the community.)

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  367763373
Powered by Datasette · Queries took 0.897ms · About: xarray-datasette