Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Fix issue in decomposition plotting to specified axes #280

Merged
merged 9 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ Enhancements
~~~~~~~~~~~~

- Add a new :class:`~mne_connectivity.decoding.CoherencyDecomposition` class for decomposing connectivity sources using multivariate coherency-based methods, by `Thomas Binns`_ (:pr:`193`).
- Add new plotting methods :meth:`CoherencyDecomposition.plot_filters() <mne_connectivity.decoding.CoherencyDecomposition.plot_filters>` and :meth:`CoherencyDecomposition.plot_patterns() <mne_connectivity.decoding.CoherencyDecomposition.plot_patterns>` for visualising the decomposed connectivity sources, by `Thomas Binns`_ (:pr:`208`).
- Add new plotting methods :meth:`CoherencyDecomposition.plot_filters() <mne_connectivity.decoding.CoherencyDecomposition.plot_filters>` and :meth:`CoherencyDecomposition.plot_patterns() <mne_connectivity.decoding.CoherencyDecomposition.plot_patterns>` for visualising the decomposed connectivity sources, by `Thomas Binns`_ (:pr:`208`) and (:pr:`279`).
tsbinns marked this conversation as resolved.
Show resolved Hide resolved
- Add support for computing multiple components of multivariate connectivity in the :func:`~mne_connectivity.spectral_connectivity_epochs` and :func:`~mne_connectivity.spectral_connectivity_time` functions and :class:`~mne_connectivity.decoding.CoherencyDecomposition` class, and add support for storing data with a components dimension in all :class:`~mne_connectivity.Connectivity` classes, by `Thomas Binns`_ and `Eric Larson`_ (:pr:`213`).
- Add support for :class:`mne.time_frequency.EpochsSpectrum` objects to be passed as data to the :func:`~mne_connectivity.spectral_connectivity_epochs` function, by `Thomas Binns`_ and `Eric Larson`_ (:pr:`220`).
- Add support for :class:`mne.time_frequency.EpochsTFR` objects to be passed as data to the :func:`~mne_connectivity.spectral_connectivity_epochs` and :func:`~mne_connectivity.spectral_connectivity_time` functions, by `Thomas Binns`_ and `Daniel McCloy`_ (:pr:`232`).
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was missing before #232 was merged. My bad.

- Update the cross-references for relevant functions and classes and make data types more explicit throughout the documentation, by `Thomas Binns`_ (:pr:`214`).

Bug
Expand Down
6 changes: 4 additions & 2 deletions mne_connectivity/decoding/decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def plot_filters(
"""Plot topographic filters of components.

The filters are used to extract discriminant neural sources from the measured
data (a.k.a. the backward model). :footcite:`HaufeEtAl2014`.
data (a.k.a. the backward model) :footcite:`HaufeEtAl2014`.

Seed and target filters are plotted separately.

Expand Down Expand Up @@ -714,6 +714,8 @@ def _plot_filters_patterns(
_validate_type(info, Info, "`info`", "mne.Info")
if components is None:
components = np.arange(self.n_components)
if axes is not None:
_check_option("axes", len(axes), [2], " length")

# plot seeds and targets
figs = []
Expand Down Expand Up @@ -749,7 +751,7 @@ def _plot_filters_patterns(
colorbar=colorbar,
cbar_fmt=cbar_fmt,
units=units,
axes=axes,
axes=axes[group_idx] if axes is not None else None,
time_format=f"{self._conn_estimator.name}%01d"
if name_format is None
else name_format,
Expand Down
4 changes: 4 additions & 0 deletions mne_connectivity/decoding/tests/test_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,3 +715,7 @@ def test_spectral_decomposition_error_catch(method, mode):
for plot in (decomp_class.plot_filters, decomp_class.plot_patterns):
with pytest.raises(TypeError, match="`info` must be an instance of mne.Info"):
plot({"info": epochs.info})
with pytest.raises(ValueError, match="Invalid value for the 'axes' parameter"):
plot(epochs.info, axes=[None])
with pytest.raises(ValueError, match="Invalid value for the 'axes' parameter"):
plot(epochs.info, axes=[None, None, None])
8 changes: 5 additions & 3 deletions mne_connectivity/utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,16 @@
"""

docdict["axes_topomap"] = """
axes : matplotlib.axes.Axes | list of matplotlib.axes.Axes | None (default None)
axes : list of list of matplotlib.axes.Axes | None (default None)
tsbinns marked this conversation as resolved.
Show resolved Hide resolved
The axes to plot to. If `None`, a new figure will be created with the correct number
of axes. If not `None`, the number of axes must match ``components``.
of axes. If not `None`, there must be two lists containing the axes for the seeds
and targets, respectively. In each of these two lists, the number of axes must match
``components`` if ``colorbar=False``, or ``components * 2`` if ``colorbar=True``.
"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the docstring and also added more info about the required number of axes when colourbar is plotted or not.


docdict["name_format_topomap"] = r"""
name_format : str | None (default None)
The string format for axes titles. If `None`, uses ``f"{method}%%01d"``, i.e. the
The string format for axes titles. If `None`, uses ``f"{method}%01d"``, i.e. the
method name followed by the component number.
"""
tsbinns marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Loading