You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Run the Artifact Subspace Reconstruction (ASR) method on EEG data.
36
+
37
+
This is an automated artifact rejection function that ensures that the data
38
+
contains no events that have abnormally strong power; the subspaces on which
39
+
those events occur are reconstructed (interpolated) based on the rest of the
40
+
EEG signal during these time periods.
41
+
42
+
Args:
43
+
EEG (Dict[str, Any]): EEG data structure. Expected fields:
44
+
'data' (np.ndarray): Channels x Samples matrix.
45
+
'srate' (float): Sampling rate in Hz.
46
+
'nbchan' (int): Number of channels.
47
+
It's assumed the data is zero-mean (e.g., high-pass filtered).
48
+
cutoff (float, optional): Standard deviation cutoff for rejection. Data portions whose variance
49
+
is larger than this threshold relative to the calibration data are
50
+
considered artifactual and removed. Aggressive: 3, Default: 5, Conservative: 20.
51
+
window_len (float, optional): Length of the statistics window in seconds. Should not be much longer
52
+
than artifact timescale. Samples in window should be >= 1.5x channels.
53
+
Default: max(0.5, 1.5 * nbchan / srate).
54
+
step_size (int, optional): Step size for processing in samples. Reconstruction matrix updated every
55
+
`step_size` samples. If None, defaults to window_len / 2 samples.
56
+
max_dims (float, optional): Maximum dimensionality/fraction of dimensions to reconstruct. Default: 0.66.
57
+
ref_maxbadchannels (Union[float, str, np.ndarray], optional): Parameter for automatic calibration data selection.
58
+
float: Max fraction (0-1) of bad channels tolerated in a window for it to be used as calibration data. Lower is more aggressive (e.g., 0.05). Default: 0.075.
59
+
'off': Use all data for calibration. Assumes artifact contamination < ~30-50%.
60
+
np.ndarray: Directly provides the calibration data (channels x samples).
61
+
ref_tolerances (Union[Tuple[float, float], str], optional): Power tolerances (lower, upper) in SDs from robust EEG power
62
+
for a channel to be considered 'bad' during calibration data selection. Default: (-3.5, 5.5). Use 'off' to disable.
63
+
ref_wndlen (Union[float, str], optional): Window length in seconds for calibration data selection granularity. Default: 1.0. Use 'off' to disable.
64
+
use_gpu (bool, optional): Whether to try using GPU (requires compatible hardware and libraries, currently ignored). Default: False.
65
+
useriemannian (bool, optional): Whether to use Riemannian ASR variant (NOT IMPLEMENTED). Default: False.
66
+
maxmem (Optional[int], optional): Maximum memory in MB (passed to asr_calibrate/process, but chunking based on it is not implemented in Python port). Default: 64.
67
+
68
+
Returns:
69
+
Dict[str, Any]: The EEG dictionary with the 'data' field containing the cleaned data.
70
+
71
+
Raises:
72
+
NotImplementedError: If useriemannian is True.
73
+
ImportError: If automatic calibration data selection is needed (`ref_maxbadchannels` is float) but `clean_windows` cannot be imported.
74
+
ValueError: If input arguments are invalid or calibration fails critically.
75
+
"""
76
+
ifuseriemannian:
77
+
raiseNotImplementedError("The Riemannian ASR variant is not implemented in this Python port.")
0 commit comments