Skip to content

Commit

Permalink
remove H5DataIO references
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD committed Sep 24, 2024
1 parent ae20c59 commit 59911e3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 97 deletions.
28 changes: 4 additions & 24 deletions src/ibl_to_nwb/datainterfaces/_brainwide_map_trials.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from neuroconv.basedatainterface import BaseDataInterface
from neuroconv.utils import load_dict_from_file
from one.api import ONE
from pynwb import H5DataIO, NWBFile
from pynwb import NWBFile
from pynwb.epoch import TimeIntervals


Expand All @@ -19,15 +19,6 @@ def get_metadata(self) -> dict:
metadata.update(trial_metadata)
return metadata

def get_original_timestamps(self):
pass

def get_timestamps(self):
pass

def align_timestamps(self):
pass

def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict):
trials = self.one.load_object(id=self.session, obj="trials", collection="alf")

Expand All @@ -49,20 +40,20 @@ def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict):
VectorData(
name="start_time",
description="The beginning of the trial.",
data=H5DataIO(trials["intervals"][:, 0], compression=True),
data=trials["intervals"][:, 0],
),
VectorData(
name="stop_time",
description="The end of the trial.",
data=H5DataIO(trials["intervals"][:, 1], compression=True),
data=trials["intervals"][:, 1],
),
]
for ibl_key in column_ordering:
columns.append(
VectorData(
name=metadata["Trials"][ibl_key]["name"],
description=metadata["Trials"][ibl_key]["description"],
data=H5DataIO(trials[ibl_key], compression=True),
data=trials[ibl_key],
)
)
nwbfile.add_time_intervals(
Expand All @@ -72,14 +63,3 @@ def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict):
columns=columns,
)
)

# compression only works using the method above; method below fails
# for start_time, stop_time in trials["intervals"]:
# nwbfile.add_trial(start_time=start_time, stop_time=stop_time)

# for ibl_key in column_ordering:
# nwbfile.add_trial_column(
# name=metadata["Trials"][ibl_key]["name"],
# description=metadata["Trials"][ibl_key]["description"],
# data=H5DataIO(trials[ibl_key], compression=True),
# )
20 changes: 3 additions & 17 deletions src/ibl_to_nwb/datainterfaces/_lick_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from neuroconv.basedatainterface import BaseDataInterface
from neuroconv.tools.nwb_helpers import get_module
from one.api import ONE
from pynwb import H5DataIO
from pynwb import NWBFile
from pynwb.file import DynamicTable


Expand All @@ -11,16 +11,7 @@ def __init__(self, one: ONE, session: str):
self.one = one
self.session = session

def get_original_timestamps(self):
pass

def get_timestamps(self):
pass

def align_timestamps(self):
pass

def add_to_nwbfile(self, nwbfile, metadata: dict):
def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict):
licks = self.one.load_object(id=self.session, obj="licks", collection="alf")

lick_events_table = DynamicTable(
Expand All @@ -33,15 +24,10 @@ def add_to_nwbfile(self, nwbfile, metadata: dict):
VectorData(
name="lick_time",
description="Time stamps of licks as detected from tongue dlc traces",
data=H5DataIO(licks["times"], compression=True),
data=licks["times"],
)
],
)
# lick_events_table.add_column(
# name="lick_time",
# description="Time stamps of licks as detected from tongue dlc traces",
# data=H5DataIO(licks["times"], compression=True),
# )

behavior_module = get_module(nwbfile=nwbfile, name="behavior", description="Processed behavioral data.")
behavior_module.add(lick_events_table)
25 changes: 7 additions & 18 deletions src/ibl_to_nwb/datainterfaces/_pose_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from neuroconv.basedatainterface import BaseDataInterface
from neuroconv.tools.nwb_helpers import get_module
from one.api import ONE
from pynwb import H5DataIO
from pynwb import NWBFile
from pynwb.image import ImageSeries


