risk-network 0.0.8b18__py3-none-any.whl → 0.0.9b26__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.
- risk/__init__.py +2 -2
- risk/annotations/__init__.py +2 -2
- risk/annotations/annotations.py +133 -72
- risk/annotations/io.py +50 -34
- risk/log/__init__.py +4 -2
- risk/log/{config.py → console.py} +5 -3
- risk/log/{params.py → parameters.py} +21 -46
- risk/neighborhoods/__init__.py +3 -5
- risk/neighborhoods/api.py +446 -0
- risk/neighborhoods/community.py +281 -96
- risk/neighborhoods/domains.py +92 -38
- risk/neighborhoods/neighborhoods.py +210 -149
- risk/network/__init__.py +1 -3
- risk/network/geometry.py +69 -58
- risk/network/graph/__init__.py +6 -0
- risk/network/graph/api.py +194 -0
- risk/network/graph/network.py +269 -0
- risk/network/graph/summary.py +254 -0
- risk/network/io.py +58 -48
- risk/network/plotter/__init__.py +6 -0
- risk/network/plotter/api.py +54 -0
- risk/network/{plot → plotter}/canvas.py +80 -26
- risk/network/{plot → plotter}/contour.py +43 -34
- risk/network/{plot → plotter}/labels.py +123 -113
- risk/network/plotter/network.py +424 -0
- risk/network/plotter/utils/colors.py +416 -0
- risk/network/plotter/utils/layout.py +94 -0
- risk/risk.py +11 -469
- risk/stats/__init__.py +8 -4
- risk/stats/binom.py +51 -0
- risk/stats/chi2.py +69 -0
- risk/stats/hypergeom.py +28 -18
- risk/stats/permutation/__init__.py +1 -1
- risk/stats/permutation/permutation.py +45 -39
- risk/stats/permutation/test_functions.py +25 -17
- risk/stats/poisson.py +17 -11
- risk/stats/stats.py +20 -16
- risk/stats/zscore.py +68 -0
- {risk_network-0.0.8b18.dist-info → risk_network-0.0.9b26.dist-info}/METADATA +9 -5
- risk_network-0.0.9b26.dist-info/RECORD +44 -0
- {risk_network-0.0.8b18.dist-info → risk_network-0.0.9b26.dist-info}/WHEEL +1 -1
- risk/network/graph.py +0 -159
- risk/network/plot/__init__.py +0 -6
- risk/network/plot/network.py +0 -282
- risk/network/plot/plotter.py +0 -137
- risk/network/plot/utils/color.py +0 -353
- risk/network/plot/utils/layout.py +0 -53
- risk_network-0.0.8b18.dist-info/RECORD +0 -37
- {risk_network-0.0.8b18.dist-info → risk_network-0.0.9b26.dist-info}/LICENSE +0 -0
- {risk_network-0.0.8b18.dist-info → risk_network-0.0.9b26.dist-info}/top_level.txt +0 -0
risk/network/plot/utils/color.py
DELETED
@@ -1,353 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
risk/network/plot/utils/color
|
3
|
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4
|
-
"""
|
5
|
-
|
6
|
-
from typing import Any, Dict, List, Tuple, Union
|
7
|
-
|
8
|
-
import matplotlib
|
9
|
-
import matplotlib.colors as mcolors
|
10
|
-
import numpy as np
|
11
|
-
|
12
|
-
from risk.network.graph import NetworkGraph
|
13
|
-
from risk.network.plot.utils.layout import calculate_centroids
|
14
|
-
|
15
|
-
|
16
|
-
def get_annotated_domain_colors(
|
17
|
-
graph: NetworkGraph,
|
18
|
-
cmap: str = "gist_rainbow",
|
19
|
-
color: Union[str, list, tuple, np.ndarray, None] = None,
|
20
|
-
min_scale: float = 0.8,
|
21
|
-
max_scale: float = 1.0,
|
22
|
-
scale_factor: float = 1.0,
|
23
|
-
random_seed: int = 888,
|
24
|
-
) -> np.ndarray:
|
25
|
-
"""Get colors for the domains based on node annotations, or use a specified color.
|
26
|
-
|
27
|
-
Args:
|
28
|
-
graph (NetworkGraph): The network data and attributes to be visualized.
|
29
|
-
cmap (str, optional): Colormap to use for generating domain colors. Defaults to "gist_rainbow".
|
30
|
-
color (str, list, tuple, np.ndarray, or None, optional): Color to use for the domains. Can be a single color or an array of colors.
|
31
|
-
If None, the colormap will be used. Defaults to None.
|
32
|
-
min_scale (float, optional): Minimum scale for color intensity when generating domain colors. Defaults to 0.8.
|
33
|
-
max_scale (float, optional): Maximum scale for color intensity when generating domain colors. Defaults to 1.0.
|
34
|
-
scale_factor (float, optional): Factor for adjusting the contrast in the colors generated based on enrichment. Higher values
|
35
|
-
increase the contrast. Defaults to 1.0.
|
36
|
-
random_seed (int, optional): Seed for random number generation to ensure reproducibility. Defaults to 888.
|
37
|
-
|
38
|
-
Returns:
|
39
|
-
np.ndarray: Array of RGBA colors for each domain.
|
40
|
-
"""
|
41
|
-
# Generate domain colors based on the enrichment data
|
42
|
-
node_colors = get_domain_colors(
|
43
|
-
graph=graph,
|
44
|
-
cmap=cmap,
|
45
|
-
color=color,
|
46
|
-
min_scale=min_scale,
|
47
|
-
max_scale=max_scale,
|
48
|
-
scale_factor=scale_factor,
|
49
|
-
random_seed=random_seed,
|
50
|
-
)
|
51
|
-
annotated_colors = []
|
52
|
-
for _, node_ids in graph.domain_id_to_node_ids_map.items():
|
53
|
-
if len(node_ids) > 1:
|
54
|
-
# For multi-node domains, choose the brightest color based on RGB sum
|
55
|
-
domain_colors = np.array([node_colors[node] for node in node_ids])
|
56
|
-
brightest_color = domain_colors[
|
57
|
-
np.argmax(domain_colors[:, :3].sum(axis=1)) # Sum the RGB values
|
58
|
-
]
|
59
|
-
annotated_colors.append(brightest_color)
|
60
|
-
else:
|
61
|
-
# Single-node domains default to white (RGBA)
|
62
|
-
default_color = np.array([1.0, 1.0, 1.0, 1.0])
|
63
|
-
annotated_colors.append(default_color)
|
64
|
-
|
65
|
-
return np.array(annotated_colors)
|
66
|
-
|
67
|
-
|
68
|
-
def get_domain_colors(
|
69
|
-
graph: NetworkGraph,
|
70
|
-
cmap: str = "gist_rainbow",
|
71
|
-
color: Union[str, list, tuple, np.ndarray, None] = None,
|
72
|
-
min_scale: float = 0.8,
|
73
|
-
max_scale: float = 1.0,
|
74
|
-
scale_factor: float = 1.0,
|
75
|
-
random_seed: int = 888,
|
76
|
-
) -> np.ndarray:
|
77
|
-
"""Generate composite colors for domains based on enrichment or specified colors.
|
78
|
-
|
79
|
-
Args:
|
80
|
-
graph (NetworkGraph): The network data and attributes to be visualized.
|
81
|
-
cmap (str, optional): Name of the colormap to use for generating domain colors. Defaults to "gist_rainbow".
|
82
|
-
color (str, list, tuple, np.ndarray, or None, optional): A specific color or array of colors to use for all domains.
|
83
|
-
If None, the colormap will be used. Defaults to None.
|
84
|
-
min_scale (float, optional): Minimum intensity scale for the colors generated by the colormap. Controls the dimmest colors.
|
85
|
-
Defaults to 0.8.
|
86
|
-
max_scale (float, optional): Maximum intensity scale for the colors generated by the colormap. Controls the brightest colors.
|
87
|
-
Defaults to 1.0.
|
88
|
-
scale_factor (float, optional): Exponent for adjusting the color scaling based on enrichment scores. Higher values increase
|
89
|
-
contrast by dimming lower scores more. Defaults to 1.0.
|
90
|
-
random_seed (int, optional): Seed for random number generation to ensure reproducibility of color assignments. Defaults to 888.
|
91
|
-
|
92
|
-
Returns:
|
93
|
-
np.ndarray: Array of RGBA colors generated for each domain, based on enrichment or the specified color.
|
94
|
-
"""
|
95
|
-
# Get colors for each domain
|
96
|
-
domain_colors = _get_domain_colors(graph=graph, cmap=cmap, color=color, random_seed=random_seed)
|
97
|
-
# Generate composite colors for nodes
|
98
|
-
node_colors = _get_composite_node_colors(graph=graph, domain_colors=domain_colors)
|
99
|
-
# Transform colors to ensure proper alpha values and intensity
|
100
|
-
transformed_colors = _transform_colors(
|
101
|
-
node_colors,
|
102
|
-
graph.node_enrichment_sums,
|
103
|
-
min_scale=min_scale,
|
104
|
-
max_scale=max_scale,
|
105
|
-
scale_factor=scale_factor,
|
106
|
-
)
|
107
|
-
return transformed_colors
|
108
|
-
|
109
|
-
|
110
|
-
def _get_domain_colors(
|
111
|
-
graph: NetworkGraph,
|
112
|
-
cmap: str = "gist_rainbow",
|
113
|
-
color: Union[str, list, tuple, np.ndarray, None] = None,
|
114
|
-
random_seed: int = 888,
|
115
|
-
) -> Dict[str, Any]:
|
116
|
-
"""Get colors for each domain.
|
117
|
-
|
118
|
-
Args:
|
119
|
-
graph (NetworkGraph): The network data and attributes to be visualized.
|
120
|
-
cmap (str, optional): The name of the colormap to use. Defaults to "gist_rainbow".
|
121
|
-
color (str, list, tuple, np.ndarray, or None, optional): A specific color or array of colors to use for the domains.
|
122
|
-
If None, the colormap will be used. Defaults to None.
|
123
|
-
random_seed (int, optional): Seed for random number generation. Defaults to 888.
|
124
|
-
|
125
|
-
Returns:
|
126
|
-
dict: A dictionary mapping domain keys to their corresponding RGBA colors.
|
127
|
-
"""
|
128
|
-
# Get colors for each domain based on node positions
|
129
|
-
domain_colors = _get_colors(
|
130
|
-
graph.network,
|
131
|
-
graph.domain_id_to_node_ids_map,
|
132
|
-
cmap=cmap,
|
133
|
-
color=color,
|
134
|
-
random_seed=random_seed,
|
135
|
-
)
|
136
|
-
return dict(zip(graph.domain_id_to_node_ids_map.keys(), domain_colors))
|
137
|
-
|
138
|
-
|
139
|
-
def _get_composite_node_colors(graph: NetworkGraph, domain_colors: np.ndarray) -> np.ndarray:
|
140
|
-
"""Generate composite colors for nodes based on domain colors and counts.
|
141
|
-
|
142
|
-
Args:
|
143
|
-
graph (NetworkGraph): The network data and attributes to be visualized.
|
144
|
-
domain_colors (np.ndarray): Array of colors corresponding to each domain.
|
145
|
-
|
146
|
-
Returns:
|
147
|
-
np.ndarray: Array of composite colors for each node.
|
148
|
-
"""
|
149
|
-
# Determine the number of nodes
|
150
|
-
num_nodes = len(graph.node_coordinates)
|
151
|
-
# Initialize composite colors array with shape (number of nodes, 4) for RGBA
|
152
|
-
composite_colors = np.zeros((num_nodes, 4))
|
153
|
-
# Assign colors to nodes based on domain_colors
|
154
|
-
for domain_id, nodes in graph.domain_id_to_node_ids_map.items():
|
155
|
-
color = domain_colors[domain_id]
|
156
|
-
for node in nodes:
|
157
|
-
composite_colors[node] = color
|
158
|
-
|
159
|
-
return composite_colors
|
160
|
-
|
161
|
-
|
162
|
-
def _get_colors(
|
163
|
-
network,
|
164
|
-
domain_id_to_node_ids_map,
|
165
|
-
cmap: str = "gist_rainbow",
|
166
|
-
color: Union[str, list, tuple, np.ndarray, None] = None,
|
167
|
-
random_seed: int = 888,
|
168
|
-
) -> List[Tuple]:
|
169
|
-
"""Generate a list of RGBA colors based on domain centroids, ensuring that domains
|
170
|
-
close in space get maximally separated colors, while keeping some randomness.
|
171
|
-
|
172
|
-
Args:
|
173
|
-
network (NetworkX graph): The graph representing the network.
|
174
|
-
domain_id_to_node_ids_map (dict): Mapping from domain IDs to lists of node IDs.
|
175
|
-
cmap (str, optional): The name of the colormap to use. Defaults to "gist_rainbow".
|
176
|
-
color (str, list, tuple, np.ndarray, or None, optional): A specific color or array of colors to use for the domains.
|
177
|
-
If None, the colormap will be used. Defaults to None.
|
178
|
-
random_seed (int, optional): Seed for random number generation. Defaults to 888.
|
179
|
-
|
180
|
-
Returns:
|
181
|
-
List[Tuple]: List of RGBA colors.
|
182
|
-
"""
|
183
|
-
# Set random seed for reproducibility
|
184
|
-
np.random.seed(random_seed)
|
185
|
-
# Determine the number of colors to generate based on the number of domains
|
186
|
-
num_colors_to_generate = len(domain_id_to_node_ids_map)
|
187
|
-
if color:
|
188
|
-
# Generate all colors as the same specified color
|
189
|
-
rgba = to_rgba(color, num_repeats=num_colors_to_generate)
|
190
|
-
return rgba
|
191
|
-
|
192
|
-
# Load colormap
|
193
|
-
colormap = matplotlib.colormaps.get_cmap(cmap)
|
194
|
-
# Step 1: Calculate centroids for each domain
|
195
|
-
centroids = calculate_centroids(network, domain_id_to_node_ids_map)
|
196
|
-
# Step 2: Calculate pairwise distances between centroids
|
197
|
-
centroid_array = np.array(centroids)
|
198
|
-
dist_matrix = np.linalg.norm(centroid_array[:, None] - centroid_array, axis=-1)
|
199
|
-
# Step 3: Assign distant colors to close centroids
|
200
|
-
color_positions = _assign_distant_colors(dist_matrix, num_colors_to_generate)
|
201
|
-
# Step 4: Randomly shift the entire color palette while maintaining relative distances
|
202
|
-
global_shift = np.random.uniform(-0.1, 0.1) # Small global shift to change the overall palette
|
203
|
-
color_positions = (color_positions + global_shift) % 1 # Wrap around to keep within [0, 1]
|
204
|
-
# Step 5: Ensure that all positions remain between 0 and 1
|
205
|
-
color_positions = np.clip(color_positions, 0, 1)
|
206
|
-
|
207
|
-
# Step 6: Generate RGBA colors based on positions
|
208
|
-
return [colormap(pos) for pos in color_positions]
|
209
|
-
|
210
|
-
|
211
|
-
def _assign_distant_colors(dist_matrix, num_colors_to_generate):
|
212
|
-
"""Assign colors to centroids that are close in space, ensuring stark color differences.
|
213
|
-
|
214
|
-
Args:
|
215
|
-
dist_matrix (ndarray): Matrix of pairwise centroid distances.
|
216
|
-
num_colors_to_generate (int): Number of colors to generate.
|
217
|
-
|
218
|
-
Returns:
|
219
|
-
np.array: Array of color positions in the range [0, 1].
|
220
|
-
"""
|
221
|
-
color_positions = np.zeros(num_colors_to_generate)
|
222
|
-
# Step 1: Sort indices by centroid proximity (based on sum of distances to others)
|
223
|
-
proximity_order = sorted(
|
224
|
-
range(num_colors_to_generate), key=lambda idx: np.sum(dist_matrix[idx])
|
225
|
-
)
|
226
|
-
# Step 2: Assign colors starting with the most distant points in proximity order
|
227
|
-
for i, idx in enumerate(proximity_order):
|
228
|
-
color_positions[idx] = i / num_colors_to_generate
|
229
|
-
|
230
|
-
# Step 3: Adjust colors so that centroids close to one another are maximally distant on the color spectrum
|
231
|
-
half_spectrum = int(num_colors_to_generate / 2)
|
232
|
-
for i in range(half_spectrum):
|
233
|
-
# Split the spectrum so that close centroids are assigned distant colors
|
234
|
-
color_positions[proximity_order[i]] = (i * 2) / num_colors_to_generate
|
235
|
-
color_positions[proximity_order[-(i + 1)]] = ((i * 2) + 1) / num_colors_to_generate
|
236
|
-
|
237
|
-
return color_positions
|
238
|
-
|
239
|
-
|
240
|
-
def _transform_colors(
|
241
|
-
colors: np.ndarray,
|
242
|
-
enrichment_sums: np.ndarray,
|
243
|
-
min_scale: float = 0.8,
|
244
|
-
max_scale: float = 1.0,
|
245
|
-
scale_factor: float = 1.0,
|
246
|
-
) -> np.ndarray:
|
247
|
-
"""Transform colors using power scaling to emphasize high enrichment sums more. Black colors are replaced with
|
248
|
-
very dark grey to avoid issues with color scaling (rgb(0.1, 0.1, 0.1)).
|
249
|
-
|
250
|
-
Args:
|
251
|
-
colors (np.ndarray): An array of RGBA colors.
|
252
|
-
enrichment_sums (np.ndarray): An array of enrichment sums corresponding to the colors.
|
253
|
-
min_scale (float, optional): Minimum scale for color intensity. Defaults to 0.8.
|
254
|
-
max_scale (float, optional): Maximum scale for color intensity. Defaults to 1.0.
|
255
|
-
scale_factor (float, optional): Exponent for scaling, where values > 1 increase contrast by dimming small
|
256
|
-
values more. Defaults to 1.0.
|
257
|
-
|
258
|
-
Returns:
|
259
|
-
np.ndarray: The transformed array of RGBA colors with adjusted intensities.
|
260
|
-
"""
|
261
|
-
# Ensure that min_scale is less than max_scale
|
262
|
-
if min_scale == max_scale:
|
263
|
-
min_scale = max_scale - 10e-6 # Avoid division by zero
|
264
|
-
|
265
|
-
# Replace black colors (#000000) with very dark grey (#1A1A1A)
|
266
|
-
black_color = np.array([0.0, 0.0, 0.0]) # Pure black RGB
|
267
|
-
dark_grey = np.array([0.1, 0.1, 0.1]) # Very dark grey RGB (#1A1A1A)
|
268
|
-
# Check where colors are black (very close to [0, 0, 0]) and replace with dark grey
|
269
|
-
is_black = np.all(colors[:, :3] == black_color, axis=1)
|
270
|
-
colors[is_black, :3] = dark_grey
|
271
|
-
|
272
|
-
# Normalize the enrichment sums to the range [0, 1]
|
273
|
-
normalized_sums = enrichment_sums / np.max(enrichment_sums)
|
274
|
-
# Apply power scaling to dim lower values and emphasize higher values
|
275
|
-
scaled_sums = normalized_sums**scale_factor
|
276
|
-
# Linearly scale the normalized sums to the range [min_scale, max_scale]
|
277
|
-
scaled_sums = min_scale + (max_scale - min_scale) * scaled_sums
|
278
|
-
# Adjust RGB values based on scaled sums
|
279
|
-
for i in range(3): # Only adjust RGB values
|
280
|
-
colors[:, i] = scaled_sums * colors[:, i]
|
281
|
-
|
282
|
-
return colors
|
283
|
-
|
284
|
-
|
285
|
-
def to_rgba(
|
286
|
-
color: Union[str, list, tuple, np.ndarray],
|
287
|
-
alpha: Union[float, None] = None,
|
288
|
-
num_repeats: Union[int, None] = None,
|
289
|
-
) -> np.ndarray:
|
290
|
-
"""Convert color(s) to RGBA format, applying alpha and repeating as needed.
|
291
|
-
|
292
|
-
Args:
|
293
|
-
color (str, list, tuple, np.ndarray): The color(s) to convert. Can be a string (e.g., 'red'), a list or tuple of RGB/RGBA values,
|
294
|
-
or an `np.ndarray` of colors.
|
295
|
-
alpha (float, None, optional): Alpha value (transparency) to apply. If provided, it overrides any existing alpha values found
|
296
|
-
in color.
|
297
|
-
num_repeats (int, None, optional): If provided, the color(s) will be repeated this many times. Defaults to None.
|
298
|
-
|
299
|
-
Returns:
|
300
|
-
np.ndarray: Array of RGBA colors repeated `num_repeats` times, if applicable.
|
301
|
-
"""
|
302
|
-
|
303
|
-
def convert_to_rgba(c: Union[str, List, Tuple, np.ndarray]) -> np.ndarray:
|
304
|
-
"""Convert a single color to RGBA format, handling strings, hex, and RGB/RGBA lists."""
|
305
|
-
# Note: if no alpha is provided, the default alpha value is 1.0 by mcolors.to_rgba
|
306
|
-
if isinstance(c, str):
|
307
|
-
# Convert color names or hex values (e.g., 'red', '#FF5733') to RGBA
|
308
|
-
rgba = np.array(mcolors.to_rgba(c))
|
309
|
-
elif isinstance(c, (list, tuple, np.ndarray)) and len(c) in [3, 4]:
|
310
|
-
# Convert RGB (3) or RGBA (4) values to RGBA format
|
311
|
-
rgba = np.array(mcolors.to_rgba(c))
|
312
|
-
else:
|
313
|
-
raise ValueError(
|
314
|
-
f"Invalid color format: {c}. Must be a valid string or RGB/RGBA sequence."
|
315
|
-
)
|
316
|
-
|
317
|
-
if alpha is not None: # Override alpha if provided
|
318
|
-
rgba[3] = alpha
|
319
|
-
return rgba
|
320
|
-
|
321
|
-
# If color is a 2D array of RGBA values, convert it to a list of lists
|
322
|
-
if isinstance(color, np.ndarray) and color.ndim == 2 and color.shape[1] == 4:
|
323
|
-
color = [list(c) for c in color]
|
324
|
-
|
325
|
-
# Handle a single color (string or RGB/RGBA list/tuple)
|
326
|
-
if (
|
327
|
-
isinstance(color, str)
|
328
|
-
or isinstance(color, (list, tuple, np.ndarray))
|
329
|
-
and not any(isinstance(c, (str, list, tuple, np.ndarray)) for c in color)
|
330
|
-
):
|
331
|
-
rgba_color = convert_to_rgba(color)
|
332
|
-
if num_repeats:
|
333
|
-
return np.tile(
|
334
|
-
rgba_color, (num_repeats, 1)
|
335
|
-
) # Repeat the color if num_repeats is provided
|
336
|
-
return np.array([rgba_color]) # Return a single color wrapped in a numpy array
|
337
|
-
|
338
|
-
# Handle a list/array of colors
|
339
|
-
elif isinstance(color, (list, tuple, np.ndarray)):
|
340
|
-
rgba_colors = np.array(
|
341
|
-
[convert_to_rgba(c) for c in color]
|
342
|
-
) # Convert each color in the list to RGBA
|
343
|
-
# Handle repetition if num_repeats is provided
|
344
|
-
if num_repeats:
|
345
|
-
repeated_colors = np.array(
|
346
|
-
[rgba_colors[i % len(rgba_colors)] for i in range(num_repeats)]
|
347
|
-
)
|
348
|
-
return repeated_colors
|
349
|
-
|
350
|
-
return rgba_colors
|
351
|
-
|
352
|
-
else:
|
353
|
-
raise ValueError("Color must be a valid RGB/RGBA or array of RGB/RGBA colors.")
|
@@ -1,53 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
risk/network/plot/utils/layout
|
3
|
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4
|
-
"""
|
5
|
-
|
6
|
-
from typing import Tuple
|
7
|
-
|
8
|
-
import numpy as np
|
9
|
-
|
10
|
-
|
11
|
-
def calculate_bounding_box(
|
12
|
-
node_coordinates: np.ndarray, radius_margin: float = 1.05
|
13
|
-
) -> Tuple[np.ndarray, float]:
|
14
|
-
"""Calculate the bounding box of the network based on node coordinates.
|
15
|
-
|
16
|
-
Args:
|
17
|
-
node_coordinates (np.ndarray): Array of node coordinates (x, y).
|
18
|
-
radius_margin (float, optional): Margin factor to apply to the bounding box radius. Defaults to 1.05.
|
19
|
-
|
20
|
-
Returns:
|
21
|
-
tuple: Center of the bounding box and the radius (adjusted by the radius margin).
|
22
|
-
"""
|
23
|
-
# Find minimum and maximum x, y coordinates
|
24
|
-
x_min, y_min = np.min(node_coordinates, axis=0)
|
25
|
-
x_max, y_max = np.max(node_coordinates, axis=0)
|
26
|
-
# Calculate the center of the bounding box
|
27
|
-
center = np.array([(x_min + x_max) / 2, (y_min + y_max) / 2])
|
28
|
-
# Calculate the radius of the bounding box, adjusted by the margin
|
29
|
-
radius = max(x_max - x_min, y_max - y_min) / 2 * radius_margin
|
30
|
-
return center, radius
|
31
|
-
|
32
|
-
|
33
|
-
def calculate_centroids(network, domain_id_to_node_ids_map):
|
34
|
-
"""Calculate the centroid for each domain based on node x and y coordinates in the network.
|
35
|
-
|
36
|
-
Args:
|
37
|
-
network (NetworkX graph): The graph representing the network.
|
38
|
-
domain_id_to_node_ids_map (dict): Mapping from domain IDs to lists of node IDs.
|
39
|
-
|
40
|
-
Returns:
|
41
|
-
List[Tuple[float, float]]: List of centroids (x, y) for each domain.
|
42
|
-
"""
|
43
|
-
centroids = []
|
44
|
-
for domain_id, node_ids in domain_id_to_node_ids_map.items():
|
45
|
-
# Extract x and y coordinates from the network nodes
|
46
|
-
node_positions = np.array(
|
47
|
-
[[network.nodes[node_id]["x"], network.nodes[node_id]["y"]] for node_id in node_ids]
|
48
|
-
)
|
49
|
-
# Compute the centroid as the mean of the x and y coordinates
|
50
|
-
centroid = np.mean(node_positions, axis=0)
|
51
|
-
centroids.append(tuple(centroid))
|
52
|
-
|
53
|
-
return centroids
|
@@ -1,37 +0,0 @@
|
|
1
|
-
risk/__init__.py,sha256=EoQiOdiY9moo1L8d1ybzWAGTSGsM9MzK9H_PfU8miI4,113
|
2
|
-
risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
|
3
|
-
risk/risk.py,sha256=slJXca_a726_D7oXwe765HaKTv3ZrOvhttyrWdCGPkA,21231
|
4
|
-
risk/annotations/__init__.py,sha256=vUpVvMRE5if01Ic8QY6M2Ae3EFGJHdugEe9PdEkAW4Y,138
|
5
|
-
risk/annotations/annotations.py,sha256=7ilzXxrlHqN75J3q8WeHz0n79D-jAtUQx5czvC9wfIM,11303
|
6
|
-
risk/annotations/io.py,sha256=TTXVJQgUGAlKpnGBcx7Dow146IGyozA03nSbl3S7M5M,9475
|
7
|
-
risk/log/__init__.py,sha256=aDUz5LMFQsz0UlsQI2EdXtiBKRLfml1UMeZKC7QQIGU,134
|
8
|
-
risk/log/config.py,sha256=m8pzj-hN4vI_2JdJUfyOoSvzT8_lhoIfBt27sKbnOes,4535
|
9
|
-
risk/log/params.py,sha256=DUmsqPo9hi3rQHFgLTunP14I-vVoyQSFZbx5aSYmVts,6363
|
10
|
-
risk/neighborhoods/__init__.py,sha256=tKKEg4lsbqFukpgYlUGxU_v_9FOqK7V0uvM9T2QzoL0,206
|
11
|
-
risk/neighborhoods/community.py,sha256=stYYBXeZlGLMV-k8ckQeIqThT6v9y-S3hETobAo9590,6817
|
12
|
-
risk/neighborhoods/domains.py,sha256=D5MUIghbwyKKCAE8PN_HXvsO9NxLTGejQmyEqetD1Bk,10743
|
13
|
-
risk/neighborhoods/neighborhoods.py,sha256=M-wL4xB_BUTlSZg90swygO5NdrZ6hFUFqs6jsiZaqHk,18260
|
14
|
-
risk/network/__init__.py,sha256=iEPeJdZfqp0toxtbElryB8jbz9_t_k4QQ3iDvKE8C_0,126
|
15
|
-
risk/network/geometry.py,sha256=H1yGVVqgbfpzBzJwEheDLfvGLSA284jGQQTn612L4Vc,6759
|
16
|
-
risk/network/graph.py,sha256=x5cur1meitkR0YuE5vGxX0s_IFa5wkx8z44f_C1vK7U,6509
|
17
|
-
risk/network/io.py,sha256=u0PPcKjp6Xze--7eDOlvalYkjQ9S2sjiC-ac2476PUI,22942
|
18
|
-
risk/network/plot/__init__.py,sha256=MfmaXJgAZJgXZ2wrhK8pXwzETlcMaLChhWXKAozniAo,98
|
19
|
-
risk/network/plot/canvas.py,sha256=JnjPQaryRb_J6LP36BT2-rlsbJO3T4tTBornL8Oqqbs,10778
|
20
|
-
risk/network/plot/contour.py,sha256=8uwJ7K-Z6VMyr_uQ5VUyoQSqDHA7zDvR_nYAmLn60-I,14647
|
21
|
-
risk/network/plot/labels.py,sha256=ttEUiKkDq024v4MI-ZADW3sT7uRNQ6aL3kNB598Em90,44468
|
22
|
-
risk/network/plot/network.py,sha256=9blVFeCp5x5XoGhPwOOdADegXC4gC72c2vrM2u4QPe0,13235
|
23
|
-
risk/network/plot/plotter.py,sha256=lN-_GDXRk9V3IFu8q7QmPjJGBZiP0QYwSvU6dVVDV2E,5770
|
24
|
-
risk/network/plot/utils/color.py,sha256=_ZLIw_uv--nTXhUhZVaF0iCaYmfURTn_WnoFYdUcPrc,15575
|
25
|
-
risk/network/plot/utils/layout.py,sha256=znssSqe2VZzzSz47hLZtTuXwMTpHR9b8lkQPL0BX7OA,1950
|
26
|
-
risk/stats/__init__.py,sha256=WcgoETQ-hS0LQqKRsAMIPtP15xZ-4eul6VUBuUx4Wzc,220
|
27
|
-
risk/stats/hypergeom.py,sha256=o6Qnj31gCAKxr2uQirXrbv7XvdDJGEq69MFW-ubx_hA,2272
|
28
|
-
risk/stats/poisson.py,sha256=8x9hB4DCukq4gNIlIKO-c_jYG1-BTwTX53oLauFyfj8,1793
|
29
|
-
risk/stats/stats.py,sha256=kvShov-94W6ffgDUTb522vB9hDJQSyTsYif_UIaFfSM,7059
|
30
|
-
risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
|
31
|
-
risk/stats/permutation/permutation.py,sha256=D84Rcpt6iTQniK0PfQGcw9bLcHbMt9p-ARcurUnIXZQ,10095
|
32
|
-
risk/stats/permutation/test_functions.py,sha256=lftOude6hee0pyR80HlBD32522JkDoN5hrKQ9VEbuoY,2345
|
33
|
-
risk_network-0.0.8b18.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
|
34
|
-
risk_network-0.0.8b18.dist-info/METADATA,sha256=CYJnBG0E8gmlzPx15UYKAjbbsC3zs2Mmsq42NPzi1mY,47498
|
35
|
-
risk_network-0.0.8b18.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
36
|
-
risk_network-0.0.8b18.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
|
37
|
-
risk_network-0.0.8b18.dist-info/RECORD,,
|
File without changes
|
File without changes
|