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

Add motion series from eztrack #9

Merged
merged 2 commits into from
Oct 21, 2024
Merged
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 21 additions & 3 deletions src/cai_lab_to_nwb/zaki_2024/behaviorinterface.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand All @@ -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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably can get that from the method but maybe not worth it, should be something like pixel divided by time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following best practice it should be S.I. unit, I am not sure there is one for this case

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. "a.u." atribtrary unit could work as well I guess.

starting_time=freezing_behavior_df["Frame"][0] / self.video_sampling_frequency,
alessandratrapani marked this conversation as resolved.
Show resolved Hide resolved
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]
Expand Down Expand Up @@ -67,14 +85,14 @@ 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"
)
else:
behavior_module = nwbfile.processing["behavior"]

behavior_module.add(motion_series)
behavior_module.add(freeze_intervals)
6 changes: 5 additions & 1 deletion src/cai_lab_to_nwb/zaki_2024/zaki_2024_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
https://youtu.be/BKgh-XcZhIM?t=1338


## Figures to reproduce in the example notebook:
1) ![img.png](assets/motion_freezing_across_session.png)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add other for the segmentation data on this PR #7