mne.time_frequency.EpochsTFR

class mne.time_frequency.EpochsTFR(info, data, times, freqs, comment=None, method=None, events=None, event_id=None, metadata=None, verbose=None)[source]

Container for Time-Frequency data on epochs.

Can for example store induced power at sensor level.

Parameters
infoInfo

The measurement info.

datandarray, shape (n_epochs, n_channels, n_freqs, n_times)

The data.

timesndarray, shape (n_times,)

The time values in seconds.

freqsndarray, shape (n_freqs,)

The frequencies in Hz.

commentstr | None, default None

Comment on the data, e.g., the experimental condition.

methodstr | None, default None

Comment on the method used to compute the data, e.g., morlet wavelet.

eventsndarray, 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).

event_iddict | 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.

metadatainstance of pandas.DataFrame | None

A pandas.DataFrame containing pertinent information for each trial. See mne.Epochs for further details

verbosebool, str, int, or None

If not None, override default verbose level (see mne.verbose() and Logging documentation for more).

Attributes

ch_names

Channel names.

metadata

Get the metadata.

info

(instance of Info) Measurement info.

data

(ndarray, shape (n_epochs, n_channels, n_freqs, n_times)) The data array.

times

(ndarray, shape (n_times,)) The time values in seconds.

freqs

(ndarray, shape (n_freqs,)) The frequencies in Hz.

comment

(string) Comment on dataset. Can be the condition.

method

(str | None, default None) Comment on the method used to compute the data, e.g., morlet wavelet.

events

(ndarray, shape (n_events, 3) | None) Array containing sample information as event_id

event_id

(dict | None) Names of conditions correspond to event_ids

Notes

—–

.. versionadded:: 0.13.0

Methods

__contains__(self, ch_type)

Check channel type membership.

__getitem__(self, item)

Return an Epochs object with a copied subset of epochs.

__hash__(self)

Hash the object.

__iter__(self)

Facilitate iteration over epochs.

__len__(self)

Return the number of epochs.

add_channels(self, add_list[, force_update_info])

Append new channels to the instance.

apply_baseline(self, baseline[, mode, verbose])

Baseline correct the data.

average(self)

Average the data across epochs.

copy(self)

Return a copy of the instance.

crop(self[, tmin, tmax, fmin, fmax])

Crop data to a given time interval in place.

drop_channels(self, ch_names)

Drop channel(s).

next(self[, return_event_id])

Iterate over epoch data.

pick(self, picks[, exclude])

Pick a subset of channels.

pick_channels(self, ch_names)

Pick some channels.

pick_types(self[, meg, eeg, stim, eog, ecg, …])

Pick some channels by type and names.

reorder_channels(self, ch_names)

Reorder channels.

save(self, fname[, overwrite])

Save TFR object to hdf5 file.

__contains__(self, ch_type)[source]

Check channel type membership.

Parameters
ch_typestr

Channel type to check for. Can be e.g. ‘meg’, ‘eeg’, ‘stim’, etc.

Returns
inbool

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
__getitem__(self, item)[source]

Return an Epochs object with a copied subset of epochs.

Parameters
itemslice, array_like, str, or list

See below for use cases.

Returns
epochsinstance of Epochs

See below for use cases.

Notes

Epochs can be accessed as epochs[...] in several ways:

  1. epochs[idx]: Return Epochs object with a subset of epochs (supports single index and python-style slicing).

  2. epochs['name']: Return Epochs 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.

  3. epochs[['name_1', 'name_2', ... ]]: Return Epochs 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’).

  4. epochs['pandas query']: Return Epochs object with a copy of the subset of epochs (and matching metadata) that match pandas query called with self.metadata.eval, e.g.:

    epochs["col_a > 2 and col_b == 'foo'"]
    

    This is only called if Pandas is installed and self.metadata is a pandas.DataFrame.

    New in version 0.16.

__hash__(self)[source]

Hash the object.

Returns
hashint

The hash

__iter__(self)[source]

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().

__len__(self)[source]

Return the number of epochs.

Returns
n_epochsint

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
add_channels(self, add_list, force_update_info=False)[source]

Append new channels to the instance.

Parameters
add_listlist

A list of objects to append to self. Must contain all the same type as the current object

force_update_infobool

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.

Returns
instinstance of Raw, Epochs, or Evoked

The modified instance.

See also

drop_channels

Notes

If self is a Raw instance that has been preloaded into a numpy.memmap instance, the memmap will be resized.

