Skip to content

Commit afd69af

Browse files
wmvanvlietlarsoner
andauthored
Take units (m or mm) into account when showing fieldmaps on top of brains (mne-tools#13101)
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
1 parent 21a185f commit afd69af

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ stages:
8989
DISPLAY: ':99'
9090
OPENBLAS_NUM_THREADS: '1'
9191
MNE_TEST_ALLOW_SKIP: '^.*(PySide6 causes segfaults).*$'
92+
MNE_BROWSER_PRECOMPUTE: 'false'
9293
steps:
9394
- bash: |
9495
set -e

doc/changes/devel/13101.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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`_.

mne/conftest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import inspect
77
import os
88
import os.path as op
9+
import platform
910
import re
1011
import shutil
1112
import sys
@@ -190,6 +191,8 @@ def pytest_configure(config: pytest.Config):
190191
ignore:Starting field name with a underscore.*:
191192
# joblib
192193
ignore:process .* is multi-threaded, use of fork/exec.*:DeprecationWarning
194+
# sklearn
195+
ignore:Python binding for RankQuantileOptions.*:RuntimeWarning
193196
""" # noqa: E501
194197
for warning_line in warning_lines.split("\n"):
195198
warning_line = warning_line.strip()
@@ -285,9 +288,10 @@ def __init__(self, exception_handler=None, signals=None):
285288
@pytest.fixture(scope="session")
286289
def azure_windows():
287290
"""Determine if running on Azure Windows."""
288-
return os.getenv(
289-
"AZURE_CI_WINDOWS", "false"
290-
).lower() == "true" and sys.platform.startswith("win")
291+
return (
292+
os.getenv("AZURE_CI_WINDOWS", "false").lower() == "true"
293+
and platform.system() == "Windows"
294+
)
291295

292296

293297
@pytest.fixture(scope="function")

mne/viz/evoked_field.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# License: BSD-3-Clause
88
# Copyright the MNE-Python contributors.
99

10+
from copy import deepcopy
1011
from functools import partial
1112

1213
import numpy as np
@@ -185,6 +186,7 @@ def __init__(
185186
if isinstance(fig, Brain):
186187
self._renderer = fig._renderer
187188
self._in_brain_figure = True
189+
self._units = fig._units
188190
if _get_3d_backend() == "notebook":
189191
raise NotImplementedError(
190192
"Plotting on top of an existing Brain figure "
@@ -195,6 +197,7 @@ def __init__(
195197
fig, bgcolor=(0.0, 0.0, 0.0), size=(600, 600)
196198
)
197199
self._in_brain_figure = False
200+
self._units = "m"
198201

199202
self.plotter = self._renderer.plotter
200203
self.interaction = interaction
@@ -277,7 +280,8 @@ def _prepare_surf_map(self, surf_map, color, alpha):
277280

278281
# Make a solid surface
279282
surf = surf_map["surf"]
280-
if self._in_brain_figure:
283+
if self._units == "mm":
284+
surf = deepcopy(surf)
281285
surf["rr"] *= 1000
282286
map_vmax = self._vmax.get(surf_map["kind"])
283287
if map_vmax is None:

mne/viz/tests/test_3d.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,21 @@ def test_plot_evoked_field(renderer):
191191
ch_type=t,
192192
)
193193
evoked.plot_field(maps, time=0.1, n_contours=n_contours)
194+
renderer.backend._close_all()
194195

195-
# Test plotting inside an existing Brain figure.
196-
brain = Brain("fsaverage", "lh", "inflated", subjects_dir=subjects_dir)
197-
fig = evoked.plot_field(maps, time=0.1, fig=brain)
196+
# Test plotting inside an existing Brain figure. Check that units are taken into
197+
# account.
198+
for units in ["mm", "m"]:
199+
brain = Brain(
200+
"fsaverage", "lh", "inflated", units=units, subjects_dir=subjects_dir
201+
)
202+
fig = evoked.plot_field(maps, time=0.1, fig=brain)
203+
assert brain._units == fig._units
204+
scale = 1000 if units == "mm" else 1
205+
assert (
206+
fig._surf_maps[0]["surf"]["rr"][0, 0] == scale * maps[0]["surf"]["rr"][0, 0]
207+
)
208+
renderer.backend._close_all()
198209

199210
# Test some methods
200211
fig = evoked.plot_field(maps, time_viewer=True)
@@ -214,6 +225,7 @@ def test_plot_evoked_field(renderer):
214225

215226
fig = evoked.plot_field(maps, time_viewer=False)
216227
assert isinstance(fig, Figure3D)
228+
renderer.backend._close_all()
217229

218230

219231
@testing.requires_testing_data

0 commit comments

Comments
 (0)