Interoperability#
nocad keeps the names of the nodes and converts networks, systems and annotated
configurations in both directions. Wherever a network is expected, a NumPy array, a
SciPy sparse matrix, a NetworkX graph, an igraph graph (via nocad.io.from_igraph())
or a pandas DataFrame can be passed; node names become the labels of every table and
figure, and positions may be NetworkX pos dictionaries.
Role annotations#
nocad.annotate() returns two pandas tables. The node table tells for every state
variable whether it is a driver or sensor node (and through which input or output), its
role across all maximum matchings (critical, intermittent, redundant), its driver or
sensor type, its strongly connected component and level of the hierarchy, its control
and observation depth and region, and its part in the control and observation cacti.
The edge table tells whether an edge is matched, its class across all maximum
matchings (critical, ordinary, redundant), its part in the cacti and its connection
type. A classes column joins the categorical roles for style sheets (Cytoscape.js).
import networkx as nx
import nocad
G = nx.DiGraph([("feed", "reactor"), ("reactor", "reactor"), ("reactor", "flash"),
("flash", "recycle"), ("recycle", "reactor"), ("flash", "product")])
design = nocad.InputOutputDesign("minimum").fit(G)
ann = design.annotate(robustness=True)
ann.nodes[["label", "io_role", "control_role", "control_depth", "control_critical"]]
nocad.viz.plot_annotation(G, "control_role", ann)
Files#
nocad.write_network() and nocad.read_network() choose the format by the
extension; every export carries the annotations as attributes and every file written
by nocad is read back with its configuration (net.drivers, net.sensors).
format |
extension |
read |
write |
typical use |
|---|---|---|---|---|
GraphML |
|
yes |
yes |
yEd, Cytoscape, NetworkX, igraph |
GEXF |
|
yes |
yes |
Gephi, with role colors and positions |
GML |
|
yes |
yes |
igraph and other network tools |
Cytoscape |
|
yes |
yes |
Cytoscape and Cytoscape.js (classes, positions) |
node-link |
|
yes |
yes |
D3.js and web applications |
DOT |
|
no |
yes |
Graphviz; components of one level share a rank |
Pajek |
|
yes |
yes |
Pajek |
edge list |
|
yes |
yes |
plain text with the node order in a header |
CSV / TSV |
|
yes |
yes |
spreadsheets; node table in |
Excel |
|
yes |
yes |
node, edge and summary sheets |
MATLAB |
|
yes |
yes |
the NOCAD MATLAB toolbox: A, B, C, D, labels |
NumPy |
|
yes |
yes |
compact binary storage |
design.write("process.gexf") # open in Gephi
design.write("process.dot") # dot -Tpdf process.dot -o process.pdf
design.write("process.csv") # process.csv (edges) + process_nodes.csv
net = nocad.read_network("process.gexf")
Python objects#
NetworkX:
nocad.from_networkx(),nocad.to_networkx()(annotated digraph);igraph:
nocad.io.from_igraph(),nocad.io.to_igraph();pandas:
nocad.io.from_pandas_edgelist(),nocad.io.to_pandas();state space:
nocad.from_state_space()(driver and sensor nodes from B and C);python-control:
nocad.io.from_control(),nocad.io.to_control()(aStateSpacesystem with generic values on the designed structure).
pip install "nocad[interop]" installs python-control, igraph and openpyxl.