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

Opto #17

Merged
merged 1 commit into from
Nov 25, 2024
Merged

Opto #17

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
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def session_to_nwb(
# Add Optogenetic
if has_opto:
source_data.update(dict(Optogenetic=dict(file_path=behavior_file_path)))
conversion_options.update(dict(Optogenetic=dict(brain_region=brain_region)))
conversion_options.update(dict(Optogenetic=dict(brain_region=brain_region, normalize_timestamps=True)))
conversion_options["Behavior"]["normalize_timestamps"] = True

# Add Intrinsic Signal Optical Imaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ def __init__(self, file_path: FilePath):
"""
super().__init__(file_path=file_path)

def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict, brain_region: Literal["A1", "M2"] = "A1"):
def add_to_nwbfile(
self,
nwbfile: NWBFile,
metadata: dict,
brain_region: Literal["A1", "M2"] = "A1",
normalize_timestamps: bool = False,
):
"""Add optogenetic stimulation data to the NWBFile.

Parameters
Expand All @@ -36,6 +42,8 @@ def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict, brain_region: Literal
Metadata dictionary with information used to create the NWBFile.
brain_region : Literal["A1", "M2"], optional
Brain region for which the optogenetic stimulation data will be added, by default "A1".
normalize_timestamps : bool, optional
Whether to normalize the timestamps to the start of the first behavioral time series, by default False
"""
# Read Data
file_path = self.source_data["file_path"]
Expand All @@ -49,6 +57,10 @@ def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict, brain_region: Literal
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"]
starting_timestamp = file["continuous"][metadata["Behavior"]["TimeSeries"][0]["name"]]["time"][0]
if normalize_timestamps:
onset_times = onset_times - starting_timestamp
offset_times = offset_times - starting_timestamp

timestamps, data = [], []
for onset_time, offset_time in zip(onset_times, offset_times):
Expand Down
Loading