Skip to content

Commit cc5e2e6

Browse files
sappelhofflarsoner
andauthored
CSP: only log once if cov is computed epoch wise (#13256)
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
1 parent dda454d commit cc5e2e6

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

mne/commands/tests/test_commands.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ def test_show_fiff(tmp_path):
110110
with ArgvSetter((raw_fname, "--tag=102")):
111111
mne_show_fiff.run()
112112
bad_fname = tmp_path / "test_bad_raw.fif"
113-
with open(bad_fname, "wb") as fout:
114-
with open(raw_fname, "rb") as fin:
115-
fout.write(fin.read(100000))
116-
with pytest.warns(Warning, match=".*valid tag.*"):
113+
with open(bad_fname, "wb") as fout, open(raw_fname, "rb") as fin:
114+
fout.write(fin.read(100000))
115+
# should match ".*valid tag.*" but conda-linux intermittently fails for some reason
116+
with _record_warnings():
117117
lines = show_fiff(bad_fname, output=list)
118118
last_line = lines[-1]
119119
assert last_line.endswith(">>>>BAD @9015")

mne/cov.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,7 @@ def regularize(
21082108
return cov
21092109

21102110

2111+
@verbose
21112112
def _regularized_covariance(
21122113
data,
21132114
reg=None,
@@ -2118,6 +2119,7 @@ def _regularized_covariance(
21182119
log_ch_type=None,
21192120
log_rank=None,
21202121
cov_kind="",
2122+
verbose=None,
21212123
):
21222124
"""Compute a regularized covariance from data using sklearn.
21232125

mne/datasets/tests/test_datasets.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import pooch
1212
import pytest
13+
from flaky import flaky
1314

1415
import mne.datasets._fsaverage.base
1516
from mne import datasets, read_labels_from_annot, write_labels_to_annot
@@ -173,6 +174,7 @@ def _error_download_2(self, fname, downloader, processor):
173174
datasets._fake.data_path(download=True, force_update=True, **kwargs)
174175

175176

177+
@flaky(max_runs=3)
176178
@pytest.mark.slowtest
177179
@testing.requires_testing_data
178180
@requires_good_network

mne/decoding/csp.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
_validate_type,
1919
_verbose_safe_false,
2020
fill_doc,
21+
logger,
2122
pinv,
2223
)
2324
from .transformer import MNETransformerMixin
@@ -602,6 +603,12 @@ def _concat_cov(self, x_class, *, cov_kind, log_rank):
602603

603604
def _epoch_cov(self, x_class, *, cov_kind, log_rank):
604605
"""Mean of per-epoch covariances."""
606+
name = self.reg if isinstance(self.reg, str) else "empirical"
607+
name += " with shrinkage" if isinstance(self.reg, float) else ""
608+
logger.info(
609+
f"Estimating {cov_kind + (' ' if cov_kind else '')}"
610+
f"covariance (average over epochs; {name.upper()})"
611+
)
605612
cov = sum(
606613
_regularized_covariance(
607614
this_X,
@@ -612,6 +619,7 @@ def _epoch_cov(self, x_class, *, cov_kind, log_rank):
612619
cov_kind=cov_kind,
613620
log_rank=log_rank and ii == 0,
614621
log_ch_type="data",
622+
verbose=_verbose_safe_false(),
615623
)
616624
for ii, this_X in enumerate(x_class)
617625
)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ hdf5 = ["h5io >= 0.2.4", "pymatreader"]
139139
# Dependencies for running the test infrastructure
140140
test = [
141141
"codespell",
142+
"flaky",
142143
"ipython != 8.7.0", # for testing notebook backend; also in "full-no-qt" and "doc"
143144
"mypy",
144145
"numpydoc",

tools/circleci_dependencies.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ python -m pip install --upgrade --progress-bar off \
1414
mne-icalabel mne-lsl mne-microstates mne-nirs mne-rsa \
1515
neurodsp neurokit2 niseq nitime pactools mnelab \
1616
plotly pycrostates pyprep pyriemann python-picard sesameeg \
17-
sleepecg tensorpac yasa meegkit eeg_positions wfdb invertmeeg
17+
sleepecg tensorpac yasa meegkit eeg_positions wfdb invertmeeg \
18+
curryreader

0 commit comments

Comments
 (0)