コード例 #1
0
#!/usr/bin/env python

import numpy as np
from jumeg.connectivity import plot_labelled_group_connectivity_circle
from jumeg import get_jumeg_path

# load the yaml grouping of Freesurfer labels
yaml_fname = get_jumeg_path() + '/examples/rsn_aparc_cortex_grouping.yaml'

# make a random matrix with 68 nodes
# use simple seed for reproducibility
np.random.seed(42)
con = np.random.random((68, 68))
con[con < 0.5] = 0.

# plotting within a subplot
plot_labelled_group_connectivity_circle(yaml_fname, con, out_fname='rsn_circle.png',
                                        show=True, n_lines=20, fontsize_names=6,
                                        title='test RSN circ labels')
コード例 #2
0
from mne.datasets import sample

from jumeg import get_jumeg_path
from jumeg.connectivity import (get_label_distances,
                                plot_grouped_connectivity_circle)
import yaml

from nilearn import plotting

data_path = sample.data_path()
subjects_dir = data_path + '/subjects'
subject = 'sample'

parc = 'aparc'

yaml_fname = get_jumeg_path() + '/data/desikan_%s_cortex_based_grouping.yaml' % parc
label_distances_fname = get_jumeg_path() + '/data/desikan_%s_label_com_distances.npy' % parc

labels_fname = get_jumeg_path() + '/data/desikan_label_names.yaml'
with open(labels_fname, 'r') as f:
    label_names = yaml.safe_load(f)['label_names']

replacer_dict_fname = get_jumeg_path() + '/data/replacer_dictionaries.yaml'
with open(replacer_dict_fname, 'r') as f:
    replacer_dict = yaml.safe_load(f)['replacer_dict_aparc']

# load the distances matrix
con = np.load(label_distances_fname)
node_order_size = con.shape[0]

# forget long range connections, plot short neighbouring connections
コード例 #3
0
#!/usr/bin/env python

import numpy as np
from jumeg.connectivity import plot_labelled_group_connectivity_circle
from jumeg import get_jumeg_path

# load the yaml grouping of Freesurfer labels
yaml_fname = get_jumeg_path() + '/examples/rsn_aparc_cortex_grouping.yaml'

# make a random matrix with 68 nodes
# use simple seed for reproducibility
np.random.seed(42)
con = np.random.random((68, 68))
con[con < 0.5] = 0.

# plotting within a subplot
plot_labelled_group_connectivity_circle(yaml_fname,
                                        con,
                                        out_fname='rsn_circle.png',
                                        show=True,
                                        n_lines=20,
                                        fontsize_names=6,
                                        title='test RSN circ labels')
コード例 #4
0
'''
Script to show functionality to plot centrality indices along with
connectivity circle plot.
'''

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

from jumeg import get_jumeg_path
from jumeg.connectivity import plot_degree_circle, plot_lines_and_blobs

import matplotlib.pyplot as plt

orig_labels_fname = get_jumeg_path() + '/data/desikan_label_names.yaml'
yaml_fname = get_jumeg_path(
) + '/data/desikan_aparc_cortex_based_grouping.yaml'
con_fname = get_jumeg_path() + '/data/sample,aparc-con.npy'

# real connectivity
con = np.load(con_fname)
con = con[0, :, :, 2] + con[0, :, :, 2].T
degrees = mne.connectivity.degree(con, threshold=0.2)

import bct
eigenvec_centrality = bct.eigenvector_centrality_und(con)

