Container for Time-Frequency data on epochs.
Can for example store induced power at sensor level.
mne.Info
The mne.Info
object with information about the sensors and methods of measurement.
ndarray
, shape (n_epochs, n_channels, n_freqs, n_times)The data.
ndarray
, shape (n_times,)The time values in seconds.
ndarray
, shape (n_freqs,)The frequencies in Hz.
str
| None
, default None
Comment on the data, e.g., the experimental condition.
str
| None
, default None
Comment on the method used to compute the data, e.g., morlet wavelet.
ndarray
, shape (n_events, 3) | None
The events as stored in the Epochs class. If None (default), all event values are set to 1 and event time-samples are set to range(n_epochs).
dict
| None
Example: dict(auditory=1, visual=3). They keys can be used to access associated events. If None, all events will be used and a dict is created with string integer names corresponding to the event id integers.
None
Iterable of indices of selected epochs. If None
, will be
automatically generated, corresponding to all non-zero events.
New in version 0.23.
tuple
| None
Tuple of tuple of strings indicating which epochs have been marked to be ignored.
New in version 0.23.
pandas.DataFrame
| None
A pandas.DataFrame
containing pertinent information for each
trial. See mne.Epochs
for further details.
str
| int
| None
Control verbosity of the logging output. If None
, use the default
verbosity level. See the logging documentation and
mne.verbose()
for details. Should only be passed as a keyword
argument.
mne.Info
The mne.Info
object with information about the sensors and methods of measurement.
ch_names
list
Channel names.
ndarray
, shape (n_epochs, n_channels, n_freqs, n_times)The data array.
times
ndarray
, shape (n_times,)Time vector in seconds.
ndarray
, shape (n_freqs,)The frequencies in Hz.
str
Comment on dataset. Can be the condition.
str
| None
, default None
Comment on the method used to compute the data, e.g., morlet wavelet.
ndarray
, shape (n_events, 3) | None
Array containing sample information as event_id
dict
| None
Names of conditions correspond to event_ids
array
List of indices of selected events (not dropped or ignored etc.). For example, if the original event array had 4 events and the second event has been dropped, this attribute would be np.array([0, 2, 3]).
tuple
of tuple
A tuple of the same length as the event array used to initialize the
EpochsTFR
object. If the i-th original event is still part of the
selection, drop_log[i] will be an empty tuple; otherwise it will be
a tuple of the reasons the event is not longer in the selection, e.g.:
'IGNORED'
If it isn’t part of the current subset defined by the user
'NO_DATA'
or 'TOO_SHORT'
If epoch didn’t contain enough data names of channels that exceeded the amplitude threshold
'EQUALIZED_COUNTS'
'USER'
For user-defined reasons (see drop()
).
metadata
pandas.DataFrame
, shape (n_events, n_cols) | None
Get the metadata.
Methods
|
Check channel type membership. |
|
Return an Epochs object with a copied subset of epochs. |
|
Facilitate iteration over epochs. |
|
Return the number of epochs. |
|
Append new channels to the instance. |
|
Add reference channels to data that consists of all zeros. |
|
Baseline correct the data. |
|
Average the data across epochs. |
|
Return a copy of the instance. |
|
Crop data to a given time interval in place. |
|
Decimate the time-series data. |
|
Drop channel(s). |
|
Get a list of channel type for each channel. |
|
Iterate over epoch data. |
|
Pick a subset of channels. |
|
Pick some channels. |
|
Pick some channels by type and names. |
|
Reorder channels. |
|
Save TFR object to hdf5 file. |
|
Shift time scale in epoched or evoked data. |
|
Convert time to indices. |
|
Export data in tabular structure as a pandas DataFrame. |
Check channel type membership.
str
Channel type to check for. Can be e.g. ‘meg’, ‘eeg’, ‘stim’, etc.
Whether or not the instance contains the given channel type.
Examples
Channel type membership can be tested as:
>>> 'meg' in inst
True
>>> 'seeg' in inst
False
Return an Epochs object with a copied subset of epochs.
slice
, array-like, str
, or list
See below for use cases.
Epochs
See below for use cases.
Notes
Epochs can be accessed as epochs[...]
in several ways:
Integer or slice: epochs[idx]
will return an Epochs
object with a subset of epochs chosen by index (supports single
index and Python-style slicing).
String: epochs['name']
will return an Epochs
object
comprising only the epochs labeled 'name'
(i.e., epochs created
around events with the label 'name'
).
If there are no epochs labeled 'name'
but there are epochs
labeled with /-separated tags (e.g. 'name/left'
,
'name/right'
), then epochs['name']
will select the epochs
with labels that contain that tag (e.g., epochs['left']
selects
epochs labeled 'audio/left'
and 'visual/left'
, but not
'audio_left'
).
If multiple tags are provided as a single string (e.g.,
epochs['name_1/name_2']
), this selects epochs containing all
provided tags. For example, epochs['audio/left']
selects
'audio/left'
and 'audio/quiet/left'
, but not
'audio/right'
. Note that tag-based selection is insensitive to
order: tags like 'audio/left'
and 'left/audio'
will be
treated the same way when selecting via tag.
List of strings: epochs[['name_1', 'name_2', ... ]]
will
return an Epochs
object comprising epochs that match any of
the provided names (i.e., the list of names is treated as an
inclusive-or condition). If none of the provided names match any
epoch labels, a KeyError
will be raised.
If epoch labels are /-separated tags, then providing multiple tags
as separate list entries will likewise act as an inclusive-or
filter. For example, epochs[['audio', 'left']]
would select
'audio/left'
, 'audio/right'
, and 'visual/left'
, but not
'visual/right'
.
Pandas query: epochs['pandas query']
will return an
Epochs
object with a subset of epochs (and matching
metadata) selected by the query called with
self.metadata.eval
, e.g.:
epochs["col_a > 2 and col_b == 'foo'"]
would return all epochs whose associated col_a
metadata was
greater than two, and whose col_b
metadata was the string ‘foo’.
Query-based indexing only works if Pandas is installed and
self.metadata
is a pandas.DataFrame
.
New in version 0.16.
Facilitate iteration over epochs.
This method resets the object iteration state to the first epoch.
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()
.
Return the number of epochs.
int
The number of remaining epochs.
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
Append new channels to the instance.
list
A list of objects to append to self. Must contain all the same type as the current object.
If True, force the info for objects to be appended to match the
values in self
. This should generally only be used when adding
stim channels for which important metadata won’t be overwritten.
New in version 0.12.
See also
Notes
If self
is a Raw instance that has been preloaded into a
numpy.memmap
instance, the memmap will be resized.
Add reference channels to data that consists of all zeros.
Adds reference channels to data that were not included during recording. This is useful when you need to re-reference your data to different channels. These added channels will consist of all zeros.
Baseline correct the data.
The time interval to apply rescaling / baseline correction. If None do not apply it. If baseline is (a, b) the interval is between “a (s)” and “b (s)”. If a is None the beginning of the data is used and if b is None then b is set to the end of the interval. If baseline is equal to (None, None) all the time interval is used.
Perform baseline correction by
subtracting the mean of baseline values (‘mean’)
dividing by the mean of baseline values (‘ratio’)
dividing by the mean of baseline values and taking the log (‘logratio’)
subtracting the mean of baseline values followed by dividing by the mean of baseline values (‘percent’)
subtracting the mean of baseline values and dividing by the standard deviation of baseline values (‘zscore’)
dividing by the mean of baseline values, taking the log, and dividing by the standard deviation of log baseline values (‘zlogratio’)
str
| int
| None
Control verbosity of the logging output. If None
, use the default
verbosity level. See the logging documentation and
mne.verbose()
for details. Should only be passed as a keyword
argument.
AverageTFR
The modified instance.
Examples using apply_baseline
:
Non-parametric 1 sample cluster statistic on single trial power
Non-parametric between conditions cluster statistic on single trial power
Mass-univariate twoway repeated measures ANOVA on single trial power
Spatiotemporal permutation F-test on full sensor data
Average the data across epochs.
str
| callable()
How to combine the data. If “mean”/”median”, the mean/median are returned. Otherwise, must be a callable which, when passed an array of shape (n_epochs, n_channels, n_freqs, n_time) returns an array of shape (n_channels, n_freqs, n_time). Note that due to file type limitations, the kind for all these will be “average”.
The dimension along which to combine the data.
Whether to return a copy of the modified instance,
or modify in place. Ignored when dim='epochs'
because a new instance must be returned.
AverageTFR
| EpochsTFR
The averaged data.
Notes
Passing in np.median
is considered unsafe when there is complex
data because NumPy doesn’t compute the marginal median. Numpy currently
sorts the complex values by real part and return whatever value is
computed. Use with caution. We use the marginal median in the
complex case (i.e. the median of each component separately) if
one passes in median
. See a discussion in scipy:
https://github.com/scipy/scipy/pull/12676#issuecomment-783370228
Examples using average
:
Compute and visualize ERDS maps
Channel names.
The current gradient compensation grade.
Return a copy of the instance.
EpochsTFR
| instance of AverageTFR
A copy of the instance.
Crop data to a given time interval in place.
float
| None
Start time of selection in seconds.
float
| None
End time of selection in seconds.
float
| None
Lowest frequency of selection in Hz.
New in version 0.18.0.
float
| None
Highest frequency of selection in Hz.
New in version 0.18.0.
If True (default), include tmax. If False, exclude tmax (similar to how Python indexing typically works).
New in version 0.19.
AverageTFR
The modified instance.
Examples using crop
:
Non-parametric 1 sample cluster statistic on single trial power
Compute and visualize ERDS maps
Decimate the time-series data.
int
Factor by which to subsample the data.
Warning
Low-pass filtering is not performed, this simply selects
every Nth sample (where N is the value passed to
decim
), i.e., it compresses the signal (see Notes).
If the data are not properly filtered, aliasing artifacts
may occur.
int
Apply an offset to where the decimation starts relative to the sample corresponding to t=0. The offset is in samples at the current sampling rate.
New in version 0.12.
str
| int
| None
Control verbosity of the logging output. If None
, use the default
verbosity level. See the logging documentation and
mne.verbose()
for details. Should only be passed as a keyword
argument.
The decimated object.
See also
Notes
For historical reasons, decim
/ “decimation” refers to simply subselecting
samples from a given signal. This contrasts with the broader signal processing
literature, where decimation is defined as (quoting
[1], p. 172; which cites
[2]):
“… a general system for downsampling by a factor of M is the one shown in Figure 4.23. Such a system is called a decimator, and downsampling by lowpass filtering followed by compression [i.e, subselecting samples] has been termed decimation (Crochiere and Rabiner, 1983).”
Hence “decimation” in MNE is what is considered “compression” in the signal processing community.
Decimation can be done multiple times. For example,
inst.decimate(2).decimate(2)
will be the same as
inst.decimate(4)
.
If decim
is 1, this method does not copy the underlying data.
New in version 0.10.0.
References
Drop channel(s).
See also
Notes
New in version 0.9.0.
Get a list of channel type for each channel.
str
| list
| slice
| None
Channels to include. Slices and lists of integers will be interpreted as
channel indices. In lists, channel type strings (e.g., ['meg',
'eeg']
) will pick channels of those types, channel name strings (e.g.,
['MEG0111', 'MEG2623']
will pick the given channels. Can also be the
string values “all” to pick all channels, or “data” to pick data
channels. None (default) will pick all channels. Note that channels in
info['bads']
will be included if their names or indices are
explicitly provided.
Whether to return only unique channel types. Default is False
.
Whether to ignore non-data channels. Default is False
.
list
The channel types.
Get the metadata.
Pick a subset of channels.
str
| list
| slice
| None
Channels to include. Slices and lists of integers will be interpreted as
channel indices. In lists, channel type strings (e.g., ['meg',
'eeg']
) will pick channels of those types, channel name strings (e.g.,
['MEG0111', 'MEG2623']
will pick the given channels. Can also be the
string values “all” to pick all channels, or “data” to pick data
channels. None (default) will pick all channels. Note that channels in
info['bads']
will be included if their names or indices are
explicitly provided.
list
| str
Set of channels to exclude, only used when picking based on types (e.g., exclude=”bads” when picks=”meg”).
str
| int
| None
Control verbosity of the logging output. If None
, use the default
verbosity level. See the logging documentation and
mne.verbose()
for details. Should only be passed as a keyword
argument.
New in version 0.24.0.
Pick some channels.
list
The list of channels to select.
If True (default False), ensure that the order of the channels in
the modified instance matches the order of ch_names
.
New in version 0.20.0.
str
| int
| None
Control verbosity of the logging output. If None
, use the default
verbosity level. See the logging documentation and
mne.verbose()
for details. Should only be passed as a keyword
argument.
New in version 1.1.
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 some channels by type and names.
str
If True include MEG channels. If string it can be ‘mag’, ‘grad’, ‘planar1’ or ‘planar2’ to select only magnetometers, all gradiometers, or a specific type of gradiometer.
If True include EEG channels.
If True include stimulus channels.
If True include EOG channels.
If True include ECG channels.
If True include EMG channels.
str
If True include CTF / 4D reference channels. If ‘auto’, reference
channels are included if compensations are present and meg
is
not False. Can also be the string options for the meg
parameter.
If True include miscellaneous analog channels.
If True
include respiratory channels.
If True include continuous HPI coil channels.
Flux excitation channel used to be a stimulus channel.
Internal Active Shielding data (maybe on Triux only).
System status channel information (on Triux systems only).
Stereotactic EEG channels.
Dipole time course channels.
Dipole goodness of fit channels.
Bio channels.
Electrocorticography channels.
str
Functional near-infrared spectroscopy channels. If True include all fNIRS channels. If False (default) include none. If string it can be ‘hbo’ (to include channels measuring oxyhemoglobin) or ‘hbr’ (to include channels measuring deoxyhemoglobin).
EEG-CSD channels.
Deep brain stimulation channels.
list
of str
List of additional channels to include. If empty do not include any.
list
of str
| str
List of channels to exclude. If ‘bads’ (default), exclude channels
in info['bads']
.
list
of str
Restrict sensor channels (MEG, EEG) to this list of channel names.
str
| int
| None
Control verbosity of the logging output. If None
, use the default
verbosity level. See the logging documentation and
mne.verbose()
for details. Should only be passed as a keyword
argument.
See also
Notes
New in version 0.9.0.
Reorder channels.
list
The desired channel order.
See also
Notes
Channel names must be unique. Channels that are not in ch_names
are dropped.
New in version 0.16.0.
Save TFR object to hdf5 file.
str
The file name, which should end with -tfr.h5
.
If True (default False), overwrite the destination file if it exists.
str
| int
| None
Control verbosity of the logging output. If None
, use the default
verbosity level. See the logging documentation and
mne.verbose()
for details. Should only be passed as a keyword
argument.
See also
Shift time scale in epoched or evoked data.
float
The (absolute or relative) time shift in seconds. If relative
is True, positive tshift increases the time value associated with
each sample, while negative tshift decreases it.
If True, increase or decrease time values by tshift
seconds.
Otherwise, shift the time values such that the time of the first
sample equals tshift
.
The modified instance.
Notes
This method allows you to shift the time values associated with each data sample by an arbitrary amount. It does not resample the signal or change the data values in any way.
Time vector in seconds.
Last time point.
First time point.
Export data in tabular structure as a pandas DataFrame.
Channels are converted to columns in the DataFrame. By default,
additional columns 'time'
, 'freq'
, 'epoch'
, and
'condition'
(epoch event description) are added, unless index
is not None
(in which case the columns specified in index
will
be used to form the DataFrame’s index instead). 'epoch'
, and
'condition'
are not supported for AverageTFR
.
str
| list
| slice
| None
Channels to include. Slices and lists of integers will be interpreted as
channel indices. In lists, channel type strings (e.g., ['meg',
'eeg']
) will pick channels of those types, channel name strings (e.g.,
['MEG0111', 'MEG2623']
will pick the given channels. Can also be the
string values “all” to pick all channels, or “data” to pick data
channels. None (default) will pick all channels. Note that channels in
info['bads']
will be included if their names or indices are
explicitly provided.
str
| list
of str
| None
Kind of index to use for the DataFrame. If None
, a sequential
integer index (pandas.RangeIndex
) will be used. If 'time'
, a
pandas.Float64Index
, pandas.Int64Index
, or
pandas.TimedeltaIndex
will be used
(depending on the value of time_format
). If a list of two or more string values, a pandas.MultiIndex
will be created.
Valid string values are 'time'
, 'freq'
, 'epoch'
, and
'condition'
for EpochsTFR
and 'time'
and 'freq'
for AverageTFR
.
Defaults to None
.
If True, the DataFrame is returned in long format where each row is one
observation of the signal at a unique combination of time point, channel, epoch number, and condition.
For convenience, a ch_type
column is added to facilitate subsetting the resulting DataFrame. Defaults to False
.
str
| None
Desired time format. If None
, no conversion is applied, and time values
remain as float values in seconds. If 'ms'
, time values will be rounded
to the nearest millisecond and converted to integers. If 'timedelta'
,
time values will be converted to pandas.Timedelta
values.
Default is None
.
New in version 0.23.
str
| int
| None
Control verbosity of the logging output. If None
, use the default
verbosity level. See the logging documentation and
mne.verbose()
for details. Should only be passed as a keyword
argument.
pandas.DataFrame
A dataframe suitable for usage with other statistical/plotting/analysis packages.
Examples using to_data_frame
:
Compute and visualize ERDS maps
mne.time_frequency.EpochsTFR
#Non-parametric 1 sample cluster statistic on single trial power
Non-parametric between conditions cluster statistic on single trial power
Mass-univariate twoway repeated measures ANOVA on single trial power
Spatiotemporal permutation F-test on full sensor data
Compute and visualize ERDS maps
Time-frequency on simulated data (Multitaper vs. Morlet vs. Stockwell)