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 name parameter to the DeepLabCutInterface #917

Merged
merged 13 commits into from
Jul 11, 2024
1 change: 1 addition & 0 deletions requirements-testing.txt
vigji marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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
vigji marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def write_subject_to_nwb(
individual_name: str,
config_file: FilePathType,
timestamps: Optional[Union[List, np.ndarray]] = None,
container_name: Optional[str] = "PoseEstimation",
):
"""
Given, subject name, write h5file to an existing nwbfile.
Expand All @@ -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
container_name : str or None, default: PoseEstimation
Description of the pose estimation procedure and output. Default from npx-pose.
Returns
-------
nwbfile : pynwb.NWBFile
Expand All @@ -45,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
nwbfile,
individual_name,
df_animal,
scorer,
video,
paf_graph,
timestamps,
exclude_nans=False,
name=container_name,
)


Expand Down Expand Up @@ -133,6 +144,7 @@ def add_to_nwbfile(
self,
nwbfile: NWBFile,
metadata: Optional[dict] = None,
container_name: Optional[str] = "PoseEstimation",
vigji marked this conversation as resolved.
Show resolved Hide resolved
):
"""
Conversion from DLC output files to nwb. Derived from dlc2nwb library.
Expand All @@ -151,4 +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,
vigji marked this conversation as resolved.
Show resolved Hide resolved
)
Original file line number Diff line number Diff line change
@@ -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)
vigji marked this conversation as resolved.
Show resolved Hide resolved
tables<3.9.2;sys_platform=="darwin"
tables;sys_platform=="linux" or sys_platform=="win32"
17 changes: 17 additions & 0 deletions tests/test_on_data/test_behavior_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
Loading