roiextractors.extractors.schnitzerextractor package#

Submodules#

roiextractors.extractors.schnitzerextractor.cnmfesegmentationextractor module#

A segmentation extractor for CNMF-E ROI segmentation method.

Classes#

CnmfeSegmentationExtractor

A segmentation extractor for CNMF-E ROI segmentation method.

class CnmfeSegmentationExtractor(file_path: str | Path)[source]#

Bases: SegmentationExtractor

A segmentation extractor for CNMF-E ROI segmentation method.

This class inherits from the SegmentationExtractor class, having all its funtionality specifically applied to the dataset output from the ‘CNMF-E’ ROI segmentation method.

Create a CnmfeSegmentationExtractor from a .mat file.

Parameters:

file_path (str) – The location of the folder containing dataset.mat file.

extractor_name = 'CnmfeSegmentation'#
installed = True#
is_writable = False#
mode = 'file'#
installation_mesg = 'To use Cnmfe install h5py: \n\n pip install h5py \n\n'#
__del__()[source]#

Close the file when the object is deleted.

_file_extractor_read()[source]#

Read the .mat file and return the file object and the group.

Returns:

  • f (h5py.File) – The file object.

  • _group0 (list) – Group of relevant segmentation objects.

_image_mask_extractor_read()[source]#

Read the image masks from the .mat file and return the image masks.

Returns:

The image masks.

Return type:

DatasetView

_trace_extractor_read()[source]#

Read the traces from the .mat file and return the traces.

Returns:

The traces.

Return type:

DatasetView

_tot_exptime_extractor_read()[source]#

Read the total experiment time from the .mat file and return the total experiment time.

Returns:

tot_exptime – The total experiment time.

Return type:

float

_summary_image_read()[source]#

Read the summary image from the .mat file and return the summary image (Cn).

Returns:

summary_image – The summary image (Cn).

Return type:

np.ndarray

_raw_datafile_read()[source]#

Read the raw data file location from the .mat file and return the raw data file location.

Returns:

raw_datafile – The raw data file location.

Return type:

str

get_accepted_list()[source]#

Get a list of accepted ROI ids.

Returns:

accepted_list – List of accepted ROI ids.

Return type:

list

get_rejected_list()[source]#

Get a list of rejected ROI ids.

Returns:

rejected_list – List of rejected ROI ids.

Return type:

list

static write_segmentation(segmentation_object: SegmentationExtractor, save_path, overwrite=True)[source]#

Write a segmentation object to a .mat file.

Parameters:
  • segmentation_object (SegmentationExtractor) – The segmentation object to be written.

  • save_path (str) – The location of the folder to save the dataset.mat file.

  • overwrite (bool) – If True, overwrite the file if it already exists.

Raises:
  • FileExistsError – If the file already exists and overwrite is False.

  • AssertionError – If save_path is not a *.mat file.

get_image_size()[source]#

Get frame size of movie (height, width).

Returns:

no_rois – 2-D array: image height x image width

Return type:

array_like

_abc_impl = <_abc._abc_data object>#

roiextractors.extractors.schnitzerextractor.extractsegmentationextractor module#

Extractor for reading the segmentation data that results from calls to EXTRACT.

Classes#

ExtractSegmentationExtractor

Abstract class that defines which extractor class to use for a given file.

NewExtractSegmentationExtractor

Extractor for reading the segmentation data that results from calls to newer versions of EXTRACT.

LegacyExtractSegmentationExtractor

Extractor for reading the segmentation data that results from calls to older versions of EXTRACT.

_decode_h5py_array(unicode_int_array: ndarray) str[source]#

Auxiliary function to decode a numpy array of unicode ints to a string.

class ExtractSegmentationExtractor(file_path: str | Path, sampling_frequency: float, output_struct_name: str | None = None)[source]#

Bases: ABC

Abstract class that defines which extractor class to use for a given file.

Abstract class that defines which extractor class to use for a given file.

For newer versions of the EXTRACT algorithm, the extractor class redirects to NewExtractSegmentationExtractor. For older versions, the extractor class redirects to LegacyExtractSegmentationExtractor.

