Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into trame
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Sep 6, 2023
2 parents b46574f + 5363603 commit a5a8df9
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 94 deletions.
14 changes: 2 additions & 12 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from datetime import datetime, timezone
import faulthandler
import gc
from importlib.metadata import metadata
import os
import subprocess
import sys
Expand Down Expand Up @@ -1431,18 +1432,7 @@ def reset_warnings(gallery_conf, fname):

# -- Dependency info ----------------------------------------------------------

try:
from importlib.metadata import metadata # new in Python 3.8

min_py = metadata("mne")["Requires-Python"]
except ModuleNotFoundError:
from pkg_resources import get_distribution

info = get_distribution("mne").get_metadata_lines("PKG-INFO")
for line in info:
if line.strip().startswith("Requires-Python"):
min_py = line.split(":")[1]
min_py = min_py.lstrip(" =<>")
min_py = metadata("mne")["Requires-Python"].lstrip(" =<>")
rst_prolog += f"\n.. |min_python_version| replace:: {min_py}\n"

# -- website redirects --------------------------------------------------------
Expand Down
55 changes: 35 additions & 20 deletions doc/install/check_installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,41 @@ a terminal::
This should display some system information along with the versions of
MNE-Python and its dependencies. Typical output looks like this::

Platform: Linux-5.0.0-1031-gcp-x86_64-with-glibc2.2.5
Python: 3.8.1 (default, Dec 20 2019, 10:06:11) [GCC 7.4.0]
Executable: /home/travis/virtualenv/python3.8.1/bin/python
CPU: x86_64: 2 cores
Memory: 7.8 GB

mne: 0.21.dev0
numpy: 1.19.0.dev0+8dfaa4a {blas=openblas, lapack=openblas}
scipy: 1.5.0.dev0+f614064
matplotlib: 3.2.1 {backend=QtAgg}

sklearn: 0.22.2.post1
numba: 0.49.0
nibabel: 3.1.0
cupy: Not found
pandas: 1.0.3
dipy: 1.1.1
pyvista: 0.25.2 {pyvistaqt=0.1.0}
vtk: 9.0.0
qtpy: 2.0.1 {PySide6=6.2.4}
Platform Windows-10-10.0.20348-SP0
Python 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:34:57) [MSC v.1936 64 bit (AMD64)]
Executable C:\Miniconda3\envs\mne\python.exe
CPU Intel64 Family 6 Model 85 Stepping 7, GenuineIntel (2 cores)
Memory 7.0 GB

Core
├☑ mne 1.6.0.dev67+gb12384562
├☑ numpy 1.25.2 (OpenBLAS 0.3.23.dev with 1 thread)
├☑ scipy 1.11.2
├☑ matplotlib 3.7.2 (backend=QtAgg)
├☑ pooch 1.7.0
└☑ jinja2 3.1.2

Numerical (optional)
├☑ sklearn 1.3.0
├☑ nibabel 5.1.0
├☑ nilearn 0.10.1
├☑ dipy 1.7.0
├☑ openmeeg 2.5.6
├☑ pandas 2.1.0
└☐ unavailable numba, cupy

Visualization (optional)
├☑ pyvista 0.41.1 (OpenGL 3.3 (Core Profile) Mesa 10.2.4 (git-d92815a) via Gallium 0.4 on llvmpipe (LLVM 3.4, 256 bits))
├☑ pyvistaqt 0.0.0
├☑ ipyvtklink 0.2.2
├☑ vtk 9.2.6
├☑ qtpy 2.4.0 (PyQt5=5.15.8)
├☑ ipympl 0.9.3
├☑ pyqtgraph 0.13.3
└☑ mne-qt-browser 0.5.2

Ecosystem (optional)
└☐ unavailable mne-bids, mne-nirs, mne-features, mne-connectivity, mne-icalabel, mne-bids-pipeline


