Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MockSegmentationInterface #1067

Merged
merged 14 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
74 changes: 74 additions & 0 deletions src/neuroconv/tools/testing/mock_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
12 changes: 11 additions & 1 deletion tests/test_ophys/test_ophys_interfaces.py
Original file line number Diff line number Diff line change
@@ -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()
Loading