apply_baseline(self, baseline, mode='mean', verbose=None)[source]

Baseline correct the data.

Parameters
baselinearray_like, shape (2,)

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.

mode‘mean’ | ‘ratio’ | ‘logratio’ | ‘percent’ | ‘zscore’ | ‘zlogratio’

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’)

verbosebool, str, int, or None

If not None, override default verbose level (see mne.verbose() and Logging documentation for more). Defaults to self.verbose.

Returns
instinstance of AverageTFR

The modified instance.

average(self)[source]

Average the data across epochs.

Returns
aveinstance of AverageTFR

The averaged data.

ch_names

Channel names.

compensation_grade

The current gradient compensation grade.

copy(self)[source]

Return a copy of the instance.

crop(self, tmin=None, tmax=None, fmin=None, fmax=None)[source]

Crop data to a given time interval in place.

Parameters
tminfloat | None

Start time of selection in seconds.

tmaxfloat | None

End time of selection in seconds.

fminfloat | None

Lowest frequency of selection in Hz.

New in version 0.18.0.

fmaxfloat | None

Highest frequency of selection in Hz.

New in version 0.18.0.

Returns
instinstance of AverageTFR

The modified instance.

drop_channels(self, ch_names)[source]

Drop channel(s).

Parameters
ch_nameslist or str

List of channel name(s) or channel name to remove.

Returns
instinstance of Raw, Epochs, or Evoked

The modified instance.

Notes

New in version 0.9.0.

metadata

Get the metadata.

next(self, return_event_id=False)[source]

Iterate over epoch data.

Parameters
return_event_idbool

If True, return both the epoch data and an event_id.

Returns
epocharray of shape (n_channels, n_times)

The epoch data.

event_idint

The event id. Only returned if return_event_id is True.

pick(self, picks, exclude=())[source]

Pick a subset of channels.

Parameters
picksstr | 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.

excludelist | str

Set of channels to exclude, only used when picking based on types (e.g., exclude=”bads” when picks=”meg”).

Returns
instinstance of Raw, Epochs, or Evoked

The modified instance.

pick_channels(self, ch_names)[source]

Pick some channels.

Parameters
ch_nameslist

The list of channels to select.

Returns
instinstance of Raw, Epochs, or Evoked

The modified instance.

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(self, 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
megbool | str

If True include all MEG channels. If False include None If string it can be ‘mag’, ‘grad’, ‘planar1’ or ‘planar2’ to select only magnetometers, all gradiometers, or a specific type of gradiometer.

eegbool

If True include EEG channels.

stimbool

If True include stimulus channels.

eogbool

If True include EOG channels.

ecgbool

If True include ECG channels.

emgbool

If True include EMG channels.

ref_meg: bool | str

If True include CTF / 4D reference channels. If ‘auto’, the reference channels are only included if compensations are present.

miscbool

If True include miscellaneous analog channels.

respbool

If True include response-trigger channel. For some MEG systems this is separate from the stim channel.

chpibool

If True include continuous HPI coil channels.

excibool

Flux excitation channel used to be a stimulus channel.

iasbool

Internal Active Shielding data (maybe on Triux only).

systbool

System status channel information (on Triux systems only).

seegbool

Stereotactic EEG channels.

dipolebool

Dipole time course channels.

gofbool

Dipole goodness of fit channels.

biobool

Bio channels.

ecogbool

Electrocorticography channels.

fnirsbool | 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).

includelist of str

List of additional channels to include. If empty do not include any.

excludelist of str | str

List of channels to exclude. If ‘bads’ (default), exclude channels in info['bads'].

selectionlist of str

Restrict sensor channels (MEG, EEG) to this list of channel names.

verbosebool, str, int, or None

If not None, override default verbose level (see mne.verbose() and Logging documentation for more). Defaults to self.verbose.

Returns
instinstance of Raw, Epochs, or Evoked

The modified instance.

See also

pick_channels

Notes

New in version 0.9.0.

reorder_channels(self, ch_names)[source]

Reorder channels.

Parameters
ch_nameslist

The desired channel order.

Returns
instinstance of Raw, Epochs, or Evoked

The modified instance.

Notes

Channel names must be unique. Channels that are not in ch_names are dropped.

New in version 0.16.0.

save(self, fname, overwrite=False)[source]

Save TFR object to hdf5 file.

Parameters
fnamestr

The file name, which should end with -tfr.h5 .

overwritebool

If True, overwrite file (if it exists). Defaults to False