Parameters:
  • file_path (str) – The location of the folder containing the .mat file.

  • output_struct_name (str, optional) – The name of output struct in the .mat file. When unspecified, we check if any of the default values can be found in the file. For newer version of extract, the default name is assumed to be “output”. For older versions the default is “extractAnalysisOutput”. If none of them can be found, it must be supplied.

  • sampling_frequency (float) – The sampling frequency in units of Hz.

extractor_name = 'ExtractSegmentation'#
installed = True#
installation_mesg = 'To use ExtractSegmentationExtractor install h5py: \n\n pip install h5py \n\n'#
static __new__(cls, file_path: str | Path, sampling_frequency: float, output_struct_name: str | None = None)[source]#

Abstract class that defines which extractor class to use for a given file.

For newer versions of the EXTRACT algorithm, the extractor class redirects to NewExtractSegmentationExtractor. For older versions, the extractor class redirects to LegacyExtractSegmentationExtractor.

Parameters:
  • file_path (str) – The location of the folder containing the .mat file.

  • output_struct_name (str, optional) – The name of output struct in the .mat file. When unspecified, we check if any of the default values can be found in the file. For newer version of extract, the default name is assumed to be “output”. For older versions the default is “extractAnalysisOutput”. If none of them can be found, it must be supplied.

  • sampling_frequency (float) – The sampling frequency in units of Hz.

_assert_file_is_mat()[source]#

Check that the file exists and is a .mat file.

_get_default_output_struct_name_from_file()[source]#

Return the default value for ‘output_struct_name’ when it is unspecified.

Returns:

output_struct_name – The name of output struct in the .mat file.

Return type:

str

Notes

For newer version of extract, the default name is assumed to be “output”. For older versions the default is “extractAnalysisOutput”. If none of them is found, raise an error that ‘output_struct_name’ must be supplied.

_assert_output_struct_name_is_in_file()[source]#

Check that ‘output_struct_name’ is in the file, raise an error if not.

_check_extract_file_version() bool[source]#

Check the version of the extract file.

Returns:

  • True if the file was created with a newer version of the EXTRACT algorithm,

  • False otherwise.

_abc_impl = <_abc._abc_data object>#
class NewExtractSegmentationExtractor(file_path: str | Path, sampling_frequency: float, output_struct_name: str = 'output')[source]#

Bases: SegmentationExtractor

Extractor for reading the segmentation data that results from calls to newer versions of EXTRACT.

This class inherits from the SegmentationExtractor class, having all its functionality specifically applied to the dataset output from the ‘EXTRACT’ ROI segmentation method.

Load a SegmentationExtractor from a .mat file containing the output and config structs of the EXTRACT algorithm.

Parameters:
  • file_path (PathType) – Path to the .mat file containing the structs.

  • sampling_frequency (float) – The sampling frequency in units of Hz. Supply if timing is regular.

  • output_struct_name (str, optional) – The user has control over the names of the variables that return from extraction(images, config). The tutorials for EXTRACT follow the naming convention of ‘output’, which we assume as the default.

Notes

For regular timing, supply the sampling frequency. For irregular timing, supply the timestamps.

extractor_name = 'NewExtractSegmentation'#
installed = True#
installation_mesg = 'To use NewExtractSegmentation install h5py: \n\n pip install h5py \n\n'#
is_writable = False#
mode = 'file'#
close()[source]#

Close the file when the object is deleted.

_file_extractor_read()[source]#

Read the .mat file and return the file object.

_config_struct_to_dict(config_struct: Group) dict[source]#

Flatten the config struct into a dictionary.

_image_mask_extractor_read() DatasetView[source]#

Read the image masks from the .mat file and return the image masks.

Returns:

image_masks – 3-D array: height x width x number of ROIs

Return type:

DatasetView

_trace_extractor_read() DatasetView[source]#

Read the traces from the .mat file and return the traces.

Returns:

traces – 2-D array: number of frames x number of ROIs

Return type:

