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

animate_topomap - CSD fix #12605

Merged
merged 9 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion mne/_fiff/pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ def _picks_by_type(info, meg_combined=False, ref_meg=False, exclude="bads"):
exclude = _check_info_exclude(info, exclude)
if meg_combined == "auto":
meg_combined = _mag_grad_dependent(info)
picks_list = []

picks_list = {ch_type: list() for ch_type in _DATA_CH_TYPES_SPLIT}
for k in range(info["nchan"]):
if info["chs"][k]["ch_name"] not in exclude:
Expand Down
18 changes: 18 additions & 0 deletions mne/viz/tests/test_topomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,24 @@ def test_plot_topomap_animation(capsys):
plt.close("all")


def test_plot_topomap_animation_csd(capsys):
"""Test topomap plotting of CSD data."""
from mne.preprocessing import compute_current_source_density
larsoner marked this conversation as resolved.
Show resolved Hide resolved

# evoked
evoked = read_evokeds(evoked_fname, "Left Auditory", baseline=(None, 0))
evoked_csd = compute_current_source_density(evoked)

# Test animation
_, anim = evoked_csd.animate_topomap(
ch_type="csd", times=[0, 0.1], butterfly=False, time_unit="s", verbose="debug"
)
anim._func(1) # _animate has to be tested separately on 'Agg' backend.
out, _ = capsys.readouterr()
assert "extrapolation mode head to 0" in out
plt.close("all")


@pytest.mark.filterwarnings("ignore:.*No contour levels.*:UserWarning")
def test_plot_topomap_animation_nirs(fnirs_evoked, capsys):
"""Test topomap plotting for nirs data."""
Expand Down
17 changes: 2 additions & 15 deletions mne/viz/topomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3249,21 +3249,8 @@ def _topomap_animation(
from matplotlib import pyplot as plt

if ch_type is None:
ch_type = _picks_by_type(evoked.info)[0][0]
if ch_type not in (
"mag",
"grad",
"eeg",
"hbo",
"hbr",
"fnirs_od",
"fnirs_cw_amplitude",
):
raise ValueError(
"Channel type not supported. Supported channel "
"types include 'mag', 'grad', 'eeg'. 'hbo', 'hbr', "
"'fnirs_cw_amplitude', and 'fnirs_od'."
)
ch_type = _get_plot_ch_type(evoked, ch_type)

time_unit, _ = _check_time_unit(time_unit, evoked.times)
if times is None:
times = np.linspace(evoked.times[0], evoked.times[-1], 10)
Expand Down
4 changes: 3 additions & 1 deletion mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2821,5 +2821,7 @@ def _get_plot_ch_type(inst, ch_type, allow_ref_meg=False):
ch_type = type_
break
else:
raise RuntimeError("No plottable channel types found")
raise RuntimeError(
f"No plottable channel types found. Allowed types are: {allowed_types}"
)
return ch_type