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 inscopix imaging extractor and test #856

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions docs/api/interfaces.ophys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ HDF5 Imaging
------------
.. automodule:: neuroconv.datainterfaces.ophys.hdf5.hdf5datainterface

Inscopix Imaging
----------------
.. automodule:: neuroconv.datainterfaces.ophys.inscopix.inscopiximaginginterface

MicroManager Tiff Imaging
-------------------------
.. automodule:: neuroconv.datainterfaces.ophys.micromanagertiff.micromanagertiffdatainterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Imaging

Bruker <imaging/brukertiff>
HDF5 <imaging/hdf5imaging>
Inscopix <imaging/inscopix>
Micro-Manager <imaging/micromanagertiff>
Miniscope <imaging/miniscope>
Scanbox <imaging/scanbox>
Expand Down
29 changes: 29 additions & 0 deletions docs/conversion_examples_gallery/imaging/inscopix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Inscopix data conversion
------------------------

Install NeuroConv with the additional dependencies necessary for reading Inscopix imaging data form .isxd files.

.. code-block:: bash

pip install neuroconv[inscopix]

Convert Inscopix .isxd imaging data to NWB using :py:class:`~neuroconv.datainterfaces.ophys.inscopix.inscopiximaginginterface.InscopixImagingInterface`.

.. code-block:: python

>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import InscopixImagingInterface
>>>
>>> file_path = OPHYS_DATA_PATH / "imaging_datasets" / "inscopix" / "movie_longer_than_3_min.isxd"
>>> interface = InscopixImagingInterface(file_path=file_path, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = metadata["NWBFile"]["session_start_time"]
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
2 changes: 2 additions & 0 deletions src/neuroconv/datainterfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
from .ophys.cnmfe.cnmfedatainterface import CnmfeSegmentationInterface
from .ophys.extract.extractdatainterface import ExtractSegmentationInterface
from .ophys.hdf5.hdf5datainterface import Hdf5ImagingInterface
from .ophys.inscopix.inscopiximaginginterface import InscopixImagingInterface
from .ophys.micromanagertiff.micromanagertiffdatainterface import (
MicroManagerTiffImagingInterface,
)
Expand Down Expand Up @@ -146,6 +147,7 @@
BrukerTiffSinglePlaneImagingInterface,
MicroManagerTiffImagingInterface,
MiniscopeImagingInterface,
InscopixImagingInterface,
# Behavior
VideoInterface,
AudioInterface,
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from datetime import datetime
from imaplib import Literal

from ..baseimagingextractorinterface import BaseImagingExtractorInterface
from ....utils import DeepDict, FilePathType


class InscopixImagingInterface(BaseImagingExtractorInterface):
"""Interface for Inscopix imaging data."""

display_name = "Inscopix Imaging"
associated_suffixes = (".isxd",)
info = "Interface for Inscopix imaging data."

def __init__(self, file_path: FilePathType, verbose: bool = True):
"""

Parameters
----------
file_path : FilePathType
Path to .isxd file.
verbose : bool, default: True
"""
super().__init__(file_path=file_path, verbose=verbose)

def get_metadata(
self, photon_series_type: Literal["OnePhotonSeries", "TwoPhotonSeries"] = "TwoPhotonSeries"
) -> DeepDict:
metadata = super().get_metadata(photon_series_type=photon_series_type)

extra_props = self.imaging_extractor.movie.footer["extraProperties"]

if extra_props["animal"]["id"]:
metadata["Subject"]["subject_id"] = extra_props["animal"]["id"]
if extra_props["animal"]["species"]:
metadata["Subject"]["species"] = extra_props["animal"]["species"]
if extra_props["animal"]["sex"]:
metadata["Subject"]["sex"] = extra_props["animal"]["sex"].upper()
if extra_props["animal"]["dob"]:
metadata["Subject"]["date_of_birth"] = extra_props["animal"]["dob"]
if extra_props["animal"]["weight"]:
metadata["Subject"]["weight"] = str(extra_props["animal"]["weight"])

if extra_props["date"]:
metadata["NWBFile"]["session_start_time"] = datetime.strptime(extra_props["date"], "%Y-%m-%dT%H:%M:%S.%fZ")

return metadata
2 changes: 1 addition & 1 deletion src/neuroconv/datainterfaces/ophys/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
roiextractors>=0.5.7
roiextractors>=0.6.0
9 changes: 9 additions & 0 deletions tests/test_on_data/test_imaging_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
BrukerTiffMultiPlaneImagingInterface,
BrukerTiffSinglePlaneImagingInterface,
Hdf5ImagingInterface,
InscopixImagingInterface,
MicroManagerTiffImagingInterface,
MiniscopeImagingInterface,
SbxImagingInterface,
Expand Down Expand Up @@ -805,3 +806,11 @@ def check_incorrect_folder_structure_raises(self):
exc_type=AssertionError, exc_msg="The main folder should contain at least one subfolder named 'Miniscope'."
):
self.data_interface_cls(folder_path=folder_path)


class TestInscopixImagingInterface(ImagingExtractorInterfaceTestMixin, TestCase):
data_interface_cls = InscopixImagingInterface
interface_kwargs = dict(
file_path=str(OPHYS_DATA_PATH / "imaging_datasets" / "inscopix" / "movie_longer_than_3_min.isxd")
)
save_directory = OUTPUT_PATH
Loading