# Compute mixed source space connectivity and visualize it using a circular graph¶

This example computes the all-to-all connectivity between 75 regions in a mixed source space based on dSPM inverse solutions and a FreeSurfer cortical parcellation. The connectivity is visualized using a circular graph which is ordered based on the locations of the regions.

Out:

Successfully extracted to: [u'/home/ubuntu/mne_data/MNE-sample-data']
Setting up the source space with the following parameters:

SUBJECTS_DIR = /home/ubuntu/mne_data/MNE-sample-data/subjects
Subject      = sample
Surface      = white

>>> 1. Creating the source space...

Doing the octahedral vertex picking...
Mapping lh sample -> oct (6) ...
Triangle neighbors and vertex normals...
Triangle neighbors and vertex normals...
Setting up the triangulation for the decimated surface...
loaded lh.white 4098/155407 selected to source space (oct = 6)

Mapping rh sample -> oct (6) ...
Triangle neighbors and vertex normals...
Triangle neighbors and vertex normals...
Setting up the triangulation for the decimated surface...
loaded rh.white 4098/156866 selected to source space (oct = 6)

You are now one step closer to computing the gain matrix
BEM file              : /home/ubuntu/mne_data/MNE-sample-data/subjects/sample/bem/sample-5120-bem.fif
grid                  : 7.0 mm
mindist               : 5.0 mm
MRI volume            : /home/ubuntu/mne_data/MNE-sample-data/subjects/sample/mri/aseg.mgz

