Experiment

class seas.experiment.Experiment(pathlist: List[str], downsample: int = False, downsample_t: int = False, n_rotations: int = 0, rotate_rois_with_video: bool = False)[source]

Bases: object

A class to store mesoscale calcium imaging experiment information and provide functions used for common experiment and video manipulations. Includes functionality for loading and rotating videos, cropping to a specific region of interest (defined by user input and/or roi files, loading and storing yaml metadata, etc.)

downsample

The spatial downsampling factor.

downsample_t

The temporal downsampling factor.

movie

The loaded raw movie file .

path

The pathlist of loaded videos.

n_rotations

The number of times the video was rotated.

rotate_rois_with_video

Whether rois are rotated with the video or not.

bounding_box

The bounding coordinates selected for the content of interest from the video file.

shape

The video shape.

name

The detected name of the experiment from the input files.

dir

The directory the video files reside in.

The following attributes are also available if rois are loaded:
n_roi_rotations:

The number of times the rois were rotated.

rois:

The roi dictionary loaded from FIJI RoiSet.zip file.

roimask:

A binary masked array denoting where the movie should be masked.

meta:

The experiment metadata loaded from a yaml file.

Functions:
load_rois:

Load rois from a FIJI RoiSet.zip file.

load_meta:

Load metadata from a yaml file.

rotate:

Rotate the video CCW, adjust mask and bounding box accordingly.

define_mask_boundaries:

Auto detect the mask boundaries from the loaded roimask.

draw_bounding_box:

Launch a GUI to draw a bounding box to crop the movie.

bound_mask:

Returns the mask bound to the bounding box.

bound_movie:

Returns the movie bound to the bounding box.

ica_project:

Perform an ICA projection to the movie.

Initialization Arguments:
pathlist:

The list of paths to load raw video data from, in order. To sort, use seas.filemanager functions.

downsample:

An integer factor to spatially downsample frames with. Implements an integer averaging spatial downsample where downsample x downsample pixels are reduced to 1.

downsample_t:

An integer factor to spatially downsample frames with. Takes the mean between sets of downsample_t frames.

n_rotations:

The number of ccw rotations to rotate the video.

rotate_rois_with_video:

If true, rotate all loaded rois by n_rotations as well.

Methods Summary

bound_mask([bounding_box])

Returns the roimask cropped by the bounding box.

bound_movie([movie, bounding_box])

Returns the movie cropped by the bounding box.

define_mask_boundaries()

Updates the experiment bounding_box to go up to the edge of the rois previously loaded by load_rois.

draw_bounding_box()

Launches an opencv GUI to click and define a bounding box for the video.

ica_project([movie, savedata, calc_dfof, …])

Apply an ica decomposition to the experiment.

load_meta(meta_path)

Load metadata to the experiment file.

load_rois(path[, n_roi_rotations])

Load rois set in an FIJI/ImageJ RoiSet.zip file to the experiment file, and creates a roimask based on the rois.

rotate()

Rotates movie by self.n_rotations, and updates the shape and bounding box to reflect this change.

Methods Documentation

bound_mask(bounding_box: Optional[List[List[int]]] = None)numpy.ndarray[source]

Returns the roimask cropped by the bounding box.

bound_movie(movie: Optional[numpy.ndarray] = None, bounding_box: Optional[List[List[int]]] = None)numpy.ndarray[source]

Returns the movie cropped by the bounding box.

define_mask_boundaries()[source]

Updates the experiment bounding_box to go up to the edge of the rois previously loaded by load_rois.

draw_bounding_box()[source]

Launches an opencv GUI to click and define a bounding box for the video. Click and drag to assign the bounding box borders.

ica_project(movie: Optional[numpy.ndarray] = None, savedata: bool = True, calc_dfof: bool = True, del_movie: bool = True, n_components: Optional[int] = None, svd_multiplier: Optional[float] = None, suffix: str = '', output_folder: Optional[str] = None, mean_filter_method: str = 'wavelet', low_cutoff: float = 0.5)dict[source]

Apply an ica decomposition to the experiment. If rois and/or a bounding box have been defined, these will be used to crop the movie before filtration.

By default, results are all saved to a [experiment]_[parameters]_ica.hdf5 file in the same directory as the original video files.

Parameters
  • movie – The movie to apply ica decomposition to. If left blank, the movie cropped by the roimask and bounding box is used.

  • save_data – Whether to save components to a file, or just return as a variable.

  • calc_dfof – If true, calculate the dFoF before applying ICA decomposition. If false, ICA is computed on the raw movie.

  • del_movie – If true, delete the original full movie array before decomposition to save memory.

  • n_components – A specified number of components to project. If left as None, the svd_multiplier auto component selection is used.

  • svd_multiplier – The factor to multiply by the detected SVD noise threshold while estimating the number of ICA components to identify. When left blank, the automatic value set in seas.ica.project is used.

  • suffix – Optional suffix to append to the ica processed file.

  • output_folder – By default, the results are saved to an [experiment]_ica.hdf5 file, in the same folder as the original video. If a different folder is specified by output_folder, the ica file will be saved there instead.

  • mean_filter_method – Which method to use while filtering the mean. Default is highpass wavelet filter.

  • low_cutoff – The lower cutoff for a highpass filter. Default is 0.5Hz.

Returns

A dictionary containing all the results, metadata, and information regarding the filter applied.

mean:

The original video mean.

roimask:

The mask applied to the video before decomposing.

shape:

The original shape of the movie array.

eig_mix:

The ICA mixing matrix.

timecourses:

The ICA component time series.

eig_vec:

The eigenvectors.

n_components:

The number of components in eig_vec (reduced to only have 25% of total components as noise).

project_meta:

The metadata for the ica projection

expmeta:

All metadata created for this class.

lag1:

The lag-1 autocorrelation.

noise_components:

A vector (n components long) to store binary representation of which components were detected as noise.

cutoff:

The signal-noise cutoff value.

mean_filtered:

The filtered mean.

mean_filter_meta:

Metadata on how the mean filter was applied.

if the n_components was automatically set, the following additional keys are also returned in components

svd_cutoff:

The number of components originally decomposed.

lag1_full:

The lag-1 autocorrelation of the full set of components decomposed before cropping to only 25% noise components.

svd_multiplier:

The svd multiplier value used to determine cutoff.

Return type

components

load_meta(meta_path: str)[source]

Load metadata to the experiment file. This is not used in any decomposition, but provides a convenient way to save metadata along with the processed file.

Parameters

meta_path – The path to the metadata .yaml file.

load_rois(path: str, n_roi_rotations: int = 0)[source]

Load rois set in an FIJI/ImageJ RoiSet.zip file to the experiment file, and creates a roimask based on the rois.

Parameters
  • path – The path to the .zip file.

  • n_roi_rotations – The number of CCW rotations to apply to the roimask after loading. This argument is not used if rotate_rois_with_video was True when loading the experiment.

rotate()[source]

Rotates movie by self.n_rotations, and updates the shape and bounding box to reflect this change.