From ad1e2a1a54068e4b1711f8fbc5e224c983131c16 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Fri, 13 Sep 2024 14:49:14 -0600 Subject: [PATCH] Add `MockSegmentationInterface` (#1067) Co-authored-by: Szonja Weigl Co-authored-by: Paul Adkisson --- CHANGELOG.md | 3 + .../basesegmentationextractorinterface.py | 3 +- .../tools/testing/mock_interfaces.py | 74 +++++++++++++++++++ tests/test_ophys/test_ophys_interfaces.py | 12 ++- 4 files changed, 90 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aec170e4..dfa9612aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ * Added `get_stream_names` to `OpenEphysRecordingInterface`: [PR #1039](https://github.com/catalystneuro/neuroconv/pull/1039) * Most data interfaces and converters now use Pydantic to validate their inputs, including existence of file and folder paths. [PR #1022](https://github.com/catalystneuro/neuroconv/pull/1022) * All remaining data interfaces and converters now use Pydantic to validate their inputs, including existence of file and folder paths. [PR #1055](https://github.com/catalystneuro/neuroconv/pull/1055) +* Added a mock for segmentation extractors interfaces in ophys: `MockSegmentationInterface` [PR #1067](https://github.com/catalystneuro/neuroconv/pull/1067) * Added automated EFS volume creation and mounting to the `submit_aws_job` helper function. [PR #1018](https://github.com/catalystneuro/neuroconv/pull/1018) @@ -44,6 +45,8 @@ * Improved device metadata of `IntanRecordingInterface` by adding the type of controller used [PR #1059](https://github.com/catalystneuro/neuroconv/pull/1059) + + ## v0.6.1 (August 30, 2024) ### Bug fixes diff --git a/src/neuroconv/datainterfaces/ophys/basesegmentationextractorinterface.py b/src/neuroconv/datainterfaces/ophys/basesegmentationextractorinterface.py index 6b55b5afb..0f2e41bb9 100644 --- a/src/neuroconv/datainterfaces/ophys/basesegmentationextractorinterface.py +++ b/src/neuroconv/datainterfaces/ophys/basesegmentationextractorinterface.py @@ -18,8 +18,9 @@ class BaseSegmentationExtractorInterface(BaseExtractorInterface): ExtractorModuleName = "roiextractors" - def __init__(self, **source_data): + def __init__(self, verbose: bool = False, **source_data): super().__init__(**source_data) + self.verbose = verbose self.segmentation_extractor = self.get_extractor()(**source_data) def get_metadata_schema(self) -> dict: diff --git a/src/neuroconv/tools/testing/mock_interfaces.py b/src/neuroconv/tools/testing/mock_interfaces.py index 12f1dafd4..87f6dcf8e 100644 --- a/src/neuroconv/tools/testing/mock_interfaces.py +++ b/src/neuroconv/tools/testing/mock_interfaces.py @@ -14,6 +14,9 @@ from ...datainterfaces.ophys.baseimagingextractorinterface import ( BaseImagingExtractorInterface, ) +from ...datainterfaces.ophys.basesegmentationextractorinterface import ( + BaseSegmentationExtractorInterface, +) from ...utils import ArrayType, get_schema_from_method_signature @@ -216,3 +219,74 @@ def get_metadata(self, photon_series_type: Optional[Literal["OnePhotonSeries", " metadata = super().get_metadata(photon_series_type=photon_series_type) metadata["NWBFile"]["session_start_time"] = session_start_time return metadata + + +class MockSegmentationInterface(BaseSegmentationExtractorInterface): + """A mock segmentation interface for testing purposes.""" + + ExtractorModuleName = "roiextractors.testing" + ExtractorName = "generate_dummy_segmentation_extractor" + + def __init__( + self, + num_rois: int = 10, + num_frames: int = 30, + 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, + seed: int = 0, + verbose: bool = False, + ): + """ + Parameters + ---------- + num_rois : int, optional + number of regions of interest, by default 10. + num_frames : int, optional + description, by default 30. + 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. + seed: int, default 0 + seed for the random number generator, by default 0 + verbose : bool, optional + controls verbosity, by default False. + """ + + super().__init__( + num_rois=num_rois, + num_frames=num_frames, + num_rows=num_rows, + num_columns=num_columns, + sampling_frequency=sampling_frequency, + has_summary_images=has_summary_images, + has_raw_signal=has_raw_signal, + has_dff_signal=has_dff_signal, + has_deconvolved_signal=has_deconvolved_signal, + has_neuropil_signal=has_neuropil_signal, + verbose=verbose, + ) + + def get_metadata(self) -> dict: + session_start_time = datetime.now().astimezone() + metadata = super().get_metadata() + metadata["NWBFile"]["session_start_time"] = session_start_time + return metadata diff --git a/tests/test_ophys/test_ophys_interfaces.py b/tests/test_ophys/test_ophys_interfaces.py index 9ae151d5a..c2c9b4a0c 100644 --- a/tests/test_ophys/test_ophys_interfaces.py +++ b/tests/test_ophys/test_ophys_interfaces.py @@ -1,9 +1,19 @@ from neuroconv.tools.testing.data_interface_mixins import ( ImagingExtractorInterfaceTestMixin, + SegmentationExtractorInterfaceTestMixin, +) +from neuroconv.tools.testing.mock_interfaces import ( + MockImagingInterface, + MockSegmentationInterface, ) -from neuroconv.tools.testing.mock_interfaces import MockImagingInterface class TestMockImagingInterface(ImagingExtractorInterfaceTestMixin): data_interface_cls = MockImagingInterface interface_kwargs = dict() + + +class TestMockSegmentationInterface(SegmentationExtractorInterfaceTestMixin): + + data_interface_cls = MockSegmentationInterface + interface_kwargs = dict()