Import and export#

Import and export of networks, systems and annotated configurations.

nocad works on the adjacency matrix of the network of state variables, but the networks come from, and the results go to, other software. This module converts in both directions:

  • Python objects: NetworkX digraphs (from_networkx(), to_networkx()), igraph graphs (from_igraph(), to_igraph()), pandas edge lists (from_pandas_edgelist(), to_pandas()), state-space matrices (from_state_space()) and python-control StateSpace systems (from_control(), to_control());

  • files (read(), write(), chosen by the file extension):

    format

    extension

    read

    write

    typical use

    GraphML

    .graphml

    yes

    yes

    yEd, Cytoscape, NetworkX, igraph

    GEXF

    .gexf

    yes

    yes

    Gephi, with role colors and positions

    GML

    .gml

    yes

    yes

    igraph and other network tools

    Cytoscape

    .cyjs

    yes

    yes

    Cytoscape and Cytoscape.js (classes, positions)

    node-link

    .json

    yes

    yes

    D3.js and web applications

    DOT

    .dot

    no

    yes

    Graphviz; components of one level share a rank

    Pajek

    .net

    yes

    yes

    Pajek

    edge list

    .edgelist

    yes

    yes

    plain text with the node order in a header

    CSV / TSV

    .csv

    yes

    yes

    spreadsheets; node table in *_nodes.csv

    Excel

    .xlsx

    yes

    yes

    node, edge and summary sheets

    MATLAB

    .mat

    yes

    yes

    the NOCAD MATLAB toolbox: A, B, C, D, labels

    NumPy

    .npz

    yes

    yes

    compact binary storage

Every export carries the annotations of nocad.annotation.annotate() as node and edge attributes (driver and sensor nodes, roles, types, components, levels, depths, regions, matched edges, edge classes, cactus parts, connection types), unless annotate=False. Files written by nocad are read back with their configuration: read() returns the driver and sensor nodes stored in the driver and sensor attributes.

NetworkX, igraph, pandas, state-space and python-control conversions; GraphML, GEXF, GML, Cytoscape, DOT, Pajek, CSV, Excel, MATLAB and NumPy files.

Functions#

from_networkx(G[, weight, nodes])

Network of state variables from a NetworkX graph.

to_networkx(adj[, labels, annotate, design, ...])

NetworkX digraph of a network, with the annotations as node and edge attributes.

from_igraph(g[, weight, name])

Network from a python-igraph graph (vertex attribute name gives the labels).

to_igraph(adj[, labels])

python-igraph graph with the annotations of to_networkx() as attributes.

from_pandas_edgelist(edges[, source, ...])

Network from an edge-list DataFrame (one row per edge \(x_j\to x_i\)).

to_pandas(adj[, labels, design, method, ...])

Node and edge tables (pandas DataFrames) of nocad.annotation.annotate().

from_state_space(A[, B, C, D, labels])

Network of a state-space model: \(\mathbf{W}=\mathbf{A}^{\mathsf T}\).

from_control(sys[, labels])

Network of a python-control StateSpace system (state names become labels).

to_control(obj[, values, random_state, dt])

python-control StateSpace system with the structure of a design.

read(path[, format])

Read a network (and a stored configuration) from a file.

write(obj, path[, format, labels, annotate, ...])

Write a network, a design or an annotated configuration to a file.

read_mat(path[, variable])

Read a MATLAB file: state-space matrices A, B, C, D or a network matrix.

write_mat(path, obj[, labels, method, design])

Write A, B, C, D, the adjacency matrix adj, labels and the 1-based drivers / sensors for the NOCAD MATLAB toolbox.

to_dot(adj[, labels, include_io, rank, ...])

Graphviz DOT source of an annotated network.

Constants#

FORMATS

File formats by extension: (name, readable, writable).