Motion Correction#

Extensions that are exlusive to motion correction

Accessor: mcorr

class mesmerize_core.MCorrExtensions(s)#

Extensions for managing motion correction outputs

Parameters:

s (Series) –

get_output_path()#

Get the path to the motion corrected output memmap file

Returns:

path to the motion correction output memmap file

Return type:

Path

get_output(mode='r')#

Get the motion corrected output as a memmaped numpy array, allows fast random-access scrolling.

Parameters:

mode (str) –

passed to numpy.memmap

one of: {‘r+’, ‘r’, ‘w+’, ‘c’}

The file is opened in this mode:

’r’

Open existing file for reading only.

’r+’

Open existing file for reading and writing.

’w+’

Create or overwrite existing file for reading and writing.

’c’

Copy-on-write: assignments affect data in memory, but changes are not saved to disk. The file on disk is read-only.

Returns:

memmap numpy array of the motion corrected movie

Return type:

np.ndarray

Examples

This example visualizes the raw movie and mcorr movie side by side. Needs fastplotlib and must be run in a notebook

from mesmerize_core import load_batch
from fastplotlib import ImageWidget

df = load_batch("/path/to/batch_dataframe_file.pickle")

# assumes item at 0th index is a mcorr batch item
input_movie = df.iloc[0].caiman.get_input_movie()
mcorr_movie = df.iloc[0].mcorr.get_output()

mcorr_iw = ImageWidget(
    data=[input_movie, mcorr_movie],
    vmin_vmax_sliders=True,
    cmap="gnuplot2"
)
mcorr_iw.show()
get_shifts(pw_rigid=False)#

Gets file path to shifts array (.npy file) for item, processes shifts array into a list of x and y shifts based on whether rigid or nonrigid motion correction was performed.

Parameters:#

pw_rigid: bool - flag for whether shifts are for rigid or nonrigid motion correction

True = Nonrigid (elastic/piecewise) False = Rigid

Returns:#

List of Processed X and Y shifts arrays

Parameters:

pw_rigid (bool) –

Return type:

Tuple[List[ndarray], List[ndarray]]