From 935bf6a41fb5505deb6b09f8d266494219d7f63d Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Tue, 14 Jan 2025 15:58:27 -0600 Subject: [PATCH] Avoid writing extra devices when using `IntanRecordingInterface` with multiple electrode groups (#1167) Co-authored-by: Szonja Weigl --- CHANGELOG.md | 1 + .../ecephys/intan/intandatainterface.py | 4 +-- .../ecephys/test_recording_interfaces.py | 26 +++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e7dfc4df..c48a29283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Small fixes should be here. ## Features ## Improvements +* Fix metadata bug in `IntanRecordingInterface` where extra devices were added incorrectly if the recording contained multiple electrode groups or names [#1166](https://github.com/catalystneuro/neuroconv/pull/1166) # v0.6.6 (December 20, 2024) diff --git a/src/neuroconv/datainterfaces/ecephys/intan/intandatainterface.py b/src/neuroconv/datainterfaces/ecephys/intan/intandatainterface.py index 2d7c849f2..126bea3b4 100644 --- a/src/neuroconv/datainterfaces/ecephys/intan/intandatainterface.py +++ b/src/neuroconv/datainterfaces/ecephys/intan/intandatainterface.py @@ -91,8 +91,8 @@ def get_metadata(self) -> dict: ecephys_metadata.update(Device=device_list) electrode_group_metadata = ecephys_metadata["ElectrodeGroup"] - electrode_group_metadata[0]["device"] = intan_device["name"] - + for electrode_group in electrode_group_metadata: + electrode_group["device"] = intan_device["name"] # Add electrodes and electrode groups ecephys_metadata.update( ElectricalSeriesRaw=dict(name="ElectricalSeriesRaw", description="Raw acquisition traces."), diff --git a/tests/test_on_data/ecephys/test_recording_interfaces.py b/tests/test_on_data/ecephys/test_recording_interfaces.py index 0520b5b42..8978efa93 100644 --- a/tests/test_on_data/ecephys/test_recording_interfaces.py +++ b/tests/test_on_data/ecephys/test_recording_interfaces.py @@ -8,6 +8,7 @@ from numpy.testing import assert_array_equal from packaging import version from pynwb import NWBHDF5IO +from pynwb.testing.mock.file import mock_NWBFile from neuroconv.datainterfaces import ( AlphaOmegaRecordingInterface, @@ -258,8 +259,6 @@ def setup_interface(self, request): def test_devices_written_correctly(self, setup_interface): - from pynwb.testing.mock.file import mock_NWBFile - nwbfile = mock_NWBFile() self.interface.add_to_nwbfile(nwbfile=nwbfile) @@ -268,6 +267,29 @@ def test_devices_written_correctly(self, setup_interface): nwbfile.devices["Intan"].description == "RHD Recording System" + def test_not_adding_extra_devices_when_recording_has_groups(self, setup_interface): + # Test that no extra-devices are added when the recording has groups + + nwbfile = mock_NWBFile() + recording = self.interface.recording_extractor + num_channels = recording.get_num_channels() + channel_groups = np.full(shape=num_channels, fill_value=0, dtype=int) + channel_groups[::2] = 1 # Every other channel is in group 1, the rest are in group 0 + recording.set_channel_groups(groups=channel_groups) + + self.interface.add_to_nwbfile(nwbfile=nwbfile) + assert len(nwbfile.devices) == 1 + + nwbfile = mock_NWBFile() + recording = self.interface.recording_extractor + num_channels = recording.get_num_channels() + group_names = np.full(shape=num_channels, fill_value="A", dtype="str") + group_names[::2] = "B" # Every other channel group is named B, the rest are named A + recording.set_property("group_name", group_names) + + self.interface.add_to_nwbfile(nwbfile=nwbfile) + assert len(nwbfile.devices) == 1 + @pytest.mark.skip(reason="This interface fails to load the necessary plugin sometimes.") class TestMaxOneRecordingInterface(RecordingExtractorInterfaceTestMixin):