Loaded inner skull from /home/ubuntu/mne_data/MNE-sample-data/subjects/sample/bem/sample-5120-bem.fif (2562 nodes)
Surface CM = (   0.7  -10.0   44.3) mm
Surface fits inside a sphere with radius   91.8 mm
Surface extent:
x =  -66.7 ...   68.8 mm
y =  -88.0 ...   79.0 mm
z =  -44.5 ...  105.8 mm
Grid extent:
x =  -70.0 ...   70.0 mm
y =  -91.0 ...   84.0 mm
z =  -49.0 ...  112.0 mm
13104 sources before omitting any.
8549 sources after omitting infeasible sources.
Source spaces are in MRI coordinates.
Checking that the sources are inside the bounding surface and at least    5.0 mm away (will take a few...)
3911 source space points omitted because they are outside the inner skull surface.
881 source space points omitted because of the    5.0-mm distance limit.
Thank you for waiting.
3757 sources remaining after excluding the sources outside the surface and less than    5.0 mm inside.
Selecting voxels from Left-Amygdala
5 sources remaining after excluding sources too far from VOI voxels
Surface CM = (   0.7  -10.0   44.3) mm
Surface fits inside a sphere with radius   91.8 mm
Surface extent:
x =  -66.7 ...   68.8 mm
y =  -88.0 ...   79.0 mm
z =  -44.5 ...  105.8 mm
Grid extent:
x =  -70.0 ...   70.0 mm
y =  -91.0 ...   84.0 mm
z =  -49.0 ...  112.0 mm
13104 sources before omitting any.
8549 sources after omitting infeasible sources.
Source spaces are in MRI coordinates.
Checking that the sources are inside the bounding surface and at least    5.0 mm away (will take a few...)
3911 source space points omitted because they are outside the inner skull surface.
881 source space points omitted because of the    5.0-mm distance limit.
Thank you for waiting.
3757 sources remaining after excluding the sources outside the surface and less than    5.0 mm inside.
Selecting voxels from Left-Thalamus-Proper
24 sources remaining after excluding sources too far from VOI voxels
Surface CM = (   0.7  -10.0   44.3) mm
Surface fits inside a sphere with radius   91.8 mm
Surface extent:
x =  -66.7 ...   68.8 mm
y =  -88.0 ...   79.0 mm
z =  -44.5 ...  105.8 mm
Grid extent:
x =  -70.0 ...   70.0 mm
y =  -91.0 ...   84.0 mm
z =  -49.0 ...  112.0 mm
13104 sources before omitting any.
8549 sources after omitting infeasible sources.
Source spaces are in MRI coordinates.
Checking that the sources are inside the bounding surface and at least    5.0 mm away (will take a few...)
3911 source space points omitted because they are outside the inner skull surface.
881 source space points omitted because of the    5.0-mm distance limit.
Thank you for waiting.
3757 sources remaining after excluding the sources outside the surface and less than    5.0 mm inside.
Selecting voxels from Left-Cerebellum-Cortex
106 sources remaining after excluding sources too far from VOI voxels
Surface CM = (   0.7  -10.0   44.3) mm
Surface fits inside a sphere with radius   91.8 mm
Surface extent:
x =  -66.7 ...   68.8 mm
y =  -88.0 ...   79.0 mm
z =  -44.5 ...  105.8 mm
Grid extent:
x =  -70.0 ...   70.0 mm
y =  -91.0 ...   84.0 mm
z =  -49.0 ...  112.0 mm
13104 sources before omitting any.
8549 sources after omitting infeasible sources.
Source spaces are in MRI coordinates.
Checking that the sources are inside the bounding surface and at least    5.0 mm away (will take a few...)
3911 source space points omitted because they are outside the inner skull surface.
881 source space points omitted because of the    5.0-mm distance limit.
Thank you for waiting.
3757 sources remaining after excluding the sources outside the surface and less than    5.0 mm inside.
Selecting voxels from Brain-Stem
65 sources remaining after excluding sources too far from VOI voxels
Surface CM = (   0.7  -10.0   44.3) mm
Surface fits inside a sphere with radius   91.8 mm
Surface extent:
x =  -66.7 ...   68.8 mm
y =  -88.0 ...   79.0 mm
z =  -44.5 ...  105.8 mm
Grid extent:
x =  -70.0 ...   70.0 mm
y =  -91.0 ...   84.0 mm
z =  -49.0 ...  112.0 mm
13104 sources before omitting any.
8549 sources after omitting infeasible sources.
Source spaces are in MRI coordinates.
Checking that the sources are inside the bounding surface and at least    5.0 mm away (will take a few...)
3911 source space points omitted because they are outside the inner skull surface.
881 source space points omitted because of the    5.0-mm distance limit.
Thank you for waiting.
3757 sources remaining after excluding the sources outside the surface and less than    5.0 mm inside.
Selecting voxels from Right-Amygdala
4 sources remaining after excluding sources too far from VOI voxels
Surface CM = (   0.7  -10.0   44.3) mm
Surface fits inside a sphere with radius   91.8 mm
Surface extent:
x =  -66.7 ...   68.8 mm
y =  -88.0 ...   79.0 mm
z =  -44.5 ...  105.8 mm
Grid extent:
x =  -70.0 ...   70.0 mm
y =  -91.0 ...   84.0 mm
z =  -49.0 ...  112.0 mm
13104 sources before omitting any.
8549 sources after omitting infeasible sources.
Source spaces are in MRI coordinates.
Checking that the sources are inside the bounding surface and at least    5.0 mm away (will take a few...)
3911 source space points omitted because they are outside the inner skull surface.
881 source space points omitted because of the    5.0-mm distance limit.
Thank you for waiting.
3757 sources remaining after excluding the sources outside the surface and less than    5.0 mm inside.
Selecting voxels from Right-Thalamus-Proper
24 sources remaining after excluding sources too far from VOI voxels
Surface CM = (   0.7  -10.0   44.3) mm
Surface fits inside a sphere with radius   91.8 mm
Surface extent:
x =  -66.7 ...   68.8 mm
y =  -88.0 ...   79.0 mm
z =  -44.5 ...  105.8 mm
Grid extent:
x =  -70.0 ...   70.0 mm
y =  -91.0 ...   84.0 mm
z =  -49.0 ...  112.0 mm
13104 sources before omitting any.
8549 sources after omitting infeasible sources.
Source spaces are in MRI coordinates.
Checking that the sources are inside the bounding surface and at least    5.0 mm away (will take a few...)
3911 source space points omitted because they are outside the inner skull surface.
881 source space points omitted because of the    5.0-mm distance limit.
Thank you for waiting.
3757 sources remaining after excluding the sources outside the surface and less than    5.0 mm inside.
Selecting voxels from Right-Cerebellum-Cortex
121 sources remaining after excluding sources too far from VOI voxels
Source space : MRI voxel -> MRI (surface RAS)
0.007000  0.000000  0.000000     -70.00 mm
0.000000  0.007000  0.000000     -91.00 mm
0.000000  0.000000  0.007000     -49.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI voxel -> MRI (surface RAS)
-0.001000  0.000000  0.000000     128.00 mm
0.000000  0.000000  0.001000    -128.00 mm
0.000000 -0.001000  0.000000     128.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI (surface RAS) -> RAS (non-zero origin)
1.000000 -0.000000 -0.000000      -5.27 mm
-0.000000  1.000000 -0.000000       9.04 mm
-0.000000  0.000000  1.000000     -27.29 mm
0.000000  0.000000  0.000000       1.00
Setting up interpolation...
60368/16777216 nonzero values [done]
Source space : MRI voxel -> MRI (surface RAS)
0.007000  0.000000  0.000000     -70.00 mm
0.000000  0.007000  0.000000     -91.00 mm
0.000000  0.000000  0.007000     -49.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI voxel -> MRI (surface RAS)
-0.001000  0.000000  0.000000     128.00 mm
0.000000  0.000000  0.001000    -128.00 mm
0.000000 -0.001000  0.000000     128.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI (surface RAS) -> RAS (non-zero origin)
1.000000 -0.000000 -0.000000      -5.27 mm
-0.000000  1.000000 -0.000000       9.04 mm
-0.000000  0.000000  1.000000     -27.29 mm
0.000000  0.000000  0.000000       1.00
Setting up interpolation...
189336/16777216 nonzero values [done]
Source space : MRI voxel -> MRI (surface RAS)
0.007000  0.000000  0.000000     -70.00 mm
0.000000  0.007000  0.000000     -91.00 mm
0.000000  0.000000  0.007000     -49.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI voxel -> MRI (surface RAS)
-0.001000  0.000000  0.000000     128.00 mm
0.000000  0.000000  0.001000    -128.00 mm
0.000000 -0.001000  0.000000     128.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI (surface RAS) -> RAS (non-zero origin)
1.000000 -0.000000 -0.000000      -5.27 mm
-0.000000  1.000000 -0.000000       9.04 mm
-0.000000  0.000000  1.000000     -27.29 mm
0.000000  0.000000  0.000000       1.00
Setting up interpolation...
743624/16777216 nonzero values [done]
Source space : MRI voxel -> MRI (surface RAS)
0.007000  0.000000  0.000000     -70.00 mm
0.000000  0.007000  0.000000     -91.00 mm
0.000000  0.000000  0.007000     -49.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI voxel -> MRI (surface RAS)
-0.001000  0.000000  0.000000     128.00 mm
0.000000  0.000000  0.001000    -128.00 mm
0.000000 -0.001000  0.000000     128.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI (surface RAS) -> RAS (non-zero origin)
1.000000 -0.000000 -0.000000      -5.27 mm
-0.000000  1.000000 -0.000000       9.04 mm
-0.000000  0.000000  1.000000     -27.29 mm
0.000000  0.000000  0.000000       1.00
Setting up interpolation...
433552/16777216 nonzero values [done]
Source space : MRI voxel -> MRI (surface RAS)
0.007000  0.000000  0.000000     -70.00 mm
0.000000  0.007000  0.000000     -91.00 mm
0.000000  0.000000  0.007000     -49.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI voxel -> MRI (surface RAS)
-0.001000  0.000000  0.000000     128.00 mm
0.000000  0.000000  0.001000    -128.00 mm
0.000000 -0.001000  0.000000     128.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI (surface RAS) -> RAS (non-zero origin)
1.000000 -0.000000 -0.000000      -5.27 mm
-0.000000  1.000000 -0.000000       9.04 mm
-0.000000  0.000000  1.000000     -27.29 mm
0.000000  0.000000  0.000000       1.00
Setting up interpolation...
54880/16777216 nonzero values [done]
Source space : MRI voxel -> MRI (surface RAS)
0.007000  0.000000  0.000000     -70.00 mm
0.000000  0.007000  0.000000     -91.00 mm
0.000000  0.000000  0.007000     -49.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI voxel -> MRI (surface RAS)
-0.001000  0.000000  0.000000     128.00 mm
0.000000  0.000000  0.001000    -128.00 mm
0.000000 -0.001000  0.000000     128.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI (surface RAS) -> RAS (non-zero origin)
1.000000 -0.000000 -0.000000      -5.27 mm
-0.000000  1.000000 -0.000000       9.04 mm
-0.000000  0.000000  1.000000     -27.29 mm
0.000000  0.000000  0.000000       1.00
Setting up interpolation...
172872/16777216 nonzero values [done]
Source space : MRI voxel -> MRI (surface RAS)
0.007000  0.000000  0.000000     -70.00 mm
0.000000  0.007000  0.000000     -91.00 mm
0.000000  0.000000  0.007000     -49.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI voxel -> MRI (surface RAS)
-0.001000  0.000000  0.000000     128.00 mm
0.000000  0.000000  0.001000    -128.00 mm
0.000000 -0.001000  0.000000     128.00 mm
0.000000  0.000000  0.000000       1.00
MRI volume : MRI (surface RAS) -> RAS (non-zero origin)
1.000000 -0.000000 -0.000000      -5.27 mm
-0.000000  1.000000 -0.000000       9.04 mm
-0.000000  0.000000  1.000000     -27.29 mm
0.000000  0.000000  0.000000       1.00
Setting up interpolation...
864360/16777216 nonzero values [done]
Source space                 : <SourceSpaces: [<surface (lh), n_vertices=155407, n_used=4098, coordinate_frame=MRI (surface RAS)>, <surface (rh), n_vertices=156866, n_used=4098, coordinate_frame=MRI (surface RAS)>, <volume (Left-Amygdala), n_used=5, coordinate_frame=MRI (surface RAS)>, <volume (Left-Thalamus-Proper), n_used=24, coordinate_frame=MRI (surface RAS)>, <volume (Left-Cerebellum-Cortex), n_used=106, coordinate_frame=MRI (surface RAS)>, <volume (Brain-Stem), n_used=65, coordinate_frame=MRI (surface RAS)>, <volume (Right-Amygdala), n_used=4, coordinate_frame=MRI (surface RAS)>, <volume (Right-Thalamus-Proper), n_used=24, coordinate_frame=MRI (surface RAS)>, <volume (Right-Cerebellum-Cortex), n_used=121, coordinate_frame=MRI (surface RAS)>]>
MRI -> head transform source : /home/ubuntu/mne_data/MNE-sample-data/MEG/sample/sample_audvis_raw-trans.fif
Measurement data             : sample_audvis_filt-0-40_raw.fif
BEM model                    : /home/ubuntu/mne_data/MNE-sample-data/subjects/sample/bem/sample-5120-bem-sol.fif
Accurate field computations
Free source orientations