.. dropdown:: If you get an error...
Expand Down
3 changes: 1 addition & 2 deletions mne/commands/mne_setup_source_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ def run():
"--add-dist",
dest="add_dist",
help='Add distances. Can be "True", "False", or "patch" '
"to only compute cortical patch statistics (like the "
"--cps option in MNE-C; requires SciPy >= 1.3)",
"to only compute cortical patch statistics (like the --cps option in MNE-C)",
default="True",
)
parser.add_option(
Expand Down
4 changes: 2 additions & 2 deletions mne/coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ def _decimate_points(pts, res=10):
mids = np.c_[x, y, z] + res / 2.0

# each point belongs to at most one voxel center, so figure those out
# (cKDTree faster than BallTree for these small problems)
tree = _DistanceQuery(mids, method="cKDTree")
# (KDTree faster than BallTree for these small problems)
tree = _DistanceQuery(mids, method="KDTree")
_, mid_idx = tree.query(pts)

# then figure out which to actually use based on proximity
Expand Down
2 changes: 1 addition & 1 deletion mne/morph.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def compute_source_morph(
Number of iterations for the smoothing of the surface data.
If None, smooth is automatically defined to fill the surface
with non-zero values. Can also be ``'nearest'`` to use the nearest
vertices on the surface (requires SciPy >= 1.3).
vertices on the surface.
.. versionchanged:: 0.20
Added support for 'nearest'.
Expand Down
2 changes: 1 addition & 1 deletion mne/morph_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _make_morph_map_hemi(subject_from, subject_to, subjects_dir, reg_from, reg_t
_normalize_vectors(to_rr)

# from surface: get nearest neighbors, find triangles for each vertex
nn_pts_idx = _compute_nearest(from_rr, to_rr, method="cKDTree")
nn_pts_idx = _compute_nearest(from_rr, to_rr, method="KDTree")
from_pt_tris = _triangle_neighbors(from_tri, len(from_rr))
from_pt_tris = [from_pt_tris[pt_idx].astype(int) for pt_idx in nn_pts_idx]
from_pt_lens = np.cumsum([0] + [len(x) for x in from_pt_tris])
Expand Down
4 changes: 2 additions & 2 deletions mne/source_space/_source_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ def setup_source_space(
add_dist : bool | str
Add distance and patch information to the source space. This takes some
time so precomputing it is recommended. Can also be 'patch' to only
compute patch information (requires SciPy 1.3+).
compute patch information.
.. versionchanged:: 0.20
Support for ``add_dist='patch'``.
Expand Down Expand Up @@ -2575,7 +2575,7 @@ def _filter_source_spaces(surf, limit, mri_head_t, src, n_jobs=None, verbose=Non
idx = idx[mask]
check_r1s = check_r1s[mask]
dists = _compute_nearest(
surf["rr"], check_r1s, return_dists=True, method="cKDTree"
surf["rr"], check_r1s, return_dists=True, method="KDTree"
)[1]
close = dists < limit / 1000.0
omit_limit = np.sum(close)
Expand Down
21 changes: 7 additions & 14 deletions mne/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ class _DistanceQuery:
"""Wrapper for fast distance queries."""

def __init__(self, xhs, method="BallTree", allow_kdtree=False):
assert method in ("BallTree", "cKDTree", "cdist")
assert method in ("BallTree", "KDTree", "cdist")

# Fastest for our problems: balltree
if method == "BallTree":
Expand All @@ -581,7 +581,7 @@ def __init__(self, xhs, method="BallTree", allow_kdtree=False):
"Nearest-neighbor searches will be significantly "
"faster if scikit-learn is installed."
)
method = "cKDTree"
method = "KDTree"
else:
self.query = partial(
_safe_query,
Expand All @@ -590,18 +590,11 @@ def __init__(self, xhs, method="BallTree", allow_kdtree=False):
return_distance=True,
)

# Then cKDTree
if method == "cKDTree":
try:
from scipy.spatial import cKDTree
except ImportError:
method = "cdist"
else:
self.query = cKDTree(xhs).query
# Then KDTree
if method == "KDTree":
from scipy.spatial import KDTree

# KDTree is really only faster for huge (~100k) sets,
# (e.g., with leafsize=2048), and it's slower for small (~5k)
# sets. We can add it later if we think it will help.
self.query = KDTree(xhs).query

# Then the worst: cdist
if method == "cdist":
Expand Down Expand Up @@ -1408,7 +1401,7 @@ def _decimate_surface_sphere(rr, tris, n_triangles):
sphere_rr, _ = read_surface(qsphere)
norms = np.linalg.norm(sphere_rr, axis=1, keepdims=True)
sphere_rr /= norms
idx = _compute_nearest(sphere_rr, ico_surf["rr"], method="cKDTree")
idx = _compute_nearest(sphere_rr, ico_surf["rr"], method="KDTree")
n_dup = len(idx) - len(np.unique(idx))
if n_dup:
raise RuntimeError(
Expand Down
6 changes: 1 addition & 5 deletions mne/tests/test_morph.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from mne.minimum_norm import apply_inverse, read_inverse_operator, make_inverse_operator
from mne.source_space._source_space import _add_interpolator, _grid_interp
from mne.transforms import quat_to_rot
from mne.utils import check_version, catch_logging, _record_warnings
from mne.utils import catch_logging, _record_warnings

# Setup paths

Expand Down Expand Up @@ -244,10 +244,6 @@ def test_surface_source_morph_round_trip(smooth, lower, upper, n_warn, dtype):
if dtype is complex:
stc.data = 1j * stc.data
assert_array_equal(stc.data.real, 0.0)
if smooth == "nearest" and not check_version("scipy", "1.3"):
with pytest.raises(ValueError, match="required to use nearest"):
morph = compute_source_morph(stc, "sample", "fsaverage", **kwargs)
return
with _record_warnings() as w:
morph = compute_source_morph(stc, "sample", "fsaverage", **kwargs)
w = [ww for ww in w if "vertices not included" in str(ww.message)]
Expand Down
4 changes: 2 additions & 2 deletions mne/tests/test_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ def test_compute_nearest():
y = x[nn_true]

nn1 = _compute_nearest(x, y, method="BallTree")
nn2 = _compute_nearest(x, y, method="cKDTree")
nn2 = _compute_nearest(x, y, method="KDTree")
nn3 = _compute_nearest(x, y, method="cdist")
assert_array_equal(nn_true, nn1)
assert_array_equal(nn_true, nn2)
assert_array_equal(nn_true, nn3)

# test distance support
nnn1 = _compute_nearest(x, y, method="BallTree", return_dists=True)
nnn2 = _compute_nearest(x, y, method="cKDTree", return_dists=True)
nnn2 = _compute_nearest(x, y, method="KDTree", return_dists=True)
nnn3 = _compute_nearest(x, y, method="cdist", return_dists=True)
assert_array_equal(nnn1[0], nn_true)
assert_array_equal(nnn1[1], np.zeros_like(nn1)) # all dists should be 0
Expand Down
34 changes: 6 additions & 28 deletions mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2838,7 +2838,7 @@ def _generate_default_filename(ext=".png"):


def _prop_kw(kind, val):
# Can be removed in when we depend on matplotlib 3.4.3+
# Can be removed in when we depend on matplotlib 3.5+
# https://github.com/matplotlib/matplotlib/pull/20585
from matplotlib.widgets import SpanSelector

Expand All @@ -2863,39 +2863,17 @@ def _handle_precompute(precompute):
def _set_3d_axes_equal(ax):
"""Make axes of 3D plot have equal scale on all dimensions.
This way spheres appear as actual spheres, cubes as cubes, etc..
This is one possible solution to Matplotlib's ``ax.set_aspect('equal')``
and ``ax.axis('equal')`` not working for 3D.
This way spheres appear as actual spheres, cubes as cubes, etc.
Parameters
----------
ax: matplotlib.axes.Axes
A matplotlib 3d axis to use.
Notes
-----
modified from:
https://stackoverflow.com/q/13685386
Should no longer be necessary for matplotlib >= 3.3.0:
https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.3.0.html#axes3d-no-longer-distorts-the-3d-plot-to-match-the-2d-aspect-ratio
"""
x_lim, y_lim, z_lim = ax.get_xlim3d(), ax.get_ylim3d(), ax.get_zlim3d()

def get_range(lim):
return lim[1] - lim[0], np.mean(lim)

x_range, x_mean = get_range(x_lim)
y_range, y_mean = get_range(y_lim)
z_range, z_mean = get_range(z_lim)

# The plot bounding box is a sphere in the sense of the infinity
# norm, hence I call half the max range the plot radius.
plot_radius = 0.5 * max([x_range, y_range, z_range])

ax.set_xlim3d([x_mean - plot_radius, x_mean + plot_radius])
ax.set_ylim3d([y_mean - plot_radius, y_mean + plot_radius])
ax.set_zlim3d([z_mean - plot_radius, z_mean + plot_radius])
ranges = tuple(
np.abs(np.diff(getattr(ax, f"get_{d}lim")())).item() for d in ("x", "y", "z")
)
ax.set_box_aspect(ranges)


def _check_type_projs(projs):
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# requirements for full MNE-Python functionality (other than raw/epochs export)
numpy>=1.15.4
scipy>=1.6.3
matplotlib>=3.4.0
scipy>=1.7.1
matplotlib>=3.4.3
tqdm
pooch>=1.5
decorator
Expand Down
3 changes: 0 additions & 3 deletions tutorials/intro/40_sensor_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
import matplotlib.pyplot as plt
import numpy as np

# the following import is required for matplotlib < 3.2:
from mpl_toolkits.mplot3d import Axes3D # noqa

import mne

# %%
Expand Down

0 comments on commit a5a8df9

Please sign in to comment.