import numpy as np import holoviews as hv from holoviews import opts import xarray as xr hv.extension('bokeh') mri_xr = xr.open_dataset('../data/mri.nc') mri_xr mri = hv.Dataset(mri_xr) mri mri.to(hv.Image, groupby='z', dynamic=True) # Exercise: Display transverse (x,z) or frontal (z,y) sections of the data by declaring the kdims in the .to method layout = (mri.to(hv.Image, ['z', 'y'], dynamic=True) + mri.to(hv.Image, ['z', 'x'], dynamic=True) + mri.to(hv.Image, ['x', 'y'], dynamic=True)).redim.range(MR=(0, 255)) layout.opts( opts.Image(xaxis=None, yaxis=None, width=225, height=225)) hv.Image(mri.reduce(z=np.mean)) # Exercise: Recreate the plot above using the aggregate method # Hint: The aggregate and reduce methods are inverses of each other # Try typing "hv.Image(mri.aggregate(" and press shift-Tab to see the signature of `aggregate`. im = hv.Image(mri.reduce(z=np.mean)) im.data