diff --git a/mne_icalabel/annotation/bids.pyi b/mne_icalabel/annotation/bids.pyi index 7910dacc..b52e9035 100644 --- a/mne_icalabel/annotation/bids.pyi +++ b/mne_icalabel/annotation/bids.pyi @@ -1,5 +1,4 @@ from pathlib import Path as Path -from typing import Union from mne.preprocessing import ICA @@ -7,7 +6,7 @@ from ..config import ICA_LABELS_TO_MNE as ICA_LABELS_TO_MNE from ..iclabel._config import ICLABEL_STRING_TO_NUMERICAL as ICLABEL_STRING_TO_NUMERICAL from ..utils._imports import import_optional_dependency as import_optional_dependency -def write_components_tsv(ica: ICA, fname: Union[str, Path]): +def write_components_tsv(ica: ICA, fname: str | Path): """Write channels tsv file for ICA components. Will create an accompanying JSON sidecar to explain the @@ -35,7 +34,7 @@ def write_components_tsv(ica: ICA, fname: Union[str, Path]): def mark_component( component: int, - fname: Union[str, Path], + fname: str | Path, method: str, label: str, author: str, diff --git a/mne_icalabel/config.pyi b/mne_icalabel/config.pyi index 7dd18c7c..42b5d55e 100644 --- a/mne_icalabel/config.pyi +++ b/mne_icalabel/config.pyi @@ -1,6 +1,6 @@ -from typing import Callable, Optional +from typing import Callable from .iclabel import iclabel_label_components as iclabel_label_components -ICALABEL_METHODS: dict[str, Optional[Callable]] +ICALABEL_METHODS: dict[str, Callable | None] ICA_LABELS_TO_MNE: dict[str, str] diff --git a/mne_icalabel/datasets/icalabel/icalabel.pyi b/mne_icalabel/datasets/icalabel/icalabel.pyi index 7ce23dde..41d05233 100644 --- a/mne_icalabel/datasets/icalabel/icalabel.pyi +++ b/mne_icalabel/datasets/icalabel/icalabel.pyi @@ -1,12 +1,11 @@ from pathlib import Path -from typing import Optional from _typeshed import Incomplete has_icalabel_testing_data: Incomplete def data_path( - path: Optional[str] = None, + path: str | None = None, force_update: bool = False, update_path: bool = True, download: bool = True, diff --git a/mne_icalabel/features/topomap.pyi b/mne_icalabel/features/topomap.pyi index d373beaf..005f0128 100644 --- a/mne_icalabel/features/topomap.pyi +++ b/mne_icalabel/features/topomap.pyi @@ -1,5 +1,3 @@ -from typing import Union - from _typeshed import Incomplete from mne import Info from mne.preprocessing import ICA @@ -13,7 +11,7 @@ def get_topomaps( picks: Incomplete | None = None, res: int = 64, image_interp: str = ..., - border: Union[float, str] = ..., + border: float | str = ..., extrapolate: str = ..., ) -> dict[str, NDArray[float]]: """Generate an array of scalp topographies for the picked components. @@ -64,7 +62,7 @@ def _get_topomap_array( info: Info, res: int = 64, image_interp: str = ..., - border: Union[float, str] = ..., + border: float | str = ..., extrapolate: str = ..., ) -> NDArray[float]: """Generate a scalp topographic map (n_pixels, n_pixels). diff --git a/mne_icalabel/gui/_label_components.pyi b/mne_icalabel/gui/_label_components.pyi index 1a906d7a..fedf4c16 100644 --- a/mne_icalabel/gui/_label_components.pyi +++ b/mne_icalabel/gui/_label_components.pyi @@ -1,5 +1,3 @@ -from typing import Union - from _typeshed import Incomplete from mne import BaseEpochs from mne.io import BaseRaw @@ -25,7 +23,7 @@ class ICAComponentLabeler(QMainWindow): _selected_component: int def __init__( - self, inst: Union[BaseRaw, BaseEpochs], ica: ICA, show: bool = True + self, inst: BaseRaw | BaseEpochs, ica: ICA, show: bool = True ) -> None: ... def _save_labels(self) -> None: """Save the selected labels to the ICA instance.""" @@ -56,11 +54,11 @@ class ICAComponentLabeler(QMainWindow): """ @staticmethod - def _check_inst_ica(inst: Union[BaseRaw, BaseEpochs], ica: ICA) -> None: + def _check_inst_ica(inst: BaseRaw | BaseEpochs, ica: ICA) -> None: """Check if the ICA was fitted.""" @property - def inst(self) -> Union[BaseRaw, BaseEpochs]: + def inst(self) -> BaseRaw | BaseEpochs: """Instance on which the ICA has been fitted.""" @property diff --git a/mne_icalabel/iclabel/features.pyi b/mne_icalabel/iclabel/features.pyi index dba66dc7..044b52e0 100644 --- a/mne_icalabel/iclabel/features.pyi +++ b/mne_icalabel/iclabel/features.pyi @@ -1,5 +1,3 @@ -from typing import Union - from mne import BaseEpochs from mne.io import BaseRaw from mne.preprocessing import ICA @@ -11,7 +9,7 @@ from ._utils import _mne_to_eeglab_locs as _mne_to_eeglab_locs from ._utils import _next_power_of_2 as _next_power_of_2 from ._utils import _pol2cart as _pol2cart -def get_iclabel_features(inst: Union[BaseRaw, BaseEpochs], ica: ICA): +def get_iclabel_features(inst: BaseRaw | BaseEpochs, ica: ICA): """Generate the features for ICLabel neural network. Parameters @@ -52,9 +50,7 @@ def _retrieve_eeglab_icawinv(ica: ICA) -> tuple[NDArray[float], NDArray[float]]: weights : array """ -def _compute_ica_activations( - inst: Union[BaseRaw, BaseEpochs], ica: ICA -) -> NDArray[float]: +def _compute_ica_activations(inst: BaseRaw | BaseEpochs, ica: ICA) -> NDArray[float]: """Compute the ICA activations 'icaact' variable from an MNE ICA instance. Parameters @@ -86,7 +82,7 @@ def _compute_ica_activations( """ def _eeg_topoplot( - inst: Union[BaseRaw, BaseEpochs], icawinv: NDArray[float], picks: list[str] + inst: BaseRaw | BaseEpochs, icawinv: NDArray[float], picks: list[str] ) -> NDArray[float]: """Topoplot feature.""" @@ -96,17 +92,17 @@ def _topoplotFast( """Implement topoplotFast.m from MATLAB. Each topographic map is a 32x32 images.""" def _eeg_rpsd( - inst: Union[BaseRaw, BaseEpochs], ica: ICA, icaact: NDArray[float] + inst: BaseRaw | BaseEpochs, ica: ICA, icaact: NDArray[float] ) -> NDArray[float]: """PSD feature.""" def _eeg_rpsd_constants( - inst: Union[BaseRaw, BaseEpochs], ica: ICA + inst: BaseRaw | BaseEpochs, ica: ICA ) -> tuple[int, int, int, int, NDArray[int], NDArray[float], NDArray[int]]: """Compute the constants before ``randperm`` is used to compute the subset.""" def _eeg_rpsd_compute_psdmed( - inst: Union[BaseRaw, BaseEpochs], + inst: BaseRaw | BaseEpochs, icaact: NDArray[float], ncomp: int, nfreqs: int, @@ -143,7 +139,7 @@ def _eeg_autocorr_fftw( MATLAB: 'eeg_autocorr_fftw.m'. """ -def _resample(ac: NDArray[float], fs: Union[int, float]) -> NDArray[float]: +def _resample(ac: NDArray[float], fs: int | float) -> NDArray[float]: """Resample the autocorrelation feature. The comment in EEGLAB is: diff --git a/mne_icalabel/iclabel/label_components.pyi b/mne_icalabel/iclabel/label_components.pyi index c8d7c4e9..c44b2807 100644 --- a/mne_icalabel/iclabel/label_components.pyi +++ b/mne_icalabel/iclabel/label_components.pyi @@ -1,5 +1,3 @@ -from typing import Optional, Union - from mne import BaseEpochs as BaseEpochs from mne.io import BaseRaw as BaseRaw from mne.preprocessing import ICA @@ -8,10 +6,10 @@ from .features import get_iclabel_features as get_iclabel_features from .network import run_iclabel as run_iclabel def iclabel_label_components( - inst: Union[BaseRaw, BaseEpochs], + inst: BaseRaw | BaseEpochs, ica: ICA, inplace: bool = True, - backend: Optional[str] = None, + backend: str | None = None, ): """Label the provided ICA components with the ICLabel neural network. diff --git a/mne_icalabel/iclabel/network/__init__.pyi b/mne_icalabel/iclabel/network/__init__.pyi index b8896342..bfde6007 100644 --- a/mne_icalabel/iclabel/network/__init__.pyi +++ b/mne_icalabel/iclabel/network/__init__.pyi @@ -1,12 +1,10 @@ -from typing import Optional - from numpy.typing import ArrayLike, NDArray def run_iclabel( images: ArrayLike, psds: ArrayLike, autocorr: ArrayLike, - backend: Optional[str] = "pytorch", + backend: str | None = "pytorch", ) -> NDArray: """Run the ICLabel network on the provided set of features. diff --git a/mne_icalabel/label_components.pyi b/mne_icalabel/label_components.pyi index bcf1632e..beb49a34 100644 --- a/mne_icalabel/label_components.pyi +++ b/mne_icalabel/label_components.pyi @@ -1,5 +1,3 @@ -from typing import Union - from mne import BaseEpochs as BaseEpochs from mne.io import BaseRaw as BaseRaw from mne.preprocessing import ICA @@ -8,7 +6,7 @@ from .config import ICALABEL_METHODS as ICALABEL_METHODS from .iclabel._config import ICLABEL_NUMERICAL_TO_STRING as ICLABEL_NUMERICAL_TO_STRING from .utils._checks import _validate_inst_and_ica as _validate_inst_and_ica -def label_components(inst: Union[BaseRaw, BaseEpochs], ica: ICA, method: str): +def label_components(inst: BaseRaw | BaseEpochs, ica: ICA, method: str): """Automatically label the ICA components with the selected method. Parameters diff --git a/mne_icalabel/utils/_checks.pyi b/mne_icalabel/utils/_checks.pyi index 8c7d4826..29f36d47 100644 --- a/mne_icalabel/utils/_checks.pyi +++ b/mne_icalabel/utils/_checks.pyi @@ -1,10 +1,8 @@ -from typing import Union - from mne import BaseEpochs from mne.io import BaseRaw from mne.preprocessing import ICA -def _validate_inst_and_ica(inst: Union[BaseRaw, BaseEpochs], ica: ICA): +def _validate_inst_and_ica(inst: BaseRaw | BaseEpochs, ica: ICA): """Make sure that the provided instance and ICA are valid.""" def _validate_ica(ica: ICA): diff --git a/mne_icalabel/utils/_imports.pyi b/mne_icalabel/utils/_imports.pyi index a2b9c32a..0e087bca 100644 --- a/mne_icalabel/utils/_imports.pyi +++ b/mne_icalabel/utils/_imports.pyi @@ -1,11 +1,10 @@ from types import ModuleType as ModuleType -from typing import Optional _INSTALL_MAPPING: dict[str, str] def import_optional_dependency( name: str, extra: str = "", raise_error: bool = True -) -> Optional[ModuleType]: +) -> ModuleType | None: """Import an optional dependency. By default, if a dependency is missing an ImportError with a nice message will be diff --git a/mne_icalabel/utils/config.pyi b/mne_icalabel/utils/config.pyi index 895294b2..71dad22d 100644 --- a/mne_icalabel/utils/config.pyi +++ b/mne_icalabel/utils/config.pyi @@ -1,8 +1,8 @@ -from typing import IO, Callable, Optional +from typing import IO, Callable from packaging.requirements import Requirement -def sys_info(fid: Optional[IO] = None, developer: bool = False): +def sys_info(fid: IO | None = None, developer: bool = False): """Print the system information for debugging. Parameters