Network topology

[1]:
import json
import pandas as pd
import numpy as np
from openpyxl import load_workbook
from typing import Dict
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 2
      1 import json
----> 2 import pandas as pd
      3 import numpy as np
      4 from openpyxl import load_workbook

ModuleNotFoundError: No module named 'pandas'

load input data

[2]:
df = pd.read_excel(open('input.xlsx', 'rb'), sheet_name=0)
df = df[df.notna()]
print(df.columns)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 df = pd.read_excel(open('input.xlsx', 'rb'), sheet_name=0)
      2 df = df[df.notna()]
      3 print(df.columns)

NameError: name 'pd' is not defined
[3]:
output = {} # network info

topology: edge information

[4]:
tail = df.t
head = df.h
tail = tail[~np.isnan(tail)]
head = head[~np.isnan(head)]
tail = tail.astype(int)
head = head.astype(int)
ed_ls = [(t, h) for t, h in zip(tail, head)]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[4], line 1
----> 1 tail = df.t
      2 head = df.h
      3 tail = tail[~np.isnan(tail)]

NameError: name 'df' is not defined

edge attributes (length and diameter)

[5]:
d = df.d
l = df.l
d = d[~np.isnan(d)]
l = l[~np.isnan(l)]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[5], line 1
----> 1 d = df.d
      2 l = df.l
      3 d = d[~np.isnan(d)]

NameError: name 'df' is not defined

save edge attributes

[6]:
output['tail'] = tail
output['head'] = head
output['l'] = l
output['d'] = d
output['ed_ls'] = ed_ls
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[6], line 1
----> 1 output['tail'] = tail
      2 output['head'] = head
      3 output['l'] = l

NameError: name 'tail' is not defined

topology: node information

[7]:
nodes = df.nodes
nodes = nodes[~np.isnan(nodes)]
nodes = [int(n) for n in nodes]

xpos = df.xpos
xpos = xpos[~np.isnan(xpos)]
ypos = df.ypos
ypos = ypos[~np.isnan(ypos)]
zpos = df.zpos
zpos = zpos[~np.isnan(zpos)]
xyz = [[x, y, z] for x, y, z in zip(xpos, ypos, zpos)]

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[7], line 1
----> 1 nodes = df.nodes
      2 nodes = nodes[~np.isnan(nodes)]
      3 nodes = [int(n) for n in nodes]

NameError: name 'df' is not defined

save node attributes

[8]:
output['nodes'] = nodes
output['source'] = df.hNode.dropna()
output['target'] = df.tNode.dropna()
output['xyz'] = xyz
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[8], line 1
----> 1 output['nodes'] = nodes
      2 output['source'] = df.hNode.dropna()
      3 output['target'] = df.tNode.dropna()

NameError: name 'nodes' is not defined
[9]:
with open('input.json', 'w') as f:
        json.dump(output, f, indent=2)

[ ]: