|
21 | 21 |
|
22 | 22 | import mne.channels.montage |
23 | 23 | from mne import ( |
24 | | - __file__ as _mne_file, |
25 | | -) |
26 | | -from mne import ( |
| 24 | + EpochsArray, |
27 | 25 | create_info, |
28 | 26 | pick_types, |
29 | 27 | read_evokeds, |
30 | 28 | ) |
| 29 | +from mne import ( |
| 30 | + __file__ as _mne_file, |
| 31 | +) |
31 | 32 | from mne._fiff._digitization import ( |
32 | 33 | _count_points_by_type, |
33 | 34 | _format_dig_points, |
@@ -2145,3 +2146,28 @@ def test_fnirs_montage(): |
2145 | 2146 | raw.set_channel_types({ch_name: "eeg" for ch_name in raw.ch_names[-2:]}) |
2146 | 2147 | with pytest.raises(ValueError, match="mix of fNIRS"): |
2147 | 2148 | raw.get_montage() |
| 2149 | + |
| 2150 | + |
| 2151 | +def test_set_montage_meg_eeg_no_digitization(): |
| 2152 | + """Regression test for GH-12011. |
| 2153 | +
|
| 2154 | + set_montage() must not crash when MEG+EEG info has EEG reference |
| 2155 | + positions set to the [1, 0, 0] sentinel (digitization was skipped). |
| 2156 | + """ |
| 2157 | + ch_names = [f"EEG{i:03d}" for i in range(1, 11)] + ["MEG0111"] |
| 2158 | + ch_types = ["eeg"] * 10 + ["grad"] |
| 2159 | + info = create_info(ch_names=ch_names, sfreq=1000.0, ch_types=ch_types) |
| 2160 | + |
| 2161 | + # Simulate MEG reader behaviour when digitization is skipped: |
| 2162 | + # EEG ref position (loc[3:6]) is set to the [1, 0, 0] sentinel |
| 2163 | + with info._unlock(): |
| 2164 | + for ch in info["chs"]: |
| 2165 | + if ch["ch_name"].startswith("EEG"): |
| 2166 | + ch["loc"][3:6] = [1.0, 0.0, 0.0] |
| 2167 | + |
| 2168 | + data = np.zeros((1, len(ch_names), 100)) |
| 2169 | + epochs = EpochsArray(data, info) |
| 2170 | + |
| 2171 | + # This must not raise IndexError (regression test for GH-12011) |
| 2172 | + montage = make_standard_montage("standard_1020") |
| 2173 | + epochs.set_montage(montage, on_missing="ignore") |
0 commit comments