Read 9 source spaces a total of 8545 active source locations

Coordinate transformation: MRI (surface RAS) -> head
0.999310  0.009985 -0.035787      -3.17 mm
0.012759  0.812405  0.582954       6.86 mm
0.034894 -0.583008  0.811716      28.88 mm
0.000000  0.000000  0.000000       1.00

Read 306 MEG channels from info
Coordinate transformation: MEG device -> head
0.991420 -0.039936 -0.124467      -6.13 mm
0.060661  0.984012  0.167456       0.06 mm
0.115790 -0.173570  0.977991      64.74 mm
0.000000  0.000000  0.000000       1.00
MEG coil definitions created in head coordinates.
Source spaces are now in head coordinates.

Setting up the BEM model using /home/ubuntu/mne_data/MNE-sample-data/subjects/sample/bem/sample-5120-bem-sol.fif...

Loaded linear_collocation BEM solution from /home/ubuntu/mne_data/MNE-sample-data/subjects/sample/bem/sample-5120-bem-sol.fif
Employing the head->MRI coordinate transform with the BEM model.
BEM model sample-5120-bem-sol.fif is now set up

Source spaces are in head coordinates.
Checking that the sources are inside the bounding surface and at least    5.0 mm away (will take a few...)
2 source space points omitted because they are outside the inner skull surface.
364 source space points omitted because of the    5.0-mm distance limit.
1 source space point omitted because it is outside the inner skull surface.
331 source space point omitted because of the    5.0-mm distance limit.
Thank you for waiting.

