mne.io.
Raw
(fname, allow_maxshield=False, preload=False, verbose=None)[source]¶Raw data in FIF format.
Parameters: |
|
---|---|
Attributes: |
Methods
__contains__ (ch_type) |
Check channel type membership. |
__getitem__ (item) |
Get raw data and times. |
__hash__ () |
Hash the object. |
__len__ () |
Return the number of time points. |
add_channels (add_list[, force_update_info]) |
Append new channels to the instance. |
add_events (events[, stim_channel]) |
Add events to stim channel. |
add_proj (projs[, remove_existing, verbose]) |
Add SSP projection vectors. |
anonymize () |
Anonymize measurement information in place. |
append (raws[, preload]) |
Concatenate raw instances as if they were continuous. |
apply_function (fun[, picks, dtype, n_jobs]) |
Apply a function to a subset of channels. |
apply_gradient_compensation (grade[, verbose]) |
Apply CTF gradient compensation. |
apply_hilbert ([picks, envelope, n_jobs, …]) |
Compute analytic signal or envelope for a subset of channels. |
apply_proj () |
Apply the signal space projection (SSP) operators to the data. |
close () |
Clean up the object. |
copy () |
Return copy of Raw instance. |
crop ([tmin, tmax]) |
Crop raw data file. |
del_proj ([idx]) |
Remove SSP projection vector. |
drop_channels (ch_names) |
Drop some channels. |
estimate_rank ([tstart, tstop, tol, …]) |
Estimate rank of the raw data. |
filter (l_freq, h_freq[, picks, …]) |
Filter a subset of channels. |
fix_mag_coil_types () |
Fix Elekta magnetometer coil types. |
get_data ([picks, start, stop, …]) |
Get data in the given range. |
interpolate_bads ([reset_bads, mode, verbose]) |
Interpolate bad MEG and EEG channels. |
load_bad_channels ([bad_file, force]) |
Mark channels as bad from a text file. |
load_data ([verbose]) |
Load raw data. |
notch_filter (freqs[, picks, filter_length, …]) |
Notch filter a subset of channels. |
pick_channels (ch_names) |
Pick some channels. |
pick_types ([meg, eeg, stim, eog, ecg, emg, …]) |
Pick some channels by type and names. |
plot ([events, duration, start, n_channels, …]) |
Plot raw data. |
plot_projs_topomap ([ch_type, layout, axes]) |
Plot SSP vector. |
plot_psd ([tmin, tmax, fmin, fmax, proj, …]) |
Plot the power spectral density across channels. |
plot_psd_topo ([tmin, tmax, fmin, fmax, …]) |
Plot channel-wise frequency spectra as topography. |
plot_sensors ([kind, ch_type, title, …]) |
Plot sensor positions. |
rename_channels (mapping) |
Rename channels. |
reorder_channels (ch_names) |
Reorder channels. |
resample (sfreq[, npad, window, stim_picks, …]) |
Resample all channels. |
save (fname[, picks, tmin, tmax, …]) |
Save raw data to file. |
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. |
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]¶Get raw data and times.
Parameters: |
|
---|---|
Returns: |
|
Examples
Generally raw data is accessed as:
>>> data, times = raw[picks, time_slice]
To get all data, you can thus do either of:
>>> data, times = raw[:]
Which will be equivalent to:
>>> data, times = raw[:, :]
To get only the good MEG data from 10-20 seconds, you could do:
>>> picks = mne.pick_types(raw.info, meg=True, exclude='bads')
>>> t_idx = raw.time_as_index([10., 20.])
>>> data, times = raw[picks, t_idx[0]:t_idx[1]]
__len__
()[source]¶Return the number of time points.
Returns: |
|
---|
Examples
This can be used as:
>>> len(raw)
1000
acqparser
¶The AcqParserFIF for the measurement info.
See also
add_channels
(add_list, force_update_info=False)[source]¶Append new channels to the instance.
Parameters: |
|
---|---|
Returns: |
|
See also
add_events
(events, stim_channel=None)[source]¶Add events to stim channel.
Parameters: |
|
---|
Notes
Data must be preloaded in order to add events.
add_proj
(projs, remove_existing=False, verbose=None)[source]¶Add SSP projection vectors.
Parameters: |
|
---|---|
Returns: |
|
annotations
¶Annotations for marking segments of data.
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.
append
(raws, preload=None)[source]¶Concatenate raw instances as if they were continuous.
Note
Boundaries of the raw files are annotated bad. If you wish to
use the data as continuous recording, you can remove the
boundary annotations after concatenation (see
mne.Annotations.delete()
).
Parameters: |
|
---|
apply_function
(fun, picks=None, dtype=None, n_jobs=1, *args, **kwargs)[source]¶Apply a function to a subset of channels.
The function “fun” is applied to the channels defined in “picks”. The data of the Raw object is modified inplace. If the function returns a different data type (e.g. numpy.complex) it must be specified using the dtype parameter, which causes the data type used for representing the raw data to change.
The Raw object has to have the data loaded e.g. with preload=True
or self.load_data()
.
Note
If n_jobs > 1, more memory is required as
len(picks) * n_times
additional time points need to
be temporaily stored in memory.
Note
If the data type changes (dtype != None), more memory is required since the original and the converted data needs to be stored in memory.
Parameters: |
|
---|---|
Returns: |
|
apply_gradient_compensation
(grade, verbose=None)[source]¶Apply CTF gradient compensation.
Warning
The compensation matrices are stored with single precision, so repeatedly switching between different of compensation (e.g., 0->1->3->2) can increase numerical noise, especially if data are saved to disk in between changing grades. It is thus best to only use a single gradient compensation level in final analyses.
Parameters: |
|
---|---|
Returns: |
|
apply_hilbert
(picks=None, envelope=False, n_jobs=1, n_fft='auto', verbose=None)[source]¶Compute analytic signal or envelope for a subset of channels.
If envelope=False, the analytic signal for the channels defined in “picks” is computed and the data of the Raw object is converted to a complex representation (the analytic signal is complex valued).
If envelope=True, the absolute value of the analytic signal for the channels defined in “picks” is computed, resulting in the envelope signal.
Note
If envelope=False, more memory is required since the original raw data as well as the analytic signal have temporarily to be stored in memory.
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
The analytic signal “x_a(t)” of “x(t)” is:
x_a = F^{-1}(F(x) 2U) = x + i y
where “F” is the Fourier transform, “U” the unit step function, and “y” the Hilbert transform of “x”. One usage of the analytic signal is the computation of the envelope signal, which is given by “e(t) = abs(x_a(t))”. Due to the linearity of Hilbert transform and the MNE inverse solution, the enevlope in source space can be obtained by computing the analytic signal in sensor space, applying the MNE inverse, and computing the envelope in source space.
Also note that the n_fft parameter will allow you to pad the signal with zeros before performing the Hilbert transform. This padding is cut off, but it may result in a slightly different result (particularly around the edges). Use at your own risk.
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
ch_names
¶Channel names.
close
()[source]¶Clean up the object.
Does nothing for objects that close their file descriptors. Things like RawFIF will override this method.
compensation_grade
¶The current gradient compensation grade.
crop
(tmin=0.0, tmax=None)[source]¶Crop raw data file.
Limit the data from the raw file to go between specific times. Note that the new tmin is assumed to be t=0 for all subsequently called functions (e.g., time_as_index, or Epochs). New first_samp and last_samp are set accordingly.
Thus function operates in-place on the instance.
Use mne.io.Raw.copy()
if operation on a copy is desired.
Parameters: |
|
---|---|
Returns: |
|
del_proj
(idx='all')[source]¶Remove SSP projection vector.
Parameters: |
|
---|---|
Returns: |
|
drop_channels
(ch_names)[source]¶Drop some channels.
Parameters: |
|
---|---|
Returns: |
|
See also
Notes
New in version 0.9.0.
estimate_rank
(tstart=0.0, tstop=30.0, tol=0.0001, return_singular=False, picks=None, scalings='norm')[source]¶Estimate rank of the raw data.
This function is meant to provide a reasonable estimate of the rank. The true rank of the data depends on many factors, so use at your own risk.
Parameters: |
|
---|---|
Returns: |
|
Notes
If data are not pre-loaded, the appropriate data will be loaded by this function (can be memory intensive).
Projectors are not taken into account unless they have been applied to the data using apply_proj(), since it is not always possible to tell whether or not projectors have been applied previously.
Bad channels will be excluded from calculations.
filenames
¶The filenames used.
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', skip_by_annotation=('edge', 'bad_acq_skip'), pad='reflect_limited', 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
. By default the data
of the Raw object is modified inplace.
The Raw 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: |
|
See also
mne.Epochs.savgol_filter
, mne.io.Raw.notch_filter
, mne.io.Raw.resample
, mne.filter.filter_data
, mne.filter.construct_iir_filter
Notes
For more information, see the tutorials Background information on filtering and Filtering and resampling data.
first_samp
¶The first data sample.
fix_mag_coil_types
()[source]¶Fix Elekta magnetometer coil types.
Returns: |
|
---|
Notes
This function changes magnetometer coil types 3022 (T1: SQ20483N) and 3023 (T2: SQ20483-A) to 3024 (T3: SQ20950N) in the channel definition records in the info structure.
Neuromag Vectorview systems can contain magnetometers with two different coil sizes (3022 and 3023 vs. 3024). The systems incorporating coils of type 3024 were introduced last and are used at the majority of MEG sites. At some sites with 3024 magnetometers, the data files have still defined the magnetometers to be of type 3022 to ensure compatibility with older versions of Neuromag software. In the MNE software as well as in the present version of Neuromag software coil type 3024 is fully supported. Therefore, it is now safe to upgrade the data files to use the true coil type.
Note
The effect of the difference between the coil sizes on the current estimates computed by the MNE software is very small. Therefore the use of mne_fix_mag_coil_types is not mandatory.
get_data
(picks=None, start=0, stop=None, reject_by_annotation=None, return_times=False)[source]¶Get data in the given range.
Parameters: |
|
---|---|
Returns: |
|
Notes
New in version 0.14.0.
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.
last_samp
¶The last data sample.
load_bad_channels
(bad_file=None, force=False)[source]¶Mark channels as bad from a text file.
This function operates mostly in the style of the C function
mne_mark_bad_channels
.
Parameters: |
|
---|
load_data
(verbose=None)[source]¶Load raw data.
Parameters: |
|
---|---|
Returns: |
|
Notes
This function will load raw data if it was not already preloaded. If data were already preloaded, it will do nothing.
New in version 0.10.0.
n_times
¶Number of time points.
notch_filter
(freqs, picks=None, filter_length='auto', notch_widths=None, trans_bandwidth=1.0, n_jobs=1, method='fft', iir_params=None, mt_bandwidth=None, p_value=0.05, phase='zero', fir_window='hamming', fir_design='firwin', pad='reflect_limited', verbose=None)[source]¶Notch filter a subset of channels.
Applies a zero-phase notch filter to the channels selected by “picks”. By default the data of the Raw object is modified inplace.
The Raw object has to have the data loaded e.g. with preload=True
or self.load_data()
.
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: |
|
See also
Notes
For details, see mne.filter.notch_filter()
.
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
(events=None, duration=10.0, start=0.0, n_channels=20, bgcolor='w', color=None, bad_color=(0.8, 0.8, 0.8), event_color='cyan', scalings=None, remove_dc=True, order=None, show_options=False, title=None, show=True, block=False, highpass=None, lowpass=None, filtorder=4, clipping=None, show_first_samp=False, proj=True, group_by='type', butterfly=False, decim='auto', noise_cov=None, event_id=None)[source]¶Plot raw data.
Parameters: |
|
---|---|
Returns: |
|
Notes
The arrow keys (up/down/left/right) can typically be used to navigate
between channels and time ranges, but this depends on the backend
matplotlib is configured to use (e.g., mpl.use(‘TkAgg’) should work). The
left/right arrows will scroll by 25% of duration
, whereas
shift+left/shift+right will scroll by 100% of duration
. The scaling can
be adjusted with - and + (or =) keys. The viewport dimensions can be
adjusted with page up/page down and home/end keys. Full screen mode can be
toggled with the F11 key. To mark or un-mark a channel as bad, click on a
channel label or a channel trace. The changes will be reflected immediately
in the raw object’s raw.info['bads']
entry.
If projectors are present, a button labelled “Proj” in the lower right corner of the plot window opens a secondary control window, which allows enabling/disabling specific projectors individually. This provides a means of interactively observing how each projector would affect the raw data if it were applied.
Annotation mode is toggled by pressing ‘a’, butterfly mode by pressing
‘b’, and whitening mode (when noise_cov is not None
) by pressing ‘w’.
plot_projs_topomap
(ch_type=None, layout=None, axes=None)[source]¶Plot SSP vector.
Parameters: |
|
---|---|
Returns: |
|
plot_psd
(tmin=0.0, tmax=inf, fmin=0, fmax=inf, proj=False, n_fft=None, picks=None, ax=None, color='black', area_mode='std', area_alpha=0.33, n_overlap=0, dB=True, estimate='auto', average=None, show=True, n_jobs=1, line_alpha=None, spatial_colors=None, xscale='linear', reject_by_annotation=True, verbose=None)[source]¶Plot the power spectral density across channels.
Different channel types are drawn in sub-plots. When the data has been processed with a bandpass, lowpass or highpass filter, dashed lines indicate the boundaries of the filter (–). The line noise frequency is also indicated with a dashed line (-.).
Parameters: |
|
---|---|
Returns: |
|
plot_psd_topo
(tmin=0.0, tmax=None, fmin=0, fmax=100, proj=False, n_fft=2048, n_overlap=0, layout=None, color='w', fig_facecolor='k', axis_facecolor='k', dB=True, show=True, block=False, n_jobs=1, axes=None, verbose=None)[source]¶Plot channel-wise frequency spectra as topography.
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.
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', stim_picks=None, n_jobs=1, events=None, pad='reflect_limited', verbose=None)[source]¶Resample all channels.
The Raw object has to have the data loaded e.g. with preload=True
or self.load_data()
.
Warning
The intended purpose of this function is primarily to speed up computations (e.g., projection calculation) when precise timing of events is not required, as downsampling raw data effectively jitters trigger timings. It is generally recommended not to epoch downsampled data, but instead epoch and then downsample, as epoching downsampled data jitters triggers. For more, see this illustrative gist.
If resampling the continuous data is desired, it is recommended to construct events using the original data. The event onsets can be jointly resampled with the raw data using the ‘events’ parameter (a resampled copy is returned).
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, picks=None, tmin=0, tmax=None, buffer_size_sec=None, drop_small_buffer=False, proj=False, fmt='single', overwrite=False, split_size='2GB', verbose=None)[source]¶Save raw data to file.
Parameters: |
|
---|
Notes
If Raw is a concatenation of several raw files, be warned that only the measurement information from the first raw file is stored. This likely means that certain operations with external tools may not work properly on a saved concatenated file (e.g., probably some or all forms of SSS). It is recommended not to concatenate and then save raw files for this reason.
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.
time_as_index
(times, use_rounding=False)[source]¶Convert time to indices.
Parameters: |
|
---|---|
Returns: |
|
times
¶Time points.
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: |
|