From f944840a5d0fa7e9f18bf1944afdcb794e003a7b Mon Sep 17 00:00:00 2001 From: pauladkisson Date: Thu, 21 Nov 2024 11:06:15 -0800 Subject: [PATCH] fixed bug with opto interface where timestamps weren't normalizing properly --- .../zempolich_2024_convert_session.py | 2 +- .../zempolich_2024_optogeneticinterface.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/schneider_lab_to_nwb/zempolich_2024/zempolich_2024_convert_session.py b/src/schneider_lab_to_nwb/zempolich_2024/zempolich_2024_convert_session.py index 60b494e..30ddd4e 100644 --- a/src/schneider_lab_to_nwb/zempolich_2024/zempolich_2024_convert_session.py +++ b/src/schneider_lab_to_nwb/zempolich_2024/zempolich_2024_convert_session.py @@ -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 diff --git a/src/schneider_lab_to_nwb/zempolich_2024/zempolich_2024_optogeneticinterface.py b/src/schneider_lab_to_nwb/zempolich_2024/zempolich_2024_optogeneticinterface.py index 27c27d9..d122ea3 100644 --- a/src/schneider_lab_to_nwb/zempolich_2024/zempolich_2024_optogeneticinterface.py +++ b/src/schneider_lab_to_nwb/zempolich_2024/zempolich_2024_optogeneticinterface.py @@ -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 @@ -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"] @@ -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):