import numpy as np import holoviews as hv hv.extension('bokeh', 'matplotlib') data = np.load('../assets/twophoton.npz') calcium_array = data['Calcium'] calcium_array.shape ds = hv.Dataset((np.arange(50), np.arange(111), np.arange(62), calcium_array), ['Time', 'x', 'y'], 'Fluorescence') ds type(ds.data), list(ds.data.keys()) ds.clone(datatype=['xarray']).data %opts Image (cmap='viridis') ds.to(hv.Image, ['x', 'y']).hist() ROIs = data['ROIs'] roi_bounds = hv.Path([hv.Bounds(tuple(roi)) for roi in ROIs]) print(ROIs.shape) %%opts Image [width=400 height=400 xaxis=None yaxis=None] %%opts Path (color='white') Text (text_color='white' text_font_size='8pt') opts = dict(halign='left', valign='bottom') roi_text = hv.NdOverlay({i: hv.Text(roi[0], roi[1], str(i), **opts) for i, roi in enumerate(ROIs)}) (ds[21].to(hv.Image, ['x', 'y']) * roi_bounds * roi_text).relabel('Time: 21') x0, y0, x1, y1 = ROIs[60] roi = ds.select(x=(x0, x1), y=(y0, y1), time=(250, 280)).relabel('ROI #60') roi.to(hv.Image, ['x', 'y']) %%opts GridSpace [shared_xaxis=True shared_yaxis=True] roi.to(hv.Curve, 'Time').grid() %%opts Overlay [show_legend=False width=600] agg = roi.aggregate('Time', np.mean, spreadfn=np.std) hv.Spread(agg) * hv.Curve(agg)