import numpy as np import holoviews as hv 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 %%opts Image [xaxis=None yaxis=None width=225 height=225] (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)) 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