home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 191697006

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/706#issuecomment-191697006 https://api.github.com/repos/pydata/xarray/issues/706 191697006 MDEyOklzc3VlQ29tbWVudDE5MTY5NzAwNg== 10050469 2016-03-03T10:29:08Z 2016-03-03T10:29:08Z MEMBER

I find @shoyer 's suggestion about custom accessor attributes very interesting!

the simplest of my use cases would be quite easy to implement:

``` python

MyLib

class MyLibGis(object): def init(self, xray_obj): self.obj = xray_obj self.georef = read_georef(xray_obj)

def subset(self, shapefile=None, roi=None):
    """Return a subset of DataSet (or DataArray)"""
    # compute regions of interests
    slicex, slicey = self.georef(stuff...)
    # return a sel of DataSet
    return self.obj.sel(x=slicex, y=slicey)

xray.register_accessor('gis', MyLibGis)

user code

import mylib import xray ds = xray.DataArray(...) ds = ds.gis.subset(shapefile='/path/to/shape') ```

This would already be quite cool! But would the mechanism allow to pass arguments to the MyLibGis class at construction time? This might also be wordy, maybe something like

ds = xray.DataArray(data, gis={'arg1':42})?

I guess that with these two mechanisms, I would be able to do almost everything I want to do with my netcdf files.

However, one other very important use case for me would be to add lazy "diagnostic" variables to a netcdf dataset. For example, if an atmospheric model output file contains the variables P andPB, then the dataset automatically proposes a new variable TP, which is the sum of P andPB. From the user perspective, this variable is no different than a variable on file. Of course, the data should be computed only on demand. It doesn't seem possible to do this without subclassing, but maybe I missed something?

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