Setting up compensation data...
No compensation set. Nothing more to do.

Composing the field computation matrix...
Computing MEG at 7847 source locations (free orientations)...

Finished.
Opening raw data file /home/ubuntu/mne_data/MNE-sample-data/MEG/sample/sample_audvis_filt-0-40_raw.fif...
Read a total of 4 projection items:
PCA-v1 (1 x 102)  idle
PCA-v2 (1 x 102)  idle
PCA-v3 (1 x 102)  idle
Average EEG reference (1 x 60)  idle
Range : 6450 ... 48149 =     42.956 ...   320.665 secs
Reading 0 ... 41699  =      0.000 ...   277.709 secs...
306 x 306 full covariance (kind = 1) found.
Read a total of 3 projection items:
PCA-v1 (1 x 102) active
PCA-v2 (1 x 102) active
PCA-v3 (1 x 102) active
72 matching events found
Created an SSP operator (subspace dimension = 3)
4 projection items activated
Computing inverse operator with 305 channels.
Created an SSP operator (subspace dimension = 3)
estimated rank (mag + grad): 302
Setting small MEG eigenvalues to zero.
Not doing PCA for MEG.
Total rank is 302
Computing inverse operator with 305 channels.
Creating the source covariance matrix
Whitening the forward solution.
Computing SVD of whitened and weighted lead field matrix.
largest singular value = 6.38887
scaling factor to adjust the trace = 4.60481e+21
Preparing the inverse operator for use...
Scaled noise and source covariance from nave = 1 to nave = 1
Created the regularized inverter
Created an SSP operator (subspace dimension = 3)
Created the whitener using a full noise covariance matrix (3 small eigenvalues omitted)
Computing noise-normalization factors (dSPM)...
[done]
Picked 305 channels from the data
Computing inverse...
Processing epoch : 1
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 2
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 3
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 4
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 5
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 6
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 7
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 8
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 9
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 10
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on EOG : [u'EOG 061']
Processing epoch : 11
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 12
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 13
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on EOG : [u'EOG 061']
Rejecting  epoch based on EOG : [u'EOG 061']
Processing epoch : 14
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 15
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 16
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 17
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on EOG : [u'EOG 061']
Processing epoch : 18
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 19
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 20
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on EOG : [u'EOG 061']
Processing epoch : 21
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 22
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 23
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on MAG : [u'MEG 1711']
Processing epoch : 24
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 25
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 26
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 27
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 28
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on EOG : [u'EOG 061']
Processing epoch : 29
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 30
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 31
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on EOG : [u'EOG 061']
Processing epoch : 32
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 33
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on EOG : [u'EOG 061']
Processing epoch : 34
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 35
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on EOG : [u'EOG 061']
Rejecting  epoch based on EOG : [u'EOG 061']
Processing epoch : 36
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on EOG : [u'EOG 061']
Rejecting  epoch based on EOG : [u'EOG 061']
Processing epoch : 37
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 38
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 39
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 40
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 41
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 42
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 43
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 44
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on EOG : [u'EOG 061']
Processing epoch : 45
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on EOG : [u'EOG 061']
Processing epoch : 46
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 47
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 48
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Rejecting  epoch based on EOG : [u'EOG 061']
Rejecting  epoch based on EOG : [u'EOG 061']
Processing epoch : 49
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 50
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 51
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 52
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 53
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 54
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
Processing epoch : 55
combining the current components...
Extracting time courses for 75 labels (mode: mean_flip)
[done]
Connectivity computation...
only using indices for lower-triangular matrix
computing connectivity for 2775 connections
using t=0.000s..0.699s for estimation (106 points)
frequencies: 8.5Hz..12.7Hz (4 points)
connectivity scores will be averaged for each band
using multitaper spectrum estimation with 7 DPSS windows
the following metrics will be computed: PLI
computing connectivity for epoch 1
computing connectivity for epoch 2
computing connectivity for epoch 3
computing connectivity for epoch 4
computing connectivity for epoch 5
computing connectivity for epoch 6
computing connectivity for epoch 7
computing connectivity for epoch 8
computing connectivity for epoch 9
computing connectivity for epoch 10
computing connectivity for epoch 11
computing connectivity for epoch 12
computing connectivity for epoch 13
computing connectivity for epoch 14
computing connectivity for epoch 15
computing connectivity for epoch 16
computing connectivity for epoch 17
computing connectivity for epoch 18
computing connectivity for epoch 19
computing connectivity for epoch 20
computing connectivity for epoch 21
computing connectivity for epoch 22
computing connectivity for epoch 23
computing connectivity for epoch 24
computing connectivity for epoch 25
computing connectivity for epoch 26
computing connectivity for epoch 27
computing connectivity for epoch 28
computing connectivity for epoch 29
computing connectivity for epoch 30
computing connectivity for epoch 31
computing connectivity for epoch 32
computing connectivity for epoch 33
computing connectivity for epoch 34
computing connectivity for epoch 35
computing connectivity for epoch 36
computing connectivity for epoch 37
computing connectivity for epoch 38
computing connectivity for epoch 39
computing connectivity for epoch 40
computing connectivity for epoch 41
computing connectivity for epoch 42
computing connectivity for epoch 43
computing connectivity for epoch 44
computing connectivity for epoch 45
computing connectivity for epoch 46
computing connectivity for epoch 47
computing connectivity for epoch 48
computing connectivity for epoch 49
computing connectivity for epoch 50
computing connectivity for epoch 51
computing connectivity for epoch 52
computing connectivity for epoch 53
computing connectivity for epoch 54
computing connectivity for epoch 55
assembling connectivity matrix (filling the upper triangular region of the matrix)
[Connectivity computation done]


