From a71dcb546c10be35b3806ce91eca19fba8523fa2 Mon Sep 17 00:00:00 2001 From: Cody Baker Date: Mon, 23 Sep 2024 23:24:34 -0400 Subject: [PATCH 1/2] expose revision --- .../datainterfaces/_pose_estimation.py | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ibl_to_nwb/datainterfaces/_pose_estimation.py b/src/ibl_to_nwb/datainterfaces/_pose_estimation.py index d0bf24b..99dcade 100644 --- a/src/ibl_to_nwb/datainterfaces/_pose_estimation.py +++ b/src/ibl_to_nwb/datainterfaces/_pose_estimation.py @@ -1,4 +1,5 @@ from datetime import datetime +from typing import Optional import numpy as np from ndx_pose import PoseEstimation, PoseEstimationSeries @@ -17,20 +18,19 @@ def __init__(self, one: ONE, session: str, camera_name: str, include_video: bool self.include_video = include_video self.include_pose = include_pose - 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*") - revision_datetime_format = "%Y-%m-%d" - revisions = [ - datetime.strptime(session_file.split("#")[1], revision_datetime_format) - for session_file in session_files - if "#" in session_file - ] - revision = None - if any(revisions): - most_recent = max(revisions) - revision = most_recent.strftime("%Y-%m-%d") + def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict, revision: Optional[str] = None): + if revision is None: + session_files = self.one.list_datasets(eid=self.session, filename=f"*{self.camera_name}.dlc*") + revision_datetime_format = "%Y-%m-%d" + revisions = [ + datetime.strptime(session_file.split("#")[1], revision_datetime_format) + for session_file in session_files + if "#" in session_file + ] + + if any(revisions): + most_recent = max(revisions) + revision = most_recent.strftime("%Y-%m-%d") camera_data = self.one.load_object(id=self.session, obj=self.camera_name, collection="alf", revision=revision) dlc_data = camera_data["dlc"] From d81fed08d0c2dfc5c31940abff230c570f2565a9 Mon Sep 17 00:00:00 2001 From: Cody Baker Date: Mon, 23 Sep 2024 23:29:36 -0400 Subject: [PATCH 2/2] expose revision --- .../convert_brainwide_map_processed_only.py | 12 +++++++--- .../datainterfaces/_pose_estimation.py | 22 ++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/ibl_to_nwb/_scripts/convert_brainwide_map_processed_only.py b/src/ibl_to_nwb/_scripts/convert_brainwide_map_processed_only.py index 068fcd8..a447471 100644 --- a/src/ibl_to_nwb/_scripts/convert_brainwide_map_processed_only.py +++ b/src/ibl_to_nwb/_scripts/convert_brainwide_map_processed_only.py @@ -18,12 +18,16 @@ WheelInterface, ) +session_id = "d32876dd-8303-4720-8e7e-20678dc2fd71" + +# Specify the revision of the pose estimation data +# Setting to 'None' will use whatever the latest released revision is +revision = None + base_path = Path("E:/IBL") nwbfiles_folder_path = base_path / "nwbfiles" nwbfiles_folder_path.mkdir(exist_ok=True) -session_id = "d32876dd-8303-4720-8e7e-20678dc2fd71" - # Initialize IBL (ONE) client to download processed data for this session one_cache_folder_path = base_path / "cache" ibl_client = ONE( @@ -46,7 +50,9 @@ for pose_estimation_file in pose_estimation_files: camera_name = pose_estimation_file.replace("alf/_ibl_", "").replace(".dlc.pqt", "") data_interfaces.append( - IblPoseEstimationInterface(one=ibl_client, session=session_id, camera_name=camera_name, include_video=False) + IblPoseEstimationInterface( + one=ibl_client, session=session_id, camera_name=camera_name, include_video=False, revision=revision + ) ) pupil_tracking_files = ibl_client.list_datasets(eid=session_id, filename="*features*") diff --git a/src/ibl_to_nwb/datainterfaces/_pose_estimation.py b/src/ibl_to_nwb/datainterfaces/_pose_estimation.py index 99dcade..11dbd25 100644 --- a/src/ibl_to_nwb/datainterfaces/_pose_estimation.py +++ b/src/ibl_to_nwb/datainterfaces/_pose_estimation.py @@ -8,18 +8,27 @@ from one.api import ONE from pynwb import NWBFile from pynwb.image import ImageSeries +from typing_extensions import Self class IblPoseEstimationInterface(BaseDataInterface): - def __init__(self, one: ONE, session: str, camera_name: str, include_video: bool, include_pose: bool): + def __init__( + self, + one: ONE, + session: str, + camera_name: str, + include_video: bool, + include_pose: bool, + revision: Optional[str] = None, + ) -> Self: self.one = one self.session = session self.camera_name = camera_name self.include_video = include_video self.include_pose = include_pose - def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict, revision: Optional[str] = None): - if revision is None: + self.revision = revision + if self.revision is None: session_files = self.one.list_datasets(eid=self.session, filename=f"*{self.camera_name}.dlc*") revision_datetime_format = "%Y-%m-%d" revisions = [ @@ -30,9 +39,12 @@ def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict, revision: Optional[st if any(revisions): most_recent = max(revisions) - revision = most_recent.strftime("%Y-%m-%d") + self.revision = most_recent.strftime("%Y-%m-%d") - camera_data = self.one.load_object(id=self.session, obj=self.camera_name, collection="alf", revision=revision) + def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict) -> None: + camera_data = self.one.load_object( + id=self.session, obj=self.camera_name, collection="alf", revision=self.revision + ) dlc_data = camera_data["dlc"] timestamps = camera_data["times"] number_of_frames = len(timestamps)