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

Avoid writing extra devices when using IntanRecordingInterface with multiple electrode groups #1167

Merged
merged 15 commits into from
Jan 14, 2025
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down
26 changes: 24 additions & 2 deletions tests/test_on_data/ecephys/test_recording_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand Down
Loading