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

Improve figure size and show argument in viz functions #158

Merged
merged 9 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions pycrostates/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
from numpy.typing import NDArray


class CHData(ABC):
class CHData(ABC): # noqa: B024
"""Typing for CHData."""

pass


class CHInfo(ABC):
class CHInfo(ABC): # noqa: B024
"""Typing for CHInfo."""

pass


class Cluster(ABC):
class Cluster(ABC): # noqa: B024
"""Typing for a clustering class."""

pass


class Segmentation(ABC):
class Segmentation(ABC): # noqa: B024
"""Typing for a clustering class."""

pass
Expand Down
5 changes: 4 additions & 1 deletion pycrostates/cluster/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,14 @@ def plot(
self,
axes: Optional[Union[Axes, NDArray[Axes]]] = None,
show_gradient: Optional[bool] = False,
gradient_kwargs: dict[str, Any] = {
gradient_kwargs: dict[str, Any] = { # noqa: B006
"color": "black",
"linestyle": "-",
"marker": "P",
},
*,
block: bool = False,
show: Optional[bool] = None,
verbose: Optional[str] = None,
**kwargs,
):
Expand All @@ -541,6 +542,7 @@ def plot(
Additional keyword arguments passed to :meth:`matplotlib.axes.Axes.plot` to
plot gradient line.
%(block)s
%(show)s
%(verbose)s
**kwargs
Additional keyword arguments are passed to :func:`mne.viz.plot_topomap`.
Expand All @@ -561,6 +563,7 @@ def plot(
show_gradient=show_gradient,
gradient_kwargs=gradient_kwargs,
block=block,
show=show,
verbose=verbose,
**kwargs,
)
Expand Down
4 changes: 4 additions & 0 deletions pycrostates/cluster/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class _BaseCluster(Cluster, ChannelsMixin, ContainsMixin, MontageMixin):
},
*,
block: bool = False,
show: Optional[bool] = None,
verbose: Optional[str] = None,
**kwargs,
):
Expand All @@ -219,6 +220,9 @@ class _BaseCluster(Cluster, ChannelsMixin, ContainsMixin, MontageMixin):
plot gradient line.
block : bool
Whether to halt program execution until the figure is closed.
show : bool | None
If True, the figure is shown. If None, the figure is shown if the matplotlib backend
is interactive.
verbose : int | str | bool | None
Sets the verbosity level. The verbosity increases gradually between ``"CRITICAL"``,
``"ERROR"``, ``"WARNING"``, ``"INFO"`` and ``"DEBUG"``. If None is provided, the
Expand Down
6 changes: 3 additions & 3 deletions pycrostates/cluster/tests/test_aahc.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,15 @@ def test_properties(caplog):
normalize_input=False,
)

aahCluster_.cluster_centers_ # pylint: disable=pointless-statement
aahCluster_.cluster_centers_ # noqa: B018
assert "Clustering algorithm has not been fitted." in caplog.text
caplog.clear()

aahCluster_.info # pylint: disable=pointless-statement
aahCluster_.info # noqa: B018
assert "Clustering algorithm has not been fitted." in caplog.text
caplog.clear()

aahCluster_.fitted_data # pylint: disable=pointless-statement
aahCluster_.fitted_data # noqa: B018
assert "Clustering algorithm has not been fitted." in caplog.text
caplog.clear()

Expand Down
16 changes: 8 additions & 8 deletions pycrostates/cluster/tests/test_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,30 +392,30 @@ def test_properties(caplog):
random_state=1,
)

ModK_.cluster_centers_ # pylint: disable=pointless-statement
ModK_.cluster_centers_ # noqa: B018
assert "Clustering algorithm has not been fitted." in caplog.text
caplog.clear()

ModK_.info # pylint: disable=pointless-statement
ModK_.info # noqa: B018
assert "Clustering algorithm has not been fitted." in caplog.text
caplog.clear()

ModK_.fitted_data # pylint: disable=pointless-statement
ModK_.fitted_data # noqa: B018
assert "Clustering algorithm has not been fitted." in caplog.text
caplog.clear()

