From 39d60403d567e71c5b1ddcf38ab40580326a3a53 Mon Sep 17 00:00:00 2001 From: aaronkanzer Date: Sat, 24 Oct 2026 07:56:26 -0400 Subject: [PATCH] Fix write_BIDS_probe crash when device_channel_indices are set --- src/probeinterface/io.py | 2 +- tests/test_io/test_io.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/probeinterface/io.py b/src/probeinterface/io.py index 84924300..2dbe20e3 100644 --- a/src/probeinterface/io.py +++ b/src/probeinterface/io.py @@ -384,7 +384,7 @@ def write_BIDS_probe(folder: str | Path, probe_or_probegroup: Probe | ProbeGroup channel_indices = [] for probe in probes: - if probe.device_channel_indices: + if probe.device_channel_indices is not None: channel_indices.extend(probe.device_channel_indices) else: channel_indices.extend([-1] * probe.get_contact_count()) diff --git a/tests/test_io/test_io.py b/tests/test_io/test_io.py index 9a69d3b5..336a999a 100644 --- a/tests/test_io/test_io.py +++ b/tests/test_io/test_io.py @@ -120,6 +120,23 @@ def test_BIDS_format(tmp_path): assert all(probe_orig.contact_plane_axes[i][dim] == probe_read.contact_plane_axes[t][i][dim]) +def test_BIDS_format_with_device_channel_indices(tmp_path): + folder_path = tmp_path / "test_BIDS_wired" + folder_path.mkdir() + + probe = generate_dummy_probe() + probe.annotate(type="laminar") + channel_indices = np.arange(probe.get_contact_count())[::-1] + probe.set_device_channel_indices(channel_indices) + + write_BIDS_probe(folder_path, probe) + probegroup_read = read_BIDS_probe(folder_path) + + probe_read = probegroup_read.probes[0] + t = np.array([list(probe_read.contact_ids).index(cid) for cid in probe.contact_ids]) + np.testing.assert_array_equal(probe_read.device_channel_indices[t], channel_indices) + + def test_BIDS_format_empty(tmp_path): folder_path = tmp_path / "test_BIDS_minimal" folder_path.mkdir()