# Author: Annalisa Pascarella <a.pascarella@iac.cnr.it>
#

import os.path as op
import numpy as np
import mne

from mne.datasets import sample
from mne import setup_volume_source_space, setup_source_space
from mne import make_forward_solution
from mne.minimum_norm import make_inverse_operator, apply_inverse_epochs
from mne.connectivity import spectral_connectivity
from mne.viz import circular_layout, plot_connectivity_circle

# Set dir
data_path = sample.data_path()
subject = 'sample'
data_dir = op.join(data_path, 'MEG', subject)
subjects_dir = op.join(data_path, 'subjects')
bem_dir = op.join(subjects_dir, subject, 'bem')

# Set file names
fname_aseg = op.join(subjects_dir, subject, 'mri', 'aseg.mgz')

fname_model = op.join(bem_dir, '%s-5120-bem.fif' % subject)
fname_bem = op.join(bem_dir, '%s-5120-bem-sol.fif' % subject)

fname_raw = data_dir + '/sample_audvis_filt-0-40_raw.fif'
fname_trans = data_dir + '/sample_audvis_raw-trans.fif'
fname_cov = data_dir + '/ernoise-cov.fif'
fname_event = data_dir + '/sample_audvis_filt-0-40_raw-eve.fif'

# List of sub structures we are interested in. We select only the
# sub structures we want to include in the source space
labels_vol = ['Left-Amygdala',
'Left-Thalamus-Proper',
'Left-Cerebellum-Cortex',
'Brain-Stem',
'Right-Amygdala',
'Right-Thalamus-Proper',
'Right-Cerebellum-Cortex']

