example CORONET networks (broken down by region)

This commit is contained in:
James Powell
2017-11-08 14:54:27 -05:00
parent c5abc4109f
commit d91e279294
5 changed files with 6533 additions and 451 deletions

View File

@@ -9,17 +9,12 @@ from argparse import ArgumentParser
from collections import namedtuple, Counter from collections import namedtuple, Counter
from json import dumps from json import dumps
Node = namedtuple('Node', 'city state country region latitutde longitude') Node = namedtuple('Node', 'city state country region latitude longitude')
Link = namedtuple('Link', 'from_city to_city distance') class Link(namedtuple('Link', 'from_city to_city distance distance_units')):
def __new__(cls, from_city, to_city, distance, distance_units='km'):
parser = ArgumentParser() return super().__new__(cls, from_city, to_city, distance, distance_units)
parser.add_argument('workbook', nargs='?', default='CORONET_Global_Topology.xls')
all_rows = lambda sh, start=0: (sh.row(x) for x in range(start, sh.nrows))
if __name__ == '__main__':
args = parser.parse_args()
def parse_excel(args):
with open_workbook(args.workbook) as wb: with open_workbook(args.workbook) as wb:
nodes_sheet = wb.sheet_by_name('Nodes') nodes_sheet = wb.sheet_by_name('Nodes')
links_sheet = wb.sheet_by_name('Links') links_sheet = wb.sheet_by_name('Links')
@@ -28,7 +23,7 @@ if __name__ == '__main__':
header = [x.value.strip() for x in nodes_sheet.row(4)] header = [x.value.strip() for x in nodes_sheet.row(4)]
expected = ['City', 'State', 'Country', 'Region', 'Latitude', 'Longitude'] expected = ['City', 'State', 'Country', 'Region', 'Latitude', 'Longitude']
if header != expected: if header != expected:
exit(f'Malformed header on Nodes sheet: {header} != {expected}') raise ValueError(f'Malformed header on Nodes sheet: {header} != {expected}')
nodes = [] nodes = []
for row in all_rows(nodes_sheet, start=5): for row in all_rows(nodes_sheet, start=5):
@@ -38,34 +33,71 @@ if __name__ == '__main__':
header = [x.value.strip() for x in links_sheet.row(4)] header = [x.value.strip() for x in links_sheet.row(4)]
expected = ['Node A', 'Node Z', 'Distance (km)'] expected = ['Node A', 'Node Z', 'Distance (km)']
if header != expected: if header != expected:
exit(f'Malformed header on Nodes sheet: {header} != {expected}') raise ValueError(f'Malformed header on Nodes sheet: {header} != {expected}')
links = [] links = []
for row in all_rows(links_sheet, start=5): for row in all_rows(links_sheet, start=5):
link = Link(*(x.value for x in row)) links.append(Link(*(x.value for x in row)))
link = link._replace(distance=link.distance * 1000) # base units
links.append(link)
# sanity check # sanity check
all_cities = Counter(n.city for n in nodes) all_cities = Counter(n.city for n in nodes)
if len(all_cities) != len(nodes): if len(all_cities) != len(nodes):
exit(f'Duplicate city: {all_cities}') ValueError(f'Duplicate city: {all_cities}')
if any(ln.from_city not in all_cities or if any(ln.from_city not in all_cities or
ln.to_city not in all_cities for ln in links): ln.to_city not in all_cities for ln in links):
exit(f'Bad link.') ValueError(f'Bad link.')
conus_nodes = [n for n in nodes if n.region == 'CONUS'] return nodes, links
conus_cities = {n.city for n in conus_nodes}
conus_links = [ln for ln in links if ln.from_city in conus_cities parser = ArgumentParser()
and ln.to_city in conus_cities] parser.add_argument('workbook', nargs='?', default='CORONET_Global_Topology.xls')
parser.add_argument('-f', '--filter-region', action='append', default=[])
all_rows = lambda sh, start=0: (sh.row(x) for x in range(start, sh.nrows))
def midpoint(city_a, city_b):
lats = city_a.latitude, city_b.latitude
longs = city_a.longitude, city_b.longitude
return {
'latitude': sum(lats) / 2,
'longitude': sum(longs) / 2,
}
if __name__ == '__main__':
args = parser.parse_args()
nodes, links = parse_excel(args)
if args.filter_region:
nodes = [n for n in nodes if n.region in args.filter_region]
cities = {n.city for n in nodes}
links = [lnk for lnk in links if lnk.from_city in cities and
lnk.to_city in cities]
cities = {lnk.from_city for lnk in links} | {lnk.to_city for lnk in links}
nodes = [n for n in nodes if n.city in cities]
nodes_by_city = {n.city: n for n in nodes}
data = { data = {
"nodes": [{"node": x.city} 'elements':
for x in conus_nodes], [{'id': x.city,
"links": [{"from_node": x.from_city, 'metadata': {'city': x.city, 'region': x.region,
"to_node": x.to_city, 'latitude': x.latitude,
"distance": x.distance} 'longitude': x.longitude},
for x in conus_links], 'type': 'City'}
for x in nodes] +
[{'id': f'fiber ({x.from_city}{x.to_city})',
'metadata': {'length': x.distance, 'units': x.distance_units,
**midpoint(nodes_by_city[x.from_city],
nodes_by_city[x.to_city])},
'type': 'Fiber'}
for x in links],
'connections':
[{'from_node': x.from_city,
'to_node': f'fiber ({x.from_city}{x.to_city})'}
for x in links] +
[{'from_node': f'fiber ({x.from_city}{x.to_city})',
'to_node': x.to_city}
for x in links]
} }
print(dumps(data, indent=2)) print(dumps(data, indent=2))

