Skip to content

Commit

Permalink
Add ref field.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackz314 committed May 11, 2021
1 parent 4049dea commit 66d242a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 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.1'
__version__ = '0.0.1-5'
14 changes: 12 additions & 2 deletions eeglabio/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from .utils import cart_to_eeglab


def export_set(fname, data, sfreq, events, tmin, tmax, ch_names,
event_id=None, ch_locs=None):
def export_set(fname, data, sfreq, events, tmin, tmax, ch_names, event_id=None,
ch_locs=None, ref_channels='common'):
"""Export epoch data to EEGLAB's .set format.
Parameters
Expand Down Expand Up @@ -34,6 +34,12 @@ def export_set(fname, data, sfreq, events, tmin, tmax, ch_names,
If None, event names will default to string versions of the event ids.
ch_locs : numpy.ndarray, shape (n_channels, 3)
Array containing channel locations in Cartesian coordinates (x, y, z)
ref_channels : list of str | str
The name(s) of the channel(s) used to construct the reference,
'average' for average reference, or 'common' (default) when there's no
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.
See Also
--------
Expand Down Expand Up @@ -93,6 +99,9 @@ def export_set(fname, data, sfreq, events, tmin, tmax, ch_names,
epochs = fromarrays([ep_event, ep_lat, ep_types],
names=["event", "eventlatency", "eventtype"])

if isinstance(ref_channels, list):
ref_channels = " ".join(ref_channels)

eeg_d = dict(data=data,
setname=fname,
nbchan=data.shape[0],
Expand All @@ -101,6 +110,7 @@ def export_set(fname, data, sfreq, events, tmin, tmax, ch_names,
srate=sfreq,
xmin=tmin,
xmax=tmax,
ref=ref_channels,
chanlocs=chanlocs,
event=events,
epoch=epochs,
Expand Down
16 changes: 13 additions & 3 deletions eeglabio/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from .utils import cart_to_eeglab


def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=None):
def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=None,
ref_channels='common'):
"""Export continuous raw data to EEGLAB's .set format.
Parameters
Expand All @@ -27,6 +28,12 @@ def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=None):
second array (float) is onset (starting time in seconds),
third array (float) is duration (in seconds)
This roughly follows MNE's Annotations structure.
ref_channels : list of str | str
The name(s) of the channel(s) used to construct the reference,
'average' for average reference, or 'common' (default) when there's no
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.
See Also
--------
Expand All @@ -53,10 +60,13 @@ def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=None):
else:
chanlocs = fromarrays([ch_names], names=["labels"])

if isinstance(ref_channels, list):
ref_channels = " ".join(ref_channels)

eeg_d = dict(data=data, setname=fname, nbchan=data.shape[0],
pnts=data.shape[1], trials=1, srate=sfreq, xmin=0,
xmax=data.shape[1] / sfreq, chanlocs=chanlocs, icawinv=[],
icasphere=[], icaweights=[])
xmax=data.shape[1] / sfreq, ref=ref_channels,
chanlocs=chanlocs, icawinv=[], icasphere=[], icaweights=[])

if annotations is not None:
events = fromarrays([annotations[0],
Expand Down

0 comments on commit 66d242a

Please sign in to comment.