Skip to content
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
2 changes: 2 additions & 0 deletions meegkit/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ def clean_windows(X, sfreq, max_bad_chans=0.2, zthresholds=[-3.5, 5],
swz = np.sort(wz, axis=0)

# determine which windows to remove
mask1 = np.zeros(len(offsets), dtype=bool)
mask2 = np.zeros(len(offsets), dtype=bool)
if np.max(zthresholds) > 0:
mask1 = swz[-(int(max_bad_chans) + 1), :] > np.max(zthresholds)
if np.min(zthresholds) < 0:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,29 @@ def test_asr_functions(show=False, method="riemann"):
plt.show()


@pytest.mark.parametrize(argnames="zthresholds", argvalues=([1, 2], [-5, -1]))
def test_clean_windows_one_sided_zthresholds(zthresholds):
"""Test clean_windows with a one-sided zthresholds.

Regression test: when zthresholds does not straddle 0 (i.e. both bounds
are positive, or both are negative), only one of the two rejection-mask
branches in clean_windows runs. The other mask must still be defined
(as an all-False "reject nothing" default) so that combining the masks
does not raise UnboundLocalError.
"""
raw = np.load(os.path.join(THIS_FOLDER, "data", "eeg_raw.npy"))
sfreq = 250
# Use a short slice for speed; still exercises the mask logic.
X = raw[:, :10 * sfreq]

clean, sample_mask = clean_windows(X, sfreq, zthresholds=zthresholds)

assert clean.shape[0] == X.shape[0]
assert clean.shape[1] <= X.shape[1]
assert sample_mask.shape == (1, X.shape[1])
assert sample_mask.dtype == bool


@pytest.mark.parametrize(argnames="method", argvalues=("riemann", "euclid"))
@pytest.mark.parametrize(argnames="reref", argvalues=(False, True))
def test_asr_class(method, reref, show=False):
Expand Down
Loading