mne.
Epochs
(raw, events, event_id=None, tmin=-0.2, tmax=0.5, baseline=(None, 0), picks=None, preload=False, reject=None, flat=None, proj=True, decim=1, reject_tmin=None, reject_tmax=None, detrend=None, on_missing='error', reject_by_annotation=True, metadata=None, verbose=None)[source]¶Epochs extracted from a Raw instance.
Parameters: |
|
---|
Notes
When accessing data, Epochs are detrended, baseline-corrected, and decimated, then projectors are (optionally) applied.
For indexing and slicing using epochs[...]
, see
mne.Epochs.__getitem__()
.
Attributes: |
|
---|
Methods
__contains__ (ch_type) |
Check channel type membership. |
__getitem__ (item) |
Return an Epochs object with a copied subset of epochs. |
__hash__ () |
Hash the object. |
__iter__ () |
Facilitate iteration over epochs. |
__len__ () |
Return the number of epochs. |
add_channels (add_list[, force_update_info]) |
Append new channels to the instance. |
add_proj (projs[, remove_existing, verbose]) |
Add SSP projection vectors. |
anonymize () |
Anonymize measurement information in place. |
apply_baseline ([baseline, verbose]) |
Baseline correct epochs. |
apply_proj () |
Apply the signal space projection (SSP) operators to the data. |
average ([picks]) |
Compute average of epochs. |
copy () |
Return copy of Epochs instance. |
crop ([tmin, tmax]) |
Crop a time interval from epochs object. |
decimate (decim[, offset, verbose]) |
Decimate the epochs. |
del_proj ([idx]) |
Remove SSP projection vector. |
drop (indices[, reason, verbose]) |
Drop epochs based on indices or boolean mask. |
drop_bad ([reject, flat, verbose]) |
Drop bad epochs without retaining the epochs data. |
drop_channels (ch_names) |
Drop some channels. |
drop_log_stats ([ignore]) |
Compute the channel stats based on a drop_log from Epochs. |
equalize_event_counts (event_ids[, method]) |
Equalize the number of trials in each condition. |
filter (l_freq, h_freq[, picks, …]) |
Filter a subset of channels. |
get_data () |
Get all epochs as a 3D array. |
interpolate_bads ([reset_bads, mode, verbose]) |
Interpolate bad MEG and EEG channels. |
iter_evoked () |
Iterate over epochs as a sequence of Evoked objects. |
load_data () |
Load the data if not already preloaded. |
next ([return_event_id]) |
Iterate over epoch data. |
pick_channels (ch_names) |
Pick some channels. |
pick_types ([meg, eeg, stim, eog, ecg, emg, …]) |
Pick some channels by type and names. |
plot ([picks, scalings, n_epochs, …]) |
Visualize epochs. |
plot_drop_log ([threshold, n_max_plot, …]) |
Show the channel stats based on a drop_log from Epochs. |
plot_image ([picks, sigma, vmin, vmax, …]) |
Plot Event Related Potential / Fields image. |
plot_projs_topomap ([ch_type, layout, axes]) |
Plot SSP vector. |
plot_psd ([fmin, fmax, tmin, tmax, proj, …]) |
Plot the power spectral density across epochs. |
plot_psd_topomap ([bands, vmin, vmax, tmin, …]) |
Plot the topomap of the power spectral density across epochs. |
plot_sensors ([kind, ch_type, title, …]) |
Plot sensor positions. |
plot_topo_image ([layout, sigma, vmin, vmax, …]) |
Plot Event Related Potential / Fields image on topographies. |
rename_channels (mapping) |
Rename channels. |
reorder_channels (ch_names) |
Reorder channels. |
resample (sfreq[, npad, window, n_jobs, pad, …]) |
Resample data. |
save (fname[, split_size, verbose]) |
Save epochs in a fif file. |
savgol_filter (h_freq[, verbose]) |
Filter the data using Savitzky-Golay polynomial method. |
set_channel_types (mapping) |
Define the sensor type of channels. |
set_eeg_reference ([ref_channels, …]) |
Specify which reference to use for EEG data. |
set_montage (montage[, set_dig, verbose]) |
Set EEG sensor configuration and head digitization. |
standard_error ([picks]) |
Compute standard error over epochs. |
subtract_evoked ([evoked]) |
Subtract an evoked response from each epoch. |
time_as_index (times[, use_rounding]) |
Convert time to indices. |
to_data_frame ([picks, index, scaling_time, …]) |
Export data in tabular structure as a pandas DataFrame. |
__contains__
(ch_type)[source]¶Check channel type membership.
Parameters: |
|
---|---|
Returns: |
|
Examples
Channel type membership can be tested as:
>>> 'meg' in inst
True
>>> 'seeg' in inst
False
__getitem__
(item)[source]¶Return an Epochs object with a copied subset of epochs.
Parameters: |
|
---|---|
Returns: |
|
Notes
Epochs can be accessed as epochs[...]
in several ways:
epochs[idx]
: ReturnEpochs
object with a subset of epochs (supports single index and python-style slicing).
epochs['name']
: ReturnEpochs
object with a copy of the subset of epochs corresponding to an experimental condition as specified by ‘name’.If conditions are tagged by names separated by ‘/’ (e.g. ‘audio/left’, ‘audio/right’), and ‘name’ is not in itself an event key, this selects every event whose condition contains the ‘name’ tag (e.g., ‘left’ matches ‘audio/left’ and ‘visual/left’; but not ‘audio_left’). Note that tags selection is insensitive to order: tags like ‘auditory/left’ and ‘left/auditory’ will be treated the same way when accessed.
epochs[['name_1', 'name_2', ... ]]
: ReturnEpochs
object with a copy of the subset of epochs corresponding to multiple experimental conditions as specified by'name_1', 'name_2', ...
.If conditions are separated by ‘/’, selects every item containing every list tag (e.g. [‘audio’, ‘left’] selects ‘audio/left’ and ‘audio/center/left’, but not ‘audio/right’).
epochs['pandas query']
: ReturnEpochs
object with a copy of the subset of epochs (and matching metadata) that matchpandas query
called withself.metadata.eval
, e.g.:epochs["col_a > 2 and col_b == 'foo'"]This is only called if Pandas is installed and
self.metadata
is apandas.DataFrame
.New in version 0.16.
__iter__
()[source]¶Facilitate iteration over epochs.
Notes
This enables the use of this Python pattern:
>>> for epoch in epochs:
>>> print(epoch)
Where epoch
is given by successive outputs of
mne.Epochs.next()
.
__len__
()[source]¶Return the number of epochs.
Returns: |
|
---|
Notes
This function only works if bad epochs have been dropped.
Examples
This can be used as:
>>> epochs.drop_bad()
>>> len(epochs)
43
>>> len(epochs.events)
43
add_channels
(add_list, force_update_info=False)[source]¶Append new channels to the instance.
Parameters: |
|
---|---|
Returns: |
|
See also
add_proj
(projs, remove_existing=False, verbose=None)[source]¶Add SSP projection vectors.
Parameters: |
|
---|---|
Returns: |
|
anonymize
()[source]¶Anonymize measurement information in place.
Reset ‘subject_info’, ‘meas_date’, ‘file_id’, and ‘meas_id’ keys if they
exist in info
.
Returns: |
|
---|
Notes
Operates in place.
New in version 0.13.0.
apply_baseline
(baseline=(None, 0), verbose=None)[source]¶Baseline correct epochs.
Parameters: |
|
---|---|
Returns: |
|
Notes
Baseline correction can be done multiple times.
New in version 0.10.0.
apply_proj
()[source]¶Apply the signal space projection (SSP) operators to the data.
Returns: |
|
---|
Notes
Once the projectors have been applied, they can no longer be removed. It is usually not recommended to apply the projectors at too early stages, as they are applied automatically later on (e.g. when computing inverse solutions). Hint: using the copy method individual projection vectors can be tested without affecting the original data. With evoked data, consider the following example:
projs_a = mne.read_proj('proj_a.fif')
projs_b = mne.read_proj('proj_b.fif')
# add the first, copy, apply and see ...
evoked.add_proj(a).copy().apply_proj().plot()
# add the second, copy, apply and see ...
evoked.add_proj(b).copy().apply_proj().plot()
# drop the first and see again
evoked.copy().del_proj(0).apply_proj().plot()
evoked.apply_proj() # finally keep both
average
(picks=None)[source]¶Compute average of epochs.
Parameters: |
|
---|---|
Returns: |
|
Notes
Computes an average of all epochs in the instance, even if
they correspond to different conditions. To average by condition,
do epochs[condition].average()
for each condition separately.
When picks is None and epochs contain only ICA channels, no channels are selected, resulting in an error. This is because ICA channels are not considered data channels (they are of misc type) and only data channels are selected when picks is None.
ch_names
¶Channel names.
compensation_grade
¶The current gradient compensation grade.
crop
(tmin=None, tmax=None)[source]¶Crop a time interval from epochs object.
Parameters: |
|
---|---|
Returns: |
|
Notes
Unlike Python slices, MNE time intervals include both their end points; crop(tmin, tmax) returns the interval tmin <= t <= tmax.
decimate
(decim, offset=0, verbose=None)[source]¶Decimate the epochs.
Note
No filtering is performed. To avoid aliasing, ensure your data are properly lowpassed.
Parameters: |
|
---|---|
Returns: |
|
Notes
Decimation can be done multiple times. For example,
epochs.decimate(2).decimate(2)
will be the same as
epochs.decimate(4)
.
New in version 0.10.0.
del_proj
(idx='all')[source]¶Remove SSP projection vector.
Parameters: |
|
---|---|
Returns: |
|
drop
(indices, reason='USER', verbose=None)[source]¶Drop epochs based on indices or boolean mask.
Note
The indices refer to the current set of undropped epochs
rather than the complete set of dropped and undropped epochs.
They are therefore not necessarily consistent with any
external indices (e.g., behavioral logs). To drop epochs
based on external criteria, do not use the preload=True
flag when constructing an Epochs object, and call this
method before calling the mne.Epochs.drop_bad()
or
mne.Epochs.load_data()
methods.
Parameters: |
|
---|---|
Returns: |
|
drop_bad
(reject='existing', flat='existing', verbose=None)[source]¶Drop bad epochs without retaining the epochs data.
Should be used before slicing operations.
Warning
This operation is slow since all epochs have to be read
from disk. To avoid reading epochs from disk multiple
times, use mne.Epochs.load_data()
.
Parameters: |
|
---|---|
Returns: |
|
Notes
Dropping bad epochs can be done multiple times with different
reject
and flat
parameters. However, once an epoch is
dropped, it is dropped forever, so if more lenient thresholds may
subsequently be applied, epochs.copy should be used.
drop_channels
(ch_names)[source]¶Drop some channels.
Parameters: |
|
---|---|
Returns: |
|
See also
Notes
New in version 0.9.0.
drop_log_stats
(ignore=('IGNORED', ))[source]¶Compute the channel stats based on a drop_log from Epochs.
Parameters: |
|
---|---|
Returns: |
|
See also
equalize_event_counts
(event_ids, method='mintime')[source]¶Equalize the number of trials in each condition.
It tries to make the remaining epochs occurring as close as possible in time. This method works based on the idea that if there happened to be some time-varying (like on the scale of minutes) noise characteristics during a recording, they could be compensated for (to some extent) in the equalization process. This method thus seeks to reduce any of those effects by minimizing the differences in the times of the events in the two sets of epochs. For example, if one had event times [1, 2, 3, 4, 120, 121] and the other one had [3.5, 4.5, 120.5, 121.5], it would remove events at times [1, 2] in the first epochs and not [20, 21].
Parameters: |
|
---|---|
Returns: |
|
Notes
For example (if epochs.event_id was {‘Left’: 1, ‘Right’: 2, ‘Nonspatial’:3}:
epochs.equalize_event_counts([[‘Left’, ‘Right’], ‘Nonspatial’])
would equalize the number of trials in the ‘Nonspatial’ condition with the total number of trials in the ‘Left’ and ‘Right’ conditions.
If multiple indices are provided (e.g. ‘Left’ and ‘Right’ in the example above), it is not guaranteed that after equalization, the conditions will contribute evenly. E.g., it is possible to end up with 70 ‘Nonspatial’ trials, 69 ‘Left’ and 1 ‘Right’.
filename
¶The filename.
filter
(l_freq, h_freq, picks=None, filter_length='auto', l_trans_bandwidth='auto', h_trans_bandwidth='auto', n_jobs=1, method='fir', iir_params=None, phase='zero', fir_window='hamming', fir_design='firwin', pad='edge', verbose=None)[source]¶Filter a subset of channels.
Applies a zero-phase low-pass, high-pass, band-pass, or band-stop
filter to the channels selected by picks
.
The data are modified inplace.
The object has to have the data loaded e.g. with preload=True
or self.load_data()
.
l_freq
and h_freq
are the frequencies below which and above
which, respectively, to filter out of the data. Thus the uses are:
l_freq < h_freq
: band-pass filterl_freq > h_freq
: band-stop filterl_freq is not None and h_freq is None
: high-pass filterl_freq is None and h_freq is not None
: low-pass filter
self.info['lowpass']
and self.info['highpass']
are only
updated with picks=None.
Note
If n_jobs > 1, more memory is required as
len(picks) * n_times
additional time points need to
be temporaily stored in memory.
Parameters: |
|
---|---|
Returns: |
|
Notes
New in version 0.15.
get_data
()[source]¶Get all epochs as a 3D array.
Returns: |
|
---|
interpolate_bads
(reset_bads=True, mode='accurate', verbose=None)[source]¶Interpolate bad MEG and EEG channels.
Operates in place.
Parameters: |
|
---|---|
Returns: |
|
Notes
New in version 0.9.0.
iter_evoked
()[source]¶Iterate over epochs as a sequence of Evoked objects.
The Evoked objects yielded will each contain a single epoch (i.e., no averaging is performed).
load_data
()[source]¶Load the data if not already preloaded.
Returns: |
|
---|
Notes
This function operates in-place.
New in version 0.10.0.
metadata
¶Get the metadata.
next
(return_event_id=False)[source]¶Iterate over epoch data.
Parameters: |
|
---|---|
Returns: |
|
pick_channels
(ch_names)[source]¶Pick some channels.
Parameters: |
|
---|---|
Returns: |
|
See also
Notes
The channel names given are assumed to be a set, i.e. the order
does not matter. The original order of the channels is preserved.
You can use reorder_channels
to set channel order if necessary.
New in version 0.9.0.
pick_types
(meg=True, eeg=False, stim=False, eog=False, ecg=False, emg=False, ref_meg='auto', misc=False, resp=False, chpi=False, exci=False, ias=False, syst=False, seeg=False, dipole=False, gof=False, bio=False, ecog=False, fnirs=False, include=(), exclude='bads', selection=None, verbose=None)[source]¶Pick some channels by type and names.
Parameters: |
|
---|---|
Returns: |
|
See also
Notes
New in version 0.9.0.
plot
(picks=None, scalings=None, n_epochs=20, n_channels=20, title=None, events=None, event_colors=None, show=True, block=False, decim='auto', noise_cov=None)[source]¶Visualize epochs.
Bad epochs can be marked with a left click on top of the epoch. Bad channels can be selected by clicking the channel name on the left side of the main axes. Calling this function drops all the selected bad epochs as well as bad epochs marked beforehand with rejection parameters.
Parameters: |
|
---|---|
Returns: |
|
Notes
The arrow keys (up/down/left/right) can be used to navigate between
channels and epochs and the scaling can be adjusted with - and + (or =)
keys, but this depends on the backend matplotlib is configured to use
(e.g., mpl.use(TkAgg
) should work). Full screen mode can be toggled
with f11 key. The amount of epochs and channels per view can be adjusted
with home/end and page down/page up keys. These can also be set through
options dialog by pressing o
key. h
key plots a histogram of
peak-to-peak values along with the used rejection thresholds. Butterfly
plot can be toggled with b
key. Right mouse click adds a vertical line
to the plot. Click ‘help’ button at bottom left corner of the plotter to
view all the options.
New in version 0.10.0.
plot_drop_log
(threshold=0, n_max_plot=20, subject='Unknown', color=(0.9, 0.9, 0.9), width=0.8, ignore=('IGNORED', ), show=True)[source]¶Show the channel stats based on a drop_log from Epochs.
Parameters: |
|
---|---|
Returns: |
|
plot_image
(picks=None, sigma=0.0, vmin=None, vmax=None, colorbar=True, order=None, show=True, units=None, scalings=None, cmap=None, fig=None, axes=None, overlay_times=None, combine=None, group_by=None, evoked=True, ts_args={'show_sensors': False}, title=None)[source]¶Plot Event Related Potential / Fields image.
Parameters: |
|
---|---|
Returns: |
|
plot_projs_topomap
(ch_type=None, layout=None, axes=None)[source]¶Plot SSP vector.
Parameters: |
|
---|---|
Returns: |
|
plot_psd
(fmin=0, fmax=inf, tmin=None, tmax=None, proj=False, bandwidth=None, adaptive=False, low_bias=True, normalization='length', picks=None, ax=None, color='black', area_mode='std', area_alpha=0.33, dB=True, n_jobs=1, show=True, verbose=None)[source]¶Plot the power spectral density across epochs.
Parameters: |
|
---|---|
Returns: |
|
plot_psd_topomap
(bands=None, vmin=None, vmax=None, tmin=None, tmax=None, proj=False, bandwidth=None, adaptive=False, low_bias=True, normalization='length', ch_type=None, layout=None, cmap='RdBu_r', agg_fun=None, dB=True, n_jobs=1, normalize=False, cbar_fmt='%0.3f', outlines='head', axes=None, show=True, verbose=None)[source]¶Plot the topomap of the power spectral density across epochs.
Parameters: |
|
---|---|
Returns: |
|
plot_sensors
(kind='topomap', ch_type=None, title=None, show_names=False, ch_groups=None, to_sphere=True, axes=None, block=False, show=True)[source]¶Plot sensor positions.
Parameters: |
|
---|---|
Returns: |
|
See also
Notes
This function plots the sensor locations from the info structure using
matplotlib. For drawing the sensors using mayavi see
mne.viz.plot_alignment()
.
New in version 0.12.0.
plot_topo_image
(layout=None, sigma=0.0, vmin=None, vmax=None, colorbar=True, order=None, cmap='RdBu_r', layout_scale=0.95, title=None, scalings=None, border='none', fig_facecolor='k', fig_background=None, font_color='w', show=True)[source]¶Plot Event Related Potential / Fields image on topographies.
Parameters: |
|
---|---|
Returns: |
|
proj
¶Whether or not projections are active.
rename_channels
(mapping)[source]¶Rename channels.
Parameters: |
|
---|
Notes
New in version 0.9.0.
reorder_channels
(ch_names)[source]¶Reorder channels.
Parameters: |
|
---|---|
Returns: |
|
See also
Notes
Channel names must be unique. Channels that are not in ch_names
are dropped.
New in version 0.16.0.
resample
(sfreq, npad='auto', window='boxcar', n_jobs=1, pad='edge', verbose=None)[source]¶Resample data.
Note
Data must be loaded.
Parameters: |
|
---|---|
Returns: |
|
See also
Notes
For some data, it may be more accurate to use npad=0 to reduce artifacts. This is dataset dependent – check your data!
save
(fname, split_size='2GB', verbose=True)[source]¶Save epochs in a fif file.
Parameters: |
|
---|
Notes
Bad epochs will be dropped before saving the epochs to disk.
savgol_filter
(h_freq, verbose=None)[source]¶Filter the data using Savitzky-Golay polynomial method.
Parameters: |
|
---|---|
Returns: |
|
See also
Notes
For Savitzky-Golay low-pass approximation, see:
New in version 0.9.0.
References
[1] | (1, 2) Savitzky, A., Golay, M.J.E. (1964). “Smoothing and Differentiation of Data by Simplified Least Squares Procedures”. Analytical Chemistry 36 (8): 1627-39. |
Examples
>>> import mne
>>> from os import path as op
>>> evoked_fname = op.join(mne.datasets.sample.data_path(), 'MEG', 'sample', 'sample_audvis-ave.fif')
>>> evoked = mne.read_evokeds(evoked_fname, baseline=(None, 0))[0]
>>> evoked.savgol_filter(10.) # low-pass at around 10 Hz
>>> evoked.plot()
set_channel_types
(mapping)[source]¶Define the sensor type of channels.
Parameters: |
|
---|
Notes
New in version 0.9.0.
set_eeg_reference
(ref_channels='average', projection=None, verbose=None)[source]¶Specify which reference to use for EEG data.
By default, MNE-Python will automatically re-reference the EEG signal to use an average reference (see below). Use this function to explicitly specify the desired reference for EEG. This can be either an existing electrode or a new virtual channel. This function will re-reference the data according to the desired reference and prevent MNE-Python from automatically adding an average reference projection.
Some common referencing schemes and the corresponding value for the
ref_channels
parameter:
ref_channels=[]
. This will prevent MNE-Python from
automatically adding an average reference projection.ref_channels='average'
. Bad EEG
channels are automatically excluded if they are properly set in
info['bads']
.ref_channels
to a list containing the name of the channel
that will act as the new reference, for example
ref_channels=['Cz']
.ref_channels
to a list of channel names,
indicating which channels to use. For example, to apply an average
mastoid reference, when using the 10-20 naming scheme, set
ref_channels=['M1', 'M2']
.Note
In case of ref_channels='average'
in combination with
projection=True
, the reference is added as a projection
and it is not applied automatically. For it to take effect,
apply with method apply_proj
.
Other references are directly applied (this behavior will
change in MNE 0.16).
Parameters: |
|
---|---|
Returns: |
|
See also
mne.set_bipolar_reference
Notes
ref_channels='average'
and projection=True
.info['bads']
.New in version 0.9.0.
set_montage
(montage, set_dig=True, verbose=None)[source]¶Set EEG sensor configuration and head digitization.
Parameters: |
|
---|
Notes
Operates in place.
New in version 0.9.0.
standard_error
(picks=None)[source]¶Compute standard error over epochs.
Parameters: |
|
---|---|
Returns: |
|
subtract_evoked
(evoked=None)[source]¶Subtract an evoked response from each epoch.
Can be used to exclude the evoked response when analyzing induced activity, see e.g. [1].
Parameters: |
|
---|---|
Returns: |
|
References
[1] David et al. “Mechanisms of evoked and induced responses in MEG/EEG”, NeuroImage, vol. 31, no. 4, pp. 1580-1591, July 2006.
time_as_index
(times, use_rounding=False)[source]¶Convert time to indices.
Parameters: |
|
---|---|
Returns: |
|
tmax
¶Last time point.
tmin
¶First time point.
to_data_frame
(picks=None, index=None, scaling_time=1000.0, scalings=None, copy=True, start=None, stop=None)[source]¶Export data in tabular structure as a pandas DataFrame.
Columns and indices will depend on the object being converted. Generally this will include as much relevant information as possible for the data type being converted. This makes it easy to convert data for use in packages that utilize dataframes, such as statsmodels or seaborn.
Parameters: |
|
---|---|
Returns: |
|