From 9e068e1839e36eecfce6e95451c51dff579d5c1e Mon Sep 17 00:00:00 2001 From: ruuskas Date: Tue, 10 Dec 2024 14:14:29 +0200 Subject: [PATCH 01/15] Fix documentation bug The section "Running the test suite" was labeled as _run_tests although the references are to _run-tests. For some reason, the _run_tests reference points to a similar section in the documentation of statsmodels. --- doc/development/contributing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/development/contributing.rst b/doc/development/contributing.rst index 1cca8a8608d..07c28f55d3d 100644 --- a/doc/development/contributing.rst +++ b/doc/development/contributing.rst @@ -860,7 +860,7 @@ data with a meaningful middle (zero-point) and ``Reds`` otherwise. This applies to both visualization functions and tutorials/examples. -.. _run_tests: +.. _run-tests: Running the test suite ~~~~~~~~~~~~~~~~~~~~~~ From ed112a7c7ec2d33b409538ac8c6065bcbfd50ae0 Mon Sep 17 00:00:00 2001 From: ruuskas Date: Tue, 14 Jan 2025 15:35:48 +0200 Subject: [PATCH 02/15] Choose contours within vlim --- mne/viz/topomap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index dd63a626683..c6bc0d15dcb 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -3340,6 +3340,7 @@ def _set_contour_locator(vmin, vmax, contours): # correct number of bins is equal to contours + 1. locator = ticker.MaxNLocator(nbins=contours + 1) contours = locator.tick_values(vmin, vmax) + contours = contours[1:-1] return locator, contours From d6a13119592a7acdd977c6a1b954c9d58a58c7c5 Mon Sep 17 00:00:00 2001 From: ruuskas Date: Tue, 14 Jan 2025 16:00:35 +0200 Subject: [PATCH 03/15] Fix the case where contours is passed but not vlim --- mne/viz/topomap.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index c6bc0d15dcb..847d0eafe02 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -2287,11 +2287,17 @@ def plot_evoked_topomap( _vlim = [ _setup_vmin_vmax(data[:, i], *vlim, norm=merge_channels) for i in range(n_times) ] - _vlim = (np.min(_vlim), np.max(_vlim)) + _vlim = [np.min(_vlim), np.max(_vlim)] cmap = _setup_cmap(cmap, n_axes=n_times, norm=_vlim[0] >= 0) # set up contours if not isinstance(contours, list | np.ndarray): _, contours = _set_contour_locator(*_vlim, contours) + else: + if vlim[0] is None and np.any((contours < _vlim[0])): + _vlim[0] = contours[0] + if vlim[1] is None and np.any((contours > _vlim[1])): + _vlim[1] = contours[-1] + # prepare for main loop over times kwargs = dict( sensors=sensors, From 5bb39ae3009d8eba533b92e8dc7f762886599d64 Mon Sep 17 00:00:00 2001 From: ruuskas Date: Tue, 14 Jan 2025 16:37:49 +0200 Subject: [PATCH 04/15] Fix auto vlim in plot_evoked_joint --- mne/viz/evoked.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py index 10ec5459e02..b047de4ea32 100644 --- a/mne/viz/evoked.py +++ b/mne/viz/evoked.py @@ -27,6 +27,7 @@ _clean_names, _is_numeric, _pl, + _time_mask, _to_rgb, _validate_type, fill_doc, @@ -1988,10 +1989,18 @@ def plot_evoked_joint( contours = topomap_args.get("contours", 6) ch_type = ch_types.pop() # set should only contain one element # Since the data has all the ch_types, we get the limits from the plot. - vmin, vmax = ts_ax.get_ylim() + vmin, vmax = (None, None) norm = ch_type == "grad" vmin = 0 if norm else vmin - vmin, vmax = _setup_vmin_vmax(evoked.data, vmin, vmax, norm) + time_idx = [ + np.where( + _time_mask(evoked.times, tmin=t, tmax=None, sfreq=evoked.info["sfreq"]) + )[0][0] + for t in times_sec + ] + scalings = topomap_args["scalings"] if "scalings" in topomap_args else None + scaling = _handle_default("scalings", scalings)[ch_type] + vmin, vmax = _setup_vmin_vmax(evoked.data[:, time_idx] * scaling, vmin, vmax, norm) if not isinstance(contours, list | np.ndarray): locator, contours = _set_contour_locator(vmin, vmax, contours) else: From 1629139e6249fed5228e1c3d39238354073c1225 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 14:54:48 +0000 Subject: [PATCH 05/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/viz/topomap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 847d0eafe02..d2f715f1aaa 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -2293,9 +2293,9 @@ def plot_evoked_topomap( if not isinstance(contours, list | np.ndarray): _, contours = _set_contour_locator(*_vlim, contours) else: - if vlim[0] is None and np.any((contours < _vlim[0])): + if vlim[0] is None and np.any(contours < _vlim[0]): _vlim[0] = contours[0] - if vlim[1] is None and np.any((contours > _vlim[1])): + if vlim[1] is None and np.any(contours > _vlim[1]): _vlim[1] = contours[-1] # prepare for main loop over times From e0e092a6aed94013709a7d738a5e570d8cd5f856 Mon Sep 17 00:00:00 2001 From: Santeri Date: Tue, 14 Jan 2025 21:05:45 +0200 Subject: [PATCH 06/15] Add changelog entry --- doc/changes/devel/13063.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changes/devel/13063.bugfix.rst diff --git a/doc/changes/devel/13063.bugfix.rst b/doc/changes/devel/13063.bugfix.rst new file mode 100644 index 00000000000..76eba2032a1 --- /dev/null +++ b/doc/changes/devel/13063.bugfix.rst @@ -0,0 +1 @@ +Fix bug in the colorbars created by :func:`mne.viz.plot_evoked_topomap` by `Santeri Ruuskanen`_. \ No newline at end of file From 09b4de544656bfece37869bf6ae04f58a01d0cd0 Mon Sep 17 00:00:00 2001 From: Santeri Date: Tue, 14 Jan 2025 21:06:04 +0200 Subject: [PATCH 07/15] Add some whitespace to trigger CI --- examples/visualization/evoked_topomap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/visualization/evoked_topomap.py b/examples/visualization/evoked_topomap.py index 83d1916c6f9..96e69bda3a4 100644 --- a/examples/visualization/evoked_topomap.py +++ b/examples/visualization/evoked_topomap.py @@ -193,3 +193,4 @@ # sphinx_gallery_thumbnail_number = 9 times = np.arange(0.05, 0.151, 0.01) fig, anim = evoked.animate_topomap(times=times, ch_type="mag", frame_rate=2, blit=False) + From 87ff9aa5c7f9c56bbc50374a180e24e9c0a4a64e Mon Sep 17 00:00:00 2001 From: Santeri Date: Tue, 14 Jan 2025 21:06:57 +0200 Subject: [PATCH 08/15] Add a note in the docs of plot_evoked_topomap --- mne/viz/topomap.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 89303e18e5b..06523f7a6c4 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -2116,6 +2116,19 @@ def plot_evoked_topomap( :ref:`gridspec ` interface to adjust the colorbar size yourself. + The defaults for ``contours`` and ``vlim`` are handled as follows: + + * When neither ``vlim`` nor a list of ``contours`` is passed, MNE sets + ``vlim`` at ± the maximum absolute value of the data and then chooses + contours within those bounds. + * When ``vlim`` but not a list of ``contours`` is passed, MNE chooses + contours to be within the ``vlim``. + * When a list of ``contours`` but not ``vlim`` is passed, MNE chooses + ``vlim`` to encompass the ``contours`` and the maximum absolute value of the + data. + * When both a list of ``contours`` and ``vlim`` are passed, MNE uses them + as-is. + When ``time=="interactive"``, the figure will publish and subscribe to the following UI events: From 7a3cdb5df7754533079ef8981d0fda35bf62792b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 19:07:30 +0000 Subject: [PATCH 09/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/visualization/evoked_topomap.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/visualization/evoked_topomap.py b/examples/visualization/evoked_topomap.py index 96e69bda3a4..83d1916c6f9 100644 --- a/examples/visualization/evoked_topomap.py +++ b/examples/visualization/evoked_topomap.py @@ -193,4 +193,3 @@ # sphinx_gallery_thumbnail_number = 9 times = np.arange(0.05, 0.151, 0.01) fig, anim = evoked.animate_topomap(times=times, ch_type="mag", frame_rate=2, blit=False) - From e23146b632b03149f464036b08b65cbb7729191f Mon Sep 17 00:00:00 2001 From: Santeri Ruuskanen <66060772+ruuskas@users.noreply.github.com> Date: Tue, 14 Jan 2025 21:30:44 +0200 Subject: [PATCH 10/15] Fix sphinx error (hopefully) --- mne/viz/topomap.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 06523f7a6c4..30358c8f39d 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -2121,14 +2121,18 @@ def plot_evoked_topomap( * When neither ``vlim`` nor a list of ``contours`` is passed, MNE sets ``vlim`` at ± the maximum absolute value of the data and then chooses contours within those bounds. + * When ``vlim`` but not a list of ``contours`` is passed, MNE chooses contours to be within the ``vlim``. + * When a list of ``contours`` but not ``vlim`` is passed, MNE chooses ``vlim`` to encompass the ``contours`` and the maximum absolute value of the data. + * When both a list of ``contours`` and ``vlim`` are passed, MNE uses them as-is. + When ``time=="interactive"``, the figure will publish and subscribe to the following UI events: From c0d11bfb413feeaa8aa3d86923763c408c7144b6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 19:31:00 +0000 Subject: [PATCH 11/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/viz/topomap.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 30358c8f39d..3e3a96ccb66 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -2121,14 +2121,14 @@ def plot_evoked_topomap( * When neither ``vlim`` nor a list of ``contours`` is passed, MNE sets ``vlim`` at ± the maximum absolute value of the data and then chooses contours within those bounds. - + * When ``vlim`` but not a list of ``contours`` is passed, MNE chooses contours to be within the ``vlim``. - + * When a list of ``contours`` but not ``vlim`` is passed, MNE chooses ``vlim`` to encompass the ``contours`` and the maximum absolute value of the data. - + * When both a list of ``contours`` and ``vlim`` are passed, MNE uses them as-is. From dff1e40de6c8f06cd562a1da6fa7ce19f1ecfa19 Mon Sep 17 00:00:00 2001 From: Santeri Date: Wed, 15 Jan 2025 10:55:00 +0200 Subject: [PATCH 12/15] Remove double newline --- mne/viz/topomap.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 3e3a96ccb66..5180b3f497f 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -2132,7 +2132,6 @@ def plot_evoked_topomap( * When both a list of ``contours`` and ``vlim`` are passed, MNE uses them as-is. - When ``time=="interactive"``, the figure will publish and subscribe to the following UI events: From 8ea9bdd8af6b805028266c1598d6c240fbc45f6a Mon Sep 17 00:00:00 2001 From: Santeri Ruuskanen <66060772+ruuskas@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:52:40 +0200 Subject: [PATCH 13/15] Fix doc indents Co-authored-by: Eric Larson --- mne/viz/topomap.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 5180b3f497f..d2c28c0a937 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -2119,18 +2119,18 @@ def plot_evoked_topomap( The defaults for ``contours`` and ``vlim`` are handled as follows: * When neither ``vlim`` nor a list of ``contours`` is passed, MNE sets - ``vlim`` at ± the maximum absolute value of the data and then chooses - contours within those bounds. + ``vlim`` at ± the maximum absolute value of the data and then chooses + contours within those bounds. * When ``vlim`` but not a list of ``contours`` is passed, MNE chooses - contours to be within the ``vlim``. + contours to be within the ``vlim``. * When a list of ``contours`` but not ``vlim`` is passed, MNE chooses - ``vlim`` to encompass the ``contours`` and the maximum absolute value of the - data. + ``vlim`` to encompass the ``contours`` and the maximum absolute value of the + data. * When both a list of ``contours`` and ``vlim`` are passed, MNE uses them - as-is. + as-is. When ``time=="interactive"``, the figure will publish and subscribe to the following UI events: From 14c646212aeb235f1c791084cf11c4c794bb6cf0 Mon Sep 17 00:00:00 2001 From: Santeri Ruuskanen <66060772+ruuskas@users.noreply.github.com> Date: Wed, 15 Jan 2025 20:50:03 +0200 Subject: [PATCH 14/15] This is to trigger ci to render docs --- examples/visualization/evoked_topomap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/visualization/evoked_topomap.py b/examples/visualization/evoked_topomap.py index 83d1916c6f9..f7b57b49176 100644 --- a/examples/visualization/evoked_topomap.py +++ b/examples/visualization/evoked_topomap.py @@ -5,8 +5,8 @@ Plotting topographic maps of evoked data ======================================== -Load evoked data and plot topomaps for selected time points using multiple -additional options. +Load evoked data and plot topomaps for selected time points using +multiple additional options. """ # Authors: Christian Brodbeck # Tal Linzen From f28cc100738ac85b62ee1ed423efff32f24df119 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:50:22 +0000 Subject: [PATCH 15/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/visualization/evoked_topomap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/visualization/evoked_topomap.py b/examples/visualization/evoked_topomap.py index f7b57b49176..53b7a60dbba 100644 --- a/examples/visualization/evoked_topomap.py +++ b/examples/visualization/evoked_topomap.py @@ -5,7 +5,7 @@ Plotting topographic maps of evoked data ======================================== -Load evoked data and plot topomaps for selected time points using +Load evoked data and plot topomaps for selected time points using multiple additional options. """ # Authors: Christian Brodbeck