diff --git a/src/cai_lab_to_nwb/zaki_2024/assets/motion_freezing_across_session.png b/src/cai_lab_to_nwb/zaki_2024/assets/motion_freezing_across_session.png new file mode 100644 index 0000000..35c7e84 Binary files /dev/null and b/src/cai_lab_to_nwb/zaki_2024/assets/motion_freezing_across_session.png differ diff --git a/src/cai_lab_to_nwb/zaki_2024/behaviorinterface.py b/src/cai_lab_to_nwb/zaki_2024/behaviorinterface.py index 33b8675..bfe0e19 100644 --- a/src/cai_lab_to_nwb/zaki_2024/behaviorinterface.py +++ b/src/cai_lab_to_nwb/zaki_2024/behaviorinterface.py @@ -1,13 +1,17 @@ """Primary class for converting experiment-specific behavior.""" import numpy as np +from pynwb import TimeSeries +from pynwb.epoch import TimeIntervals from pynwb.file import NWBFile from neuroconv.basedatainterface import BaseDataInterface from neuroconv.utils import DeepDict from pydantic import FilePath from typing import Optional -from pynwb.epoch import TimeIntervals + +from explore_segmentation_data import unit_ids + class FreezingBehaviorInterface(BaseDataInterface): """Adds intervals of freezing behavior interface.""" @@ -33,6 +37,20 @@ def add_to_nwbfile(self, nwbfile: NWBFile, metadata: Optional[dict] = None): freezing_behavior_df = pd.read_csv(self.file_path) + #Extract motion data + motion_data = freezing_behavior_df["Motion"].values + + motion_series = TimeSeries( + name="MotionSeries", + description="ezTrack measures the motion of the animal by assessing the number of pixels of the behavioral " + "video whose grayscale change exceeds a particular threshold from one frame to the next.", + data=motion_data, + unit="n.a", + starting_time=freezing_behavior_df["Frame"][0] / self.video_sampling_frequency, + rate=self.video_sampling_frequency, + ) + + # Extract parameters, those values are unique per run file = freezing_behavior_df["File"].unique()[0] motion_cutoff = freezing_behavior_df["MotionCutoff"].unique()[0] @@ -67,9 +85,8 @@ def add_to_nwbfile(self, nwbfile: NWBFile, metadata: Optional[dict] = None): freeze_intervals = TimeIntervals(name="TimeIntervalsFreezingBehavior", description=description) for start_time, stop_time in zip(start_times, stop_times): - freeze_intervals.add_interval(start_time=start_time, stop_time=stop_time) + freeze_intervals.add_interval(start_time=start_time, stop_time=stop_time, timeseries=[motion_series]) - if "behavior" not in nwbfile.processing: behavior_module = nwbfile.create_processing_module( name="behavior", description="Contains behavior data" @@ -77,4 +94,5 @@ def add_to_nwbfile(self, nwbfile: NWBFile, metadata: Optional[dict] = None): else: behavior_module = nwbfile.processing["behavior"] + behavior_module.add(motion_series) behavior_module.add(freeze_intervals) diff --git a/src/cai_lab_to_nwb/zaki_2024/zaki_2024_notes.md b/src/cai_lab_to_nwb/zaki_2024/zaki_2024_notes.md index ea623ec..07e151b 100644 --- a/src/cai_lab_to_nwb/zaki_2024/zaki_2024_notes.md +++ b/src/cai_lab_to_nwb/zaki_2024/zaki_2024_notes.md @@ -868,4 +868,8 @@ https://youtu.be/BKgh-XcZhIM?t=731 More about synch can be found in the video to align with behavior on this timestamp -https://youtu.be/BKgh-XcZhIM?t=1338 \ No newline at end of file +https://youtu.be/BKgh-XcZhIM?t=1338 + + +## Figures to reproduce in the example notebook: +1) ![img.png](assets/motion_freezing_across_session.png) \ No newline at end of file