From ae3670990303815b724feff4f59c16199d4e0218 Mon Sep 17 00:00:00 2001 From: Stefan Appelhoff Date: Thu, 12 Jun 2025 10:32:37 +0200 Subject: [PATCH 1/8] DOC: fix numpydoc --- meegkit/asr.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/meegkit/asr.py b/meegkit/asr.py index 29ce33ca..45c1720f 100755 --- a/meegkit/asr.py +++ b/meegkit/asr.py @@ -21,14 +21,12 @@ class ASR: component-based artifact removal method for removing transient or large-amplitude artifacts in multi-channel EEG recordings [1]_. + The key parameter of the method is ``cutoff``. + Parameters ---------- sfreq : float Sampling rate of the data, in Hz. - - The following are optional parameters (the key parameter of the method is - the ``cutoff``): - cutoff: float Standard deviation cutoff for rejection. X portions whose variance is larger than this threshold relative to the calibration data are @@ -60,7 +58,7 @@ class ASR: ASR [2]_. memory : float Memory size (s), regulates the number of covariance matrices to store. - estimator : str in {'scm', 'lwf', 'oas', 'mcd'} + estimator : {'scm', 'lwf', 'oas', 'mcd'} Covariance estimator (default: 'scm' which computes the sample covariance). Use 'lwf' if you need regularization (requires pyriemann). From 81efe6e972ab00b5b259848e234c88857831c6f3 Mon Sep 17 00:00:00 2001 From: Stefan Appelhoff Date: Thu, 12 Jun 2025 10:55:22 +0200 Subject: [PATCH 2/8] DOC: fix typos --- meegkit/asr.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/meegkit/asr.py b/meegkit/asr.py index 45c1720f..4e6aaff2 100755 --- a/meegkit/asr.py +++ b/meegkit/asr.py @@ -139,10 +139,10 @@ def fit(self, X, y=None, **kwargs): """Calibration for the Artifact Subspace Reconstruction method. The input to this data is a multi-channel time series of calibration - data. In typical uses the calibration data is clean resting EEG data of - data if the fraction of artifact content is below the breakdown point + data. In typical uses the calibration data is clean resting EEG data. + The fraction of artifact content should be below the breakdown point of the robust statistics used for estimation (50% theoretical, ~30% - practical). If the data has a proportion of more than 30-50% artifacts + practical). If the data has a proportion of more than 30-50% artifacts, then bad time windows should be removed beforehand. This data is used to estimate the thresholds that are used by the ASR processing function to identify and remove artifact components. From e41dd17115ecbae7f9cdc3ceccd2c200c87c8583 Mon Sep 17 00:00:00 2001 From: Stefan Appelhoff Date: Thu, 12 Jun 2025 10:57:48 +0200 Subject: [PATCH 3/8] make ASR init kw only, fix name and memory kwargs --- meegkit/asr.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/meegkit/asr.py b/meegkit/asr.py index 4e6aaff2..7d2ae7e3 100755 --- a/meegkit/asr.py +++ b/meegkit/asr.py @@ -56,8 +56,9 @@ class ASR: method : {'riemann', 'euclid'} Method to use. If riemann, use the riemannian-modified version of ASR [2]_. - memory : float + memory : float | None Memory size (s), regulates the number of covariance matrices to store. + If None (default), will use twice the sampling frequency. estimator : {'scm', 'lwf', 'oas', 'mcd'} Covariance estimator (default: 'scm' which computes the sample covariance). Use 'lwf' if you need regularization (requires pyriemann). @@ -96,9 +97,9 @@ class ASR: """ - def __init__(self, sfreq=250, cutoff=5, blocksize=100, win_len=0.5, + def __init__(self, *, sfreq=250, cutoff=5, blocksize=100, win_len=0.5, win_overlap=0.66, max_dropout_fraction=0.1, - min_clean_fraction=0.25, name="asrfilter", method="euclid", + min_clean_fraction=0.25, method="euclid", memory=None, estimator="scm", **kwargs): if pyriemann is None and method == "riemann": @@ -113,7 +114,10 @@ def __init__(self, sfreq=250, cutoff=5, blocksize=100, win_len=0.5, self.min_clean_fraction = min_clean_fraction self.max_bad_chans = 0.3 self.method = method - self.memory = int(2 * sfreq) # smoothing window for covariances + if memory is None: + self.memory = int(2 * sfreq) # smoothing window for covariances + else: + self.memory = memory self.sample_weight = np.geomspace(0.05, 1, num=self.memory + 1) self.sfreq = sfreq self.estimator = estimator From 3dd6f0e42d78a9a65dd4153f434eb1543a26601b Mon Sep 17 00:00:00 2001 From: Stefan Appelhoff Date: Thu, 12 Jun 2025 11:06:55 +0200 Subject: [PATCH 4/8] DOC: add Returns section to fit method --- meegkit/asr.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/meegkit/asr.py b/meegkit/asr.py index 7d2ae7e3..f0509338 100755 --- a/meegkit/asr.py +++ b/meegkit/asr.py @@ -166,6 +166,12 @@ def fit(self, X, y=None, **kwargs): reasonably clean not less than 30 seconds (this method is typically used with 1 minute or more). + Returns + ------- + clean : array, shape=(n_channels, n_samples) + Dataset with bad time periods removed. + sample_mask : boolean array, shape=(1, n_samples) + Mask of retained samples (logical array). """ if X.ndim == 3: X = X.squeeze() From 2c84f733cbbfc9967aaf74587850f73710dd0485 Mon Sep 17 00:00:00 2001 From: Stefan Appelhoff Date: Thu, 12 Jun 2025 11:27:23 +0200 Subject: [PATCH 5/8] increase test coverage --- tests/test_asr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_asr.py b/tests/test_asr.py index f213939d..f417c2e7 100644 --- a/tests/test_asr.py +++ b/tests/test_asr.py @@ -193,7 +193,7 @@ def test_asr_class(method, reref, show=False): blah = ASR(method=method, estimator="scm") blah.fit(raw2[:, train_idx]) - asr = ASR(method=method, estimator="lwf") + asr = ASR(method=method, estimator="lwf", memory=int(2 * sfreq)) asr.fit(raw2[:, train_idx]) else: asr = ASR(method=method, estimator="scm") From 6b9e9323f07a087449466b32d168566acc169ba8 Mon Sep 17 00:00:00 2001 From: Stefan Appelhoff Date: Thu, 12 Jun 2025 15:58:43 +0200 Subject: [PATCH 6/8] remove duplicate doc of state_ attribute --- meegkit/asr.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/meegkit/asr.py b/meegkit/asr.py index f0509338..b321d84a 100755 --- a/meegkit/asr.py +++ b/meegkit/asr.py @@ -65,8 +65,6 @@ class ASR: Attributes ---------- - ``state_`` : dict - Initial state of the ASR filter. ``zi_``: array, shape=(n_channels, filter_order) Filter initial conditions. ``ab_``: 2-tuple From ba55b6d0415e1839628d67669cd2c27203729b5b Mon Sep 17 00:00:00 2001 From: Stefan Appelhoff Date: Thu, 12 Jun 2025 16:25:01 +0200 Subject: [PATCH 7/8] doc: add missing numpydoc param item --- meegkit/asr.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/meegkit/asr.py b/meegkit/asr.py index b321d84a..2ecd39cd 100755 --- a/meegkit/asr.py +++ b/meegkit/asr.py @@ -474,6 +474,9 @@ def asr_calibrate(X, sfreq, cutoff=5, blocksize=100, win_len=0.5, estimation (default=0.25). method : {'euclid', 'riemann'} Metric to compute the covariance matrix average. + estimator : {'scm', 'lwf', 'oas', 'mcd'} + Covariance estimator (default: 'scm' which computes the sample + covariance). Use 'lwf' if you need regularization (requires pyriemann). Returns ------- From d5ba50f15bc6e7af0aaf4503aebf37ac274fc5d6 Mon Sep 17 00:00:00 2001 From: Stefan Appelhoff Date: Fri, 13 Jun 2025 10:18:56 +0200 Subject: [PATCH 8/8] Update meegkit/asr.py Co-authored-by: Nicolas Barascud --- meegkit/asr.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meegkit/asr.py b/meegkit/asr.py index 2ecd39cd..f33a7b56 100755 --- a/meegkit/asr.py +++ b/meegkit/asr.py @@ -57,7 +57,8 @@ class ASR: Method to use. If riemann, use the riemannian-modified version of ASR [2]_. memory : float | None - Memory size (s), regulates the number of covariance matrices to store. + Memory size (samples), regulates the number of covariance matrices to + store. If None (default), will use twice the sampling frequency. estimator : {'scm', 'lwf', 'oas', 'mcd'} Covariance estimator (default: 'scm' which computes the sample