-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
xarray.py
61 lines (45 loc) · 1.85 KB
/
xarray.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import xarray as xr
from panel.widgets import Widget
from .interactive import Interactive
class XArrayInteractive(Interactive):
@classmethod
def applies(cls, obj):
return isinstance(obj, (xr.DataArray, xr.Dataset))
def sel(self, **kwargs):
processed = {}
for k, v in kwargs.items():
if isinstance(v, type) and issubclass(v, Widget):
if hasattr(v, 'end'):
values = self._current[k].values
v = v(name=k, start=values.min(), end=values.max())
if hasattr(v, 'options'):
v = v(name=k, options={str(v): v for v in self._current[k].values})
processed[k] = v
self._method = 'sel'
return self.__call__(**processed)
sel.__doc__ = xr.DataArray.sel.__doc__
def isel(self, **kwargs):
processed = {}
for k, v in kwargs.items():
if isinstance(v, type) and issubclass(v, Widget):
if hasattr(v, 'end'):
v = v(name=k, end=len(self._current[k]))
processed[k] = v
self._method = 'isel'
return self.__call__(**processed)
isel.__doc__ = xr.DataArray.isel.__doc__
def patch(name='hvplot', interactive='interactive', extension='bokeh', logo=False):
from . import hvPlot, post_patch
try:
import xarray as xr
except:
raise ImportError('Could not patch plotting API onto xarray. '
'xarray could not be imported.')
# Remove the class docstring as it very developer focused
XArrayInteractive.__doc__ = ""
xr.register_dataset_accessor(name)(hvPlot)
xr.register_dataarray_accessor(name)(hvPlot)
xr.register_dataset_accessor(interactive)(XArrayInteractive)
xr.register_dataarray_accessor(interactive)(XArrayInteractive)
post_patch(extension, logo)
patch()