From 5489c0f0e4d5b193da71051acebe1880c6060c93 Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Fri, 23 Apr 2021 21:01:56 +0200 Subject: [PATCH 1/2] nitpicks in eeglab export --- doc/changes/latest.inc | 4 +--- mne/epochs.py | 16 +++++++++------- mne/io/base.py | 11 ++++++----- mne/io/tests/test_raw.py | 4 ++-- mne/tests/test_epochs.py | 2 +- mne/utils/docs.py | 1 + 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/doc/changes/latest.inc b/doc/changes/latest.inc index 55769d1b764..5c93e59cfa5 100644 --- a/doc/changes/latest.inc +++ b/doc/changes/latest.inc @@ -59,9 +59,7 @@ Current (0.23.dev0) Enhancements ~~~~~~~~~~~~ -- Add support for exporting to EEGLAB's set format with :mod:`eeglabio` in :meth:`mne.io.Raw.export` and :meth:`mne.Epochs.export`. (:gh:`9192` **by new contributor** |Jack Zhang|_) - -- Add methods for exporting to external formats with :meth:`mne.io.Raw.export` and :meth:`mne.Epochs.export` (:gh:`9192` **by new contributor** |Jack Zhang|_) +- Add support for exporting to EEGLAB's set format with :mod:`eeglabio` with new methods :meth:`mne.io.Raw.export` and :meth:`mne.Epochs.export`. (:gh:`9192` **by new contributor** |Jack Zhang|_) - Add exclude parameter to :func:`mne.viz.plot_evoked_topo` (:gh:`9278` by |Ram Pari|_) diff --git a/mne/epochs.py b/mne/epochs.py index e4899ec33ca..e3342750fb1 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -1823,7 +1823,6 @@ def export(self, fname, fmt='auto', verbose=None): Parameters ---------- %(export_params_fname)s - fmt : 'auto' | 'eeglab' %(export_params_fmt)s %(verbose)s @@ -1846,15 +1845,18 @@ def export(self, fname, fmt='auto', verbose=None): # remove extra epoc and STI channels drop_chs = ['epoc', 'STI 014'] - pick_chs = [ch for ch in self.ch_names if ch not in drop_chs] - + ch_names = [ch for ch in self.ch_names if ch not in drop_chs] cart_coords = _get_als_coords_from_chs(self.info['chs'], drop_chs) - eeglabio.epochs.export_set(fname, self.get_data(picks=pick_chs), - self.info['sfreq'], self.events, - self.tmin, self.tmax, pick_chs, - self.event_id, cart_coords) + eeglabio.epochs.export_set(fname, + data=self.get_data(picks=ch_names), + sfreq=self.info['sfreq'], + events=self.events, + tmin=self.tmin, tmax=self.tmax, + ch_names=ch_names, + event_id=self.event_id, + ch_locs=cart_coords) elif fmt == 'edf': raise NotImplementedError('Export to EDF format not implemented.') elif fmt == 'brainvision': diff --git a/mne/io/base.py b/mne/io/base.py index 6ba4df17fec..787ea274a1a 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -1463,7 +1463,6 @@ def export(self, fname, fmt='auto', verbose=None): Parameters ---------- %(export_params_fname)s - fmt : 'auto' | 'eeglab' %(export_params_fmt)s %(verbose)s @@ -1488,17 +1487,19 @@ def export(self, fname, fmt='auto', verbose=None): drop_chs = ['epoc'] if not (self.filenames[0].endswith('.fif')): drop_chs.append('STI 014') - pick_chs = [ch for ch in self.ch_names if ch not in drop_chs] + ch_names = [ch for ch in self.ch_names if ch not in drop_chs] cart_coords = _get_als_coords_from_chs(self.info['chs'], drop_chs) annotations = [self.annotations.description, self.annotations.onset, self.annotations.duration] - eeglabio.raw.export_set(fname, self.get_data(picks=pick_chs), - self.info['sfreq'], pick_chs, cart_coords, - annotations) + eeglabio.raw.export_set(fname, data=self.get_data(picks=ch_names), + sfreq=self.info['sfreq'], + ch_names=ch_names, + ch_locs=cart_coords, + annotations=annotations) elif fmt == 'edf': raise NotImplementedError('Export to EDF format not implemented.') elif fmt == 'brainvision': diff --git a/mne/io/tests/test_raw.py b/mne/io/tests/test_raw.py index 78ad44bf2d6..d46e04a1fa1 100644 --- a/mne/io/tests/test_raw.py +++ b/mne/io/tests/test_raw.py @@ -30,6 +30,7 @@ from mne.io._digitization import DigPoint from mne.io.proj import Projection from mne.io.utils import _mult_cal_one +from mne.io import read_raw_eeglab def assert_named_constants(info): @@ -695,7 +696,7 @@ def test_get_data_units(): @pytest.mark.skipif(not _check_eeglabio_installed(strict=False), reason='eeglabio not installed') -def test_export_set(): +def test_export_eeglab(): """Test saving a Raw instance to EEGLAB's set format.""" fname = Path(__file__).parent / "data" / "test_raw.fif" raw = read_raw_fif(fname) @@ -705,7 +706,6 @@ def test_export_set(): raw.export(temp_fname) raw.drop_channels([ch for ch in ['epoc'] if ch in raw.ch_names]) - from ..eeglab.eeglab import read_raw_eeglab raw_read = read_raw_eeglab(temp_fname, preload=True) assert raw.ch_names == raw_read.ch_names cart_coords = np.array([d['loc'][:3] for d in raw.info['chs']]) # just xyz diff --git a/mne/tests/test_epochs.py b/mne/tests/test_epochs.py index af809f2b5c7..8d944d985c5 100644 --- a/mne/tests/test_epochs.py +++ b/mne/tests/test_epochs.py @@ -3100,7 +3100,7 @@ def test_save_complex_data(tmpdir, preload, is_complex, fmt, rtol): @pytest.mark.skipif(not _check_eeglabio_installed(strict=False), reason='eeglabio not installed') @pytest.mark.parametrize('preload', (True, False)) -def test_export_set(tmpdir, preload): +def test_export_eeglab(tmpdir, preload): """Test saving an Epochs instance to EEGLAB's set format.""" raw, events = _get_data()[:2] raw.load_data() diff --git a/mne/utils/docs.py b/mne/utils/docs.py index bcbeb06f8b9..435fcc3149e 100644 --- a/mne/utils/docs.py +++ b/mne/utils/docs.py @@ -2274,6 +2274,7 @@ Name of the output file. """ docdict['export_params_fmt'] = """ +fmt : 'auto' | 'eeglab' Format of the export. Defaults to ``'auto'``, which will infer the format from the filename extension. See supported formats above for more information. From 70daed40b51ba8adfb02f963a71db4ec474b74a1 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Fri, 23 Apr 2021 16:03:03 -0400 Subject: [PATCH 2/2] FIX: Tweak tol --- mne/preprocessing/tests/test_fine_cal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/preprocessing/tests/test_fine_cal.py b/mne/preprocessing/tests/test_fine_cal.py index 90002b35522..44ad4377c11 100644 --- a/mne/preprocessing/tests/test_fine_cal.py +++ b/mne/preprocessing/tests/test_fine_cal.py @@ -102,7 +102,7 @@ def test_compute_fine_cal(): # processing a very short (one 10-sec segment), downsampled (90 Hz) # file assert 66 < want_orig_max_angle < 68, want_orig_max_angle - assert 67 < got_orig_max_angle < 107, got_orig_max_angle + assert 56 < got_orig_max_angle < 107, got_orig_max_angle assert 53 < got_want_max_angle < 60, got_want_max_angle kwargs = dict(bad_condition='warning', cross_talk=ctc, coord_frame='meg')