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
4 changes: 1 addition & 3 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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|_)

Expand Down
16 changes: 9 additions & 7 deletions mne/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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':
Expand Down
11 changes: 6 additions & 5 deletions mne/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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':
Expand Down
4 changes: 2 additions & 2 deletions mne/io/tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mne/preprocessing/tests/test_fine_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion mne/tests/test_epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions mne/utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down