Testing#

Testing#

Testing utilities for the roiextractors package.

generate_dummy_video(size: tuple[int, int, int] | tuple[int, int, int, int], dtype: dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any] = 'uint16', seed: int = 0)[source]#

Generate a dummy video of a given size and dtype.

Parameters:
  • size (tuple[int, int, int] or tuple[int, int, int, int]) – Size of the video to generate. For planar data: (num_frames, num_rows, num_columns) For volumetric data: (num_frames, num_rows, num_columns, num_planes)

  • dtype (DtypeType, optional) – Dtype of the video to generate, by default “uint16”.

  • seed (int, default 0) – seed for the random number generator, by default 0.

Returns:

video – A dummy video of the given size and dtype.

Return type:

np.ndarray

generate_dummy_imaging_extractor(*, num_rows: int = 10, num_columns: int = 10, sampling_frequency: float = 30.0, dtype: dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any] = 'uint16', seed: int = 0, num_samples: int | None = 30, has_native_timestamps: bool = False, num_planes: int | None = None)[source]#

Generate a dummy imaging extractor for testing.

The imaging extractor is built by feeding random data into the NumpyImagingExtractor.

Parameters:
  • num_rows (int, optional) – number of rows in the video, by default 10.

  • num_columns (int, optional) – number of columns in the video, by default 10.

  • sampling_frequency (float, optional) – sampling frequency of the video, by default 30.

  • dtype (DtypeType, optional) – dtype of the video, by default “uint16”.

  • seed (int, default 0) – seed for the random number generator, by default 0.

  • num_samples (int, default 30) – number of samples in the video, by default 30.

  • has_native_timestamps (bool, default False) – if True, the extractor will return native timestamps (irregularly spaced).

  • num_planes (int, optional) – number of depth planes for volumetric data. If None, creates 2D data.

Returns:

An imaging extractor with random data fed into NumpyImagingExtractor.

Return type:

ImagingExtractor

generate_dummy_segmentation_extractor(*, num_rois: int = 10, num_rows: int = 25, num_columns: int = 25, sampling_frequency: float = 30.0, has_summary_images: bool = True, has_raw_signal: bool = True, has_dff_signal: bool = True, has_deconvolved_signal: bool = True, has_neuropil_signal: bool = True, rejected_list: list | None = None, seed: int = 0, num_samples: int | None = 30) SegmentationExtractor[source]#

Generate a dummy segmentation extractor for testing.

The segmentation extractor is built by feeding random data into the NumpySegmentationExtractor.

Parameters:
  • num_rois (int, optional) – number of regions of interest, by default 10.

  • num_rows (int, optional) – number of rows in the hypothetical video from which the data was extracted, by default 25.

  • num_columns (int, optional) – number of columns in the hypothetical video from which the data was extracted, by default 25.

  • sampling_frequency (float, optional) – sampling frequency of the hypothetical video from which the data was extracted, by default 30.0.

  • has_summary_images (bool, optional) – whether the dummy segmentation extractor has summary images or not (mean and correlation).

  • has_raw_signal (bool, optional) – whether a raw fluorescence signal is desired in the object, by default True.

  • has_dff_signal (bool, optional) – whether a relative (df/f) fluorescence signal is desired in the object, by default True.

  • has_deconvolved_signal (bool, optional) – whether a deconvolved signal is desired in the object, by default True.

  • has_neuropil_signal (bool, optional) – whether a neuropil signal is desired in the object, by default True.

  • rejected_list (list, optional) – A list of rejected rois, None by default.

  • seed (int, default 0) – seed for the random number generator, by default 0.

  • num_samples (int, optional) – Number of samples in the recording, by default 30.

Returns:

A segmentation extractor with random data fed into NumpySegmentationExtractor

Return type:

SegmentationExtractor

Notes

Note that this dummy example is meant to be a mock object with the right shape, structure and objects but does not contain meaningful content. That is, the image masks matrices are not plausible image mask for a roi, the raw signal is not a meaningful biological signal and is not related appropriately to the deconvolved signal , etc.

check_segmentations_equal(segmentation_extractor1: SegmentationExtractor, segmentation_extractor2: SegmentationExtractor)[source]#

Check that two segmentation extractors have equal fields.

check_segmentations_images(segmentation_extractor1: SegmentationExtractor, segmentation_extractor2: SegmentationExtractor)[source]#

Check that the segmentation images are equal for the given segmentation extractors.

check_segmentation_return_types(seg: SegmentationExtractor)[source]#

Check that the return types of the segmentation extractor are correct.

check_imaging_equal(imaging_extractor1: ImagingExtractor, imaging_extractor2: ImagingExtractor)[source]#

Check that two imaging extractors have equal fields.

check_imaging_return_types(img_ex: ImagingExtractor)[source]#

Check that the return types of the imaging extractor are correct.

Toy Examples#

Toy example ImagingExtractor and SegmentationExtractor for testing.

Functions#

toy_example

Create a toy example of an ImagingExtractor and a SegmentationExtractor.

toy_example(duration=10, num_rois=10, size_x=100, size_y=100, roi_size=4, min_dist=5, mode='uniform', sampling_frequency=30.0, decay_time=0.5, noise_std=0.05)[source]#

Create a toy example of an ImagingExtractor and a SegmentationExtractor.

Parameters:
  • duration (float) – Duration in s

  • num_rois (int) – Number of ROIs

  • size_x (int) – Size of x dimension (pixels)

  • size_y (int) – Size of y dimension (pixels)

  • roi_size (int) – Size of ROI in x and y dimension (pixels)

  • min_dist (int) – Minimum distance between ROI centers (pixels)

  • mode (str) – ‘uniform’ or ‘gaussian’. If ‘uniform’, ROI values are uniform and equal to 1. If ‘gaussian’, ROI values are gaussian modulated

  • sampling_frequency (float) – The sampling rate

  • decay_time (float) – Decay time of fluorescence response

  • noise_std (float) – Standard deviation of added gaussian noise

Returns:

  • imag (NumpyImagingExtractor) – The output imaging extractor

  • seg (NumpySegmentationExtractor) – The output segmentation extractor