Skip to content

Commit

Permalink
add test and error message if montage is entirely absent
Browse files Browse the repository at this point in the history
  • Loading branch information
mscheltienne committed Apr 27, 2024
1 parent 7846c72 commit 77b0145
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mne_icalabel/iclabel/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def _cart2sph(_x, _y, _z):

# get the channel position dictionary
montage = raw.copy().pick(picks).get_montage()
if montage is None:
raise ValueError(
"Montage is not set. Please set the montage to provide the electrode "
"positions."
)
positions = montage.get_positions()
ch_pos = positions["ch_pos"]
# check that we do have a coordinate for every points
Expand Down
15 changes: 15 additions & 0 deletions mne_icalabel/iclabel/tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ def test_eeg_topoplot(file, eeglab_result_file):
assert np.allclose(topo, topo_eeglab, equal_nan=True)


def test_eeg_topoplot_invalid_montage():
"""Test that we raise an error if the montage is badly set."""
raw = read_raw(raw_eeglab_path, preload=True)
ica = read_ica_eeglab(raw_eeglab_path)
# get icawinv
icawinv, _ = _retrieve_eeglab_icawinv(ica)
# compute feature
raw.info["chs"][0]["loc"] = np.array([np.nan] * 12)
with pytest.raises(ValueError, match="Channel position for .* is missing"):
_eeg_topoplot(raw, icawinv, ica.ch_names)
raw.set_montage(None)
with pytest.raises(ValueError, match="Montage is not set"):
_eeg_topoplot(raw, icawinv, ica.ch_names)


# ----------------------------------------------------------------------------
@pytest.mark.filterwarnings("ignore:Estimated head radius.*:RuntimeWarning")
@pytest.mark.parametrize(
Expand Down

0 comments on commit 77b0145

Please sign in to comment.