1. Core#
Core functions used to run the pipeline.
- convertScanImageTiffToVolume(data_path, varargin)#
Convert ScanImage .tif files into a 4D volume.
Convert raw scanimage multi-roi .tif files from a single session into a single 4D volumetric time-series (x, y, z, t). It’s designed to process files for the ScanImage Version: 2016 software.
- Parameters:
- data_pathchar
The directory containing the raw .tif files. Only raw .tif files from one session should be in the directory.
- save_pathchar, optional
The directory where processed files will be saved. It is created if it does not exist. Defaults to the data_path directory.
- dsstring, optional
Name of the group (h5 dataset) to save the assembled data. Default is ‘/Y’. Must contain a leading slash.
- debug_flagdouble, logical, optional
If set to 1, the function displays the files in the command window and does not continue processing. Defaults to 0.
- do_figureslogical, optional
If set to 1, mean image and single frame figures are generated and saved to save_path. Defaults to 1. Note, figures will impact performance, particularly on datasets with many ROI’s.
- overwritelogical, optional
Whether to overwrite existing files. In many instances, entire file will be deleted. Default is 0.
- fix_scan_phaselogical, optional
Whether to correct for bi-directional scan artifacts. Default is true.
- trim_roidouble, optional
Pixels to trim from [left, right, top, bottom] edge of each INDIVIDUAL ROI before horizontally concatenating the ROI’s within an image. Default is [0 0 0 0]. Only applies to ScanImage multi-ROI recordings.
- trim_imagedouble, optional
Pixels to trim from [left, right, top, bottom] edge of each TILED IMAGE before horizontally concatenating the ROI’s within an image. Default is [0 0 0 0]. Only applies to ScanImage multi-ROI recordings.
- z_plane_orderdouble, optional
If interleaved z-planes are not ordered from 1-n_planes, reorder the stack using this array as index.
- motionCorrectPlane(data_path, varargin)#
Perform motion correction on imaging data.
Each motion-corrected plane is saved as a .h5 group containing the 2D shift vectors in x and y. The raw movie is saved in ‘/Y’ and the
- Parameters:
- data_pathchar
Path to the directory containing the files assembled via convertScanImageTiffToVolume.
- save_pathchar
Path to the directory to save the motion vectors.
- dschar, optional
Group path within the hdf5 file that contains raw data. Default is ‘/Y’.
- debug_flagdouble, logical, optional
If set to 1, the function displays the files in the command window and does not continue processing. Defaults to 0.
- do_figuresdouble, integer, positive
If true, correlation metrics will be saved to save_path/figures.
- overwritelogical, optional
Whether to overwrite existing files (default is 0).
- num_coresdouble, integer, positive
Number of cores to use for computation. The value is limited to a maximum of 24 cores.
- start_planedouble, integer, positive
The starting plane index for processing.
- end_planedouble, integer, positive
The ending plane index for processing. Must be greater than or equal to start_plane.
- optionsstruct
NormCorre Params Object,
Notes
Only .h5 files containing processed volumes should be in the file_path.
- segmentPlane(data_path, varargin)#
Segment imaging data using CaImAn CNMF.
This function applies the CaImAn algorithm to segment neurons from motion-corrected, pre-processed and ROI re-assembled MAxiMuM data. The processing is conducted for specified planes, and the results are saved to disk.
- Parameters:
- data_pathchar
Path to the directory containing the files assembled via convertScanImageTiffToVolume.
- save_pathchar
Path to the directory to save the motion vectors.
- dsstring, optional
Group path within the hdf5 file that contains raw data.
- debug_flagdouble, logical, optional
If set to 1, the function displays the files in the command window and does not continue processing. Defaults to 0.
- do_figuresdouble, integer, positive
If true, correlation metrics will be saved to save_path/figures.
- overwritelogical, optional
Whether to overwrite existing files (default is 0).
- num_coresdouble, integer, positive
Number of cores to use for computation. The value is limited to a maximum of 24 cores.
- start_planedouble, integer, positive
The starting plane index for processing.
- end_planedouble, integer, positive
The ending plane index for processing. Must be greater than or equal to start_plane.
- optionsstruct
key:value pairs of all of your CNMF parameters. See the example parameters in the LBM_demo_pipeline.
Notes
T_keep
: neuronal time series [Km, T].single
Ac_keep
: neuronal footprints [2*tau+1, 2*tau+1, Km].single
C_keep
: denoised time series [Km, T].single
Km
: number of neurons found.single
Cn
: correlation image [x, y].single
b
: background spatial components [x*y, 3].single
f
: background temporal components [3, T].single
acx
: centroid in x direction for each neuron [1, Km].single
acy
: centroid in y direction for each neuron [1, Km].single
acm
: sum of component pixels for each neuron [1, Km].single
- collatePlanes(data_path, varargin)#
Parameters :param data_path: Path to the directory containing the files assembled via convertScanImageTiffToVolume. :type data_path: char :param save_path: Path to the directory to save the motion vectors. :type save_path: char :param ds: Group path within the hdf5 file that contains raw data. :type ds: string, optional :param debug_flag: If set to 1, the function displays the files in the command window and does
not continue processing. Defaults to 0.
- Parameters:
do_figures (
double, integer, positive
) – If true, correlation metrics will be saved to save_path/figures.overwrite (
logical, optional
) – Whether to overwrite existing files (default is 0).num_cores (
double, integer, positive
) – Number of cores to use for computation. The value is limited to a maximum of 24 cores.start_plane (
double, integer, positive
) – The starting plane index for processing.end_plane (
double, integer, positive
) – The ending plane index for processing. Must be greater than or equal to start_plane.num_features (
double, positive
) – The number of neurons to select for the lateral offset correction between z-planes. Default is 1 feature/neuron.options (
struct
) – Struct containing key-value pairs for ‘min_SNR’ and ‘merge_thresh’.motion_corrected_path (
string
) – Path to motion corrected data. Default is data_path/../motion_corrected/,
- calculateZOffset(data_path, varargin)#
- Parameters:
- data_pathstring
Path to the directory containing the image data and calibration files. The function expects to find ‘pollen_sample_xy_calibration.mat’ in this directory along with each caiman_output_plane_N.
- motion_corrected_path: string
Path to motion corrected data. Default is data_path/../motion_corrected/,
- debug_flagdouble, logical, optional
If set to 1, the function displays the files in the command window and does not continue processing. Default is 0.
- overwritelogical, optional
Whether to overwrite existing files. Default is 0.
- start_planedouble, integer, positive
The starting plane index for processing. Default is 1.
- end_planedouble, integer, positive
The ending plane index for processing. Must be greater than or equal to start_plane. Default is 1.
- num_featuresdouble, integer, positive
The number of features to identify and use in each plane for calculating offsets. Default is 2 features (neurons) compared across z-plane/z-plane+1.
- Returns:
- offsetsNx2 array
An array of offsets between consecutive planes, where N is the number of planes processed. Each row corresponds to a plane, and the two columns represent the calculated offset in pixels along the x and y directions, respectively.
- metadata: struct
Notes
This function requires calibration data in input datapath: - pollen_sample_xy_calibration.mat
The function uses MATLAB’s ginput function for manual feature selection on the images. It expects the user to manually select the corresponding points on each plane.
The function assumes that the consecutive images will have some overlap and that features will be manually identifiable and trackable across planes.
Examples
[offsets, metadata] = calculateZOffset(‘C:/data/images/’, metadata, 1, 10, 5);