diff --git a/eeglabio/_version.py b/eeglabio/_version.py index fdd113e..595ae51 100644 --- a/eeglabio/_version.py +++ b/eeglabio/_version.py @@ -1,3 +1,3 @@ """The version number.""" -__version__ = '0.0.2-2' +__version__ = '0.0.2-3' diff --git a/eeglabio/epochs.py b/eeglabio/epochs.py index 625aed7..df0ccf4 100644 --- a/eeglabio/epochs.py +++ b/eeglabio/epochs.py @@ -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 @@ -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 -------- @@ -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: diff --git a/eeglabio/raw.py b/eeglabio/raw.py index 5a9769d..553af34 100644 --- a/eeglabio/raw.py +++ b/eeglabio/raw.py @@ -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 @@ -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 -------- @@ -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)) diff --git a/eeglabio/utils.py b/eeglabio/utils.py index 3b4bd9f..1009955 100644 --- a/eeglabio/utils.py +++ b/eeglabio/utils.py @@ -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`. @@ -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`. @@ -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)