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 Minian data interface #1107

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions src/neuroconv/datainterfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
from .ophys.micromanagertiff.micromanagertiffdatainterface import (
MicroManagerTiffImagingInterface,
)
from .ophys.minian.miniandatainterface import MinianSegmentationInterface
from .ophys.miniscope.miniscopeimagingdatainterface import MiniscopeImagingInterface
from .ophys.sbx.sbxdatainterface import SbxImagingInterface
from .ophys.scanimage.scanimageimaginginterfaces import (
Expand Down Expand Up @@ -151,6 +152,7 @@
MicroManagerTiffImagingInterface,
MiniscopeImagingInterface,
TDTFiberPhotometryInterface,
MinianSegmentationInterface,
# Behavior
VideoInterface,
AudioInterface,
Expand Down
Empty file.
59 changes: 59 additions & 0 deletions src/neuroconv/datainterfaces/ophys/minian/miniandatainterface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from typing import Optional

from pynwb import NWBFile
from roiextractors.extraction_tools import PathType

from ..basesegmentationextractorinterface import BaseSegmentationExtractorInterface


class MinianSegmentationInterface(BaseSegmentationExtractorInterface):
"""Data interface for MinianSegmentationExtractor."""

display_name = "Minian Segmentation"
associated_suffixes = (".zarr",)
info = "Interface for Minian segmentation data."

@classmethod
def get_source_schema(cls) -> dict:
source_metadata = super().get_source_schema()
source_metadata["properties"]["folder_path"]["description"] = "Path to .zarr output."
return source_metadata

def __init__(self, folder_path: PathType, verbose: bool = True):
"""

Parameters
----------
folder_path : PathType
Path to .zarr path.
verbose : bool, default True
Whether to print progress
"""
super().__init__(folder_path=folder_path)
self.verbose = verbose

def add_to_nwbfile(
self,
nwbfile: NWBFile,
metadata: Optional[dict] = None,
stub_test: bool = False,
stub_frames: int = 100,
include_background_segmentation: bool = True,
include_roi_centroids: bool = True,
include_roi_acceptance: bool = False,
mask_type: Optional[str] = "image", # Literal["image", "pixel", "voxel"]
plane_segmentation_name: Optional[str] = None,
iterator_options: Optional[dict] = None,
):
super().add_to_nwbfile(
nwbfile=nwbfile,
metadata=metadata,
stub_test=stub_test,
stub_frames=stub_frames,
include_background_segmentation=include_background_segmentation,
include_roi_centroids=include_roi_centroids,
include_roi_acceptance=include_roi_acceptance,
mask_type=mask_type,
plane_segmentation_name=plane_segmentation_name,
iterator_options=iterator_options,
)
45 changes: 45 additions & 0 deletions tests/test_on_data/ophys/test_segmentation_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
CaimanSegmentationInterface,
CnmfeSegmentationInterface,
ExtractSegmentationInterface,
MinianSegmentationInterface,
Suite2pSegmentationInterface,
)
from neuroconv.tools.testing.data_interface_mixins import (
Expand Down Expand Up @@ -204,3 +205,47 @@ class TestSuite2pSegmentationInterfaceWithStubTest(SegmentationExtractorInterfac
)
save_directory = OUTPUT_PATH
conversion_options = dict(stub_test=True)


class TestMinianSegmentationInterface(SegmentationExtractorInterfaceTestMixin):
data_interface_cls = MinianSegmentationInterface
interface_kwargs = dict(folder_path=OPHYS_DATA_PATH / "segmentation_datasets" / "minian")
save_directory = OUTPUT_PATH

@pytest.fixture(
params=[
{"mask_type": "image", "include_background_segmentation": True},
{"mask_type": "pixel", "include_background_segmentation": True},
{"mask_type": "voxel", "include_background_segmentation": True},
# {"mask_type": None, "include_background_segmentation": True}, # Uncomment when https://github.com/catalystneuro/neuroconv/issues/530 is resolved
{"include_roi_centroids": False, "include_background_segmentation": True},
{"include_roi_acceptance": False, "include_background_segmentation": True},
{"include_background_segmentation": False},
],
ids=[
"mask_type_image",
"mask_type_pixel",
"mask_type_voxel",
"exclude_roi_centroids",
"exclude_roi_acceptance",
"exclude_background_segmentation",
],
)
def setup_interface(self, request):

test_id = request.node.callspec.id
self.test_name = test_id
self.interface_kwargs = self.interface_kwargs
self.conversion_options = request.param
self.interface = self.data_interface_cls(**self.interface_kwargs)

return self.interface, self.test_name


class TestMinianSegmentationInterfaceWithStubTest(SegmentationExtractorInterfaceTestMixin):
data_interface_cls = MinianSegmentationInterface
interface_kwargs = dict(
folder_path=OPHYS_DATA_PATH / "segmentation_datasets" / "minian",
)
save_directory = OUTPUT_PATH
conversion_options = dict(stub_test=True)
Loading