topolib 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of topolib might be problematic. Click here for more details.
- diagrams/class_diagram.puml +75 -0
- docs/Makefile +20 -0
- docs/requirements.txt +2 -0
- docs/source/conf.py +37 -0
- docs/source/index.rst +33 -0
- docs/source/modules.rst +7 -0
- docs/source/topolib.analysis.rst +21 -0
- docs/source/topolib.elements.rst +23 -0
- docs/source/topolib.rst +20 -0
- docs/source/topolib.topology.rst +29 -0
- examples/show_topology_in_map.py +11 -0
- tests/__init__.py +1 -0
- tests/test_link.py +77 -0
- tests/test_mapview.py +33 -0
- tests/test_metrics.py +53 -0
- tests/test_node.py +44 -0
- tests/test_path.py +46 -0
- tests/test_topology.py +225 -0
- tests/test_version.py +6 -0
- topolib/__init__.py +4 -0
- topolib/analysis/__init__.py +3 -0
- topolib/analysis/metrics.py +80 -0
- topolib/assets/Abilene_IXP.json +285 -0
- topolib/assets/China_pop.json +1063 -0
- topolib/assets/DT-50_pop.json +1415 -0
- topolib/elements/__init__.py +8 -0
- topolib/elements/link.py +145 -0
- topolib/elements/node.py +221 -0
- topolib/topology/__init__.py +4 -0
- topolib/topology/path.py +84 -0
- topolib/topology/topology.py +172 -0
- topolib/visualization/__init__.py +1 -0
- topolib/visualization/mapview.py +75 -0
- topolib-0.0.0.dist-info/METADATA +127 -0
- topolib-0.0.0.dist-info/RECORD +38 -0
- topolib-0.0.0.dist-info/WHEEL +5 -0
- topolib-0.0.0.dist-info/licenses/LICENSE +22 -0
- topolib-0.0.0.dist-info/top_level.txt +5 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MapView class for visualizing network topologies.
|
|
3
|
+
|
|
4
|
+
This module provides visualization methods for Topology objects.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Any
|
|
8
|
+
from topolib.topology import Topology
|
|
9
|
+
import matplotlib.pyplot as plt
|
|
10
|
+
import contextily as ctx
|
|
11
|
+
import geopandas as gpd
|
|
12
|
+
from shapely.geometry import Point
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class MapView:
|
|
16
|
+
"""
|
|
17
|
+
Provides visualization methods for Topology objects.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, topology: Topology) -> None:
|
|
21
|
+
"""
|
|
22
|
+
Initialize MapView with a Topology object.
|
|
23
|
+
:param topology: Topology object
|
|
24
|
+
"""
|
|
25
|
+
self.topology = topology
|
|
26
|
+
|
|
27
|
+
def show_map(self) -> None:
|
|
28
|
+
"""
|
|
29
|
+
Show all nodes and links of the topology on an OpenStreetMap base using contextily and Matplotlib.
|
|
30
|
+
The figure and plot title will be the topology name if available.
|
|
31
|
+
"""
|
|
32
|
+
lons: list[float] = [node.longitude for node in self.topology.nodes]
|
|
33
|
+
lats: list[float] = [node.latitude for node in self.topology.nodes]
|
|
34
|
+
names: list[str] = [node.name for node in self.topology.nodes]
|
|
35
|
+
gdf: gpd.GeoDataFrame = gpd.GeoDataFrame(
|
|
36
|
+
{"name": names},
|
|
37
|
+
geometry=[Point(x, y) for x, y in zip(lons, lats)],
|
|
38
|
+
crs="EPSG:4326",
|
|
39
|
+
)
|
|
40
|
+
gdf = gdf.to_crs(epsg=3857)
|
|
41
|
+
|
|
42
|
+
# Map node id to projected coordinates
|
|
43
|
+
node_id_to_xy = {
|
|
44
|
+
node.id: (pt.x, pt.y) for node, pt in zip(self.topology.nodes, gdf.geometry)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# Try to get topology name (from attribute or fallback)
|
|
48
|
+
topo_name = getattr(self.topology, "name", None)
|
|
49
|
+
if topo_name is None:
|
|
50
|
+
# Try to get from dict if loaded from JSON
|
|
51
|
+
topo_name = getattr(self.topology, "_name", None)
|
|
52
|
+
if topo_name is None:
|
|
53
|
+
topo_name = "Topology"
|
|
54
|
+
|
|
55
|
+
fig, ax = plt.subplots(figsize=(10, 7))
|
|
56
|
+
fig.suptitle(topo_name, fontsize=16)
|
|
57
|
+
# Draw links as simple lines
|
|
58
|
+
for link in getattr(self.topology, "links", []):
|
|
59
|
+
src_id = getattr(link, "source").id
|
|
60
|
+
tgt_id = getattr(link, "target").id
|
|
61
|
+
if src_id in node_id_to_xy and tgt_id in node_id_to_xy:
|
|
62
|
+
x0, y0 = node_id_to_xy[src_id]
|
|
63
|
+
x1, y1 = node_id_to_xy[tgt_id]
|
|
64
|
+
ax.plot(
|
|
65
|
+
[x0, x1], [y0, y1], color="gray", linewidth=1, alpha=0.7, zorder=2
|
|
66
|
+
)
|
|
67
|
+
# Draw nodes
|
|
68
|
+
gdf.plot(ax=ax, color="blue", markersize=40, zorder=5)
|
|
69
|
+
for x, y, name in zip(gdf.geometry.x, gdf.geometry.y, gdf["name"]):
|
|
70
|
+
ax.text(x, y, name, fontsize=8, ha="right", va="bottom", color="black")
|
|
71
|
+
ctx.add_basemap(ax, source=ctx.providers.OpenStreetMap.Mapnik)
|
|
72
|
+
ax.set_axis_off()
|
|
73
|
+
ax.set_title(f"Nodes and links ({topo_name})")
|
|
74
|
+
plt.tight_layout()
|
|
75
|
+
plt.show()
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: topolib
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: A compact Python library for modeling, analyzing, and visualizing optical network topologies.
|
|
5
|
+
Author-email: Danilo Bórquez-Paredes <danilo.borquez.p@uai.cl>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://gitlab.com/DaniloBorquez/topolib
|
|
8
|
+
Project-URL: Documentation, https://topolib.readthedocs.io/
|
|
9
|
+
Project-URL: Source, https://gitlab.com/DaniloBorquez/topolib
|
|
10
|
+
Project-URL: Issues, https://gitlab.com/DaniloBorquez/topolib/-/issues
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: numpy>=1.21
|
|
20
|
+
Requires-Dist: networkx>=2.6
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# Topolib 🚀
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
[](https://www.python.org/)
|
|
27
|
+
[](LICENSE)
|
|
28
|
+
[](https://gitlab.com/DaniloBorquez/topolib/-/issues)
|
|
29
|
+
[](https://gitlab.com/DaniloBorquez/topolib/-/pipelines?ref=develop)
|
|
30
|
+
[](https://gitlab.com/DaniloBorquez/topolib/-/pipelines?ref=release)
|
|
31
|
+
[](https://topolib.readthedocs.io/en/latest/?badge=latest)
|
|
32
|
+
|
|
33
|
+
A compact Python library for working with optical network topologies: nodes, links, metrics and visualization tools. 🌐
|
|
34
|
+
|
|
35
|
+
## Overview
|
|
36
|
+
|
|
37
|
+
Topolib models network topologies with three main modules:
|
|
38
|
+
|
|
39
|
+
- `topolib.elements` — Definitions of elementary building blocks
|
|
40
|
+
- `Node` — represents a network node with id, name and geographic coordinates
|
|
41
|
+
- `Link` — connects two `Node` objects and stores link length and id
|
|
42
|
+
|
|
43
|
+
- `topolib.topology` — High-level topology model
|
|
44
|
+
- `Topology` — holds nodes and links, provides methods to add/remove nodes and links, compute metrics, export JSON, and compute shortest/disjoint paths
|
|
45
|
+
- `Path` — represents a path through the topology
|
|
46
|
+
|
|
47
|
+
- `topolib.analysis` — Metrics and analysis helpers
|
|
48
|
+
- `Metrics` — functions to compute node degree, link length statistics, connection matrices, etc.
|
|
49
|
+
|
|
50
|
+
- `topolib.visualization` — Visualization helpers
|
|
51
|
+
- `MapView` — functions to display topology with OSM or paper-style maps
|
|
52
|
+
|
|
53
|
+
(These components are derived from the project's class diagram in `diagrams/class_diagram.puml`.)
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
- Modular design: elements, topology, analysis, and visualization
|
|
57
|
+
- Easy-to-use classes for nodes, links, and paths
|
|
58
|
+
- Built-in metrics and analysis helpers
|
|
59
|
+
- JSON import/export and interoperability
|
|
60
|
+
- Ready for Sphinx, Read the Docs, and PyPI
|
|
61
|
+
|
|
62
|
+
## Quickstart ⚡
|
|
63
|
+
|
|
64
|
+
Create and activate a virtual environment, install dev dependencies and run tests:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
python -m venv .venv
|
|
68
|
+
source .venv/bin/activate
|
|
69
|
+
python -m pip install -U pip
|
|
70
|
+
python -m pip install -r dev-requirements.txt
|
|
71
|
+
python -m pytest -q
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Installation
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install topolib
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Or for development:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
git clone https://gitlab.com/DaniloBorquez/topolib.git
|
|
84
|
+
cd topolib
|
|
85
|
+
python -m venv .venv
|
|
86
|
+
source .venv/bin/activate
|
|
87
|
+
pip install -e .
|
|
88
|
+
pip install -r dev-requirements.txt
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Documentation
|
|
92
|
+
|
|
93
|
+
Full documentation: [https://topolib.readthedocs.io/](https://topolib.readthedocs.io/)
|
|
94
|
+
|
|
95
|
+
## Basic usage example
|
|
96
|
+
|
|
97
|
+
```py
|
|
98
|
+
from topolib.elements.node import Node
|
|
99
|
+
from topolib.topology.topology import Topology
|
|
100
|
+
|
|
101
|
+
# Create nodes
|
|
102
|
+
n1 = Node(1, 'A', 10.0, 20.0)
|
|
103
|
+
n2 = Node(2, 'B', 11.0, 21.0)
|
|
104
|
+
|
|
105
|
+
# Build topology
|
|
106
|
+
topo = Topology()
|
|
107
|
+
topo.add_node(n1)
|
|
108
|
+
topo.add_node(n2)
|
|
109
|
+
# add links, compute metrics, visualize
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
## Development 🛠️
|
|
114
|
+
|
|
115
|
+
See `CONTRIBUTING.md` for development guidelines, commit message rules and pre-commit setup.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
## Class diagram
|
|
120
|
+
|
|
121
|
+

|
|
122
|
+
|
|
123
|
+
(If you prefer a rendered image of the UML, render the PlantUML file locally or in your CI pipeline.)
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
See `LICENSE` in the project root.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
diagrams/class_diagram.puml,sha256=4EUNpMrbHJYJ8wDM4DqtlIrJDTrvoyIeIiUdOoPsWlM,2183
|
|
2
|
+
docs/Makefile,sha256=4zv3TVkTACm6JBaKgTES3ZI9cETXgM6ULbZkXZP1as8,638
|
|
3
|
+
docs/requirements.txt,sha256=JBlj0kqsxcteWZpXAEKCobzqG-piWPAfj3_Bx46i9-c,24
|
|
4
|
+
docs/source/conf.py,sha256=YeakUjMbnzKQov9CjOiFPmL4mOQ2JP2aHa4No55OYB4,1170
|
|
5
|
+
docs/source/index.rst,sha256=ZFCeE5lH5ijU_oVfhGCYe5pq7ko_C1PhML0UHeKVXsg,1171
|
|
6
|
+
docs/source/modules.rst,sha256=kRhINzEdye-kWHfUkCy6NByB3oT6FpEcCDWOscakUAA,58
|
|
7
|
+
docs/source/topolib.analysis.rst,sha256=1NFOxh0O6ebf19ruvCcb9Oile2uzm_hWkKSb0RufT90,355
|
|
8
|
+
docs/source/topolib.elements.rst,sha256=vk_Q_frmUk69gfxOx-_1VNdl7x3tLvc-QAIF4Wxo7wI,379
|
|
9
|
+
docs/source/topolib.rst,sha256=J1kJ07JXz0yVyChjPofjTkP02Ns1fM96k9QX3HJCVVs,260
|
|
10
|
+
docs/source/topolib.topology.rst,sha256=rdJH23kxZuGtB6rFISAWKUfEFGp5mZS1zRQ4zgwDRSc,510
|
|
11
|
+
examples/show_topology_in_map.py,sha256=xjgLiSBHZJ8KYeaCdOBkwAAEJk4hSDkCxBvKNW7Ll9U,441
|
|
12
|
+
tests/__init__.py,sha256=eAUS1VPZN5alBWqBdLK4sDxjRPxCvviXncxNvztzVGU,59
|
|
13
|
+
tests/test_link.py,sha256=TEfNEivuE17OMmVP4YSi2-8-Mh9_2RDUXBG6Ds3Ljuc,1960
|
|
14
|
+
tests/test_mapview.py,sha256=oOx_mYBSy95cacv4PfknP1N5VJzFTEoprhKLovU35Yo,977
|
|
15
|
+
tests/test_metrics.py,sha256=-9RM5BGb-oqHl6JNPHIzVTsxPSPBvcHeMxDJqqqnlGs,1374
|
|
16
|
+
tests/test_node.py,sha256=9nkrnAP8TnmtSXc83w-e8QJaCG56pzgTbdnueZZrta0,1049
|
|
17
|
+
tests/test_path.py,sha256=Dg6NQ7Oz9UrvM4dqNOh-80odzCEWl8q2vM3BAGxpmqA,1091
|
|
18
|
+
tests/test_topology.py,sha256=TnGKrtYRPG9wO85lCpVLg6MoOYhHgkWrwjA40xE652g,6258
|
|
19
|
+
tests/test_version.py,sha256=rJheq9nRxTaSmvl5yEFGPNmwnMa0I-NkSu2oH47jpt0,253
|
|
20
|
+
topolib/__init__.py,sha256=iLmy2rOkHS_4KZWMD8BgT7R3tLMKeaTCDVf3B4FyYxM,91
|
|
21
|
+
topolib/analysis/__init__.py,sha256=qvUC9wV_jQNQIlwJXk7LJ-dkTXhH1Ttn0lKWIdwBbrc,52
|
|
22
|
+
topolib/analysis/metrics.py,sha256=Di4HGHlz9c2UTCYdfnmjtPjo7w3wwYuyDPeXI7bR0zA,2592
|
|
23
|
+
topolib/assets/Abilene_IXP.json,sha256=5cnPMbjsNDjmpySdQDYQ2yd83zOFvCRjlAnbX1wyzgk,6010
|
|
24
|
+
topolib/assets/China_pop.json,sha256=v-bs5qib8-CB81rvBNNM9ssoelrNGuFrPEyRCht9YpY,22262
|
|
25
|
+
topolib/assets/DT-50_pop.json,sha256=hCv1MCvipgdrQ34VT-qXJ68BdATriQ8ZObh0fLPqar4,29719
|
|
26
|
+
topolib/elements/__init__.py,sha256=ZWSd5uwVtppJtMnZ30zrAdzXhUAYIK62RrUaH9rsWu0,180
|
|
27
|
+
topolib/elements/link.py,sha256=BwjdCR8peh7dDpKunZodlIsjKcfvwjKxyQ3tmp1obb8,3778
|
|
28
|
+
topolib/elements/node.py,sha256=uOnljwA3jcVR4utUfI-om4SIt_QBsEQt8QLW9uvjr3Y,4974
|
|
29
|
+
topolib/topology/__init__.py,sha256=2VRhVm4ZvKBiTDB2T8BDmLZBpwGCVFRF3fvtxxC_d28,86
|
|
30
|
+
topolib/topology/path.py,sha256=oUNwmpBcS6LMMAJIxokROm3MVqr7vRR44M3Fh5ADq_w,2057
|
|
31
|
+
topolib/topology/topology.py,sha256=PzPx80TxWMcOwpOCh4fohcWT2YUra-4m04tBjqyMU40,5605
|
|
32
|
+
topolib/visualization/__init__.py,sha256=wv065-KB5uDbTaQIASPVfMMW5sE76Bs-q0oai48vAzk,29
|
|
33
|
+
topolib/visualization/mapview.py,sha256=4iKJMYsH6oFNj9tOcgSKLVRtoYfUuH3XLjShsGwUXcM,2799
|
|
34
|
+
topolib-0.0.0.dist-info/licenses/LICENSE,sha256=kbnIP0XU6f2ualiTjEawdlU81IGPBbwc-_GF3N-1e9E,1081
|
|
35
|
+
topolib-0.0.0.dist-info/METADATA,sha256=4OEpNmsfDsL7k0230z4ObnVFu3o2mKT_SEeJifiE8P4,4294
|
|
36
|
+
topolib-0.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
37
|
+
topolib-0.0.0.dist-info/top_level.txt,sha256=7ynOTanzCkVNSIj7GUDQ1TveIoSt3tcfSi0I0JYTrq0,37
|
|
38
|
+
topolib-0.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2025 Danilo Bórquez-Paredes
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|