From 776f129d044d22a0e15011e9cd6a0d23da3c5bc5 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sat, 23 Sep 2023 12:46:40 -0400 Subject: [PATCH] BUG: Fix doc building bugs --- doc/conf.py | 2 ++ examples/decoding/receptive_field_mtrf.py | 2 +- examples/inverse/mixed_norm_inverse.py | 2 +- mne/conftest.py | 4 ++++ mne/fixes.py | 5 ----- mne/transforms.py | 18 +++++++----------- mne/viz/_3d.py | 1 + tutorials/io/60_ctf_bst_auditory.py | 3 --- tutorials/machine-learning/30_strf.py | 5 ++--- .../stats-sensor-space/10_background_stats.py | 4 ++-- 10 files changed, 20 insertions(+), 26 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 422ac8fe8ef..df6a30db062 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -37,6 +37,8 @@ os.environ["MNE_BROWSER_OVERVIEW_MODE"] = "hidden" os.environ["MNE_BROWSER_THEME"] = "light" os.environ["MNE_3D_OPTION_THEME"] = "light" +# https://numba.readthedocs.io/en/latest/reference/deprecation.html#deprecation-of-old-style-numba-captured-errors # noqa: E501 +os.environ["NUMBA_CAPTURED_ERRORS"] = "new_style" sphinx_logger = sphinx.util.logging.getLogger("mne") # -- Path setup -------------------------------------------------------------- diff --git a/examples/decoding/receptive_field_mtrf.py b/examples/decoding/receptive_field_mtrf.py index 0773811f1f3..0d24d5ebfa1 100644 --- a/examples/decoding/receptive_field_mtrf.py +++ b/examples/decoding/receptive_field_mtrf.py @@ -55,7 +55,7 @@ data = loadmat(join(path, "speech_data.mat")) raw = data["EEG"].T speech = data["envelope"].T -sfreq = float(data["Fs"]) +sfreq = float(data["Fs"].item()) sfreq /= decim speech = mne.filter.resample(speech, down=decim, npad="auto") raw = mne.filter.resample(raw, down=decim, npad="auto") diff --git a/examples/inverse/mixed_norm_inverse.py b/examples/inverse/mixed_norm_inverse.py index be8b5c7e8db..f64a9f55665 100644 --- a/examples/inverse/mixed_norm_inverse.py +++ b/examples/inverse/mixed_norm_inverse.py @@ -87,7 +87,7 @@ ) t = 0.083 -tidx = evoked.time_as_index(t) +tidx = evoked.time_as_index(t).item() for di, dip in enumerate(dipoles, 1): print(f"Dipole #{di} GOF at {1000 * t:0.1f} ms: " f"{float(dip.gof[tidx]):0.1f}%") diff --git a/mne/conftest.py b/mne/conftest.py index 8f00f8202d4..6048554d07c 100644 --- a/mne/conftest.py +++ b/mne/conftest.py @@ -104,6 +104,10 @@ def pytest_configure(config): if os.getenv("PYTEST_QT_API") is None and os.getenv("QT_API") is not None: os.environ["PYTEST_QT_API"] = os.environ["QT_API"] + # https://numba.readthedocs.io/en/latest/reference/deprecation.html#deprecation-of-old-style-numba-captured-errors # noqa: E501 + if "NUMBA_CAPTURED_ERRORS" not in os.environ: + os.environ["NUMBA_CAPTURED_ERRORS"] = "old_style" + # Warnings # - Once SciPy updates not to have non-integer and non-tuple errors (1.2.0) # we should remove them from here. diff --git a/mne/fixes.py b/mne/fixes.py index c86ece210f9..1999ce1a3a1 100644 --- a/mne/fixes.py +++ b/mne/fixes.py @@ -797,7 +797,6 @@ def _jit(func): prange = range bincount = np.bincount - mean = np.mean else: @@ -823,10 +822,6 @@ def _np_apply_along_axis(func1d, axis, arr): result[i] = func1d(arr[i, :]) return result - @jit() - def mean(array, axis): # noqa: D103 - return _np_apply_along_axis(np.mean, axis, array) - ############################################################################### # Matplotlib diff --git a/mne/transforms.py b/mne/transforms.py index 00124b335a6..58f88450c56 100644 --- a/mne/transforms.py +++ b/mne/transforms.py @@ -15,7 +15,7 @@ from scipy.spatial.distance import cdist from scipy.special import sph_harm -from .fixes import jit, mean, _get_img_fdata +from .fixes import jit, _get_img_fdata from ._fiff.constants import FIFF from ._fiff.open import fiff_open from ._fiff.tag import read_tag @@ -1466,16 +1466,12 @@ def _fit_matched_points(p, x, weights=None, scale=False): assert p.ndim == 2 assert p.shape[1] == 3 # (weighted) centroids - if weights is None: - mu_p = mean(p, axis=0) # eq 23 - mu_x = mean(x, axis=0) - dots = np.dot(p.T, x) - dots /= p.shape[0] - else: - weights_ = np.reshape(weights / weights.sum(), (weights.size, 1)) - mu_p = np.dot(weights_.T, p)[0] - mu_x = np.dot(weights_.T, x)[0] - dots = np.dot(p.T, weights_ * x) + weights_ = np.full((p.shape[0], 1), 1.0 / max(p.shape[0], 1)) + if weights is not None: + weights_[:] = np.reshape(weights / weights.sum(), (weights.size, 1)) + mu_p = np.dot(weights_.T, p)[0] + mu_x = np.dot(weights_.T, x)[0] + dots = np.dot(p.T, weights_ * x) Sigma_px = dots - np.outer(mu_p, mu_x) # eq 24 # x and p should no longer be used A_ij = Sigma_px - Sigma_px.T diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index 287cbdf66b1..2b994f5f9bb 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -3464,6 +3464,7 @@ def plot_sparse_source_estimates( plt_show(show) renderer.show() + renderer.set_camera(distance="auto", focalpoint="auto") return renderer.scene() diff --git a/tutorials/io/60_ctf_bst_auditory.py b/tutorials/io/60_ctf_bst_auditory.py index 2b6d16f6918..7cb970bc986 100644 --- a/tutorials/io/60_ctf_bst_auditory.py +++ b/tutorials/io/60_ctf_bst_auditory.py @@ -21,7 +21,6 @@ `FieldTrip bug tracker `__. """ - # Authors: Mainak Jas # Eric Larson # Jaakko Leppakangas @@ -39,8 +38,6 @@ from mne.datasets.brainstorm import bst_auditory from mne.io import read_raw_ctf -print(__doc__) - # %% # To reduce memory consumption and running time, some of the steps are # precomputed. To run everything from scratch change ``use_precomputed`` to diff --git a/tutorials/machine-learning/30_strf.py b/tutorials/machine-learning/30_strf.py index f44389a6e5a..af0db4d1d20 100644 --- a/tutorials/machine-learning/30_strf.py +++ b/tutorials/machine-learning/30_strf.py @@ -93,7 +93,6 @@ plt.autoscale(tight=True) mne.viz.tight_layout() - # %% # Simulate a neural response # -------------------------- @@ -186,7 +185,7 @@ rf.fit(X_train, y_train) # Now make predictions about the model output, given input stimuli. - scores[ii] = rf.score(X_test, y_test) + scores[ii] = rf.score(X_test, y_test).item() models.append(rf) times = rf.delays_ / float(rf.sfreq) @@ -294,7 +293,7 @@ rf.fit(X_train, y_train) # Now make predictions about the model output, given input stimuli. - scores_lap[ii] = rf.score(X_test, y_test) + scores_lap[ii] = rf.score(X_test, y_test).item() models_lap.append(rf) ix_best_alpha_lap = np.argmax(scores_lap) diff --git a/tutorials/stats-sensor-space/10_background_stats.py b/tutorials/stats-sensor-space/10_background_stats.py index caf6b951951..066ab249121 100644 --- a/tutorials/stats-sensor-space/10_background_stats.py +++ b/tutorials/stats-sensor-space/10_background_stats.py @@ -8,7 +8,6 @@ Here we will briefly cover multiple concepts of inferential statistics in an introductory manner, and demonstrate how to use some MNE statistical functions. """ - # Authors: Eric Larson # # License: BSD-3-Clause @@ -250,7 +249,8 @@ def plot_t_p(t, p, title, mcc, axes=None): ps.append(np.zeros(width * width)) mccs.append(False) for ii in range(n_src): - ts[-1][ii], ps[-1][ii] = permutation_t_test(X[:, [ii]], verbose=False)[:2] + t, p = permutation_t_test(X[:, [ii]], verbose=False)[:2] + ts[-1][ii], ps[-1][ii] = t[0], p[0] plot_t_p(ts[-1], ps[-1], titles[-1], mccs[-1]) # %%