Skip to content

Commit 566fa07

Browse files
authored
BUG: Fix bug with ch_name resolution (mne-tools#12086)
1 parent 23fa43c commit 566fa07

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

mne/channels/channels.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,10 @@ def find_ch_adjacency(info, ch_type):
15561556

15571557
if conn_name is not None:
15581558
logger.info(f"Reading adjacency matrix for {conn_name}.")
1559-
return read_ch_adjacency(conn_name)
1559+
adjacency, ch_names = read_ch_adjacency(conn_name)
1560+
if conn_name.startswith("neuromag") and info["ch_names"][0].startswith("MEG "):
1561+
ch_names = [ch_name.replace("MEG", "MEG ") for ch_name in ch_names]
1562+
return adjacency, ch_names
15601563
logger.info(
15611564
"Could not find a adjacency matrix for the data. "
15621565
"Computing adjacency based on Delaunay triangulations."

mne/channels/tests/test_channels.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,21 @@ def test_1020_selection():
465465
@testing.requires_testing_data
466466
def test_find_ch_adjacency():
467467
"""Test computing the adjacency matrix."""
468-
raw = read_raw_fif(raw_fname, preload=True)
468+
raw = read_raw_fif(raw_fname)
469469
sizes = {"mag": 828, "grad": 1700, "eeg": 384}
470470
nchans = {"mag": 102, "grad": 204, "eeg": 60}
471471
for ch_type in ["mag", "grad", "eeg"]:
472472
conn, ch_names = find_ch_adjacency(raw.info, ch_type)
473473
# Silly test for checking the number of neighbors.
474474
assert_equal(conn.getnnz(), sizes[ch_type])
475475
assert_equal(len(ch_names), nchans[ch_type])
476+
kwargs = dict(exclude=())
477+
if ch_type in ("mag", "grad"):
478+
kwargs["meg"] = ch_type
479+
else:
480+
kwargs[ch_type] = True
481+
want_names = [raw.ch_names[pick] for pick in pick_types(raw.info, **kwargs)]
482+
assert ch_names == want_names
476483
pytest.raises(ValueError, find_ch_adjacency, raw.info, None)
477484

478485
# Test computing the conn matrix with gradiometers.
@@ -506,7 +513,7 @@ def test_find_ch_adjacency():
506513
def test_neuromag122_adjacency():
507514
"""Test computing the adjacency matrix of Neuromag122-Data."""
508515
nm122_fname = testing_path / "misc" / "neuromag122_test_file-raw.fif"
509-
raw = read_raw_fif(nm122_fname, preload=True)
516+
raw = read_raw_fif(nm122_fname)
510517
conn, ch_names = find_ch_adjacency(raw.info, "grad")
511518
assert conn.getnnz() == 1564
512519
assert len(ch_names) == 122
@@ -515,7 +522,7 @@ def test_neuromag122_adjacency():
515522

516523
def test_drop_channels():
517524
"""Test if dropping channels works with various arguments."""
518-
raw = read_raw_fif(raw_fname, preload=True).crop(0, 0.1)
525+
raw = read_raw_fif(raw_fname).crop(0, 0.1)
519526
raw.drop_channels(["MEG 0111"]) # list argument
520527
raw.drop_channels("MEG 0112") # str argument
521528
raw.drop_channels({"MEG 0132", "MEG 0133"}) # set argument
@@ -535,7 +542,7 @@ def test_drop_channels():
535542

536543
def test_pick_channels():
537544
"""Test if picking channels works with various arguments."""
538-
raw = read_raw_fif(raw_fname, preload=True).crop(0, 0.1)
545+
raw = read_raw_fif(raw_fname).crop(0, 0.1)
539546

540547
# selected correctly 3 channels
541548
raw.pick(["MEG 0113", "MEG 0112", "MEG 0111"])

tutorials/stats-sensor-space/40_cluster_1samp_time_freq.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
Non-parametric 1 sample cluster statistic on single trial power
66
===============================================================
77
8-
This script shows how to estimate significant clusters
9-
in time-frequency power estimates. It uses a non-parametric
10-
statistical procedure based on permutations and cluster
11-
level statistics.
8+
This script shows how to estimate significant clusters in time-frequency power
9+
estimates. It uses a non-parametric statistical procedure based on permutations and
10+
cluster level statistics.
1211
1312
The procedure consists of:
1413

tutorials/stats-sensor-space/75_cluster_ftest_spatiotemporal.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
Spatiotemporal permutation F-test on full sensor data
66
=====================================================
77
8-
Tests for differential evoked responses in at least
9-
one condition using a permutation clustering test.
10-
The FieldTrip neighbor templates will be used to determine
11-
the adjacency between sensors. This serves as a spatial prior
12-
to the clustering. Spatiotemporal clusters will then
13-
be visualized using custom matplotlib code.
8+
Tests for differential evoked responses in at least one condition using a permutation
9+
clustering test. The FieldTrip neighbor templates will be used to determine the
10+
adjacency between sensors. This serves as a spatial prior to the clustering.
11+
Spatiotemporal clusters will then be visualized using custom matplotlib code.
1412
1513
Here, the unit of observation is epochs from a specific study subject.
1614
However, the same logic applies when the unit observation is

0 commit comments

Comments
 (0)