Hi again,
After all I used
https://gist.github.com/unidesigner/1092080 script but changed it a little to upload matlab data like the sample data sets found here:
https://sites.google.com/site/bctnet/datasetsI
run the altered script with the first data set
(Coactivation_matrix.mat; 638 nodes; Weighted; Undirected) which
includes the adjacency matrix (Coactivation_matrix) and the coordinates
matrix (Coord).
The script was executed successfully and the network 3D visualization was fine.
The script:
import numpy as np
import networkx as nx
import
scipy.io# Input: matlab .mat file that contains both the adjacency matrix and the coordinates
# Output: my_net.cff file and my_net.gpickle
matrix = 'Coactivation_matrix.mat' # the .mat file with the data set
adj = 'Coactivation_matrix' # the adjacency matrix
coord = 'Coord' # the coordinates matrix
output_name = 'my_net'
# load matlab matrix
aa=scipy.io.loadmat(matrix)
# extract matrix
mat=aa[adj]
# convert numpy to networkx graph
net=nx.from_numpy_matrix(mat)
# load nodes coordinates
pos = aa[coord]
# index of last node
card = len(pos)-1
# update the networkx graph with the positions
for k in range(0, len(pos)):
net.node[k]['position'] = str(tuple(pos[k]))
# relabel node ids by incrementing by one
# in order to start with one
net = nx.relabel_nodes(net, lambda x: x + 1)
# write graph out as graph pickle (binarized version
# of the networkx graph
nx.write_gpickle(net, output_name + '.gpickle')
# we need cfflib to create a connectome file
import cfflib
# create a new connectome object
newconn = cfflib.connectome()
# create connectome network object. add more parameters
# you can show the docstring in ipython with cfflib.CNetwork?
cnet = cfflib.CNetwork(output_name, src = output_name + '.gpickle', fileformat = "NXGPickle" )
# add to connectome file
newconn.add_connectome_
network(cnet)
# show the meta cml file
print newconn.to_xml()
# store out as cff, to load it in connectome viewer
cfflib.save_to_cff(newconn, output_name + '.cff')
# in the connectome viewer, you can create the visualization script with
# Code Oracle->Connectome->CNetwork->Visualization->3D Network
# You might have to update the scale factor of the Nodes to e.g. 0.05 by
# double-clicking Nodes the Mayavi Visualization Tre