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.
Deprecated since version ``generate_dummy_video``: is deprecated and will be removed in or after March 2027. Use
GaussianNoiseImagingExtractororPoissonNoiseImagingExtractorinstead.- 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 (DTypeLike, 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
- class MockImagingExtractor(*, num_samples: int = 30, num_rows: int = 10, num_columns: int = 10, num_planes: int | None = None, sampling_frequency: float = 30.0, seed: int = 0, baseline: float = 100.0, native_timestamps: Literal['evenly_spaced', 'unevenly_spaced'] | None = None, 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')[source]#
Bases:
PoissonNoiseImagingExtractorA mock imaging extractor for use in tests.
Stands in for a raw acquisition file, so it generates Poisson noise (photon counts, which are non-negative integers) rather than Gaussian noise, and defaults to
uint16the way real cameras and digitizers do. On top of the base generator it adds optional synthetic timestamps and a configurable dtype, for testing code paths that depend on those.Use
GaussianNoiseImagingExtractordirectly when the data being imitated is float and can go negative, such as a background-subtracted movie, or when a test needs a known mean and standard deviation.- Parameters:
num_samples (int, default 30) – Number of samples in the video.
num_rows (int, default 10) – Number of rows in each sample.
num_columns (int, default 10) – Number of columns in each sample.
num_planes (int or None, default None) – Number of depth planes. The extractor is volumetric only when this is greater than 1, which matches the rule the concrete extractors use; a single plane is planar.
sampling_frequency (float, default 30.0) – Sampling frequency in Hz.
seed (int, default 0) – Random seed for reproducibility.
baseline (float, default 100.0) – Mean photon count per pixel (the lambda of the Poisson distribution).
native_timestamps (“evenly_spaced” | “unevenly_spaced” | None, default None) – Controls whether the extractor returns native timestamps. None: no native timestamps (returns None). “evenly_spaced”: evenly spaced timestamps based on sampling_frequency. “unevenly_spaced”: timestamps with small random jitter around the regular spacing.
dtype (DTypeLike, default “uint16”) – The dtype of the data returned by
get_series. Defaults touint16because that is what scientific cameras and PMT digitizers write. Poisson counts are non-negative and centred onbaseline, so the cast is lossless for any integer dtype wide enough to hold them.
Initialize the ImagingExtractor object.
- get_dtype() dtype[source]#
Get the data type of the video.
- Returns:
dtype – Data type of the video.
- Return type:
dtype
- get_series(start_sample: int | None = None, end_sample: int | None = None) ndarray[source]#
Return Poisson noise for the requested sample range.
Data is read from a pregenerated tile that is conceptually repeated along the time axis. No RNG work at read time.
- get_native_timestamps(start_sample: int | None = None, end_sample: int | None = None) ndarray | None[source]#
Retrieve the original unaltered timestamps for the data in this interface.
This function should retrieve the data on-demand by re-initializing the IO. Can be overridden to return None if the extractor does not have native timestamps.
- Parameters:
start_sample (int, optional) – The starting sample index. If None, starts from the beginning.
end_sample (int, optional) – The ending sample index. If None, goes to the end.
- Returns:
timestamps – The timestamps for the data stream, or None if native timestamps are not available.
- Return type:
numpy.ndarray or None
- 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, native_timestamps: Literal['evenly_spaced', 'unevenly_spaced'] | None = None, num_planes: int | None = None)[source]#
Generate a dummy imaging extractor for testing.
The imaging extractor is built using a MockImagingExtractor, which generates Poisson noise (photon counts) on-the-fly.
- 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 (DTypeLike, optional) – dtype of the returned data, 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) – Deprecated. Use
native_timestamps="evenly_spaced"instead.native_timestamps (“evenly_spaced” | “unevenly_spaced” | None, default None) – Controls whether the extractor returns native timestamps. None: no native timestamps (returns None). “evenly_spaced”: evenly spaced timestamps based on sampling_frequency. “unevenly_spaced”: timestamps with small random jitter around the regular spacing.
num_planes (int, optional) – number of depth planes. Values greater than 1 give a volumetric extractor; None or 1 give a planar one, matching the rule the concrete extractors use.
- Returns:
An imaging extractor with random Poisson noise data.
- Return type:
- 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, mask_type: Literal['image', 'pixel'] = 'image', native_timestamps: Literal['evenly_spaced', 'unevenly_spaced'] | None = None) 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.
mask_type (str, default “image”) – Type of mask to generate. One of “image” or “pixel”. “image” generates dense masks of shape (num_rows, num_columns, num_rois). “pixel” generates sparse masks as a list of (n_pixels, 3) arrays with columns [y, x, weight].
native_timestamps (“evenly_spaced” | “unevenly_spaced” | None, default None) – Controls whether the extractor returns native timestamps. None: no native timestamps (returns None). “evenly_spaced”: evenly spaced timestamps based on sampling_frequency. “unevenly_spaced”: timestamps with small random jitter around the regular spacing.
- Returns:
A segmentation extractor with random data fed into NumpySegmentationExtractor
- Return type:
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.