# Fitted
ModK_ = ModK.copy()

ModK_.cluster_centers_
ModK_.cluster_centers_ # noqa: B018
assert "Clustering algorithm has not been fitted." not in caplog.text
caplog.clear()

ModK_.info
ModK_.info # noqa: B018
assert "Clustering algorithm has not been fitted." not in caplog.text
caplog.clear()

ModK_.fitted_data
ModK_.fitted_data # noqa: B018
assert "Clustering algorithm has not been fitted." not in caplog.text
caplog.clear()

Expand Down Expand Up @@ -1100,15 +1100,15 @@ def test_contains_mixin():
with pytest.raises(
ValueError, match="Instance 'ModKMeans' attribute 'info' is None."
):
"eeg" in ModK_
"eeg" in ModK_ # noqa: B015
with pytest.raises(
ValueError, match="Instance 'ModKMeans' attribute 'info' is None."
):
ModK_.get_channel_types()
with pytest.raises(
ValueError, match="Instance 'ModKMeans' attribute 'info' is None."
):
ModK_.compensation_grade
ModK_.compensation_grade # noqa: B018


def test_montage_mixin():
Expand Down
6 changes: 3 additions & 3 deletions pycrostates/io/tests/test_meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_create_from_info():
info.set_montage("standard_1020")
chinfo = ChInfo(info=info)
assert chinfo["ch_names"] == ["Fp1", "Fp2", "Fpz"]
for k, ch in enumerate(info["chs"]):
for ch in info["chs"]:
assert ch["coord_frame"] == FIFF.FIFFV_COORD_HEAD
assert not all(np.isnan(elt) for elt in ch["loc"])
assert chinfo["dig"] is not None
Expand Down Expand Up @@ -228,7 +228,7 @@ def test_montage():
info.set_montage("standard_1020")
chinfo = ChInfo(info=info)
assert chinfo["ch_names"] == ["Fp1", "Fp2", "Fpz"]
for k, ch in enumerate(info["chs"]):
for ch in info["chs"]:
assert ch["coord_frame"] == FIFF.FIFFV_COORD_HEAD
assert not all(np.isnan(elt) for elt in ch["loc"])
assert chinfo["dig"] is not None
Expand Down Expand Up @@ -261,7 +261,7 @@ def test_montage():
elif isinstance(montage.get_positions()[key], np.ndarray):
assert_allclose(montage.get_positions()[key], montage2.get_positions()[key])
elif isinstance(montage.get_positions()[key], OrderedDict):
for k, v in montage.get_positions()[key].items():
for k in montage.get_positions()[key]:
assert_allclose(
montage.get_positions()[key][k],
montage2.get_positions()[key][k],
Expand Down
4 changes: 4 additions & 0 deletions pycrostates/segmentation/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,17 @@ def entropy(
def plot_cluster_centers(
self,
axes: Optional[Union[Axes, NDArray[Axes]]] = None,
*,
block: bool = False,
show: Optional[bool] = None,
):
"""Plot cluster centers as topographic maps.

Parameters
----------
%(axes_topo)s
%(block)s
%(show)s

Returns
-------
Expand All @@ -324,6 +327,7 @@ def plot_cluster_centers(
self._cluster_names,
axes,
block=block,
show=show,
)

# --------------------------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion pycrostates/segmentation/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ class _BaseSegmentation(Segmentation):
"""

def plot_cluster_centers(
self, axes: Optional[Union[Axes, NDArray[Axes]]] = None, block: bool = False
self,
axes: Optional[Union[Axes, NDArray[Axes]]] = None,
*,
block: bool = False,
show: Optional[bool] = None,
):
"""Plot cluster centers as topographic maps.

Expand All @@ -207,6 +211,9 @@ class _BaseSegmentation(Segmentation):
``≥ 1``, an array of axes of size ``n_clusters`` should be provided.
block : bool
Whether to halt program execution until the figure is closed.
show : bool | None
If True, the figure is shown. If None, the figure is shown if the matplotlib backend
is interactive.

Returns
-------
Expand Down
6 changes: 6 additions & 0 deletions pycrostates/segmentation/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def plot(
cbar_axes: Optional[Axes] = None,
*,
block: bool = False,
show: Optional[bool] = None,
verbose: Optional[str] = None,
):
"""Plot the segmentation.
Expand All @@ -65,6 +66,7 @@ def plot(
%(axes_seg)s
%(axes_cbar)s
%(block)s
%(show)s
%(verbose)s

Returns
Expand All @@ -84,6 +86,7 @@ def plot(
axes=axes,
cbar_axes=cbar_axes,
block=block,
show=show,
verbose=verbose,
)

Expand Down Expand Up @@ -138,6 +141,7 @@ def plot(
cbar_axes: Optional[Axes] = None,
*,
block: bool = False,
show: Optional[bool] = None,
verbose=None,
):
"""Plot segmentation.
Expand All @@ -148,6 +152,7 @@ def plot(
%(axes_seg)s
%(axes_cbar)s
%(block)s
%(show)s
%(verbose)s

Returns
Expand All @@ -165,6 +170,7 @@ def plot(
axes=axes,
cbar_axes=cbar_axes,
block=block,
show=show,
verbose=verbose,
)

Expand Down
8 changes: 8 additions & 0 deletions pycrostates/segmentation/segmentation.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class RawSegmentation(_BaseSegmentation):
cbar_axes: Optional[Axes] = None,
*,
block: bool = False,
show: Optional[bool] = None,
verbose: Optional[str] = None,
):
"""Plot the segmentation.
Expand All @@ -59,6 +60,9 @@ class RawSegmentation(_BaseSegmentation):
axes.
block : bool
Whether to halt program execution until the figure is closed.
show : bool | None
If True, the figure is shown. If None, the figure is shown if the matplotlib backend
is interactive.
verbose : int | str | bool | None
Sets the verbosity level. The verbosity increases gradually between ``"CRITICAL"``,
``"ERROR"``, ``"WARNING"``, ``"INFO"`` and ``"DEBUG"``. If None is provided, the
Expand Down Expand Up @@ -100,6 +104,7 @@ class EpochsSegmentation(_BaseSegmentation):
cbar_axes: Optional[Axes] = None,
*,
block: bool = False,
show: Optional[bool] = None,
verbose: Incomplete | None = None,
):
"""Plot segmentation.
Expand All @@ -116,6 +121,9 @@ class EpochsSegmentation(_BaseSegmentation):
axes.
block : bool
Whether to halt program execution until the figure is closed.
show : bool | None
If True, the figure is shown. If None, the figure is shown if the matplotlib backend
is interactive.
verbose : int | str | bool | None
Sets the verbosity level. The verbosity increases gradually between ``"CRITICAL"``,
``"ERROR"``, ``"WARNING"``, ``"INFO"`` and ``"DEBUG"``. If None is provided, the
Expand Down
8 changes: 8 additions & 0 deletions pycrostates/utils/_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Any

import numpy as np
from matplotlib import pyplot as plt
from matplotlib.axes import Axes
from mne import pick_info
from mne.utils import check_random_state
Expand Down Expand Up @@ -337,3 +338,10 @@ def _check_verbose(verbose: Any) -> int:
)

return verbose


def _ensure_valid_show(show: Any) -> bool:
"""Check show parameter."""
_check_type(show, (bool, None), "show")
show = plt.isinteractive() if show is None else show
return show
5 changes: 5 additions & 0 deletions pycrostates/utils/_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@
segmentation : RawSegmentation | EpochsSegmentation
Segmentation object containing the microstate symbolic sequence."""

docdict["show"] = """
show : bool | None
If True, the figure is shown. If None, the figure is shown if the matplotlib backend
is interactive."""

docdict["stat_expected_transitions"] = """
stat : str
Aggregate statistic to compute transitions. Can be:
Expand Down
Loading