Expand All @@ -17,16 +17,7 @@ def __init__(self, one: ONE, session: str, camera_name: str, include_video: bool
self.include_video = include_video
self.include_pose = include_pose

def get_original_timestamps(self):
pass

def get_timestamps(self):
pass

def align_timestamps(self):
pass

def add_to_nwbfile(self, nwbfile, metadata: dict):
def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict):
# Sometimes the DLC data has been revised, possibly multiple times
# Always use the most recent revision available
session_files = self.one.list_datasets(eid=self.session, filename=f"*{self.camera_name}.dlc*")
Expand All @@ -50,7 +41,6 @@ def add_to_nwbfile(self, nwbfile, metadata: dict):
)

left_right_or_body = self.camera_name[:5].rstrip("C")
# camera_name_snake_case = f"{left_right_or_body}_camera"
reused_timestamps = None
all_pose_estimation_series = list()
if self.include_pose:
Expand All @@ -62,15 +52,15 @@ def add_to_nwbfile(self, nwbfile, metadata: dict):
pose_estimation_series = PoseEstimationSeries(
name=body_part,
description=f"Marker placed on or around, labeled '{body_part}'.",
data=H5DataIO(body_part_data, compression=True),
data=body_part_data,
unit="px",
reference_frame="(0,0) corresponds to the upper left corner when using width by height convention.",
timestamps=reused_timestamps or H5DataIO(timestamps, compression=True),
timestamps=reused_timestamps or timestamps,
confidence=np.array(dlc_data[f"{body_part}_likelihood"]),
)
all_pose_estimation_series.append(pose_estimation_series)

reused_timestamps = all_pose_estimation_series[0] # trick for linking timestamps across series
reused_timestamps = all_pose_estimation_series[0] # A trick for linking timestamps across series

pose_estimation_kwargs = dict(
name=f"PoseEstimation{left_right_or_body.capitalize()}Camera",
Expand All @@ -88,7 +78,7 @@ def add_to_nwbfile(self, nwbfile, metadata: dict):
):
all_pose_estimation_series.append(pose_estimation_series)

reused_timestamps = all_pose_estimation_series[0] # trick for linking timestamps across series
reused_timestamps = all_pose_estimation_series[0] # A trick for linking timestamps across series

original_video_file = self.one.load_dataset(
id=self.session, dataset=f"raw_video_data/*{self.camera_name}*", download_only=True
Expand All @@ -99,7 +89,6 @@ def add_to_nwbfile(self, nwbfile, metadata: dict):
unit="n.a.",
external_file=[str(original_video_file)],
format="external",
timestamps=reused_timestamps or H5DataIO(timestamps, compression=True),
timestamps=reused_timestamps or timestamps,
)
# pose_estimation_kwargs.update(original_videos_series=[image_series]) # For future version of ndx-pose
nwbfile.add_acquisition(image_series)
13 changes: 2 additions & 11 deletions src/ibl_to_nwb/datainterfaces/_pupil_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from neuroconv.tools.nwb_helpers import get_module
from neuroconv.utils import load_dict_from_file
from one.api import ONE
from pynwb import H5DataIO, TimeSeries
from pynwb import TimeSeries
from pynwb.behavior import PupilTracking


Expand All @@ -25,15 +25,6 @@ def get_metadata(self) -> dict:

return metadata

def get_original_timestamps(self):
pass

def get_timestamps(self):
pass

def align_timestamps(self):
pass

def add_to_nwbfile(self, nwbfile, metadata: dict):
left_or_right = self.camera_name[:5].rstrip("C")

