From 9588f4e226b053cea1f31ecf1383cd8dc857eb2f Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Wed, 19 Jun 2024 17:20:50 +0200 Subject: [PATCH 01/11] add name parameter to the interface --- .../behavior/deeplabcut/deeplabcutdatainterface.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py b/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py index 8fa1d3cf1..8c0bc35e1 100644 --- a/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py +++ b/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py @@ -15,6 +15,7 @@ def write_subject_to_nwb( individual_name: str, config_file: FilePathType, timestamps: Optional[Union[List, np.ndarray]] = None, + name: Optional[str] = "PoseEstimation", ): """ Given, subject name, write h5file to an existing nwbfile. @@ -32,6 +33,8 @@ def write_subject_to_nwb( Path to a project config.yaml file timestamps : list, np.ndarray or None, default: None Alternative timestamps vector. If None, then use the inferred timestamps from DLC2NWB + name : str or None, default: PoseEstimation + Description of the pose estimation procedure and output. Default from npx-pose. Returns ------- nwbfile : pynwb.NWBFile @@ -45,7 +48,7 @@ def write_subject_to_nwb( df_animal = df.groupby(level="individuals", axis=1).get_group(individual_name) return dlc2nwb.utils._write_pes_to_nwbfile( - nwbfile, individual_name, df_animal, scorer, video, paf_graph, timestamps, exclude_nans=False + nwbfile, individual_name, df_animal, scorer, video, paf_graph, timestamps, exclude_nans=False, name=name, ) @@ -133,6 +136,7 @@ def add_to_nwbfile( self, nwbfile: NWBFile, metadata: Optional[dict] = None, + name: Optional[str] = "PoseEstimation", ): """ Conversion from DLC output files to nwb. Derived from dlc2nwb library. @@ -151,4 +155,5 @@ def add_to_nwbfile( individual_name=self.subject_name, config_file=str(self.source_data["config_file_path"]), timestamps=self._timestamps, + name=name, ) From c4d2a50ad9c5d247b4b4d51d77c32e9e3fed4bb6 Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Wed, 19 Jun 2024 20:15:19 +0200 Subject: [PATCH 02/11] Update src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py Co-authored-by: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> --- .../behavior/deeplabcut/deeplabcutdatainterface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py b/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py index 8c0bc35e1..fbf667126 100644 --- a/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py +++ b/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py @@ -15,7 +15,7 @@ def write_subject_to_nwb( individual_name: str, config_file: FilePathType, timestamps: Optional[Union[List, np.ndarray]] = None, - name: Optional[str] = "PoseEstimation", + container_name: Optional[str] = "PoseEstimation", ): """ Given, subject name, write h5file to an existing nwbfile. From 51032b447c05cb6429be4ddf03d8b86a8c4d1088 Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Wed, 19 Jun 2024 20:24:45 +0200 Subject: [PATCH 03/11] fix to passed variable, blacked (?) --- .../behavior/deeplabcut/deeplabcutdatainterface.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py b/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py index fbf667126..a5a13c838 100644 --- a/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py +++ b/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py @@ -48,7 +48,15 @@ def write_subject_to_nwb( df_animal = df.groupby(level="individuals", axis=1).get_group(individual_name) return dlc2nwb.utils._write_pes_to_nwbfile( - nwbfile, individual_name, df_animal, scorer, video, paf_graph, timestamps, exclude_nans=False, name=name, + nwbfile, + individual_name, + df_animal, + scorer, + video, + paf_graph, + timestamps, + exclude_nans=False, + name=container_name, ) From 8cd084fc341218ed23d1afd6a81c16b5af011765 Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Wed, 19 Jun 2024 20:38:30 +0200 Subject: [PATCH 04/11] More name changes --- .../behavior/deeplabcut/deeplabcutdatainterface.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py b/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py index a5a13c838..0c9914ca0 100644 --- a/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py +++ b/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py @@ -33,7 +33,7 @@ def write_subject_to_nwb( Path to a project config.yaml file timestamps : list, np.ndarray or None, default: None Alternative timestamps vector. If None, then use the inferred timestamps from DLC2NWB - name : str or None, default: PoseEstimation + container_name : str or None, default: PoseEstimation Description of the pose estimation procedure and output. Default from npx-pose. Returns ------- @@ -144,7 +144,7 @@ def add_to_nwbfile( self, nwbfile: NWBFile, metadata: Optional[dict] = None, - name: Optional[str] = "PoseEstimation", + container_name: Optional[str] = "PoseEstimation", ): """ Conversion from DLC output files to nwb. Derived from dlc2nwb library. @@ -163,5 +163,5 @@ def add_to_nwbfile( individual_name=self.subject_name, config_file=str(self.source_data["config_file_path"]), timestamps=self._timestamps, - name=name, + container_name=container_name, ) From cd741bec7c1d24230a8db587fee1ef531edde0e7 Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Thu, 20 Jun 2024 10:27:38 +0200 Subject: [PATCH 05/11] Added test --- tests/test_on_data/test_behavior_interfaces.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_on_data/test_behavior_interfaces.py b/tests/test_on_data/test_behavior_interfaces.py index f6d568ae5..4c82b701e 100644 --- a/tests/test_on_data/test_behavior_interfaces.py +++ b/tests/test_on_data/test_behavior_interfaces.py @@ -336,6 +336,7 @@ class TestDeepLabCutInterface(DeepLabCutInterfaceMixin, unittest.TestCase): def run_custom_checks(self): self.check_custom_timestamps(nwbfile_path=self.nwbfile_path) + self.check_renaming_instance(nwbfile_path=self.nwbfile_path) def check_custom_timestamps(self, nwbfile_path: str): # TODO: Peel out into separate test class and replace this part with check_read_nwb @@ -362,6 +363,22 @@ def check_custom_timestamps(self, nwbfile_path: str): pose_timestamps = pose_estimation.timestamps np.testing.assert_array_equal(pose_timestamps, self._custom_timestamps_case_1) + def check_renaming_instance(self, nwbfile_path: str): + custom_container_name = "TestPoseEstimation" + + metadata = self.interface.get_metadata() + metadata["NWBFile"].update(session_start_time=datetime.now().astimezone()) + + self.interface.run_conversion( + nwbfile_path=nwbfile_path, overwrite=True, metadata=metadata, container_name=custom_container_name + ) + + with NWBHDF5IO(path=nwbfile_path, mode="r", load_namespaces=True) as io: + nwbfile = io.read() + assert "behavior" in nwbfile.processing + assert "PoseEstimation" not in nwbfile.processing["behavior"].data_interfaces + assert custom_container_name in nwbfile.processing["behavior"].data_interfaces + def check_read_nwb(self, nwbfile_path: str): # TODO: move this to the upstream mixin with NWBHDF5IO(path=nwbfile_path, mode="r", load_namespaces=True) as io: From 5952da0148b4006c504a353b9e610fa76c0715e7 Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Thu, 20 Jun 2024 10:33:51 +0200 Subject: [PATCH 06/11] specify new dep in requirements-testing --- requirements-testing.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-testing.txt b/requirements-testing.txt index 3b786502a..c957e4cd5 100644 --- a/requirements-testing.txt +++ b/requirements-testing.txt @@ -6,3 +6,4 @@ ndx-miniscope spikeinterface[qualitymetrics]>=0.100.0 zarr<2.18.0 # Error with Blosc (read-only during decode) in numcodecs on May 7; check later if resolved pytest-xdist +dlc2nwb @ git+https://github.com/vigji/dlc2nwb.git@main From 98ec3ac3bc94cd2c578075519ab08ccc35e82443 Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Thu, 4 Jul 2024 07:19:49 +0200 Subject: [PATCH 07/11] fixed dep --- .../datainterfaces/behavior/deeplabcut/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neuroconv/datainterfaces/behavior/deeplabcut/requirements.txt b/src/neuroconv/datainterfaces/behavior/deeplabcut/requirements.txt index 17d8300fb..76f0ec988 100644 --- a/src/neuroconv/datainterfaces/behavior/deeplabcut/requirements.txt +++ b/src/neuroconv/datainterfaces/behavior/deeplabcut/requirements.txt @@ -1,4 +1,4 @@ -dlc2nwb>=0.3 +dlc2nwb @ git+https://github.com/vigji/dlc2nwb.git@main tables<3.9.0;python_version<'3.9' # imported by package but not included in pip setup (is included in setup.cfg) tables<3.9.2;sys_platform=="darwin" tables;sys_platform=="linux" or sys_platform=="win32" From 99247a0fd4792154db885fb0c1049cc9dc89858e Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Wed, 10 Jul 2024 21:23:40 +0200 Subject: [PATCH 08/11] Update requirements-testing.txt Co-authored-by: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> --- requirements-testing.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements-testing.txt b/requirements-testing.txt index c957e4cd5..3b786502a 100644 --- a/requirements-testing.txt +++ b/requirements-testing.txt @@ -6,4 +6,3 @@ ndx-miniscope spikeinterface[qualitymetrics]>=0.100.0 zarr<2.18.0 # Error with Blosc (read-only during decode) in numcodecs on May 7; check later if resolved pytest-xdist -dlc2nwb @ git+https://github.com/vigji/dlc2nwb.git@main From 0cb1e3107ab531f34b023cd97a3ec1bc1c2128a5 Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Wed, 10 Jul 2024 21:23:50 +0200 Subject: [PATCH 09/11] Update src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py Co-authored-by: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> --- .../behavior/deeplabcut/deeplabcutdatainterface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py b/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py index 0c9914ca0..fb4ff3678 100644 --- a/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py +++ b/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py @@ -163,5 +163,5 @@ def add_to_nwbfile( individual_name=self.subject_name, config_file=str(self.source_data["config_file_path"]), timestamps=self._timestamps, - container_name=container_name, + pose_estimation_container_kwargs=dict(name=container_name), ) From 1f35ec3adbb516b4aaee69f645bff416f97981fd Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Wed, 10 Jul 2024 21:23:59 +0200 Subject: [PATCH 10/11] Update src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py Co-authored-by: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> --- .../behavior/deeplabcut/deeplabcutdatainterface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py b/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py index fb4ff3678..1141e91a6 100644 --- a/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py +++ b/src/neuroconv/datainterfaces/behavior/deeplabcut/deeplabcutdatainterface.py @@ -144,7 +144,7 @@ def add_to_nwbfile( self, nwbfile: NWBFile, metadata: Optional[dict] = None, - container_name: Optional[str] = "PoseEstimation", + container_name: str = "PoseEstimation", ): """ Conversion from DLC output files to nwb. Derived from dlc2nwb library. From c5513ba43d7615db1c67955c0a855bb55c1100fc Mon Sep 17 00:00:00 2001 From: Luigi Petrucco Date: Wed, 10 Jul 2024 21:24:08 +0200 Subject: [PATCH 11/11] Update src/neuroconv/datainterfaces/behavior/deeplabcut/requirements.txt Co-authored-by: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> --- .../datainterfaces/behavior/deeplabcut/requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/neuroconv/datainterfaces/behavior/deeplabcut/requirements.txt b/src/neuroconv/datainterfaces/behavior/deeplabcut/requirements.txt index 76f0ec988..55d49878f 100644 --- a/src/neuroconv/datainterfaces/behavior/deeplabcut/requirements.txt +++ b/src/neuroconv/datainterfaces/behavior/deeplabcut/requirements.txt @@ -1,4 +1,3 @@ -dlc2nwb @ git+https://github.com/vigji/dlc2nwb.git@main tables<3.9.0;python_version<'3.9' # imported by package but not included in pip setup (is included in setup.cfg) tables<3.9.2;sys_platform=="darwin" tables;sys_platform=="linux" or sys_platform=="win32"