Skip to content

Export Brain Net Viewer

Patricia Wollstadt edited this page Jul 18, 2018 · 1 revision

Export networks to BrainNet Viewer MATLAB toolbox. BrainNet Viewer offers brain network visualisation (e.g., 'glass' brains). The export function creates text files *.node and *.edge, containing information on node location (in MNI coordinates), directed edges, node color and size.

Reference:

Import IO functions and load example data

import pickle
import numpy as np
from idtxl import idtxl_io as io

results = pickle.load(open('test/data/mute_results_0.p', 'rb'))

Export inferred network graph

Example: export inferred network, using the lag of the past variable with maximum information transfer into the target to weight edges

outfile = 'brain_net'
n_nodes = results.data_properties.n_nodes
mni_coord = np.random.randint(10, size=(n_nodes, 3))
node_color = np.random.randint(10, size=n_nodes)
node_size = np.random.randint(10, size=n_nodes)
labels = ['node_0', 'node_1', 'node_2', 'node_3', 'node_4']
adj_matrix = results.get_adjacency_matrix(
    weights='max_te_lag', fdr=False,)
io.export_brain_net_viewer(adjacency_matrix=adj_matrix,
                            mni_coord=mni_coord,
                            file_name=outfile,
                            labels=labels,
                            node_color=node_color,
                            node_size=node_size)