-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from catalystneuro/opto
Opto
- Loading branch information
Showing
6 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .schneider_2024_behaviorinterface import Schneider2024BehaviorInterface | ||
from .schneider_2024_optogeneticinterface import Schneider2024OptogeneticInterface | ||
from .schneider_2024_intrinsic_signal_imaging_interface import Schneider2024IntrinsicSignalOpticalImagingInterface | ||
from .schneider_2024_nwbconverter import Schneider2024NWBConverter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/schneider_lab_to_nwb/schneider_2024/schneider_2024_optogeneticinterface.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"""Primary class for converting optogenetic stimulation.""" | ||
from pynwb.file import NWBFile | ||
from pydantic import FilePath | ||
import numpy as np | ||
from pymatreader import read_mat | ||
from pynwb.device import Device | ||
from pynwb.ogen import OptogeneticSeries, OptogeneticStimulusSite | ||
|
||
from neuroconv.basedatainterface import BaseDataInterface | ||
from neuroconv.utils import DeepDict | ||
|
||
|
||
class Schneider2024OptogeneticInterface(BaseDataInterface): | ||
"""Optogenetic interface for schneider_2024 conversion""" | ||
|
||
keywords = ["optogenetics"] | ||
|
||
def __init__(self, file_path: FilePath): | ||
super().__init__(file_path=file_path) | ||
|
||
def get_metadata(self) -> DeepDict: | ||
metadata = super().get_metadata() | ||
|
||
return metadata | ||
|
||
def get_metadata_schema(self) -> dict: | ||
metadata_schema = super().get_metadata_schema() | ||
return metadata_schema | ||
|
||
def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict): | ||
# Read Data | ||
file_path = self.source_data["file_path"] | ||
file = read_mat(file_path) | ||
onset_times = file["events"]["push"]["opto_time"] | ||
is_opto_trial = np.logical_not(np.isnan(onset_times)) | ||
onset_times = onset_times[is_opto_trial] | ||
offset_times = file["events"]["push"]["opto_time_end"] | ||
offset_times = offset_times[is_opto_trial] | ||
assert np.all( | ||
np.logical_not(np.isnan(offset_times)) | ||
), "Some of the offset times are nan when onset times are not nan." | ||
power = metadata["Optogenetics"]["OptogeneticSeries"]["power"] | ||
|
||
timestamps, data = [], [] | ||
for onset_time, offset_time in zip(onset_times, offset_times): | ||
timestamps.append(onset_time) | ||
data.append(power) | ||
timestamps.append(offset_time) | ||
data.append(0) | ||
timestamps, data = np.array(timestamps, dtype=np.float64), np.array(data, dtype=np.float64) | ||
|
||
# Add Data to NWBFile | ||
# Add Device | ||
device = Device(**metadata["Optogenetics"]["Device"]) | ||
nwbfile.add_device(device) | ||
|
||
# Add OptogeneticStimulusSite | ||
site_metadata = metadata["Optogenetics"]["OptogeneticStimulusSite"] | ||
location = f"Injection location: {site_metadata['injection_location']} \n Stimulation location: {site_metadata['stimulation_location']}" | ||
ogen_site = OptogeneticStimulusSite( | ||
name=site_metadata["name"], | ||
device=device, | ||
description=site_metadata["description"], | ||
excitation_lambda=site_metadata["excitation_lambda"], | ||
location=location, | ||
) | ||
nwbfile.add_ogen_site(ogen_site) | ||
|
||
# Add OptogeneticSeries | ||
series_metadata = metadata["Optogenetics"]["OptogeneticSeries"] | ||
optogenetic_series = OptogeneticSeries( | ||
name=series_metadata["name"], | ||
site=ogen_site, | ||
description=series_metadata["description"], | ||
data=data, | ||
timestamps=timestamps, | ||
) | ||
nwbfile.add_stimulus(optogenetic_series) |