Note
This page was generated from a Jupyter notebook. Not all interactive visualization will work on this web page. Consider downloading the notebooks for full Python-backed interactivity.
[ ]:
# holoviews initialization
2. Allign Videos¶
2.1. open datasets¶
All the metadata defined in id_dims will be printed out for each dataset. It is important to make sure all the metadata are correct, otherwise you may get unexpected results. If metadata was not saved correctly, consider putting the datasets into correct hierarchical directory structures and use the post_process argument of open_minian_mf to correct for metadata. See the main pipeline.ipynb and API
reference for more detail.
[5]:
minian_ds = open_minian_mf(
dpath, id_dims, pattern=f_pattern)
opening dataset under /home/runner/work/minian/minian/demo_data/session2
opening minian.nc
['session: session2']
opening dataset under /home/runner/work/minian/minian/demo_data/session1
opening minian.nc
['session: session1']
2.2. estimate shifts¶
Here we estimate a translational shift along the session dimension using the max projection for each dataset. We combine the shifts, original templates temps, and shifted templates temps_sh into a single dataset shiftds to use later.
[6]:
%%time
temps = minian_ds['max_proj'].rename('temps')
shifts = estimate_motion(temps, dim='session').compute().rename('shifts')
temps_sh = apply_transform(temps, shifts).compute().rename('temps_shifted')
shiftds = xr.merge([temps, shifts, temps_sh])
CPU times: user 241 ms, sys: 172 ms, total: 413 ms
Wall time: 430 ms
2.3. visualize alignment¶
We visualize alignment of sessions by plotting the templates before and after the shift for each session.
[7]:
hv.output(size=int(output_size * 0.6))
opts_im = {
'aspect': shiftds.sizes['width'] / shiftds.sizes['height'],
'frame_width': 500, 'cmap': 'viridis'}
hv_temps = (hv.Dataset(temps).to(hv.Image, kdims=['width', 'height'])
.opts(**opts_im).layout('session').cols(1))
hv_temps_sh = (hv.Dataset(temps_sh).to(hv.Image, kdims=['width', 'height'])
.opts(**opts_im).layout('session').cols(1))
display(hv_temps + hv_temps_sh)