Read and visualize projections (SSP and other)

This example shows how to read and visualize Signal Subspace Projectors (SSP) vector. Such projections are sometimes referred to as PCA projections.

# Author: Joan Massich <mailsik@gmail.com>
#
# License: BSD (3-clause)

import matplotlib.pyplot as plt

import mne
from mne import read_proj
from mne.io import read_raw_fif

from mne.datasets import sample

print(__doc__)

data_path = sample.data_path()

subjects_dir = data_path + '/subjects'
fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
ecg_fname = data_path + '/MEG/sample/sample_audvis_ecg-proj.fif'

Load the FIF file and display the projections present in the file. Here the projections are added to the file during the acquisition and are obtained from empty room recordings.

raw = read_raw_fif(fname)
empty_room_proj = raw.info['projs']

# Display the projections stored in `info['projs']` from the raw object
raw.plot_projs_topomap()
../../_images/sphx_glr_plot_read_proj_001.png

Out:

Opening raw data file /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis_raw.fif...
    Read a total of 3 projection items:
        PCA-v1 (1 x 102)  idle
        PCA-v2 (1 x 102)  idle
        PCA-v3 (1 x 102)  idle
    Range : 25800 ... 192599 =     42.956 ...   320.670 secs
Ready.
Current compensation grade : 0

Display the projections one by one

fig, axes = plt.subplots(1, len(empty_room_proj))
for proj, ax in zip(empty_room_proj, axes):
    proj.plot_topomap(axes=ax)
../../_images/sphx_glr_plot_read_proj_002.png

Use the function in mne.viz to display a list of projections

../../_images/sphx_glr_plot_read_proj_003.png

The ECG projections can be loaded from a file and added to the raw object

# read the projections
ecg_projs = read_proj(ecg_fname)

# add them to raw and plot everything
raw.add_proj(ecg_projs)
raw.plot_projs_topomap()
../../_images/sphx_glr_plot_read_proj_004.png

Out:

    Read a total of 6 projection items:
        ECG-planar-999--0.200-0.400-PCA-01 (1 x 203)  idle
        ECG-planar-999--0.200-0.400-PCA-02 (1 x 203)  idle
        ECG-axial-999--0.200-0.400-PCA-01 (1 x 102)  idle
        ECG-axial-999--0.200-0.400-PCA-02 (1 x 102)  idle
        ECG-eeg-999--0.200-0.400-PCA-01 (1 x 59)  idle
        ECG-eeg-999--0.200-0.400-PCA-02 (1 x 59)  idle
6 projection items deactivated

Displaying the projections from a raw object requires no extra information since all the layout information is present in raw.info. MNE is able to automatically determine the layout for some magnetometer and gradiometer configurations but not the layout of EEG electrodes.

Here we display the ecg_projs individually and we provide extra parameters for EEG. (Notice that planar projection refers to the gradiometers and axial refers to magnetometers.)

Notice that the conditional is just for illustration purposes. We could raw.info in all cases to avoid the guesswork in plot_topomap and ensure that the right layout is always found

fig, axes = plt.subplots(1, len(ecg_projs))
for proj, ax in zip(ecg_projs, axes):
    if proj['desc'].startswith('ECG-eeg'):
        proj.plot_topomap(axes=ax, info=raw.info)
    else:
        proj.plot_topomap(axes=ax)
../../_images/sphx_glr_plot_read_proj_005.png

The correct layout or a list of layouts from where to choose can also be provided. Just for illustration purposes, here we generate the possible_layouts from the raw object itself, but it can come from somewhere else.

possible_layouts = [mne.find_layout(raw.info, ch_type=ch_type)
                    for ch_type in ('grad', 'mag', 'eeg')]
mne.viz.plot_projs_topomap(ecg_projs, layout=possible_layouts)
../../_images/sphx_glr_plot_read_proj_006.png

Total running time of the script: ( 0 minutes 4.091 seconds)

Estimated memory usage: 14 MB

Gallery generated by Sphinx-Gallery