Skip to content

Commit e711615

Browse files
hoechenbergeralexrockhilllarsoner
authored
MRG: Backport #10619 and #10620 (#10621)
* Drop EEG rejection thresholds when replacing EEG with CSD channels (#10619) * Drop EEG rejection thresholds when replacing EEG with CSD channels This is an attempt to fix the issue reported at https://mne.discourse.group/t/saving-epoch-error-no-eeg-channel-found * fix, working version * Update doc/changes/latest.inc Co-authored-by: Richard Höchenberger <[email protected]> Co-authored-by: Alex <[email protected]> * Simplify #10619 (#10620) * MAINT: Fix * FIX: Fix for regression * FIX: Fix for pandas * FIX: Better fix * FIX: Adjust Co-authored-by: Alex <[email protected]> Co-authored-by: Eric Larson <[email protected]>
1 parent 5ec4d87 commit e711615

File tree

8 files changed

+31
-24
lines changed

8 files changed

+31
-24
lines changed

azure-pipelines.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ stages:
111111
- bash: |
112112
set -e
113113
python -m pip install --progress-bar off --upgrade pip setuptools wheel codecov
114-
python -m pip install --progress-bar off mne-qt-browser[opengl] vtk scikit-learn pytest-error-for-skips python-picard
114+
python -m pip install --progress-bar off mne-qt-browser[opengl] vtk scikit-learn pytest-error-for-skips python-picard "pyqt5>=5.10,!=5.15.3"
115115
python -m pip uninstall -yq mne
116116
python -m pip install --progress-bar off --upgrade -e .[test]
117117
displayName: 'Install dependencies with pip'

doc/changes/1.0.inc

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Version 1.0.X
2424

2525
- Retain epochs metadata when using :func:`mne.channels.combine_channels` (:gh:`10504` by `Clemens Brunner`_)
2626

27+
- Fix issue with saving epochs once :func:`~mne.preprocessing.compute_current_source_density` has been used if a rejection threshold was used first (:gh:`10619` by `Alex Rockhill`_ and `Richard Höchenberger`_)
28+
2729
Version 1.0.2 (2022-04-15)
2830
--------------------------
2931
- Fix bug where ``theme`` was not handled properly in :meth:`mne.io.Raw.plot` (:gh:`10500` by `Eric Larson`_)

mne/beamformer/tests/test_lcmv.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,8 @@ def test_localization_bias_fixed(bias_params_fixed, reg, weight_norm, use_cov,
677677
# no reg
678678
(0.00, 'vector', None, True, None, 23, 24, 0.96, 0.97),
679679
(0.00, 'vector', 'unit-noise-gain-invariant', True, None, 52, 54, 0.95, 0.96), # noqa: E501
680-
(0.00, 'vector', 'unit-noise-gain', True, None, 44, 46, 0.97, 0.98),
681-
(0.00, 'vector', 'nai', True, None, 44, 46, 0.97, 0.98),
680+
(0.00, 'vector', 'unit-noise-gain', True, None, 44, 48, 0.97, 0.99),
681+
(0.00, 'vector', 'nai', True, None, 44, 48, 0.97, 0.99),
682682
(0.00, 'max-power', None, True, None, 14, 15, 0, 0),
683683
(0.00, 'max-power', 'unit-noise-gain-invariant', True, None, 35, 37, 0, 0), # noqa: E501
684684
(0.00, 'max-power', 'unit-noise-gain', True, None, 35, 37, 0, 0),

mne/preprocessing/_csd.py

+8
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,12 @@ def compute_current_source_density(inst, sphere='auto', lambda2=1e-5,
172172
for pick in picks:
173173
inst.info['chs'][pick].update(coil_type=FIFF.FIFFV_COIL_EEG_CSD,
174174
unit=FIFF.FIFF_UNIT_V_M2)
175+
176+
# Remove rejection thresholds for EEG
177+
if isinstance(inst, BaseEpochs):
178+
if inst.reject and 'eeg' in inst.reject:
179+
del inst.reject['eeg']
180+
if inst.flat and 'eeg' in inst.flat:
181+
del inst.flat['eeg']
182+
175183
return inst

mne/preprocessing/tests/test_csd.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from scipy import linalg
1818

1919
from mne.channels import make_dig_montage
20-
from mne import create_info, EvokedArray, pick_types, Epochs
20+
from mne import (create_info, EvokedArray, pick_types, Epochs, find_events,
21+
read_epochs)
2122
from mne.io import read_raw_fif, RawArray
2223
from mne.io.constants import FIFF
2324
from mne.utils import object_diff
@@ -183,3 +184,16 @@ def test_csd_fif():
183184
ch.update(coil_type=FIFF.FIFFV_COIL_EEG, unit=FIFF.FIFF_UNIT_V)
184185
raw_csd._data[pick] = raw._data[pick]
185186
assert object_diff(raw.info, raw_csd.info) == ''
187+
188+
189+
def test_csd_epochs(tmp_path):
190+
"""Test making epochs, saving to disk and loading."""
191+
raw = read_raw_fif(raw_fname)
192+
raw.pick_types(eeg=True, stim=True).load_data()
193+
events = find_events(raw)
194+
epochs = Epochs(raw, events, reject=dict(eeg=1e-4), preload=True)
195+
epochs = compute_current_source_density(epochs)
196+
epo_fname = tmp_path / 'test_csd_epo.fif'
197+
epochs.save(epo_fname)
198+
epochs2 = read_epochs(epo_fname, preload=True)
199+
assert_allclose(epochs._data, epochs2._data)

mne/viz/backends/_utils.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ def _qt_get_stylesheet(theme):
232232
# but it's easy enough just to set it transparent and inherit
233233
# the bgcolor of the window (which is the same). We also take
234234
# the separator images from QDarkStyle (MIT).
235-
icons_path = _qt_init_icons()
236235
stylesheet = """\
237236
QStatusBar {
238237
border: 1px solid rgb(76, 76, 75);
@@ -245,23 +244,7 @@ def _qt_get_stylesheet(theme):
245244
background-color: transparent;
246245
border-bottom: 1px solid rgb(99, 99, 99);
247246
}
248-
QToolBar::separator:horizontal {
249-
width: 16px;
250-
image: url("%(icons_path)s/[email protected]");
251-
}
252-
QToolBar::separator:vertical {
253-
height: 16px;
254-
image: url("%(icons_path)s/[email protected]");
255-
}
256-
QToolBar::handle:horizontal {
257-
width: 16px;
258-
image: url("%(icons_path)s/[email protected]");
259-
}
260-
QToolBar::handle:vertical {
261-
height: 16px;
262-
image: url("%(icons_path)s/[email protected]");
263-
}
264-
""" % dict(icons_path=icons_path)
247+
"""
265248
else:
266249
stylesheet = ''
267250
else:

tools/azure_dependencies.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ elif [ "${TEST_MODE}" == "pip-pre" ]; then
1414
# SciPy Windows build is missing from conda nightly builds
1515
python -m pip install --progress-bar off --upgrade --pre --only-binary ":all:" --no-deps -i "https://pypi.anaconda.org/scipy-wheels-nightly/simple" numpy
1616
python -m pip install --progress-bar off --upgrade --pre --only-binary ":all:" --no-deps scipy
17-
python -m pip install --progress-bar off --upgrade --pre --only-binary ":all:" --no-deps -i "https://pypi.anaconda.org/scipy-wheels-nightly/simple" pandas scikit-learn dipy statsmodels
17+
python -m pip install --progress-bar off --upgrade --pre --only-binary ":all:" --no-deps --default-timeout=60 -i "https://pypi.anaconda.org/scipy-wheels-nightly/simple" pandas scikit-learn dipy statsmodels
1818
python -m pip install --progress-bar off --upgrade --pre --only-binary ":all:" --no-deps -f "https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83.ssl.cf2.rackcdn.com" h5py Pillow matplotlib
1919
# Until VTK comes out with a 3.10 wheel, we need to use PyVista's
2020
python -m pip install --progress-bar off --upgrade --pre --only-binary ":all:" https://github.com/pyvista/pyvista-wheels/raw/3b70f3933bc246b035354b172a0459ffc96b0343/vtk-9.1.0.dev0-cp310-cp310-win_amd64.whl

tools/github_actions_dependencies.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ else
1717
echo "PyQt5"
1818
pip install $STD_ARGS --pre --only-binary ":all:" --no-deps --extra-index-url https://www.riverbankcomputing.com/pypi/simple PyQt5 PyQt5-sip PyQt5-Qt5
1919
echo "NumPy/SciPy/pandas etc."
20-
pip install $STD_ARGS --pre --only-binary ":all:" --no-deps -i "https://pypi.anaconda.org/scipy-wheels-nightly/simple" numpy scipy pandas scikit-learn statsmodels dipy
20+
pip install $STD_ARGS --pre --only-binary ":all:" --no-deps --default-timeout=60 -i "https://pypi.anaconda.org/scipy-wheels-nightly/simple" numpy scipy pandas scikit-learn statsmodels dipy
2121
echo "H5py, pillow, matplotlib"
2222
pip install $STD_ARGS --pre --only-binary ":all:" --no-deps -f "https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83.ssl.cf2.rackcdn.com" h5py pillow matplotlib
2323
# We don't install Numba here because it forces an old NumPy version

0 commit comments

Comments
 (0)