Skip to content

Commit

Permalink
Add export precision support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackz314 committed Oct 22, 2022
1 parent cb158d5 commit 961ee90
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion eeglabio/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""The version number."""

__version__ = '0.0.2-2'
__version__ = '0.0.2-3'
10 changes: 9 additions & 1 deletion eeglabio/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@


def export_set(fname, data, sfreq, events, tmin, tmax, ch_names, event_id=None,
ch_locs=None, annotations=None, ref_channels="common"):
ch_locs=None, annotations=None, ref_channels="common",
precision="single"):
"""Export epoch data to EEGLAB's .set format.
Parameters
Expand Down Expand Up @@ -46,6 +47,8 @@ def export_set(fname, data, sfreq, events, tmin, tmax, ch_names, event_id=None,
specific reference set. Note that this parameter is only used to inform
EEGLAB of the existing reference, this method will not reference the
data for you.
precision : "single" or "double"
Precision of the exported data (specifically EEG.data in EEGLAB)
See Also
--------
Expand All @@ -60,6 +63,11 @@ def export_set(fname, data, sfreq, events, tmin, tmax, ch_names, event_id=None,
data = data * 1e6 # convert to microvolts
data = np.moveaxis(data, 0, 2) # convert to EEGLAB 3D format

if precision not in ("single", "double"):
raise ValueError(f"Unsupported precision '{precision}', "
f"supported precisions are 'single' and 'double'.")
data = data.astype(precision)

ch_cnt, epoch_len, trials = data.shape

if ch_locs is not None:
Expand Down
9 changes: 8 additions & 1 deletion eeglabio/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=None,
ref_channels="common", ch_types=None):
ref_channels="common", ch_types=None, precision="single"):
"""Export continuous raw data to EEGLAB's .set format.
Parameters
Expand Down Expand Up @@ -36,6 +36,8 @@ def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=None,
data for you.
ch_types : list of str | None
Channel types e.g. ‘EEG’, ‘MEG’, ‘EMG’, ‘ECG’, ‘Events’, ..
precision : "single" or "double"
Precision of the exported data (specifically EEG.data in EEGLAB)
See Also
--------
Expand All @@ -49,6 +51,11 @@ def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=None,

data = data * 1e6 # convert to microvolts

if precision not in ("single", "double"):
raise ValueError(f"Unsupported precision '{precision}', "
f"supported precisions are 'single' and 'double'.")
data = data.astype(precision)

# channel types
ch_types = np.array(ch_types) if ch_types is not None \
else np.repeat('', len(ch_names))
Expand Down
10 changes: 5 additions & 5 deletions eeglabio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def cart_to_eeglab(cart):
return np.append(cart, cart_to_eeglab_sph(cart), 1) # hstack


def export_mne_epochs(inst, fname):
def export_mne_epochs(inst, fname, precision="single"):
"""Export MNE's Epochs instance to EEGLAB's .set format using
:func:`.epochs.export_set`.
Expand Down Expand Up @@ -168,10 +168,10 @@ def export_mne_epochs(inst, fname):
annot = None
export_set(fname, inst.get_data(), inst.info['sfreq'], inst.events,
inst.tmin, inst.tmax, inst.ch_names, inst.event_id,
cart_coords, annot)
cart_coords, annot, precision=precision)


def export_mne_raw(inst, fname):
def export_mne_raw(inst, fname, precision="single"):
"""Export MNE's Raw instance to EEGLAB's .set format using
:func:`.raw.export_set`.
Expand Down Expand Up @@ -206,5 +206,5 @@ def export_mne_raw(inst, fname):
ch_types = inst.get_channel_types()
annotations = [inst.annotations.description, inst.annotations.onset,
inst.annotations.duration]
export_set(fname, inst.get_data(), inst.info['sfreq'],
inst.ch_names, cart_coords, annotations, ch_types=ch_types)
export_set(fname, inst.get_data(), inst.info['sfreq'], inst.ch_names,
cart_coords, annotations, ch_types=ch_types, precision=precision)

0 comments on commit 961ee90

Please sign in to comment.