-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
209 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
from . import epochs | ||
from . import raw | ||
|
||
__all__ = [epochs, raw] | ||
__all__ = [epochs, raw] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""The version number.""" | ||
|
||
__version__ = '0.0.1-1' | ||
__version__ = '0.0.1-2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,66 @@ | ||
import numpy as np | ||
from numpy.core.records import fromarrays | ||
from scipy.io import savemat | ||
from .utils import _get_eeglab_full_cords | ||
|
||
from .utils import cart_to_eeglab | ||
|
||
def export_set(inst, fname): | ||
"""Export Raw to EEGLAB's .set format. | ||
|
||
def export_set(fname, data, sfreq, ch_names, ch_locs=None, annotations=None): | ||
"""Export continuous raw data to EEGLAB's .set format. | ||
Parameters | ||
---------- | ||
inst : mne.io.BaseRaw | ||
Raw instance to save | ||
fname : str | ||
Name of the export file. | ||
data : np.ndarray, shape (n_epochs, n_channels, n_samples) | ||
Data array containing epochs. Follows the same format as | ||
MNE Epochs' data array. | ||
sfreq : int | ||
sample frequency of data | ||
ch_names : list of str | ||
Channel names. | ||
ch_locs : np.ndarray, shape (n_channels, 3) | ||
Array containing channel locations in Cartesian coordinates (x, y, z) | ||
annotations : list, shape (3, n_annotations) | ||
List containing three annotation subarrays: | ||
first array (str) is description, | ||
second array (float) is onset (starting time in seconds), | ||
third array (float) is duration (in seconds) | ||
This roughly follows MNE's Annotations structure. | ||
Notes | ||
----- | ||
Channel locations are expanded to the full EEGLAB format | ||
For more details see .utils.cart_to_eeglab_full_coords | ||
""" | ||
# load data first | ||
inst.load_data() | ||
|
||
# remove extra epoc and STI channels | ||
chs_drop = [ch for ch in ['epoc'] if ch in inst.ch_names] | ||
if 'STI 014' in inst.ch_names and \ | ||
not (inst.filenames[0].endswith('.fif')): | ||
chs_drop.append('STI 014') | ||
inst.drop_channels(chs_drop) | ||
data = data * 1e6 # convert to microvolts | ||
|
||
data = inst.get_data() * 1e6 # convert to microvolts | ||
fs = inst.info["sfreq"] | ||
times = inst.times | ||
if ch_locs is not None: | ||
# get full EEGLAB coordinates to export | ||
full_coords = cart_to_eeglab(ch_locs) | ||
|
||
# convert xyz to full eeglab coordinates | ||
full_coords = _get_eeglab_full_cords(inst) | ||
# convert to record arrays for MATLAB format | ||
chanlocs = fromarrays( | ||
[ch_names, *full_coords.T, np.repeat('', len(ch_names))], | ||
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"]) | ||
|
||
ch_names = inst.ch_names | ||
eeg = 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=[]) | ||
|
||
# convert to record arrays for MATLAB format | ||
chanlocs = fromarrays( | ||
[ch_names, *full_coords.T, np.repeat('', len(ch_names))], | ||
names=["labels", "X", "Y", "Z", "sph_theta", "sph_phi", | ||
"sph_radius", "theta", "radius", | ||
"sph_theta_besa", "sph_phi_besa", "type"]) | ||
if annotations is not None: | ||
events = fromarrays([annotations[0], | ||
annotations[1] * sfreq + 1, | ||
annotations[2] * sfreq], | ||
names=["type", "latency", "duration"]) | ||
eeg['event'] = events | ||
|
||
events = fromarrays([inst.annotations.description, | ||
inst.annotations.onset * fs + 1, | ||
inst.annotations.duration * fs], | ||
names=["type", "latency", "duration"]) | ||
eeg_d = dict(EEG=dict(data=data, | ||
setname=fname, | ||
nbchan=data.shape[0], | ||
pnts=data.shape[1], | ||
trials=1, | ||
srate=fs, | ||
xmin=times[0], | ||
xmax=times[-1], | ||
chanlocs=chanlocs, | ||
event=events, | ||
icawinv=[], | ||
icasphere=[], | ||
icaweights=[])) | ||
eeg_d = dict(EEG=eeg) | ||
|
||
savemat(fname, eeg_d, | ||
appendmat=False) | ||
savemat(fname, eeg_d, appendmat=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import os.path as op | ||
|
||
data_dir = op.join(op.dirname(__file__), 'data') | ||
data_dir = op.join(op.dirname(__file__), 'data') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.