Expand All @@ -45,7 +36,7 @@ def add_to_nwbfile(self, nwbfile, metadata: dict):
TimeSeries(
name=left_or_right.capitalize() + metadata["Pupils"][ibl_key]["name"],
description=metadata["Pupils"][ibl_key]["description"],
data=H5DataIO(np.array(camera_data["features"][ibl_key]), compression=True),
data=np.array(camera_data["features"][ibl_key]),
timestamps=camera_data["times"],
unit="px",
)
Expand Down
15 changes: 3 additions & 12 deletions src/ibl_to_nwb/datainterfaces/_roi_motion_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from neuroconv.basedatainterface import BaseDataInterface
from neuroconv.tools.nwb_helpers import get_module
from one.api import ONE
from pynwb import H5DataIO, TimeSeries
from pynwb import TimeSeries


class RoiMotionEnergyInterface(BaseDataInterface):
Expand All @@ -12,15 +12,6 @@ def __init__(self, one: ONE, session: str, camera_name: str):
self.session = session
self.camera_name = camera_name

def get_original_timestamps(self):
pass

def get_timestamps(self):
pass

def align_timestamps(self):
pass

def add_to_nwbfile(self, nwbfile, metadata: dict):
left_right_or_body = self.camera_name[:5].rstrip("C")

Expand All @@ -42,8 +33,8 @@ def add_to_nwbfile(self, nwbfile, metadata: dict):
motion_energy_series = TimeSeries(
name=f"{left_right_or_body.capitalize()}CameraMotionEnergy",
description=description,
data=H5DataIO(camera_data["ROIMotionEnergy"]),
timestamps=H5DataIO(camera_data["times"]),
data=camera_data["ROIMotionEnergy"],
timestamps=camera_data["times"],
unit="a.u.",
)

Expand Down
21 changes: 6 additions & 15 deletions src/ibl_to_nwb/datainterfaces/_wheel_movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from neuroconv.tools.nwb_helpers import get_module
from neuroconv.utils import load_dict_from_file
from one.api import ONE
from pynwb import H5DataIO, TimeSeries
from pynwb import TimeSeries
from pynwb.behavior import CompassDirection, SpatialSeries
from pynwb.epoch import TimeIntervals

Expand All @@ -22,15 +22,6 @@ def get_metadata(self) -> dict:

return metadata

def get_original_timestamps(self):
pass

def get_timestamps(self):
pass

def align_timestamps(self):
pass

def add_to_nwbfile(self, nwbfile, metadata: dict):
wheel_moves = self.one.load_object(id=self.session, obj="wheelMoves", collection="alf")
wheel = self.one.load_object(id=self.session, obj="wheel", collection="alf")
Expand All @@ -56,32 +47,32 @@ def add_to_nwbfile(self, nwbfile, metadata: dict):
wheel_movement_intervals.add_column(
name=metadata["WheelMovement"]["columns"]["peakAmplitude"]["name"],
description=metadata["WheelMovement"]["columns"]["peakAmplitude"]["description"],
data=H5DataIO(wheel_moves["peakAmplitude"], compression=True),
data=wheel_moves["peakAmplitude"],
)

# Wheel position over time
compass_direction = CompassDirection(
spatial_series=SpatialSeries(
name=metadata["WheelPosition"]["name"],
description=metadata["WheelPosition"]["description"],
data=H5DataIO(wheel["position"], compression=True),
timestamps=H5DataIO(wheel["timestamps"], compression=True),
data=wheel["position"],
timestamps=wheel["timestamps"],
unit="rad",
reference_frame="Initial angle at start time is zero. Counter-clockwise is positive.",
)
)
velocity_series = TimeSeries(
name=metadata["WheelVelocity"]["name"],
description=metadata["WheelVelocity"]["description"],
data=H5DataIO(velocity, compression=True),
data=velocity,
starting_time=interpolated_starting_time,
rate=interpolated_rate,
unit="rad/s",
)
acceleration_series = TimeSeries(
name=metadata["WheelAcceleration"]["name"],
description=metadata["WheelAcceleration"]["description"],
data=H5DataIO(acceleration, compression=True),
data=acceleration,
starting_time=interpolated_starting_time,
rate=interpolated_rate,
unit="rad/s^2",
Expand Down

0 comments on commit 59911e3

Please sign in to comment.