This guide covers how to import data into MNE python. It includes instructions for importing from common recording equipment in MEG and EEG, as well as how to import raw data from numpy arrays.
This section describes the data reading and conversion utilities included with the MNE software. The cheatsheet below summarizes the different file formats supported by MNE software.
All IO functions in MNE-Python performing reading/conversion of MEG and EEG data can be found in mne.io and start with read_raw_ . All supported data formats can be read in MNE-Python directly without first saving it to fif.
Irrespective of the units used in your manufacturer’s format, MNE-Python will always use the units listed below and perform conversions during the IO procedure if necessary.
MNE-Python performs all computation in memory using the double-precision 64-bit floating point format. This means that the data is typecasted into float64 format as soon as it is read into memory. The reason for this is that operations such as filtering, preprocessing etc. are more accurate when using the double-precision format. However, for backward compatibility, it writes the fif files in a 32-bit format by default. This is advantageous when saving data to disk as it consumes less space.
Neuromag Raw FIF files can be loaded using mne.io.read_raw_fif().
If the data were recorded with MaxShield on and have not been processed with MaxFilter, they may need to be loaded with mne.io.read_raw_fif(..., allow_maxshield=True).
A data file (typically c,rfDC) containing the recorded MEG time-series.
A hs_file containing the digitizer data.
A config file containing acquisition information and metadata.
By default mne.io.read_raw_bti() assumes these three files to be located in the same folder.
While reading the reference or compensation channels, currently, the compensation weights are not processed. As a result, the mne.io.Raw object and the corresponding fif file does not include information about the compensation channels and the weights to be applied to realize software gradient compensation. To augment the Magnes fif files with the necessary information, the command line tools include the utilities mne_create_comp_data, and mne_add_to_meas_info. Including the compensation channel data is recommended but not mandatory. If the data are saved in the Magnes system are already compensated, there will be a small error in the forward calculations whose significance has not been evaluated carefully at this time.
The utility mne_create_comp_data was written to create software gradient compensation weight data for 4D Magnes fif files. This utility takes a text file containing the compensation data as input and writes the corresponding fif file as output. This file can be merged into the fif file containing 4D Magnes data with the utility mne_add_to_meas_info. See mne_create_comp_data for command-line options.
In MNE-Python, mne.io.read_raw_ctf() can be used to read CTF data.
The CTF MEG systems store the Polhemus digitization data in text files. The utility mne_ctf_dig2fiff was created to convert these data files into the fif and hpts formats.
Since the software gradient compensation employed in CTF systems is a reversible operation, it is possible to change the compensation status of CTF data in the data files as desired. This section contains information about the technical details of the compensation procedure and a description of mne_compensate_data , which is a utility to change the software gradient compensation state in evoked-response data files.
The fif files containing CTF data converted using the utility mne_ctf2fiff contain several compensation matrices which are employed to suppress external disturbances with help of the reference channel data. The reference sensors are located further away from the brain than the helmet sensors and are thus measuring mainly the external disturbances rather than magnetic fields originating in the brain. Most often, a compensation matrix corresponding to a scheme nicknamed Third-order gradient compensation is employed.
This operation is performed by mne_compensate_data.
MNE-Python includes the mne.io.read_raw_kit() and mne.read_epochs_kit() to read and convert KIT MEG data. This reader function will by default replace the original channel names, which typically with index starting with zero, with ones with an index starting with one.
To import continuous data, only the input .sqd or .con file is needed. For epochs, an Nx3 matrix containing the event number/corresponding trigger value in the third column is needed.
A KIT marker file (mrk file) or an array-like containing the locations of the HPI coils in the MEG device coordinate system. These data are used together with the elp file to establish the coordinate transformation between the head and device coordinate systems.
A Polhemus points file (elp file) or an array-like containing the locations of the fiducials and the head-position indicator (HPI) coils. These data are usually given in the Polhemus head coordinate system.
A Polhemus head shape data file (hsp file) or an array-like containing locations of additional points from the head surface. These points must be given in the same coordinate system as that used for the elp file.
The output fif file will use the Neuromag head coordinate system convention, see The head and device coordinate systems. A coordinate transformation between the Polhemus head coordinates and the Neuromag head coordinates is included.
By default, KIT-157 systems assume the first 157 channels are the MEG channels, the next 3 channels are the reference compensation channels, and channels 160 onwards are designated as miscellaneous input channels (MISC 001, MISC 002, etc.). By default, KIT-208 systems assume the first 208 channels are the MEG channels, the next 16 channels are the reference compensation channels, and channels 224 onwards are designated as miscellaneous input channels (MISC 001, MISC 002, etc.).
A list of trigger channels (stim) or default triggers with order: ‘<’ | ‘>’ Channel-value correspondence when converting KIT trigger channels to a Neuromag-style stim channel. By default, we assume the first eight miscellaneous channels are trigger channels. For ‘<’, the largest values are assigned to the first channel (little endian; default). For ‘>’, the largest values are assigned to the last channel (big endian). Can also be specified as a list of trigger channel indexes.
The trigger channel slope (slope) : ‘+’ | ‘-‘ How to interpret values on KIT trigger channels when synthesizing a Neuromag-style stim channel. With ‘+’, a positive slope (low-to-high) is interpreted as an event. With ‘-‘, a negative slope (high-to-low) is interpreted as an event.
A stimulus threshold (stimthresh) : float The threshold level for accepting voltage changes in KIT trigger channels as a trigger event.
The threshold value \(t\) can be adjusted with the stimthresh parameter, see below.
The MNE package includes various functions and utilities for reading EEG data and electrode templates.
BrainVision EEG files can be read in using mne.io.read_raw_brainvision() with the .vhdr header file as an input.
Renaming BrainVision files can be problematic due to their multifile structure. See this example for an instruction.
EDF and EDF+ files can be read in using mne.io.read_raw_edf().
EDF (European Data Format) and EDF+ are 16-bit formats.
The EDF+ files may contain an annotation channel which can be used to store trigger information. The Time-stamped Annotation Lists (TALs) on the annotation data can be converted to a trigger channel (STI 014) using an annotation map file which associates an annotation label with a number on the trigger channel.
The BDF format is a 24-bit variant of the EDF format used by the EEG systems manufactured by a company called BioSemi. It can also be read in using mne.io.read_raw_edf().
The data samples in a BDF file are represented in a 3-byte (24-bit) format. Since 3-byte raw data buffers are not presently supported in the fif format these data will be changed to 4-byte integers in the conversion.
GDF files can be read in using mne.io.read_raw_edf().
GDF (General Data Format) is a flexible format for biomedical signals, that overcomes some of the limitations of the EDF format. The original specification (GDF v1) includes a binary header, and uses an event table. An updated specification (GDF v2) was released in 2011 and adds fields for additional subject-specific information (gender, age, etc.) and allows storing several physical units and other properties. Both specifications are supported in MNE.
Reading channel locations from the file header may be dangerous, as the x_coord and y_coord in ELECTLOC section of the header do not necessarily translate to absolute locations. Furthermore, EEG-electrode locations that do not fit to a sphere will distort the layout when computing the z-values. If you are not sure about the channel locations in the header, use of a montage is encouraged.
EGI simple binary files can be read in using mne.io.read_raw_egi(). The EGI raw files are simple binary files with a header and can be exported from using the EGI Netstation acquisition software.
EEGLAB .set files can be read in using mne.io.read_raw_eeglab() and mne.read_epochs_eeglab().
The command line utility mne_tufts2fiff was created in collaboration with Phillip Holcomb and Annette Schmid from Tufts University to import their EEG data to the MNE software.
The raw data file containing the acquired EEG data. The name of this file ends with the suffix .raw .
The calibration raw data file. This file contains known calibration signals and is required to bring the data to physical units. The name of this file ends with the suffix c.raw .
The electrode location information file. The name of this file ends with the suffix .elp .
See the options for the command-line utility mne_tufts2fiff.
EEG data from the Nexstim eXimia system can be read in using the mne.io.read_raw_eximia() function.
The preferred method for applying an EEG reference in MNE is mne.set_eeg_reference(), or equivalent instance methods like raw.set_eeg_reference(). By default, an average reference is used. Instead of applying the average reference to the data directly, an average EEG reference projector is created that is applied like any other SSP projection operator.
There are also other functions that can be useful for other referencing operations. See mne.set_bipolar_reference() and mne.add_reference_channels() for more information.
Some EEG formats (EGI, EDF/EDF+, BDF) neither contain electrode location information nor head shape digitization information. Therefore, this information has to be provided separately. For that purpose all readers have a montage parameter to read locations from standard electrode templates or a polhemus digitizer file. This can also be done post-hoc using the mne.io.Raw.set_montage() method of the Raw object in memory.
When using the locations of the fiducial points the digitization data are converted to the MEG head coordinate system employed in the MNE software, see The head and device coordinate systems.
Arbitrary (e.g., simulated or manually read in) raw data can be constructed from memory by making use of mne.io.RawArray, mne.EpochsArray or mne.EvokedArray in combination with mne.create_info().
This functionality is illustrated in Creating MNE objects from data arrays. Using 3rd party libraries such as NEO (https://pythonhosted.org/neo/) in combination with these functions abundant electrophysiological file formats can be easily loaded into MNE.
MNE-Python includes mne.io.read_raw_fieldtrip(), mne.read_epochs_fieldtrip() and mne.read_evoked_fieldtrip() to read data coming from FieldTrip.
The data is imported directly from a .mat file.
All channel locations will be in head coordinates.
Channel orientations cannot be guaranteed to be accurate.
All channel types will be set to generic types.
This is probably fine for anything that does not need that information, but if you intent to do things like interpolation of missing channels, source analysis or look at the RMS pairs of planar gradiometers, you most likely run into problems.
The imported data can have less channels than the original data. Only the information for the present ones is extracted from the info dictionary.
CNT Data imported as microvolts. Otherwise fine. Data imported as microvolts. Otherwise fine. Data imported as microvolts. Otherwise fine.
EGI Mostly Ok.Data imported as microvolts. FieldTrip does not apply calibration. Mostly Ok.Data imported as microvolts. FieldTrip does not apply calibration. Mostly Ok.Data imported as microvolts. FieldTrip does not apply calibration.