378
examples/coronet.asia.json Normal file
View File

@@ -0,0 +1,378 @@
{
"elements": [
{
"id": "Bangkok",
"metadata": {
"city": "Bangkok",
"region": "Asia",
"latitude": 13.73,
"longitude": 100.5
},
"type": "City"
},
{
"id": "Beijing",
"metadata": {
"city": "Beijing",
"region": "Asia",
"latitude": 39.92999979,
"longitude": 116.4000013
},
"type": "City"
},
{
"id": "Delhi",
"metadata": {
"city": "Delhi",
"region": "Asia",
"latitude": 28.6700003,
"longitude": 77.2099989
},
"type": "City"
},
{
"id": "Hong_Kong",
"metadata": {
"city": "Hong_Kong",
"region": "Asia",
"latitude": 22.267,
"longitude": 114.14
},
"type": "City"
},
{
"id": "Honolulu",
"metadata": {
"city": "Honolulu",
"region": "Asia",
"latitude": 21.3199996,
"longitude": -157.800003
},
"type": "City"
},
{
"id": "Mumbai",
"metadata": {
"city": "Mumbai",
"region": "Asia",
"latitude": 18.9599987,
"longitude": 72.8199999
},
"type": "City"
},
{
"id": "Seoul",
"metadata": {
"city": "Seoul",
"region": "Asia",
"latitude": 37.56000108,
"longitude": 126.9899988
},
"type": "City"
},
{
"id": "Shanghai",
"metadata": {
"city": "Shanghai",
"region": "Asia",
"latitude": 31.23,
"longitude": 121.47
},
"type": "City"
},
{
"id": "Singapore",
"metadata": {
"city": "Singapore",
"region": "Asia",
"latitude": 1.299999907,
"longitude": 103.8499992
},
"type": "City"
},
{
"id": "Sydney",
"metadata": {
"city": "Sydney",
"region": "Asia",
"latitude": -33.86999896,
"longitude": 151.2100066
},
"type": "City"
},
{
"id": "Taipei",
"metadata": {
"city": "Taipei",
"region": "Asia",
"latitude": 25.0200005,
"longitude": 121.449997
},
"type": "City"
},
{
"id": "Tokyo",
"metadata": {
"city": "Tokyo",
"region": "Asia",
"latitude": 35.6699986,
"longitude": 139.770004
},
"type": "City"
},
{
"id": "fiber (Bangkok \u2192 Delhi)",
"metadata": {
"length": 3505.949664416427,
"units": "km",
"latitude": 21.20000015,
"longitude": 88.85499945000001
},
"type": "Fiber"
},
{
"id": "fiber (Bangkok \u2192 Hong_Kong)",
"metadata": {
"length": 2070.724162058727,
"units": "km",
"latitude": 17.9985,
"longitude": 107.32
},
"type": "Fiber"
},
{
"id": "fiber (Beijing \u2192 Seoul)",
"metadata": {
"length": 1146.1242170685186,
"units": "km",
"latitude": 38.745000434999994,
"longitude": 121.69500005
},
"type": "Fiber"
},
{
"id": "fiber (Beijing \u2192 Shanghai)",
"metadata": {
"length": 1284.46539141146,
"units": "km",
"latitude": 35.579999895,
"longitude": 118.93500065
},
"type": "Fiber"
},
{
"id": "fiber (Delhi \u2192 Mumbai)",
"metadata": {
"length": 1402.1410424889511,
"units": "km",
"latitude": 23.8149995,
"longitude": 75.0149994
},
"type": "Fiber"
},
{
"id": "fiber (Hong_Kong \u2192 Shanghai)",
"metadata": {
"length": 1480.405514673738,
"units": "km",
"latitude": 26.7485,
"longitude": 117.805
},
"type": "Fiber"
},
{
"id": "fiber (Hong_Kong \u2192 Sydney)",
"metadata": {
"length": 8856.6,
"units": "km",
"latitude": -5.801499479999999,
"longitude": 132.67500330000001
},
"type": "Fiber"
},
{
"id": "fiber (Hong_Kong \u2192 Taipei)",
"metadata": {
"length": 966.1766738801513,
"units": "km",
"latitude": 23.64350025,
"longitude": 117.79499849999999
},
"type": "Fiber"
},
{
"id": "fiber (Honolulu \u2192 Sydney)",
"metadata": {
"length": 9808.61585417977,
"units": "km",
"latitude": -6.274999679999999,
"longitude": -3.294998199999995
},
"type": "Fiber"
},
{
"id": "fiber (Honolulu \u2192 Taipei)",
"metadata": {
"length": 9767.012902360886,
"units": "km",
"latitude": 23.17000005,
"longitude": -18.175003000000004
},
"type": "Fiber"
},
{
"id": "fiber (Mumbai \u2192 Singapore)",
"metadata": {
"length": 4692.7080485536935,
"units": "km",
"latitude": 10.1299993035,
"longitude": 88.33499954999999
},
"type": "Fiber"
},
{
"id": "fiber (Seoul \u2192 Tokyo)",
"metadata": {
"length": 1391.0845320188098,
"units": "km",
"latitude": 36.614999839999996,
"longitude": 133.3800014
},
"type": "Fiber"
},
{
"id": "fiber (Singapore \u2192 Sydney)",
"metadata": {
"length": 7562.33052211171,
"units": "km",
"latitude": -16.2849995265,
"longitude": 127.5300029
},
"type": "Fiber"
},
{
"id": "fiber (Taipei \u2192 Tokyo)",
"metadata": {
"length": 2537.3446021508994,
"units": "km",
"latitude": 30.344999549999997,
"longitude": 130.6100005
},
"type": "Fiber"
}
],
"connections": [
{
"from_node": "Bangkok",
"to_node": "fiber (Bangkok \u2192 Delhi)"
},
{
"from_node": "Bangkok",
"to_node": "fiber (Bangkok \u2192 Hong_Kong)"
},
{
"from_node": "Beijing",
"to_node": "fiber (Beijing \u2192 Seoul)"
},
{
"from_node": "Beijing",
"to_node": "fiber (Beijing \u2192 Shanghai)"
},
{
"from_node": "Delhi",
"to_node": "fiber (Delhi \u2192 Mumbai)"
},
{
"from_node": "Hong_Kong",
"to_node": "fiber (Hong_Kong \u2192 Shanghai)"
},
{
"from_node": "Hong_Kong",
"to_node": "fiber (Hong_Kong \u2192 Sydney)"
},
{
"from_node": "Hong_Kong",
"to_node": "fiber (Hong_Kong \u2192 Taipei)"
},
{
"from_node": "Honolulu",
"to_node": "fiber (Honolulu \u2192 Sydney)"
},
{
"from_node": "Honolulu",
"to_node": "fiber (Honolulu \u2192 Taipei)"
},
{
"from_node": "Mumbai",
"to_node": "fiber (Mumbai \u2192 Singapore)"
},
{
"from_node": "Seoul",
"to_node": "fiber (Seoul \u2192 Tokyo)"
},
{
"from_node": "Singapore",
"to_node": "fiber (Singapore \u2192 Sydney)"
},
{
"from_node": "Taipei",
"to_node": "fiber (Taipei \u2192 Tokyo)"
},
{
"from_node": "fiber (Bangkok \u2192 Delhi)",
"to_node": "Delhi"
},
{
"from_node": "fiber (Bangkok \u2192 Hong_Kong)",
"to_node": "Hong_Kong"
},
{
"from_node": "fiber (Beijing \u2192 Seoul)",
"to_node": "Seoul"
},
{
"from_node": "fiber (Beijing \u2192 Shanghai)",
"to_node": "Shanghai"
},
{
"from_node": "fiber (Delhi \u2192 Mumbai)",
"to_node": "Mumbai"
},
{
"from_node": "fiber (Hong_Kong \u2192 Shanghai)",
"to_node": "Shanghai"
},
{
"from_node": "fiber (Hong_Kong \u2192 Sydney)",
"to_node": "Sydney"
},
{
"from_node": "fiber (Hong_Kong \u2192 Taipei)",
"to_node": "Taipei"
},
{
"from_node": "fiber (Honolulu \u2192 Sydney)",
"to_node": "Sydney"
},
{
"from_node": "fiber (Honolulu \u2192 Taipei)",
"to_node": "Taipei"
},
{
"from_node": "fiber (Mumbai \u2192 Singapore)",
"to_node": "Singapore"
},
{
"from_node": "fiber (Seoul \u2192 Tokyo)",
"to_node": "Tokyo"
},
{
"from_node": "fiber (Singapore \u2192 Sydney)",
"to_node": "Sydney"
},
{
"from_node": "fiber (Taipei \u2192 Tokyo)",
"to_node": "Tokyo"
}
]
}

