Skip to content

Commit

Permalink
fixed bug with opto interface where timestamps weren't normalizing pr…
Browse files Browse the repository at this point in the history
…operly
  • Loading branch information
pauladkisson committed Nov 21, 2024
1 parent 1e36537 commit f944840
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit f944840

Please sign in to comment.