tmapper-py 0.1.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.
- tmapper/__init__.py +63 -0
- tmapper/_shortest_path.py +22 -0
- tmapper/app/__init__.py +10 -0
- tmapper/app/launcher.py +35 -0
- tmapper/app/streamlit_app.py +1240 -0
- tmapper/cknngraph.py +73 -0
- tmapper/cycle_cluster.py +111 -0
- tmapper/cycle_cluster_conn.py +112 -0
- tmapper/cycle_count.py +150 -0
- tmapper/cycle_count2p.py +72 -0
- tmapper/cycle_cutter.py +47 -0
- tmapper/cycle_overlap.py +71 -0
- tmapper/cycle_path_decomp.py +104 -0
- tmapper/cycles_to_paths.py +40 -0
- tmapper/filtergraph.py +107 -0
- tmapper/graph_utils.py +283 -0
- tmapper/knngraph.py +61 -0
- tmapper/labeling.py +45 -0
- tmapper/modularity.py +74 -0
- tmapper/path_traffic.py +35 -0
- tmapper/plotting.py +463 -0
- tmapper/sample_data.py +19 -0
- tmapper/sampledata/EL_temp.csv +57710 -0
- tmapper/tcm_distance.py +63 -0
- tmapper/tknndigraph.py +190 -0
- tmapper_py-0.1.0.dist-info/METADATA +108 -0
- tmapper_py-0.1.0.dist-info/RECORD +31 -0
- tmapper_py-0.1.0.dist-info/WHEEL +5 -0
- tmapper_py-0.1.0.dist-info/entry_points.txt +2 -0
- tmapper_py-0.1.0.dist-info/licenses/LICENSE +28 -0
- tmapper_py-0.1.0.dist-info/top_level.txt +1 -0
tmapper/__init__.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from .sample_data import sample_data_path
|
|
2
|
+
from .tknndigraph import tknndigraph
|
|
3
|
+
from .filtergraph import filtergraph
|
|
4
|
+
from .labeling import find_node_label
|
|
5
|
+
from .tcm_distance import tcm_distance
|
|
6
|
+
from .plotting import plot_tmgraph, plot_tmgraph_tcm, plot_tmgraph_interactive
|
|
7
|
+
from .knngraph import knngraph
|
|
8
|
+
from .cknngraph import cknngraph
|
|
9
|
+
from .cycle_count import cycle_count
|
|
10
|
+
from .cycle_count2p import cycle_count2p, reorg_cycles
|
|
11
|
+
from .cycle_overlap import cycle_path_overlap
|
|
12
|
+
from .cycle_cluster import cycle_cluster
|
|
13
|
+
from .cycle_cluster_conn import cycle_cluster_conn
|
|
14
|
+
from .cycle_cutter import cycle_cutter
|
|
15
|
+
from .cycles_to_paths import cycles_to_paths
|
|
16
|
+
from .cycle_path_decomp import cycle_path_decomp
|
|
17
|
+
from .path_traffic import path_traffic
|
|
18
|
+
from .modularity import qasym, cal_mod
|
|
19
|
+
from .graph_utils import (
|
|
20
|
+
node_size,
|
|
21
|
+
node_measure,
|
|
22
|
+
normalize_geodesic,
|
|
23
|
+
normalize_tcm,
|
|
24
|
+
members_to_tidx,
|
|
25
|
+
subgraph_from_members,
|
|
26
|
+
sym_dyn_to_digraph,
|
|
27
|
+
digraph_to_graph,
|
|
28
|
+
find_blocks,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"sample_data_path",
|
|
33
|
+
"tknndigraph",
|
|
34
|
+
"filtergraph",
|
|
35
|
+
"find_node_label",
|
|
36
|
+
"tcm_distance",
|
|
37
|
+
"plot_tmgraph",
|
|
38
|
+
"plot_tmgraph_tcm",
|
|
39
|
+
"plot_tmgraph_interactive",
|
|
40
|
+
"knngraph",
|
|
41
|
+
"cknngraph",
|
|
42
|
+
"cycle_count",
|
|
43
|
+
"cycle_count2p",
|
|
44
|
+
"reorg_cycles",
|
|
45
|
+
"cycle_path_overlap",
|
|
46
|
+
"cycle_cluster",
|
|
47
|
+
"cycle_cluster_conn",
|
|
48
|
+
"cycle_cutter",
|
|
49
|
+
"cycles_to_paths",
|
|
50
|
+
"cycle_path_decomp",
|
|
51
|
+
"path_traffic",
|
|
52
|
+
"qasym",
|
|
53
|
+
"cal_mod",
|
|
54
|
+
"node_size",
|
|
55
|
+
"node_measure",
|
|
56
|
+
"normalize_geodesic",
|
|
57
|
+
"normalize_tcm",
|
|
58
|
+
"members_to_tidx",
|
|
59
|
+
"subgraph_from_members",
|
|
60
|
+
"sym_dyn_to_digraph",
|
|
61
|
+
"digraph_to_graph",
|
|
62
|
+
"find_blocks",
|
|
63
|
+
]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Shared all-pairs shortest-path helper.
|
|
2
|
+
|
|
3
|
+
Uses scipy's compiled Dijkstra (via ``scipy.sparse.csgraph.shortest_path``)
|
|
4
|
+
instead of networkx's ``floyd_warshall_numpy``. The latter is O(n^3) with
|
|
5
|
+
substantial per-iteration numpy overhead and becomes the dominant cost at
|
|
6
|
+
realistic graph sizes (a few thousand nodes); our graphs are sparse (a
|
|
7
|
+
handful of edges per node from the k-NN construction), where Dijkstra from
|
|
8
|
+
every source is asymptotically and practically much faster.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import networkx as nx
|
|
12
|
+
from scipy.sparse.csgraph import shortest_path
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def all_pairs_distance(g, nodelist, weight="weight"):
|
|
16
|
+
"""All-pairs shortest-path distance matrix for ``g``, ordered by
|
|
17
|
+
``nodelist``. ``weight=None`` treats every edge as weight 1 (hop
|
|
18
|
+
count); ``weight="weight"`` (default) uses ``g``'s edge weights.
|
|
19
|
+
Unreachable pairs are ``inf``, matching ``nx.floyd_warshall_numpy``.
|
|
20
|
+
"""
|
|
21
|
+
adj = nx.to_scipy_sparse_array(g, nodelist=nodelist, weight=weight, dtype=float)
|
|
22
|
+
return shortest_path(adj, method="auto", directed=True)
|
tmapper/app/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""The interactive Streamlit app, and its launcher.
|
|
2
|
+
|
|
3
|
+
Lives inside the package so that ``pip install "tmapper[app]"`` ships it --
|
|
4
|
+
otherwise the app would only be runnable from a clone of the repository,
|
|
5
|
+
which is exactly the friction it exists to remove.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .launcher import main
|
|
9
|
+
|
|
10
|
+
__all__ = ["main"]
|
tmapper/app/launcher.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Console-script entry point: ``tmapper-app``.
|
|
2
|
+
|
|
3
|
+
A Streamlit app is a *script Streamlit runs*, not a program you import and
|
|
4
|
+
call, so this hands the app file to Streamlit's own CLI rather than
|
|
5
|
+
executing it directly -- running it as a plain script would just print
|
|
6
|
+
Streamlit's "missing ScriptRunContext" warnings and do nothing useful.
|
|
7
|
+
|
|
8
|
+
Any extra arguments are passed straight through, so the usual Streamlit
|
|
9
|
+
options still work::
|
|
10
|
+
|
|
11
|
+
tmapper-app --server.port 8600 --server.address 0.0.0.0
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
APP_FILE = Path(__file__).resolve().parent / "streamlit_app.py"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def main(argv=None):
|
|
21
|
+
try:
|
|
22
|
+
from streamlit.web import cli as stcli
|
|
23
|
+
except ImportError: # pragma: no cover - depends on install extras
|
|
24
|
+
raise SystemExit(
|
|
25
|
+
"The interactive app needs Streamlit, which is not installed.\n"
|
|
26
|
+
"Install it with: pip install 'tmapper[app]'"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
args = sys.argv[1:] if argv is None else list(argv)
|
|
30
|
+
sys.argv = ["streamlit", "run", str(APP_FILE), *args]
|
|
31
|
+
return stcli.main()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if __name__ == "__main__": # pragma: no cover
|
|
35
|
+
sys.exit(main())
|