fig, ax = plot_lines_and_blobs(con,
                               degrees,
                               yaml_fname,
                               orig_labels_fname,
コード例 #5
0
#!/usr/bin/env python3

"""Example showing how to plot a causality matrix on a circle plot."""

import numpy as np

from jumeg import get_jumeg_path
from jumeg.connectivity import plot_grouped_causality_circle
import yaml

# load the yaml grouping of Freesurfer labels
yaml_fname = get_jumeg_path() + '/data/desikan_aparc_cortex_based_grouping.yaml'
labels_fname = get_jumeg_path() + '/data/desikan_label_names.yaml'
replacer_dict_fname = get_jumeg_path() + '/data/replacer_dictionaries.yaml'

with open(labels_fname, 'r') as f:
    label_names = yaml.safe_load(f)['label_names']

with open(replacer_dict_fname, 'r') as f:
    replacer_dict = yaml.safe_load(f)['replacer_dict_aparc']

# make a random causality matrix
n_nodes = 68  # currently needs to be always this number
caus = np.random.random((n_nodes, n_nodes))
caus[np.diag_indices_from(caus)] = 0.
caus[caus < 0.7] = 0.

plot_grouped_causality_circle(caus, yaml_fname, label_names, n_lines=10,
                              labels_mode='replace', replacer_dict=replacer_dict,
                              out_fname='fig_causality_circle.png',
                              colormap='Blues', colorbar=True,
コード例 #6
0
#!/usr/bin/env python
'''
Read grouped aparc labels from yaml file.
Plot grouped connectivity circle with these grouped labels.
'''

import numpy as np
from jumeg import get_jumeg_path
from jumeg.connectivity import plot_grouped_connectivity_circle
import pickle

labels_fname = get_jumeg_path() + '/examples/label_names.list'
yaml_fname = get_jumeg_path() + '/examples/aparc_cortex_based_grouping.yaml'

with open('label_names.list', 'r') as f:
    label_names = pickle.load(f)

# make a random matrix with 68 nodes
# use simple seed for reproducibility
np.random.seed(42)
con = np.random.random((68, 68))
con[con < 0.5] = 0.

indices = (np.array((1, 2, 3)), np.array((5, 6, 7)))
plot_grouped_connectivity_circle(yaml_fname,
                                 con,
                                 label_names,
                                 labels_mode='cortex_only',
                                 colorbar_pos=(0.1, 0.1),
                                 n_lines=10,
                                 colorbar=True)
コード例 #7
0
con, freqs, times, n_epochs, n_tapers = spectral_connectivity(
    label_ts, method=con_methods, mode='multitaper', sfreq=sfreq, fmin=fmin,
    fmax=fmax, faverage=True, mt_adaptive=True, n_jobs=4)

# con is a 3D array, get the connectivity for the first (and only) freq. band
# for each method
con_res = dict()
for method, c in zip(con_methods, con):
    con_res[method] = c[:, :, 0]

# Now, we visualize the connectivity using a circular graph layout
# First, we reorder the labels based on their location in the left hemi
label_names = [label.name for label in labels]

from jumeg import get_jumeg_path
yaml_fname = get_jumeg_path() + '/data/standard_garces_rsns_grouping.yaml'

import yaml
with open(yaml_fname, 'r') as f:
    xlabels = yaml.safe_load(f)

# the yaml file has been hand curated to follow the same order as label_names
# if not the node order has to be changed appropriately
node_order = list()
node_order.extend(label_names)

group_bound = [len(list(key.values())[0]) for key in xlabels]
group_bound = [0] + group_bound
group_boundaries = [sum(group_bound[:i+1]) for i in range(len(group_bound))]
group_boundaries.pop()
コード例 #8
0
#!/usr/bin/env python
"""Read grouped aparc labels from yaml file.

Plot grouped connectivity circle with these grouped labels
for the Destriux atlas.
"""

from jumeg import get_jumeg_path
from jumeg.connectivity import (plot_grouped_connectivity_circle,
                                generate_random_connectivity_matrix)
import yaml

grouping_yaml_fname = get_jumeg_path(
) + '/data/destriux_aparc_cortex_based_grouping.yaml'
label_names_yaml_fname = get_jumeg_path() + '/data/destriux_label_names.yaml'

with open(label_names_yaml_fname, 'r') as f:
    label_names = yaml.safe_load(f)['label_names']

# make a random matrix with 148 nodes
con = generate_random_connectivity_matrix(size=(148, 148), symmetric=True)
con[con < 0.5] = 0.

# plot grouped connnectivity
plot_grouped_connectivity_circle(grouping_yaml_fname,
                                 con,
                                 label_names,
                                 labels_mode=None,
                                 colorbar_pos=(0.1, 0.1),
                                 replacer_dict=None,
                                 out_fname='fig_destriux_circle.png',
#!/usr/bin/env python3
"""Script exposing circle plots with outer ring.

Author: Praveen Sripad <*****@*****.**>

"""
from jumeg.connectivity import (plot_generic_grouped_circle,
                                plot_fica_grouped_circle,
                                generate_random_connectivity_matrix)
from jumeg import get_jumeg_path

# load the yaml grouping of Freesurfer labels
yaml_fname = get_jumeg_path() + '/data/rsn_desikan_aparc_cortex_grouping.yaml'

# make a random matrix
con = generate_random_connectivity_matrix(size=(34, 34), symmetric=True)

# load the label names in the original order
# this should be same order as the connectivity matrix
labels_fname = get_jumeg_path() + '/data/fica_names.txt'
with open(labels_fname, 'r') as f:
    orig_labels = [line.rstrip('\n') for line in f]

# plot the connectivity circle grouped
plot_generic_grouped_circle(yaml_fname,
                            con,
                            orig_labels,
                            node_order_size=34,
                            out_fname='fig_fica_circle.png',
                            show=False,
                            n_lines=20,
コード例 #10
0
#!/usr/bin/env python3
"""
Example exposing the plot_labelled_group_connectivity_circle function.

Author: Praveen Sripad <*****@*****.**>

"""
from jumeg.connectivity import (plot_labelled_group_connectivity_circle,
                                generate_random_connectivity_matrix)
from jumeg import get_jumeg_path
import yaml

# load the yaml grouping of Freesurfer labels
yaml_fname = get_jumeg_path() + '/data/rsn_desikan_aparc_cortex_grouping.yaml'
label_names_yaml_fname = get_jumeg_path() + '/data/desikan_label_names.yaml'

with open(label_names_yaml_fname, 'r') as f:
    label_names = yaml.safe_load(f)['label_names']

# make a random matrix with 68 nodes
con = generate_random_connectivity_matrix(size=(68, 68), symmetric=True)

# plotting within a subplot
plot_labelled_group_connectivity_circle(yaml_fname,
                                        con,
                                        label_names,
                                        out_fname='fig_rsn_circle.png',
                                        show=False,
                                        n_lines=20,
                                        fontsize_names=6,
                                        title='test RSN circ labels')
コード例 #11
0
#!/usr/bin/env python

import numpy as np
from jumeg.connectivity import plot_generic_grouped_circle, plot_fica_grouped_circle
from jumeg import get_jumeg_path

# load the yaml grouping of Freesurfer labels
yaml_fname = get_jumeg_path() + '/examples/rsn_aparc_cortex_grouping.yaml'

# make a random matrix with 68 nodes
# use simple seed for reproducibility
np.random.seed(42)
con = np.random.random((34, 34))
con[con < 0.5] = 0.

# load the label names in the original order
# this should be same order as the connectivity matrix
labels_fname = get_jumeg_path() + '/examples/fica_names.txt'
with open(labels_fname, 'r') as f:
    orig_labels = [line.rstrip('\n') for line in f]


# plot the connectivity circle grouped
plot_generic_grouped_circle(yaml_fname, con, orig_labels,
                            node_order_size=34,
                            out_fname='fica_circle.png',
                            show=False, n_lines=20,
                            title='Groups')

# plot the connectivity circle with outer group labels ring
plot_fica_grouped_circle(yaml_fname, con,
コード例 #12
0
"""
Example how to create a custom label groups and plot grouped connectivity
circle with these labels.

Author: Praveen Sripad <*****@*****.**>
        Christian Kiefer <*****@*****.**>
"""

import matplotlib.pyplot as plt
from jumeg import get_jumeg_path
from jumeg.connectivity import (plot_grouped_connectivity_circle,
                                generate_random_connectivity_matrix)

import yaml

labels_fname = get_jumeg_path() + '/data/desikan_label_names.yaml'
replacer_dict_fname = get_jumeg_path() + '/data/replacer_dictionaries.yaml'

with open(labels_fname, 'r') as f:
    label_names = yaml.safe_load(f)['label_names']

with open(replacer_dict_fname, 'r') as f:
    replacer_dict = yaml.safe_load(f)['replacer_dict_aparc']

# make a random matrix with 68 nodes
con = generate_random_connectivity_matrix(size=(68, 68), symmetric=True)

# make groups based on lobes
occipital = ['lateraloccipital', 'lingual', 'cuneus', 'pericalcarine']
parietal = [
    'superiorparietal', 'inferiorparietal', 'precuneus', 'postcentral',
コード例 #13
0
#!/usr/bin/env python

'''
Read grouped aparc labels from yaml file.
Plot grouped connectivity circle with these grouped labels.
'''

import numpy as np
from jumeg import get_jumeg_path
from jumeg.connectivity import plot_grouped_connectivity_circle
import pickle

labels_fname = get_jumeg_path() + '/examples/label_names.list'
yaml_fname = get_jumeg_path() + '/examples/aparc_cortex_based_grouping.yaml'

with open('label_names.list', 'r') as f:
        label_names = pickle.load(f)

# make a random matrix with 68 nodes
# use simple seed for reproducibility
np.random.seed(42)
con = np.random.random((68, 68))
con[con < 0.5] = 0.

plot_grouped_connectivity_circle(yaml_fname, con, label_names, n_lines=10, colorbar=True)