import numpy as np import holoviews as hv from holoviews import opts 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()) opts.defaults( opts.GridSpace(shared_xaxis=True, shared_yaxis=True), opts.Image(cmap='viridis', width=400, height=400), opts.Labels(text_color='white', text_font_size='8pt', text_align='left', text_baseline='bottom'), opts.Path(color='white'), opts.Spread(width=600), opts.Overlay(show_legend=False)) 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) labels = hv.Labels([(roi[0], roi[1], i) for i, roi in enumerate(ROIs)]) (ds[21].to(hv.Image, ['x', 'y']) * roi_bounds * labels).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']) roi.to(hv.Curve, 'Time').grid() agg = roi.aggregate('Time', np.mean, spreadfn=np.std) hv.Spread(agg) * hv.Curve(agg)