Skip to content

Commit

Permalink
MRG: Add support for channel types, add .DS_Store to .gitignore, add …
Browse files Browse the repository at this point in the history
…a conversion to str for fname (#4)

* Add .DS_Store to .gitignore.

* Adding ch_types argument.

* Add conversion of fname to string to fix error raised by savemat when a pathlib.Path is provided instead.

* Remove useless channel type mapping.

* Add support even if ch_locs is not provided.
  • Loading branch information
mscheltienne authored Apr 25, 2022
1 parent c6f6957 commit bd0d627
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ dmypy.json
cython_debug/

/doc/generated/
.DS_Store
2 changes: 1 addition & 1 deletion eeglabio/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ def export_set(fname, data, sfreq, events, tmin, tmax, ch_names, event_id=None,
icawinv=[],
icasphere=[],
icaweights=[])
savemat(fname, eeg_d, appendmat=False)
savemat(str(fname), eeg_d, appendmat=False)
14 changes: 10 additions & 4 deletions 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"):
ref_channels="common", ch_types=None):
"""Export continuous raw data to EEGLAB's .set format.
Parameters
Expand Down Expand Up @@ -34,6 +34,8 @@ def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=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.
ch_types : list of str | None
Channel types e.g. ‘EEG’, ‘MEG’, ‘EMG’, ‘ECG’, ‘Events’, ..
See Also
--------
Expand All @@ -47,18 +49,22 @@ def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=None,

data = data * 1e6 # convert to microvolts

# channel types
ch_types = np.array(ch_types) if ch_types is not None \
else np.repeat('', len(ch_names))

if ch_locs is not None:
# get full EEGLAB coordinates to export
full_coords = cart_to_eeglab(ch_locs)

# convert to record arrays for MATLAB format
chanlocs = fromarrays(
[ch_names, *full_coords.T, np.repeat('', len(ch_names))],
[ch_names, *full_coords.T, ch_types],
names=["labels", "X", "Y", "Z", "sph_theta", "sph_phi",
"sph_radius", "theta", "radius",
"sph_theta_besa", "sph_phi_besa", "type"])
else:
chanlocs = fromarrays([ch_names], names=["labels"])
chanlocs = fromarrays([ch_names, ch_types], names=["labels", "type"])

if isinstance(ref_channels, list):
ref_channels = " ".join(ref_channels)
Expand All @@ -75,4 +81,4 @@ def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=None,
names=["type", "latency", "duration"])
eeg_d['event'] = events

savemat(fname, eeg_d, appendmat=False)
savemat(str(fname), eeg_d, appendmat=False)
3 changes: 2 additions & 1 deletion eeglabio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def export_mne_raw(inst, fname):
else:
cart_coords = None

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)
inst.ch_names, cart_coords, annotations, ch_types=ch_types)

0 comments on commit bd0d627

Please sign in to comment.