# Setup a surface-based source space
src = setup_source_space(subject, subjects_dir=subjects_dir,

# Setup a volume source space
# set pos=7.0 for speed issue
vol_src = setup_volume_source_space(subject, mri=fname_aseg,
pos=7.0,
bem=fname_model,
volume_label=labels_vol,
subjects_dir=subjects_dir)
# Generate the mixed source space
src += vol_src

# compute the fwd matrix
fwd = make_forward_solution(fname_raw, fname_trans, src, fname_bem,
mindist=5.0,  # ignore sources<=5mm from innerskull
meg=True, eeg=False,
n_jobs=1)

# Pick MEG channels
picks = mne.pick_types(raw.info, meg=True, eeg=False, stim=False, eog=True,

# Define epochs for left-auditory condition
event_id, tmin, tmax = 1, -0.2, 0.5
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks,
eog=150e-6))

# Compute inverse solution and for each epoch
snr = 1.0           # use smaller SNR for raw data
inv_method = 'dSPM'  # sLORETA, MNE, dSPM
parc = 'aparc'      # the parcellation to use, e.g., 'aparc' 'aparc.a2009s'

lambda2 = 1.0 / snr ** 2

# Compute inverse operator
inverse_operator = make_inverse_operator(raw.info, fwd, noise_cov,
depth=None, fixed=False)

