-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from catalystneuro/behavior
Prototype Behavior Interface
- Loading branch information
Showing
5 changed files
with
130 additions
and
32 deletions.
There are no files selected for viewing
104 changes: 97 additions & 7 deletions
104
src/schneider_lab_to_nwb/schneider_2024/schneider_2024_behaviorinterface.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,115 @@ | ||
"""Primary class for converting experiment-specific behavior.""" | ||
from pynwb.file import NWBFile | ||
from pydantic import FilePath | ||
import numpy as np | ||
from h5py import File | ||
from hdmf.common.table import DynamicTableRegion | ||
from pynwb.behavior import BehavioralTimeSeries, TimeSeries | ||
from ndx_events import EventTypesTable, EventsTable, Task, TimestampVectorData | ||
|
||
from neuroconv.basedatainterface import BaseDataInterface | ||
from neuroconv.utils import DeepDict | ||
from neuroconv.tools import nwb_helpers | ||
|
||
|
||
class Schneider2024BehaviorInterface(BaseDataInterface): | ||
"""Behavior interface for schneider_2024 conversion""" | ||
|
||
keywords = ["behavior"] | ||
|
||
def __init__(self): | ||
# This should load the data lazily and prepare variables you need | ||
pass | ||
|
||
def __init__(self, file_path: FilePath): | ||
super().__init__(file_path=file_path) | ||
|
||
def get_metadata(self) -> DeepDict: | ||
# Automatically retrieve as much metadata as possible from the source files available | ||
metadata = super().get_metadata() | ||
metadata = super().get_metadata() | ||
|
||
return metadata | ||
|
||
def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict): | ||
# All the custom code to add the data the nwbfile | ||
# Read Data | ||
file_path = self.source_data["file_path"] | ||
with File(file_path, "r") as file: | ||
behavioral_time_series, name_to_times, name_to_values = [], dict(), dict() | ||
for time_series_dict in metadata["Behavior"]["TimeSeries"]: | ||
name = time_series_dict["name"] | ||
timestamps = np.array(file["continuous"][name]["time"]).squeeze() | ||
data = np.array(file["continuous"][name]["value"]).squeeze() | ||
time_series = TimeSeries( | ||
name=name, | ||
timestamps=timestamps, | ||
data=data, | ||
unit="a.u.", | ||
description=time_series_dict["description"], | ||
) | ||
behavioral_time_series.append(time_series) | ||
for event_dict in metadata["Behavior"]["Events"]: | ||
name = event_dict["name"] | ||
times = np.array(file["events"][name]["time"]).squeeze() | ||
name_to_times[name] = times | ||
for event_dict in metadata["Behavior"]["ValuedEvents"]: | ||
name = event_dict["name"] | ||
times = np.array(file["events"][name]["time"]).squeeze() | ||
values = np.array(file["events"][name]["value"]).squeeze() | ||
name_to_times[name] = times | ||
name_to_values[name] = values | ||
|
||
# Add Data to NWBFile | ||
behavior_module = nwb_helpers.get_module( | ||
nwbfile=nwbfile, | ||
name="behavior", | ||
description="Behavioral data from the experiment.", | ||
) | ||
|
||
# Add BehavioralTimeSeries | ||
behavioral_time_series = BehavioralTimeSeries( | ||
time_series=behavioral_time_series, | ||
name="behavioral_time_series", | ||
) | ||
behavior_module.add(behavioral_time_series) | ||
|
||
# Add Events | ||
event_types_table = EventTypesTable(name="event_types", description="Metadata about event types.") | ||
event_type_name_to_row = dict() | ||
i = 0 | ||
for event_dict in metadata["Behavior"]["Events"]: | ||
event_type_name_to_row[event_dict["name"]] = i | ||
event_types_table.add_row( | ||
event_name=event_dict["name"], | ||
event_type_description=event_dict["description"], | ||
) | ||
i += 1 | ||
for event_dict in metadata["Behavior"]["ValuedEvents"]: | ||
event_type_name_to_row[event_dict["name"]] = i | ||
event_types_table.add_row( | ||
event_name=event_dict["name"], | ||
event_type_description=event_dict["description"], | ||
) | ||
i += 1 | ||
events_table = EventsTable( | ||
name="events_table", | ||
description="Metadata about events.", | ||
target_tables={"event_type": event_types_table}, | ||
) | ||
for event_dict in metadata["Behavior"]["Events"]: | ||
event_times = name_to_times[event_dict["name"]] | ||
event_type = event_type_name_to_row[event_dict["name"]] | ||
for event_time in event_times: | ||
events_table.add_row(timestamp=event_time, event_type=event_type) | ||
valued_events_table = EventsTable( | ||
name="valued_events_table", | ||
description="Metadata about valued events.", | ||
target_tables={"event_type": event_types_table}, | ||
) | ||
valued_events_table.add_column(name="value", description="Value of the event.") | ||
for event_dict in metadata["Behavior"]["ValuedEvents"]: | ||
event_times = name_to_times[event_dict["name"]] | ||
event_values = name_to_values[event_dict["name"]] | ||
event_type = event_type_name_to_row[event_dict["name"]] | ||
for event_time, event_value in zip(event_times, event_values): | ||
valued_events_table.add_row(timestamp=event_time, event_type=event_type, value=event_value) | ||
behavior_module.add(events_table) | ||
behavior_module.add(valued_events_table) | ||
|
||
raise NotImplementedError() | ||
task = Task(event_types=event_types_table) | ||
nwbfile.add_lab_meta_data(task) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
src/schneider_lab_to_nwb/schneider_2024/schneider_2024_notes.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
# Notes concerning the schneider_2024 conversion | ||
|
||
## Behavior | ||
- opto events is just [0, 1] like empty variables (lick events), and opto_time in 'push' is all NaNs. Where is the actual opto stim times recorded? | ||
- TuningTones has a values field with integers, what does this correspond to? | ||
- 'push' is basically some kind of trials table, but need descriptions for variables ex. ITI_respect? | ||
|
||
## Data Requests | ||
- Mice sexes | ||
- Remaining data for Grant's project | ||
- More detailed position info for recording probe | ||
- Subfield of auditory cortex: A1? A2? AAF? etc. | ||
- stereotactic coordinates of the whole probe | ||
- | ||
- Detailed description of the behavioral paradigm | ||
- Description of lickometer and lever/treadmill quadrature encoder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters