risk-network 0.0.13b4__py3-none-any.whl → 0.0.14__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.
Files changed (51) hide show
  1. risk/__init__.py +3 -2
  2. risk/_annotation/__init__.py +10 -0
  3. risk/{annotation/annotation.py → _annotation/_annotation.py} +18 -11
  4. risk/{annotation/io.py → _annotation/_io.py} +22 -14
  5. risk/{annotation/nltk_setup.py → _annotation/_nltk_setup.py} +7 -5
  6. risk/_log/__init__.py +11 -0
  7. risk/{log/console.py → _log/_console.py} +22 -12
  8. risk/{log/parameters.py → _log/_parameters.py} +25 -14
  9. risk/_neighborhoods/__init__.py +8 -0
  10. risk/{neighborhoods/api.py → _neighborhoods/_api.py} +23 -17
  11. risk/{neighborhoods/community.py → _neighborhoods/_community.py} +19 -11
  12. risk/{neighborhoods/domains.py → _neighborhoods/_domains.py} +92 -35
  13. risk/{neighborhoods/neighborhoods.py → _neighborhoods/_neighborhoods.py} +69 -58
  14. risk/_neighborhoods/_stats/__init__.py +13 -0
  15. risk/_neighborhoods/_stats/_permutation/__init__.py +6 -0
  16. risk/{neighborhoods/stats/permutation/permutation.py → _neighborhoods/_stats/_permutation/_permutation.py} +9 -6
  17. risk/{neighborhoods/stats/permutation/test_functions.py → _neighborhoods/_stats/_permutation/_test_functions.py} +6 -4
  18. risk/{neighborhoods/stats/tests.py → _neighborhoods/_stats/_tests.py} +12 -7
  19. risk/_network/__init__.py +8 -0
  20. risk/_network/_graph/__init__.py +7 -0
  21. risk/{network/graph/api.py → _network/_graph/_api.py} +13 -13
  22. risk/{network/graph/graph.py → _network/_graph/_graph.py} +24 -13
  23. risk/{network/graph/stats.py → _network/_graph/_stats.py} +8 -5
  24. risk/{network/graph/summary.py → _network/_graph/_summary.py} +39 -32
  25. risk/{network/io.py → _network/_io.py} +166 -148
  26. risk/_network/_plotter/__init__.py +6 -0
  27. risk/{network/plotter/api.py → _network/_plotter/_api.py} +9 -10
  28. risk/{network/plotter/canvas.py → _network/_plotter/_canvas.py} +14 -10
  29. risk/{network/plotter/contour.py → _network/_plotter/_contour.py} +17 -11
  30. risk/{network/plotter/labels.py → _network/_plotter/_labels.py} +38 -23
  31. risk/{network/plotter/network.py → _network/_plotter/_network.py} +17 -11
  32. risk/{network/plotter/plotter.py → _network/_plotter/_plotter.py} +19 -15
  33. risk/_network/_plotter/_utils/__init__.py +7 -0
  34. risk/{network/plotter/utils/colors.py → _network/_plotter/_utils/_colors.py} +19 -11
  35. risk/{network/plotter/utils/layout.py → _network/_plotter/_utils/_layout.py} +8 -5
  36. risk/{risk.py → _risk.py} +11 -11
  37. risk_network-0.0.14.dist-info/METADATA +115 -0
  38. risk_network-0.0.14.dist-info/RECORD +41 -0
  39. {risk_network-0.0.13b4.dist-info → risk_network-0.0.14.dist-info}/WHEEL +1 -1
  40. risk/annotation/__init__.py +0 -10
  41. risk/log/__init__.py +0 -11
  42. risk/neighborhoods/__init__.py +0 -7
  43. risk/neighborhoods/stats/__init__.py +0 -13
  44. risk/neighborhoods/stats/permutation/__init__.py +0 -6
  45. risk/network/__init__.py +0 -4
  46. risk/network/graph/__init__.py +0 -4
  47. risk/network/plotter/__init__.py +0 -4
  48. risk_network-0.0.13b4.dist-info/METADATA +0 -125
  49. risk_network-0.0.13b4.dist-info/RECORD +0 -40
  50. {risk_network-0.0.13b4.dist-info → risk_network-0.0.14.dist-info}/licenses/LICENSE +0 -0
  51. {risk_network-0.0.13b4.dist-info → risk_network-0.0.14.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  """
2
- risk/network/io
3
- ~~~~~~~~~~~~~~~
2
+ risk/_network/_io
3
+ ~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
6
  import copy
@@ -15,111 +15,191 @@ import networkx as nx
15
15
  import numpy as np
16
16
  import pandas as pd
17
17
 
18
- from risk.log import log_header, logger, params
18
+ from .._log import log_header, logger, params
19
19
 
20
20
 
21
- class NetworkIO:
22
- """A class for loading, processing, and managing network data.
23
-
24
- The NetworkIO class provides methods to load network data from various formats (e.g., GPickle, NetworkX)
25
- and process the network by adjusting node coordinates, calculating edge lengths, and validating graph structure.
21
+ class NetworkAPI:
22
+ """
23
+ Public-facing interface for loading and initializing network data.
24
+ Delegates to the NetworkIO worker class for actual I/O and processing.
26
25
  """
27
26
 
28
- def __init__(
27
+ def load_network_gpickle(
29
28
  self,
29
+ filepath: str,
30
30
  compute_sphere: bool = True,
31
31
  surface_depth: float = 0.0,
32
32
  min_edges_per_node: int = 0,
33
- ):
34
- """Initialize the NetworkIO class.
33
+ ) -> nx.Graph:
34
+ """
35
+ Load a network from a GPickle file via NetworkIO.
35
36
 
36
37
  Args:
37
- compute_sphere (bool, optional): Whether to map nodes to a sphere. Defaults to True.
38
- surface_depth (float, optional): Surface depth for the sphere. Defaults to 0.0.
39
- min_edges_per_node (int, optional): Minimum number of edges per node. Defaults to 0.
38
+ filepath (str): Path to the GPickle file.
39
+ compute_sphere (bool, optional): Override or use API default. Defaults to True.
40
+ surface_depth (float, optional): Override or use API default. Defaults to 0.0.
41
+ min_edges_per_node (int, optional): Override or use API default. Defaults to 0.
42
+ Returns:
43
+ nx.Graph: Loaded and processed network.
40
44
  """
41
- self.compute_sphere = compute_sphere
42
- self.surface_depth = surface_depth
43
- self.min_edges_per_node = min_edges_per_node
44
- # Log the initialization of the NetworkIO class
45
- params.log_network(
45
+ io = NetworkIO(
46
46
  compute_sphere=compute_sphere,
47
47
  surface_depth=surface_depth,
48
48
  min_edges_per_node=min_edges_per_node,
49
49
  )
50
+ return io.load_network_gpickle(filepath=filepath)
50
51
 
51
- def load_network_gpickle(
52
+ def load_network_networkx(
52
53
  self,
53
- filepath: str,
54
+ network: nx.Graph,
54
55
  compute_sphere: bool = True,
55
56
  surface_depth: float = 0.0,
56
57
  min_edges_per_node: int = 0,
57
58
  ) -> nx.Graph:
58
- """Load a network from a GPickle file.
59
+ """
60
+ Load a NetworkX graph via NetworkIO.
59
61
 
60
62
  Args:
61
- filepath (str): Path to the GPickle file.
62
- compute_sphere (bool, optional): Whether to map nodes to a sphere. Defaults to True.
63
- surface_depth (float, optional): Surface depth for the sphere. Defaults to 0.0.
64
- min_edges_per_node (int, optional): Minimum number of edges per node. Defaults to 0.
63
+ network (nx.Graph): A NetworkX graph object.
64
+ compute_sphere (bool, optional): Override or use API default. Defaults to True.
65
+ surface_depth (float, optional): Override or use API default. Defaults to 0.0.
66
+ min_edges_per_node (int, optional): Override or use API default. Defaults to 0.
67
+ Returns:
68
+ nx.Graph: Processed network.
69
+ """
70
+ io = NetworkIO(
71
+ compute_sphere=compute_sphere,
72
+ surface_depth=surface_depth,
73
+ min_edges_per_node=min_edges_per_node,
74
+ )
75
+ return io.load_network_networkx(network=network)
65
76
 
77
+ def load_network_cytoscape(
78
+ self,
79
+ filepath: str,
80
+ source_label: str = "source",
81
+ target_label: str = "target",
82
+ view_name: str = "",
83
+ compute_sphere: bool = True,
84
+ surface_depth: float = 0.0,
85
+ min_edges_per_node: int = 0,
86
+ ) -> nx.Graph:
87
+ """
88
+ Load a network from a Cytoscape file via NetworkIO.
89
+
90
+ Args:
91
+ filepath (str): Path to the Cytoscape file.
92
+ source_label (str, optional): Source node label. Defaults to "source".
93
+ target_label (str, optional): Target node label. Defaults to "target".
94
+ view_name (str, optional): Specific view name to load. Defaults to "".
95
+ compute_sphere (bool, optional): Override or use API default. Defaults to True.
96
+ surface_depth (float, optional): Override or use API default. Defaults to 0.0.
97
+ min_edges_per_node (int, optional): Override or use API default. Defaults to 0.
66
98
  Returns:
67
99
  nx.Graph: Loaded and processed network.
68
100
  """
69
- networkio = NetworkIO(
101
+ io = NetworkIO(
70
102
  compute_sphere=compute_sphere,
71
103
  surface_depth=surface_depth,
72
104
  min_edges_per_node=min_edges_per_node,
73
105
  )
74
- return networkio._load_network_gpickle(filepath=filepath)
106
+ return io.load_network_cytoscape(
107
+ filepath=filepath,
108
+ source_label=source_label,
109
+ target_label=target_label,
110
+ view_name=view_name,
111
+ )
75
112
 
76
- def _load_network_gpickle(self, filepath: str) -> nx.Graph:
77
- """Private method to load a network from a GPickle file.
113
+ def load_network_cyjs(
114
+ self,
115
+ filepath: str,
116
+ source_label: str = "source",
117
+ target_label: str = "target",
118
+ compute_sphere: bool = True,
119
+ surface_depth: float = 0.0,
120
+ min_edges_per_node: int = 0,
121
+ ) -> nx.Graph:
122
+ """
123
+ Load a network from a Cytoscape JSON (.cyjs) file via NetworkIO.
78
124
 
79
125
  Args:
80
- filepath (str): Path to the GPickle file.
81
-
126
+ filepath (str): Path to the Cytoscape JSON file.
127
+ source_label (str, optional): Source node label. Defaults to "source".
128
+ target_label (str, optional): Target node label. Defaults to "target".
129
+ compute_sphere (bool, optional): Override or use API default. Defaults to True.
130
+ surface_depth (float, optional): Override or use API default. Defaults to 0.0.
131
+ min_edges_per_node (int, optional): Override or use API default. Defaults to 0.
82
132
  Returns:
83
133
  nx.Graph: Loaded and processed network.
84
134
  """
85
- filetype = "GPickle"
86
- # Log the loading of the GPickle file
87
- params.log_network(filetype=filetype, filepath=filepath)
88
- self._log_loading_network(filetype, filepath=filepath)
135
+ io = NetworkIO(
136
+ compute_sphere=compute_sphere,
137
+ surface_depth=surface_depth,
138
+ min_edges_per_node=min_edges_per_node,
139
+ )
140
+ return io.load_network_cyjs(
141
+ filepath=filepath,
142
+ source_label=source_label,
143
+ target_label=target_label,
144
+ )
89
145
 
90
- with open(filepath, "rb") as f:
91
- G = pickle.load(f)
92
146
 
93
- # Initialize the graph
94
- return self._initialize_graph(G)
147
+ class NetworkIO:
148
+ """
149
+ A class for loading, processing, and managing network data.
95
150
 
96
- def load_network_networkx(
151
+ The NetworkIO class provides methods to load network data from various formats (e.g., GPickle, NetworkX)
152
+ and process the network by adjusting node coordinates, calculating edge lengths, and validating graph structure.
153
+ """
154
+
155
+ def __init__(
97
156
  self,
98
- network: nx.Graph,
99
157
  compute_sphere: bool = True,
100
158
  surface_depth: float = 0.0,
101
159
  min_edges_per_node: int = 0,
102
- ) -> nx.Graph:
103
- """Load a NetworkX graph.
160
+ ):
161
+ """
162
+ Initialize the NetworkIO class.
104
163
 
105
164
  Args:
106
- network (nx.Graph): A NetworkX graph object.
107
165
  compute_sphere (bool, optional): Whether to map nodes to a sphere. Defaults to True.
108
166
  surface_depth (float, optional): Surface depth for the sphere. Defaults to 0.0.
109
- min_edges_per_node (int, optional): Minimum number of edges per node. Defaults to 0.
110
-
111
- Returns:
112
- nx.Graph: Loaded and processed network.
167
+ min_edges_per_node (int, optional): Minimum number of edges per node (k-core threshold). Defaults to 0.
113
168
  """
114
- networkio = NetworkIO(
169
+ self.compute_sphere = compute_sphere
170
+ self.surface_depth = surface_depth
171
+ self.min_edges_per_node = min_edges_per_node
172
+ # Log the initialization of the NetworkIO class
173
+ params.log_network(
115
174
  compute_sphere=compute_sphere,
116
175
  surface_depth=surface_depth,
117
176
  min_edges_per_node=min_edges_per_node,
118
177
  )
119
- return networkio._load_network_networkx(network=network)
120
178
 
121
- def _load_network_networkx(self, network: nx.Graph) -> nx.Graph:
122
- """Private method to load a NetworkX graph.
179
+ def load_network_gpickle(self, filepath: str) -> nx.Graph:
180
+ """
181
+ Load a network from a GPickle file.
182
+
183
+ Args:
184
+ filepath (str): Path to the GPickle file.
185
+
186
+ Returns:
187
+ nx.Graph: Loaded and processed network.
188
+ """
189
+ filetype = "GPickle"
190
+ # Log the loading of the GPickle file
191
+ params.log_network(filetype=filetype, filepath=filepath)
192
+ self._log_loading_network(filetype, filepath=filepath)
193
+
194
+ with open(filepath, "rb") as f:
195
+ G = pickle.load(f)
196
+
197
+ # Initialize the graph
198
+ return self._initialize_graph(G)
199
+
200
+ def load_network_networkx(self, network: nx.Graph) -> nx.Graph:
201
+ """
202
+ Load a NetworkX graph.
123
203
 
124
204
  Args:
125
205
  network (nx.Graph): A NetworkX graph object.
@@ -143,44 +223,9 @@ class NetworkIO:
143
223
  source_label: str = "source",
144
224
  target_label: str = "target",
145
225
  view_name: str = "",
146
- compute_sphere: bool = True,
147
- surface_depth: float = 0.0,
148
- min_edges_per_node: int = 0,
149
226
  ) -> nx.Graph:
150
- """Load a network from a Cytoscape file.
151
-
152
- Args:
153
- filepath (str): Path to the Cytoscape file.
154
- source_label (str, optional): Source node label. Defaults to "source".
155
- target_label (str, optional): Target node label. Defaults to "target".
156
- view_name (str, optional): Specific view name to load. Defaults to "".
157
- compute_sphere (bool, optional): Whether to map nodes to a sphere. Defaults to True.
158
- surface_depth (float, optional): Surface depth for the sphere. Defaults to 0.0.
159
- min_edges_per_node (int, optional): Minimum number of edges per node. Defaults to 0.
160
-
161
- Returns:
162
- nx.Graph: Loaded and processed network.
163
227
  """
164
- networkio = NetworkIO(
165
- compute_sphere=compute_sphere,
166
- surface_depth=surface_depth,
167
- min_edges_per_node=min_edges_per_node,
168
- )
169
- return networkio._load_network_cytoscape(
170
- filepath=filepath,
171
- source_label=source_label,
172
- target_label=target_label,
173
- view_name=view_name,
174
- )
175
-
176
- def _load_network_cytoscape(
177
- self,
178
- filepath: str,
179
- source_label: str = "source",
180
- target_label: str = "target",
181
- view_name: str = "",
182
- ) -> nx.Graph:
183
- """Private method to load a network from a Cytoscape file.
228
+ Load a network from a Cytoscape file.
184
229
 
185
230
  Args:
186
231
  filepath (str): Path to the Cytoscape file.
@@ -307,41 +352,9 @@ class NetworkIO:
307
352
  if os.path.exists(tmp_dir):
308
353
  shutil.rmtree(tmp_dir)
309
354
 
310
- def load_network_cyjs(
311
- self,
312
- filepath: str,
313
- source_label: str = "source",
314
- target_label: str = "target",
315
- compute_sphere: bool = True,
316
- surface_depth: float = 0.0,
317
- min_edges_per_node: int = 0,
318
- ) -> nx.Graph:
319
- """Load a network from a Cytoscape JSON (.cyjs) file.
320
-
321
- Args:
322
- filepath (str): Path to the Cytoscape JSON file.
323
- source_label (str, optional): Source node label. Default is "source".
324
- target_label (str, optional): Target node label. Default is "target".
325
- compute_sphere (bool, optional): Whether to map nodes to a sphere. Defaults to True.
326
- surface_depth (float, optional): Surface depth for the sphere. Defaults to 0.0.
327
- min_edges_per_node (int, optional): Minimum number of edges per node. Defaults to 0.
328
-
329
- Returns:
330
- NetworkX graph: Loaded and processed network.
355
+ def load_network_cyjs(self, filepath, source_label="source", target_label="target"):
331
356
  """
332
- networkio = NetworkIO(
333
- compute_sphere=compute_sphere,
334
- surface_depth=surface_depth,
335
- min_edges_per_node=min_edges_per_node,
336
- )
337
- return networkio._load_network_cyjs(
338
- filepath=filepath,
339
- source_label=source_label,
340
- target_label=target_label,
341
- )
342
-
343
- def _load_network_cyjs(self, filepath, source_label="source", target_label="target"):
344
- """Private method to load a network from a Cytoscape JSON (.cyjs) file.
357
+ Load a network from a Cytoscape JSON (.cyjs) file.
345
358
 
346
359
  Args:
347
360
  filepath (str): Path to the Cytoscape JSON file.
@@ -396,7 +409,8 @@ class NetworkIO:
396
409
  return self._initialize_graph(G)
397
410
 
398
411
  def _initialize_graph(self, G: nx.Graph) -> nx.Graph:
399
- """Initialize the graph by processing and validating its nodes and edges.
412
+ """
413
+ Initialize the graph by processing and validating its nodes and edges.
400
414
 
401
415
  Args:
402
416
  G (nx.Graph): The input NetworkX graph.
@@ -414,7 +428,8 @@ class NetworkIO:
414
428
  return G
415
429
 
416
430
  def _remove_invalid_graph_properties(self, G: nx.Graph) -> None:
417
- """Remove invalid properties from the graph, including self-loops, nodes with fewer edges than
431
+ """
432
+ Remove invalid properties from the graph, including self-loops, nodes with fewer edges than
418
433
  the threshold, and isolated nodes.
419
434
 
420
435
  Args:
@@ -425,20 +440,14 @@ class NetworkIO:
425
440
  num_initial_edges = G.number_of_edges()
426
441
  # Remove self-loops to ensure correct edge count
427
442
  G.remove_edges_from(nx.selfloop_edges(G))
428
- # Iteratively remove nodes with fewer edges than the threshold
429
- while True:
430
- nodes_to_remove = [
431
- node
432
- for node, degree in dict(G.degree()).items()
433
- if degree < self.min_edges_per_node
434
- ]
435
- if not nodes_to_remove:
436
- break # Exit loop if no nodes meet the condition
437
- G.remove_nodes_from(nodes_to_remove)
438
-
439
- # Remove isolated nodes
440
- isolates = list(nx.isolates(G))
441
- G.remove_nodes_from(isolates)
443
+ # Apply canonical node k-core pruning if requested
444
+ if self.min_edges_per_node > 0:
445
+ # networkx.k_core returns a subgraph; to preserve in-place behavior, copy back
446
+ core = nx.k_core(G, k=self.min_edges_per_node)
447
+ # Rebuild G in-place to keep external references valid
448
+ G.clear()
449
+ G.add_nodes_from(core.nodes(data=True))
450
+ G.add_edges_from(core.edges(data=True))
442
451
 
443
452
  # Log the number of nodes and edges before and after cleaning
444
453
  num_final_nodes = G.number_of_nodes()
@@ -449,7 +458,8 @@ class NetworkIO:
449
458
  logger.debug(f"Final edge count: {num_final_edges}")
450
459
 
451
460
  def _assign_edge_weights(self, G: nx.Graph) -> None:
452
- """Assign default edge weights to the graph.
461
+ """
462
+ Assign default edge weights to the graph.
453
463
 
454
464
  Args:
455
465
  G (nx.Graph): A NetworkX graph object.
@@ -459,7 +469,8 @@ class NetworkIO:
459
469
  nx.set_edge_attributes(G, default_weight, "weight")
460
470
 
461
471
  def _validate_nodes(self, G: nx.Graph) -> None:
462
- """Validate the graph structure and attributes with attribute fallback for positions and labels.
472
+ """
473
+ Validate the graph structure and attributes with attribute fallback for positions and labels.
463
474
 
464
475
  Args:
465
476
  G (nx.Graph): A NetworkX graph object.
@@ -519,7 +530,8 @@ class NetworkIO:
519
530
  )
520
531
 
521
532
  def _assign_edge_lengths(self, G: nx.Graph) -> None:
522
- """Prepare the network by adjusting surface depth and calculating edge lengths.
533
+ """
534
+ Prepare the network by adjusting surface depth and calculating edge lengths.
523
535
 
524
536
  Args:
525
537
  G (nx.Graph): The input network graph.
@@ -537,7 +549,8 @@ class NetworkIO:
537
549
  compute_sphere: bool = True,
538
550
  surface_depth: float = 0.0,
539
551
  ) -> nx.Graph:
540
- """Prepare the graph by normalizing coordinates and optionally mapping nodes to a sphere.
552
+ """
553
+ Prepare the graph by normalizing coordinates and optionally mapping nodes to a sphere.
541
554
 
542
555
  Args:
543
556
  G (nx.Graph): The input graph.
@@ -558,7 +571,8 @@ class NetworkIO:
558
571
  return G_depth
559
572
 
560
573
  def _calculate_and_set_edge_lengths(self, G: nx.Graph, compute_sphere: bool) -> None:
561
- """Compute and assign edge lengths in the graph.
574
+ """
575
+ Compute and assign edge lengths in the graph.
562
576
 
563
577
  Args:
564
578
  G (nx.Graph): The input graph.
@@ -592,7 +606,8 @@ class NetworkIO:
592
606
  G.edges[u, v]["length"] = distance
593
607
 
594
608
  def _map_to_sphere(self, G: nx.Graph) -> None:
595
- """Map the x and y coordinates of graph nodes onto a 3D sphere.
609
+ """
610
+ Map the x and y coordinates of graph nodes onto a 3D sphere.
596
611
 
597
612
  Args:
598
613
  G (nx.Graph): The input graph with nodes having 'x' and 'y' coordinates.
@@ -616,7 +631,8 @@ class NetworkIO:
616
631
  nx.set_node_attributes(G, xyz_coords)
617
632
 
618
633
  def _normalize_graph_coordinates(self, G: nx.Graph) -> None:
619
- """Normalize the x and y coordinates of the nodes in the graph to the [0, 1] range.
634
+ """
635
+ Normalize the x and y coordinates of the nodes in the graph to the [0, 1] range.
620
636
 
621
637
  Args:
622
638
  G (nx.Graph): The input graph with nodes having 'x' and 'y' coordinates.
@@ -633,7 +649,8 @@ class NetworkIO:
633
649
  G.nodes[node]["x"], G.nodes[node]["y"] = normalized_xy[i]
634
650
 
635
651
  def _create_depth(self, G: nx.Graph, surface_depth: float = 0.0) -> nx.Graph:
636
- """Adjust the 'z' attribute of each node based on the subcluster strengths and normalized surface depth.
652
+ """
653
+ Adjust the 'z' attribute of each node based on the subcluster strengths and normalized surface depth.
637
654
 
638
655
  Args:
639
656
  G (nx.Graph): The input graph.
@@ -677,7 +694,8 @@ class NetworkIO:
677
694
  filetype: str,
678
695
  filepath: str = "",
679
696
  ) -> None:
680
- """Log the loading of the network with relevant parameters.
697
+ """
698
+ Log the loading of the network with relevant parameters.
681
699
 
682
700
  Args:
683
701
  filetype (str): The type of the file being loaded (e.g., 'CSV', 'JSON').
@@ -0,0 +1,6 @@
1
+ """
2
+ risk/_network/_plotter
3
+ ~~~~~~~~~~~~~~~~~~~~~~
4
+ """
5
+
6
+ from ._api import PlotterAPI
@@ -1,26 +1,24 @@
1
1
  """
2
- risk/network/plotter/api
3
- ~~~~~~~~~~~~~~~~~~~~~~~~
2
+ risk/_network/_plotter/_api
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
6
  from typing import List, Tuple, Union
7
7
 
8
8
  import numpy as np
9
9
 
10
- from risk.log import log_header
11
- from risk.network.graph.graph import Graph
12
- from risk.network.plotter.plotter import Plotter
10
+ from ..._log import log_header
11
+ from .._graph import Graph
12
+ from ._plotter import Plotter
13
13
 
14
14
 
15
15
  class PlotterAPI:
16
- """Handles the loading of network plotter objects.
16
+ """
17
+ Handles the loading of network plotter objects.
17
18
 
18
19
  The PlotterAPI class provides methods to load and configure Plotter objects for plotting network graphs.
19
20
  """
20
21
 
21
- def __init__(self) -> None:
22
- pass
23
-
24
22
  def load_plotter(
25
23
  self,
26
24
  graph: Graph,
@@ -29,7 +27,8 @@ class PlotterAPI:
29
27
  background_alpha: Union[float, None] = 1.0,
30
28
  pad: float = 0.3,
31
29
  ) -> Plotter:
32
- """Get a Plotter object for plotting.
30
+ """
31
+ Get a Plotter object for plotting.
33
32
 
34
33
  Args:
35
34
  graph (Graph): The graph to plot.
@@ -1,6 +1,6 @@
1
1
  """
2
- risk/network/plotter/canvas
3
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
2
+ risk/_network/_plotter/_canvas
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
6
  from typing import List, Tuple, Union
@@ -8,17 +8,18 @@ from typing import List, Tuple, Union
8
8
  import matplotlib.pyplot as plt
9
9
  import numpy as np
10
10
 
11
- from risk.log import params
12
- from risk.network.graph.graph import Graph
13
- from risk.network.plotter.utils.colors import to_rgba
14
- from risk.network.plotter.utils.layout import calculate_bounding_box
11
+ from ..._log import params
12
+ from .._graph import Graph
13
+ from ._utils._colors import to_rgba
14
+ from ._utils._layout import calculate_bounding_box
15
15
 
16
16
 
17
17
  class Canvas:
18
18
  """A class for laying out the canvas in a network graph."""
19
19
 
20
20
  def __init__(self, graph: Graph, ax: plt.Axes) -> None:
21
- """Initialize the Canvas with a Graph and axis for plotting.
21
+ """
22
+ Initialize the Canvas with a Graph and axis for plotting.
22
23
 
23
24
  Args:
24
25
  graph (Graph): The Graph object containing the network data.
@@ -41,7 +42,8 @@ class Canvas:
41
42
  title_space_offset: float = 0.075,
42
43
  subtitle_offset: float = 0.025,
43
44
  ) -> None:
44
- """Plot title and subtitle on the network graph with customizable parameters.
45
+ """
46
+ Plot title and subtitle on the network graph with customizable parameters.
45
47
 
46
48
  Args:
47
49
  title (str, optional): Title of the plot. Defaults to None.
@@ -122,7 +124,8 @@ class Canvas:
122
124
  outline_alpha: Union[float, None] = 1.0,
123
125
  fill_alpha: Union[float, None] = 0.0,
124
126
  ) -> None:
125
- """Plot a circle around the network graph to represent the network perimeter.
127
+ """
128
+ Plot a circle around the network graph to represent the network perimeter.
126
129
 
127
130
  Args:
128
131
  scale (float, optional): Scaling factor for the perimeter diameter. Defaults to 1.0.
@@ -257,7 +260,8 @@ class Canvas:
257
260
  center_offset_x: float = 0.0,
258
261
  center_offset_y: float = 0.0,
259
262
  ) -> Tuple[float, float]:
260
- """Calculate the adjusted center for the network perimeter circle based on user-defined offsets.
263
+ """
264
+ Calculate the adjusted center for the network perimeter circle based on user-defined offsets.
261
265
 
262
266
  Args:
263
267
  center (Tuple[float, float]): Original center coordinates of the network graph.
@@ -1,6 +1,6 @@
1
1
  """
2
- risk/network/plotter/contour
3
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2
+ risk/_network/_plotter/_contour
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
6
  from typing import Any, Dict, List, Tuple, Union
@@ -11,16 +11,17 @@ from scipy import linalg
11
11
  from scipy.ndimage import label
12
12
  from scipy.stats import gaussian_kde
13
13
 
14
- from risk.log import logger, params
15
- from risk.network.graph.graph import Graph
16
- from risk.network.plotter.utils.colors import get_annotated_domain_colors, to_rgba
14
+ from ..._log import logger, params
15
+ from .._graph import Graph
16
+ from ._utils import get_annotated_domain_colors, to_rgba
17
17
 
18
18
 
19
19
  class Contour:
20
20
  """Class to generate Kernel Density Estimate (KDE) contours for nodes in a network graph."""
21
21
 
22
22
  def __init__(self, graph: Graph, ax: plt.Axes) -> None:
23
- """Initialize the Contour with a Graph and axis for plotting.
23
+ """
24
+ Initialize the Contour with a Graph and axis for plotting.
24
25
 
25
26
  Args:
26
27
  graph (Graph): The Graph object containing the network data.
@@ -40,7 +41,8 @@ class Contour:
40
41
  alpha: Union[float, None] = 1.0,
41
42
  fill_alpha: Union[float, None] = None,
42
43
  ) -> None:
43
- """Draw KDE contours for nodes in various domains of a network graph, highlighting areas of high density.
44
+ """
45
+ Draw KDE contours for nodes in various domains of a network graph, highlighting areas of high density.
44
46
 
45
47
  Args:
46
48
  levels (int, optional): Number of contour levels to plot. Defaults to 5.
@@ -105,7 +107,8 @@ class Contour:
105
107
  alpha: Union[float, None] = 1.0,
106
108
  fill_alpha: Union[float, None] = None,
107
109
  ) -> None:
108
- """Plot a subcontour for a given set of nodes or a list of node sets using Kernel Density Estimation (KDE).
110
+ """
111
+ Plot a subcontour for a given set of nodes or a list of node sets using Kernel Density Estimation (KDE).
109
112
 
110
113
  Args:
111
114
  nodes (List, Tuple, or np.ndarray): List of node labels or list of lists of node labels to plot the contour for.
@@ -179,7 +182,8 @@ class Contour:
179
182
  linewidth: float = 1.5,
180
183
  fill_alpha: Union[float, None] = 0.2,
181
184
  ) -> None:
182
- """Draw a Kernel Density Estimate (KDE) contour plot for a set of nodes on a given axis.
185
+ """
186
+ Draw a Kernel Density Estimate (KDE) contour plot for a set of nodes on a given axis.
183
187
 
184
188
  Args:
185
189
  ax (plt.Axes): The axis to draw the contour on.
@@ -283,7 +287,8 @@ class Contour:
283
287
  ids_to_colors: Union[Dict[int, Any], None] = None,
284
288
  random_seed: int = 888,
285
289
  ) -> List[Tuple]:
286
- """Get colors for the contours based on node annotation or a specified colormap.
290
+ """
291
+ Get colors for the contours based on node annotation or a specified colormap.
287
292
 
288
293
  Args:
289
294
  cmap (str, optional): Name of the colormap to use for generating contour colors. Defaults to "gist_rainbow".
@@ -317,7 +322,8 @@ class Contour:
317
322
  )
318
323
 
319
324
  def _is_connected(self, z: np.ndarray) -> bool:
320
- """Determine if a thresholded grid represents a single, connected component.
325
+ """
326
+ Determine if a thresholded grid represents a single, connected component.
321
327
 
322
328
  Args:
323
329
  z (np.ndarray): A binary grid where the component connectivity is evaluated.