2538
examples/coronet.conus.json Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,406 @@
{
"elements": [
{
"id": "Amsterdam",
"metadata": {
"city": "Amsterdam",
"region": "Europe",
"latitude": 52.3699996,
"longitude": 4.88999915
},
"type": "City"
},
{
"id": "Berlin",
"metadata": {
"city": "Berlin",
"region": "Europe",
"latitude": 52.520002,
"longitude": 13.379995
},
"type": "City"
},
{
"id": "Brussels",
"metadata": {
"city": "Brussels",
"region": "Europe",
"latitude": 50.830002,
"longitude": 4.330002
},
"type": "City"
},
{
"id": "Bucharest",
"metadata": {
"city": "Bucharest",
"region": "Europe",
"latitude": 44.44,
"longitude": 26.1
},
"type": "City"
},
{
"id": "Frankfurt",
"metadata": {
"city": "Frankfurt",
"region": "Europe",
"latitude": 50.1199992,
"longitude": 8.68000104
},
"type": "City"
},
{
"id": "Istanbul",
"metadata": {
"city": "Istanbul",
"region": "Europe",
"latitude": 41.1,
"longitude": 29.0
},
"type": "City"
},
{
"id": "London",
"metadata": {
"city": "London",
"region": "Europe",
"latitude": 51.5200005,
"longitude": -0.100000296
},
"type": "City"
},
{
"id": "Madrid",
"metadata": {
"city": "Madrid",
"region": "Europe",
"latitude": 40.419998,
"longitude": -3.7100002
},
"type": "City"
},
{
"id": "Paris",
"metadata": {
"city": "Paris",
"region": "Europe",
"latitude": 48.86,
"longitude": 2.3399995
},
"type": "City"
},
{
"id": "Rome",
"metadata": {
"city": "Rome",
"region": "Europe",
"latitude": 41.8899996,
"longitude": 12.5000004
},
"type": "City"
},
{
"id": "Vienna",
"metadata": {
"city": "Vienna",
"region": "Europe",
"latitude": 48.2200024,
"longitude": 16.3700005
},
"type": "City"
},
{
"id": "Warsaw",
"metadata": {
"city": "Warsaw",
"region": "Europe",
"latitude": 52.2599987,
"longitude": 21.0200005
},
"type": "City"
},
{
"id": "Zurich",
"metadata": {
"city": "Zurich",
"region": "Europe",
"latitude": 47.3800015,
"longitude": 8.5399996
},
"type": "City"
},
{
"id": "fiber (Amsterdam \u2192 Berlin)",
"metadata": {
"length": 690.6082920593449,
"units": "km",
"latitude": 52.4450008,
"longitude": 9.134997075
},
"type": "Fiber"
},
{
"id": "fiber (Amsterdam \u2192 Brussels)",
"metadata": {
"length": 210.72879668411468,
"units": "km",
"latitude": 51.600000800000004,
"longitude": 4.610000575000001
},
"type": "Fiber"
},
{
"id": "fiber (Amsterdam \u2192 Frankfurt)",
"metadata": {
"length": 436.32424081216897,
"units": "km",
"latitude": 51.2449994,
"longitude": 6.785000095000001
},
"type": "Fiber"
},
{
"id": "fiber (Berlin \u2192 Warsaw)",
"metadata": {
"length": 623.0146935618342,
"units": "km",
"latitude": 52.390000349999994,
"longitude": 17.199997749999998
},
"type": "Fiber"
},
{
"id": "fiber (Brussels \u2192 London)",
"metadata": {
"length": 381.913012710562,
"units": "km",
"latitude": 51.17500125,
"longitude": 2.115000852
},
"type": "Fiber"
},
{
"id": "fiber (Bucharest \u2192 Istanbul)",
"metadata": {
"length": 528.5804934964391,
"units": "km",
"latitude": 42.769999999999996,
"longitude": 27.55
},
"type": "Fiber"
},
{
"id": "fiber (Bucharest \u2192 Warsaw)",
"metadata": {
"length": 1136.2004559222928,
"units": "km",
"latitude": 48.34999935,
"longitude": 23.56000025
},
"type": "Fiber"
},
{
"id": "fiber (Frankfurt \u2192 Vienna)",
"metadata": {
"length": 717.0013849336048,
"units": "km",
"latitude": 49.1700008,
"longitude": 12.52500077
},
"type": "Fiber"
},
{
"id": "fiber (Istanbul \u2192 Rome)",
"metadata": {
"length": 1650.405833597658,
"units": "km",
"latitude": 41.4949998,
"longitude": 20.7500002
},
"type": "Fiber"
},
{
"id": "fiber (London \u2192 Paris)",
"metadata": {
"length": 411.69237336349147,
"units": "km",
"latitude": 50.19000025,
"longitude": 1.1199996019999998
},
"type": "Fiber"
},
{
"id": "fiber (Madrid \u2192 Paris)",
"metadata": {
"length": 1263.6192323447242,
"units": "km",
"latitude": 44.639999,
"longitude": -0.6850003500000001
},
"type": "Fiber"
},
{
"id": "fiber (Madrid \u2192 Zurich)",
"metadata": {
"length": 1497.3583126093179,
"units": "km",
"latitude": 43.89999975,
"longitude": 2.4149997
},
"type": "Fiber"
},
{
"id": "fiber (Rome \u2192 Vienna)",
"metadata": {
"length": 920.025605583882,
"units": "km",
"latitude": 45.055001000000004,
"longitude": 14.43500045
},
"type": "Fiber"
},
{
"id": "fiber (Rome \u2192 Zurich)",
"metadata": {
"length": 823.399678170238,
"units": "km",
"latitude": 44.63500055,
"longitude": 10.52
},
"type": "Fiber"
},
{
"id": "fiber (Vienna \u2192 Warsaw)",
"metadata": {
"length": 669.2971801468174,
"units": "km",
"latitude": 50.24000055,
"longitude": 18.6950005
},
"type": "Fiber"
}
],
"connections": [
{
"from_node": "Amsterdam",
"to_node": "fiber (Amsterdam \u2192 Berlin)"
},
{
"from_node": "Amsterdam",
"to_node": "fiber (Amsterdam \u2192 Brussels)"
},
{
"from_node": "Amsterdam",
"to_node": "fiber (Amsterdam \u2192 Frankfurt)"
},
{
"from_node": "Berlin",
"to_node": "fiber (Berlin \u2192 Warsaw)"
},
{
"from_node": "Brussels",
"to_node": "fiber (Brussels \u2192 London)"
},
{
"from_node": "Bucharest",
"to_node": "fiber (Bucharest \u2192 Istanbul)"
},
{
"from_node": "Bucharest",
"to_node": "fiber (Bucharest \u2192 Warsaw)"
},
{
"from_node": "Frankfurt",
"to_node": "fiber (Frankfurt \u2192 Vienna)"
},
{
"from_node": "Istanbul",
"to_node": "fiber (Istanbul \u2192 Rome)"
},
{
"from_node": "London",
"to_node": "fiber (London \u2192 Paris)"
},
{
"from_node": "Madrid",
"to_node": "fiber (Madrid \u2192 Paris)"
},
{
"from_node": "Madrid",
"to_node": "fiber (Madrid \u2192 Zurich)"
},
{
"from_node": "Rome",
"to_node": "fiber (Rome \u2192 Vienna)"
},
{
"from_node": "Rome",
"to_node": "fiber (Rome \u2192 Zurich)"
},
{
"from_node": "Vienna",
"to_node": "fiber (Vienna \u2192 Warsaw)"
},
{
"from_node": "fiber (Amsterdam \u2192 Berlin)",
"to_node": "Berlin"
},
{
"from_node": "fiber (Amsterdam \u2192 Brussels)",
"to_node": "Brussels"
},
{
"from_node": "fiber (Amsterdam \u2192 Frankfurt)",
"to_node": "Frankfurt"
},
{
"from_node": "fiber (Berlin \u2192 Warsaw)",
"to_node": "Warsaw"
},
{
"from_node": "fiber (Brussels \u2192 London)",
"to_node": "London"
},
{
"from_node": "fiber (Bucharest \u2192 Istanbul)",
"to_node": "Istanbul"
},
{
"from_node": "fiber (Bucharest \u2192 Warsaw)",
"to_node": "Warsaw"
},
{
"from_node": "fiber (Frankfurt \u2192 Vienna)",
"to_node": "Vienna"
},
{
"from_node": "fiber (Istanbul \u2192 Rome)",
"to_node": "Rome"
},
{
"from_node": "fiber (London \u2192 Paris)",
"to_node": "Paris"
},
{
"from_node": "fiber (Madrid \u2192 Paris)",
"to_node": "Paris"
},
{
"from_node": "fiber (Madrid \u2192 Zurich)",
"to_node": "Zurich"
},
{
"from_node": "fiber (Rome \u2192 Vienna)",
"to_node": "Vienna"
},
{
"from_node": "fiber (Rome \u2192 Zurich)",
"to_node": "Zurich"
},
{
"from_node": "fiber (Vienna \u2192 Warsaw)",
"to_node": "Warsaw"
}
]
}

File diff suppressed because it is too large Load Diff