DatasetView

get_accepted_list() list[source]#

Get a list of accepted ROI ids.

Returns:

accepted_list – List of accepted ROI ids.

Return type:

list

get_rejected_list() list[source]#

Get a list of rejected ROI ids.

Returns:

rejected_list – List of rejected ROI ids.

Return type:

list

get_roi_ids() list[source]#

Get the list of ROI ids.

Returns:

roi_ids – List of roi ids.

Return type:

list

get_image_size() _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes][source]#

Get frame size of movie (height, width).

Returns:

no_rois – 2-D array: image height x image width

Return type:

array_like

get_images_dict()[source]#

Get images as a dictionary with key as the name of the ROIResponseSeries.

Returns:

_roi_image_dict

dictionary with key, values representing different types of Images used in segmentation:

Mean, Correlation image

Return type:

dict

_abc_impl = <_abc._abc_data object>#
class LegacyExtractSegmentationExtractor(file_path: str | Path, output_struct_name: str = 'extractAnalysisOutput')[source]#

Bases: SegmentationExtractor

Extractor for reading the segmentation data that results from calls to older versions of EXTRACT.

This class inherits from the SegmentationExtractor class, having all its funtionality specifically applied to the dataset output from the ‘EXTRACT’ ROI segmentation method.

Create a LegacyExtractSegmentationExtractor from a .mat file.

Parameters:
  • file_path (str) – The location of the folder containing dataset.mat file.

  • output_struct_name (str, optional) – The user has control over the names of the variables that return from extraction(images, config). When unspecified, the default is ‘extractAnalysisOutput’.

extractor_name = 'LegacyExtractSegmentation'#
installed = True#
is_writable = False#
mode = 'file'#
installation_mesg = 'To use extract install h5py: \n\n pip install h5py \n\n'#
__del__()[source]#

Close the file when the object is deleted.

_file_extractor_read()[source]#

Read the .mat file and return the file object.

_image_mask_extractor_read()[source]#

Read the image masks from the .mat file and return the image masks.

Returns:

image_masks – 3-D array: height x width x number of ROIs

Return type:

DatasetView

_trace_extractor_read()[source]#

Read the traces from the .mat file and return the traces.

Returns:

traces – 2-D array: number of frames x number of ROIs

Return type:

DatasetView

_tot_exptime_extractor_read()[source]#

Read the total experiment time from the .mat file and return the total experiment time.

Returns:

tot_exptime – The total experiment time in units of seconds.

Return type:

float

_summary_image_read()[source]#

Read the summary image from the .mat file and return the summary image.

Returns:

summary_image – The summary image.

Return type:

numpy.ndarray

_raw_datafile_read()[source]#

Read the raw data file location from the .mat file and return the raw data file location.

Returns:

raw_datafile – The raw data file location.

Return type:

str

get_accepted_list()[source]#

Get a list of accepted ROI ids.

Returns:

accepted_list – List of accepted ROI ids.

Return type:

list

get_rejected_list()[source]#

Get a list of rejected ROI ids.

Returns:

rejected_list – List of rejected ROI ids.

Return type:

list

get_image_size()[source]#

Get frame size of movie (height, width).

Returns:

no_rois – 2-D array: image height x image width

Return type:

array_like

_abc_impl = <_abc._abc_data object>#

Module contents#

Segmentation extractors for CNMF-E and EXTRACT ROI segmentation method.

Modules#

cnmfesegmentationextractor

A segmentation extractor for CNMF-E ROI segmentation method.

extractsegmentationextractor

A segmentation extractor for EXTRACT segmentation method.

Classes#

CnmfeSegmentationExtractor

A segmentation extractor for CNMF-E ROI segmentation method.

ExtractSegmentationExtractor

Abstract class that defines which EXTRACT class to use for a given file (new vs old).

NewExtractSegmentationExtractor

Extractor for reading the segmentation data that results from calls to newer versions of EXTRACT.

LegacyExtractSegmentationExtractor

Extractor for reading the segmentation data that results from calls to older versions of EXTRACT.