diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7149edac50b..9c42b3286c1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -89,6 +89,7 @@ stages: DISPLAY: ':99' OPENBLAS_NUM_THREADS: '1' MNE_TEST_ALLOW_SKIP: '^.*(PySide6 causes segfaults).*$' + MNE_BROWSER_PRECOMPUTE: 'false' steps: - bash: | set -e diff --git a/doc/changes/devel/13101.bugfix.rst b/doc/changes/devel/13101.bugfix.rst new file mode 100644 index 00000000000..d24e55b5056 --- /dev/null +++ b/doc/changes/devel/13101.bugfix.rst @@ -0,0 +1 @@ +Take units (m or mm) into account when drawing :func:`~mne.viz.plot_evoked_field` on top of :class:`~mne.viz.Brain`, by `Marijn van Vliet`_. diff --git a/mne/conftest.py b/mne/conftest.py index 2a73c7a1b8e..fabf9f93e5a 100644 --- a/mne/conftest.py +++ b/mne/conftest.py @@ -6,6 +6,7 @@ import inspect import os import os.path as op +import platform import re import shutil import sys @@ -190,6 +191,8 @@ def pytest_configure(config: pytest.Config): ignore:Starting field name with a underscore.*: # joblib ignore:process .* is multi-threaded, use of fork/exec.*:DeprecationWarning + # sklearn + ignore:Python binding for RankQuantileOptions.*:RuntimeWarning """ # noqa: E501 for warning_line in warning_lines.split("\n"): warning_line = warning_line.strip() @@ -285,9 +288,10 @@ def __init__(self, exception_handler=None, signals=None): @pytest.fixture(scope="session") def azure_windows(): """Determine if running on Azure Windows.""" - return os.getenv( - "AZURE_CI_WINDOWS", "false" - ).lower() == "true" and sys.platform.startswith("win") + return ( + os.getenv("AZURE_CI_WINDOWS", "false").lower() == "true" + and platform.system() == "Windows" + ) @pytest.fixture(scope="function") diff --git a/mne/viz/evoked_field.py b/mne/viz/evoked_field.py index cf5a9996216..839259ee117 100644 --- a/mne/viz/evoked_field.py +++ b/mne/viz/evoked_field.py @@ -7,6 +7,7 @@ # License: BSD-3-Clause # Copyright the MNE-Python contributors. +from copy import deepcopy from functools import partial import numpy as np @@ -185,6 +186,7 @@ def __init__( if isinstance(fig, Brain): self._renderer = fig._renderer self._in_brain_figure = True + self._units = fig._units if _get_3d_backend() == "notebook": raise NotImplementedError( "Plotting on top of an existing Brain figure " @@ -195,6 +197,7 @@ def __init__( fig, bgcolor=(0.0, 0.0, 0.0), size=(600, 600) ) self._in_brain_figure = False + self._units = "m" self.plotter = self._renderer.plotter self.interaction = interaction @@ -277,7 +280,8 @@ def _prepare_surf_map(self, surf_map, color, alpha): # Make a solid surface surf = surf_map["surf"] - if self._in_brain_figure: + if self._units == "mm": + surf = deepcopy(surf) surf["rr"] *= 1000 map_vmax = self._vmax.get(surf_map["kind"]) if map_vmax is None: diff --git a/mne/viz/tests/test_3d.py b/mne/viz/tests/test_3d.py index 34022d59768..97b10621108 100644 --- a/mne/viz/tests/test_3d.py +++ b/mne/viz/tests/test_3d.py @@ -191,10 +191,21 @@ def test_plot_evoked_field(renderer): ch_type=t, ) evoked.plot_field(maps, time=0.1, n_contours=n_contours) + renderer.backend._close_all() - # Test plotting inside an existing Brain figure. - brain = Brain("fsaverage", "lh", "inflated", subjects_dir=subjects_dir) - fig = evoked.plot_field(maps, time=0.1, fig=brain) + # Test plotting inside an existing Brain figure. Check that units are taken into + # account. + for units in ["mm", "m"]: + brain = Brain( + "fsaverage", "lh", "inflated", units=units, subjects_dir=subjects_dir + ) + fig = evoked.plot_field(maps, time=0.1, fig=brain) + assert brain._units == fig._units + scale = 1000 if units == "mm" else 1 + assert ( + fig._surf_maps[0]["surf"]["rr"][0, 0] == scale * maps[0]["surf"]["rr"][0, 0] + ) + renderer.backend._close_all() # Test some methods fig = evoked.plot_field(maps, time_viewer=True) @@ -214,6 +225,7 @@ def test_plot_evoked_field(renderer): fig = evoked.plot_field(maps, time_viewer=False) assert isinstance(fig, Figure3D) + renderer.backend._close_all() @testing.requires_testing_data