вот решение, которое использует xarray
для управления набором данных.
import numpy as np
import holoviews as hv
from holoviews import opts
import param
import panel as pn
import panel.widgets as pnw
import xarray as xr
hv.extension('bokeh', 'matplotlib')
data = np.random.rand(10, 3, 100, 100)
times = np.arange(0,10)
channels=['a','b','c']
da = xr.DataArray(
data,
[
("t", times),
("c", channels),
("y", np.linspace(0., 1., 100)),
("x", np.linspace(0., 1., 100)),
],
)
ds = da.to_dataset(name="T")
class Parameters(param.Parameterized):
select_channel = param.Selector(default=channels[0], objects=channels)
select_time = param.Integer(default=int(times[0]), bounds=(0, int(len(times)-1) ) )
@param.depends('select_time','select_channel')
def plots(self):
if self.select_channel == channels[0]:
img = hv.Image(hv.Dataset(ds.loc[dict(c=self.select_channel,t=self.select_time)]))
cmap = 'inferno'
elif self.select_channel == channels[1]:
img = hv.Image(hv.Dataset(ds.loc[dict(c=self.select_channel,t=self.select_time)]))
cmap = 'jet'
else:
img = hv.Image(hv.Dataset(ds.loc[dict(c=self.select_channel,t=self.select_time)]))
cmap = 'gray'
frame_width = 500
return img.opts( cmap=cmap,
frame_width=frame_width,
frame_height=np.int(np.round(frame_width * ds.dims['y']/ds.dims['x'],0)),
framewise=False, axiswise=False, colorbar=False, aspect='equal',
fontsize={'title': 16,})
obj = Parameters()
fire_dmap = hv.DynamicMap(obj.plots)
widgets_parameters = pn.panel(obj.param, parameters=['select_channel','select_time'],width=200)
app = pn.Row(widgets_parameters, fire_dmap)
app