stcs = apply_inverse_epochs(epochs, inverse_operator, lambda2, inv_method,
pick_ori=None, return_generator=True)

subjects_dir=subjects_dir)

# Average the source estimates within each label of the cortical parcellation
# and each sub structures contained in the src space
# If mode = 'mean_flip' this option is used only for the cortical label
src = inverse_operator['src']
label_ts = mne.extract_label_time_course(stcs, labels_parc, src,
mode='mean_flip',
allow_empty=True,
return_generator=False)

# We compute the connectivity in the alpha band and plot it using a circular
# graph layout
fmin = 8.
fmax = 13.
sfreq = raw.info['sfreq']  # the sampling frequency
con, freqs, times, n_epochs, n_tapers = spectral_connectivity(
label_ts, method='pli', mode='multitaper', sfreq=sfreq, fmin=fmin,

# We create a list of Label containing also the sub structures
labels_aseg = mne.get_volume_labels_from_src(src, subject, subjects_dir)
labels = labels_parc + labels_aseg

node_colors = [label.color for label in labels]

# We reorder the labels based on their location in the left hemi
label_names = [label.name for label in labels]
lh_labels = [name for name in label_names if name.endswith('lh')]
rh_labels = [name for name in label_names if name.endswith('rh')]

# Get the y-location of the label
label_ypos_lh = list()
for name in lh_labels:
idx = label_names.index(name)
ypos = np.mean(labels[idx].pos[:, 1])
label_ypos_lh.append(ypos)
try:
idx = label_names.index('Brain-Stem')
except ValueError:
pass
else:
ypos = np.mean(labels[idx].pos[:, 1])
lh_labels.append('Brain-Stem')
label_ypos_lh.append(ypos)

# Reorder the labels based on their location
lh_labels = [label for (yp, label) in sorted(zip(label_ypos_lh, lh_labels))]

# For the right hemi
rh_labels = [label[:-2] + 'rh' for label in lh_labels
if label != 'Brain-Stem' and label[:-2] + 'rh' in rh_labels]

# Save the plot order
node_order = list()
node_order = lh_labels[::-1] + rh_labels

node_angles = circular_layout(label_names, node_order, start_pos=90,
group_boundaries=[0, len(label_names) // 2])

# Plot the graph using node colors from the FreeSurfer parcellation. We only
# show the 300 strongest connections.
conmat = con[:, :, 0]
plot_connectivity_circle(conmat, label_names, n_lines=300,
node_angles=node_angles, node_colors=node_colors,
title='All-to-All Connectivity left-Auditory '
'Condition (PLI)')


Total running time of the script: ( 2 minutes 35.953 seconds)

Gallery generated by Sphinx-Gallery