Skip to content

Instantly share code, notes, and snippets.

@shoyer
Last active February 17, 2017 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoyer/26986d85cae05f5b5211eb3f3ebc0851 to your computer and use it in GitHub Desktop.
Save shoyer/26986d85cae05f5b5211eb3f3ebc0851 to your computer and use it in GitHub Desktop.
@xr.register_dataset_accessor('crs')
@xr.register_dataarray_accessor('crs')
def make_crs(xarray_obj):
return xarray_obj.coords['crs'].item()
In [24]: ds = xr.Dataset({'x': 1}, coords={'foo': 'bar', 'crs': 'hello, my lovely unwrapped object'})
In [25]: ds
Out[25]:
<xarray.Dataset>
Dimensions: ()
Coordinates:
foo <U3 'bar'
crs <U33 'hello, my lovely unwrapped object'
Data variables:
x int64 1
In [26]: ds.crs
Out[26]: 'hello, my lovely unwrapped object'
In [27]: ds.foo.crs
Out[27]: 'hello, my lovely unwrapped object'
In [28]: (ds + 10).crs
Out[28]: 'hello, my lovely unwrapped object'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment