Skip to content

Commit

Permalink
Add holographic stimulation for Two Photon Imaging (#23)
Browse files Browse the repository at this point in the history
* fix plane map for single plane single color

* add holography metadata to converter

* add holography interface

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add tutorials

* temporary pin ndx-holographic-stimulation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add metadata

* update metadata.yaml

* update metadata schema for holographicstimulationdatainterface

* temporary pin to `ndx-holographic-stimulation` commit

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update tutorial

* Add group name to holographic stimulation plane seg table

* refresh tutorial

* Update src/pinto_lab_to_nwb/into_the_void/into_the_void_requirements.txt

* update tutorial

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
weiglszonja and pre-commit-ci[bot] authored Dec 7, 2023
1 parent c3d6ec1 commit dd1e5e0
Show file tree
Hide file tree
Showing 8 changed files with 1,075 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Ophys:
OptogeneticDevice:
SpatialLightModulator:
name: spatial_light_modulator
description: |
NeuraLight 3D SLM Module for Photoactivation Pathway, multi-region, holographic stimulation
and activation module using 512 x 512 spatial light modulator with Overdrive technology.
manufacturer: NeuraLight
LightSource:
name: light_source
description: |
The Coherent Monaco laser used for holographic stimulation with 251 fs pulse width and 2 MHz pulse rate.
stimulation_wavelength: 1035.0 # nm
power: 700.0 # the peak power of stimulation in Watts
filter_description: short pass 1040 nm filter
intensity: 0.005 # the intensity of excitation in Watts
exposure_time: 0.000000000000251 # the exposure time of the sample in seconds
pulse_rate: 2000000.0 # the pulse rate of the laser is in Hz
OptogeneticStimulusSite:
- name: site
description: |
The targeted location of the holographic stimulation.
excitation_lambda: 1050.0 # nm
effector: ChRmine # the peak power of stimulation in Watts
location: soma # should be the targeted brain area
1 change: 1 addition & 0 deletions src/pinto_lab_to_nwb/into_the_void/interfaces/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .holographicstimulationdatainterface import HolographicStimulationInterface

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def session_to_nwb(
editable_metadata = load_dict_from_file(editable_metadata_path)
metadata = dict_deep_update(metadata, editable_metadata)

# Update metadata with the holographic stimulation data
if "HolographicStimulation" in converter.data_interface_objects:
holographic_stimulation_metadata_path = Path(__file__).parent / "holographic_stimulation_metadata.yaml"
holographic_metadata = load_dict_from_file(holographic_stimulation_metadata_path)
metadata = dict_deep_update(metadata, holographic_metadata)

# Update metadata with subject_id and session_id from folder_path
# NCCR51_2023_04_07_no_task_dual_color_jrgeco_t_series-001
file_naming_pattern = r"^(?P<subject_id>[^_]+)_(?:\d{4}_\d{2}_\d{2}_)(?P<session_id>.+)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
neuroconv[suite2p, brukertiff]
neuroconv[suite2p, brukertiff] @ git+https://github.com/catalystneuro/neuroconv.git@main
ndx-holographic-stimulation @ git+https://github.com/catalystneuro/ndx-holographic-stimulation.git@423512fd37bff329b7bab708089d51c8cf91e4f7
hdmf @ git+https://github.com/hdmf-dev/hdmf.git@dev
45 changes: 28 additions & 17 deletions src/pinto_lab_to_nwb/into_the_void/into_the_voidnwbconverter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Primary NWBConverter class for this dataset."""
from pathlib import Path
from typing import Optional

from ndx_pinto_metadata import SubjectExtension
from neuroconv import NWBConverter
from neuroconv.datainterfaces import Suite2pSegmentationInterface, BrukerTiffMultiPlaneImagingInterface
from neuroconv.converters import BrukerTiffSinglePlaneConverter, BrukerTiffMultiPlaneConverter
from neuroconv.utils import FolderPathType, DeepDict

from pinto_lab_to_nwb.into_the_void.interfaces import HolographicStimulationInterface
from neuroconv.utils import FolderPathType, DeepDict, dict_deep_update
from pynwb import NWBFile


Expand All @@ -27,26 +30,25 @@ def get_default_segmentation_to_imaging_name_mapping(
plane_separation_type="disjoint",
)

plane_streams = [
plane_name for channel_name in streams["plane_streams"] for plane_name in streams["plane_streams"][channel_name]
]

available_channels = Suite2pSegmentationInterface.get_available_channels(folder_path=segmentation_folder_path)
available_planes = Suite2pSegmentationInterface.get_available_planes(folder_path=segmentation_folder_path)

if len(available_planes) == 1 and len(available_channels) == 1:
return None

segmentation_channel_plane_names = [
f"{channel_name.capitalize()}{plane_name.capitalize()}"
for plane_name in available_planes
for channel_name in available_channels
]

if len(available_planes) > 1:
imaging_channel_plane_names = [
plane_name
for channel_name in streams["plane_streams"]
for plane_name in streams["plane_streams"][channel_name]
]
num_channels = len(streams["channel_streams"])
num_planes = 1 if not plane_streams else len(plane_streams)
if num_channels == 1 and num_planes == 1:
imaging_channel_plane_names = [None]
else:
imaging_channel_plane_names = streams["channel_streams"]
imaging_channel_plane_names = plane_streams if num_planes == 1 else streams["channel_streams"]

segmentation_to_imaging_name_mapping = dict(zip(segmentation_channel_plane_names, imaging_channel_plane_names))

Expand Down Expand Up @@ -88,6 +90,13 @@ def __init__(
Imaging=BrukerTiffSinglePlaneConverter(folder_path=imaging_folder_path, verbose=verbose),
)

if list(Path(imaging_folder_path).glob("*MarkPoints*.xml")):
self.data_interface_objects.update(
HolographicStimulation=HolographicStimulationInterface(
folder_path=imaging_folder_path, verbose=verbose
),
)

if segmentation_folder_path:
available_planes = Suite2pSegmentationInterface.get_available_planes(folder_path=segmentation_folder_path)
available_channels = Suite2pSegmentationInterface.get_available_channels(
Expand Down Expand Up @@ -120,9 +129,10 @@ def __init__(
verbose=verbose,
)
if self.plane_map:
plane_segmentation_name = "PlaneSegmentation" + self.plane_map.get(
plane_name_suffix, None
).replace("_", "")
mapped_plane_suffix = self.plane_map.get(plane_name_suffix, None)
plane_segmentation_name = "PlaneSegmentation"
if mapped_plane_suffix is not None:
plane_segmentation_name = "PlaneSegmentation" + mapped_plane_suffix.replace("_", "")
segmentation_source_data.update(
plane_segmentation_name=plane_segmentation_name,
)
Expand All @@ -132,9 +142,6 @@ def __init__(
)

def get_metadata(self) -> DeepDict:
if not self.plane_map:
return super().get_metadata()

imaging_metadata = self.data_interface_objects["Imaging"].get_metadata()
metadata = super().get_metadata()

Expand All @@ -151,6 +158,10 @@ def get_metadata(self) -> DeepDict:
# override device link
metadata["Ophys"]["ImagingPlane"][metadata_ind]["device"] = device_name

if "HolographicStimulation" in self.data_interface_objects:
holographic_metadata = self.data_interface_objects["HolographicStimulation"].get_metadata()
metadata = dict_deep_update(metadata, holographic_metadata)

return metadata

def add_to_nwbfile(self, nwbfile: NWBFile, metadata, conversion_options: Optional[dict] = None) -> None:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dd1e5e0

Please sign in to comment.