risk-network 0.0.9b7__py3-none-any.whl → 0.0.9b9__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 +1 -1
- risk/network/plot/utils/colors.py +14 -53
- {risk_network-0.0.9b7.dist-info → risk_network-0.0.9b9.dist-info}/METADATA +1 -1
- {risk_network-0.0.9b7.dist-info → risk_network-0.0.9b9.dist-info}/RECORD +7 -7
- {risk_network-0.0.9b7.dist-info → risk_network-0.0.9b9.dist-info}/LICENSE +0 -0
- {risk_network-0.0.9b7.dist-info → risk_network-0.0.9b9.dist-info}/WHEEL +0 -0
- {risk_network-0.0.9b7.dist-info → risk_network-0.0.9b9.dist-info}/top_level.txt +0 -0
risk/__init__.py
CHANGED
@@ -9,6 +9,7 @@ import matplotlib
|
|
9
9
|
import matplotlib.colors as mcolors
|
10
10
|
import networkx as nx
|
11
11
|
import numpy as np
|
12
|
+
from sklearn.cluster import AgglomerativeClustering
|
12
13
|
|
13
14
|
from risk.network.graph import NetworkGraph
|
14
15
|
from risk.network.plot.utils.layout import calculate_centroids
|
@@ -233,75 +234,35 @@ def _get_colors(
|
|
233
234
|
color: Union[str, List, Tuple, np.ndarray, None] = None,
|
234
235
|
random_seed: int = 888,
|
235
236
|
) -> List[Tuple]:
|
236
|
-
"""Generate a list of RGBA colors
|
237
|
-
close in space get maximally separated colors, while keeping some randomness.
|
237
|
+
"""Generate a list of RGBA colors for domains, ensuring maximally separated colors for nearby domains.
|
238
238
|
|
239
239
|
Args:
|
240
240
|
network (nx.Graph): The graph representing the network.
|
241
241
|
domain_id_to_node_ids_map (Dict[int, Any]): Mapping from domain IDs to lists of node IDs.
|
242
242
|
cmap (str, optional): The name of the colormap to use. Defaults to "gist_rainbow".
|
243
|
-
color (str, List, Tuple, np.ndarray, or None, optional): A specific color or array of colors to use
|
243
|
+
color (str, List, Tuple, np.ndarray, or None, optional): A specific color or array of colors to use.
|
244
244
|
If None, the colormap will be used. Defaults to None.
|
245
245
|
random_seed (int, optional): Seed for random number generation. Defaults to 888.
|
246
246
|
|
247
247
|
Returns:
|
248
|
-
List[Tuple]: List of RGBA colors.
|
248
|
+
List[Tuple]: List of RGBA colors for each domain.
|
249
249
|
"""
|
250
|
-
# Set random seed for reproducibility
|
251
250
|
np.random.seed(random_seed)
|
252
|
-
|
253
|
-
num_colors_to_generate = len(domain_id_to_node_ids_map)
|
251
|
+
num_domains = len(domain_id_to_node_ids_map)
|
254
252
|
if color:
|
255
|
-
#
|
256
|
-
rgba = to_rgba(color, num_repeats=
|
253
|
+
# If a single color is specified, apply it to all domains
|
254
|
+
rgba = to_rgba(color, num_repeats=num_domains)
|
257
255
|
return rgba
|
258
256
|
|
259
|
-
# Load colormap
|
257
|
+
# Load colormap and generate a large, maximally separated set of colors
|
260
258
|
colormap = matplotlib.colormaps.get_cmap(cmap)
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
# Step 3: Assign distant colors to close centroids
|
267
|
-
color_positions = _assign_distant_colors(dist_matrix, num_colors_to_generate)
|
268
|
-
# Step 4: Randomly shift the entire color palette while maintaining relative distances
|
269
|
-
global_shift = np.random.uniform(-0.1, 0.1) # Small global shift to change the overall palette
|
270
|
-
color_positions = (color_positions + global_shift) % 1 # Wrap around to keep within [0, 1]
|
271
|
-
# Step 5: Ensure that all positions remain between 0 and 1
|
272
|
-
color_positions = np.clip(color_positions, 0, 1)
|
273
|
-
|
274
|
-
# Step 6: Generate RGBA colors based on positions
|
275
|
-
return [colormap(pos) for pos in color_positions]
|
276
|
-
|
277
|
-
|
278
|
-
def _assign_distant_colors(dist_matrix: np.ndarray, num_colors_to_generate: int) -> np.ndarray:
|
279
|
-
"""Assign colors to centroids that are close in space, ensuring stark color differences.
|
280
|
-
|
281
|
-
Args:
|
282
|
-
dist_matrix (ndarray): Matrix of pairwise centroid distances.
|
283
|
-
num_colors_to_generate (int): Number of colors to generate.
|
259
|
+
color_positions = np.linspace(0, 1, num_domains, endpoint=False)
|
260
|
+
# Shuffle color positions to avoid spatial clustering of similar colors
|
261
|
+
np.random.shuffle(color_positions)
|
262
|
+
# Assign colors based on positions in the colormap
|
263
|
+
colors = [colormap(pos) for pos in color_positions]
|
284
264
|
|
285
|
-
|
286
|
-
np.array: Array of color positions in the range [0, 1].
|
287
|
-
"""
|
288
|
-
color_positions = np.zeros(num_colors_to_generate)
|
289
|
-
# Step 1: Sort indices by centroid proximity (based on sum of distances to others)
|
290
|
-
proximity_order = sorted(
|
291
|
-
range(num_colors_to_generate), key=lambda idx: np.sum(dist_matrix[idx])
|
292
|
-
)
|
293
|
-
# Step 2: Assign colors starting with the most distant points in proximity order
|
294
|
-
for i, idx in enumerate(proximity_order):
|
295
|
-
color_positions[idx] = i / num_colors_to_generate
|
296
|
-
|
297
|
-
# Step 3: Adjust colors so that centroids close to one another are maximally distant on the color spectrum
|
298
|
-
half_spectrum = int(num_colors_to_generate / 2)
|
299
|
-
for i in range(half_spectrum):
|
300
|
-
# Split the spectrum so that close centroids are assigned distant colors
|
301
|
-
color_positions[proximity_order[i]] = (i * 2) / num_colors_to_generate
|
302
|
-
color_positions[proximity_order[-(i + 1)]] = ((i * 2) + 1) / num_colors_to_generate
|
303
|
-
|
304
|
-
return color_positions
|
265
|
+
return colors
|
305
266
|
|
306
267
|
|
307
268
|
def _blend_colors_perceptually(
|
@@ -1,4 +1,4 @@
|
|
1
|
-
risk/__init__.py,sha256=
|
1
|
+
risk/__init__.py,sha256=wOa6WyqiT30Dx0Mk77M-4ilHgFK5rf0eRjG7ceeU8Gw,112
|
2
2
|
risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
|
3
3
|
risk/risk.py,sha256=kntBxYwAEpoAjXN_l6BM3yxFKyuAKmd8OMGl2P00pZ4,22416
|
4
4
|
risk/annotations/__init__.py,sha256=kXgadEXaCh0z8OyhOhTj7c3qXGmWgOhaSZ4gSzSb59U,147
|
@@ -23,7 +23,7 @@ risk/network/plot/contour.py,sha256=VONX9l6owrZvWtR0mWQ6z2GSd1YXIv5wV_sf5ROQLT4,
|
|
23
23
|
risk/network/plot/labels.py,sha256=eorP80CmAbHmt7de2qHna1tHGKL8YiHknwFW2R3tvjI,45734
|
24
24
|
risk/network/plot/network.py,sha256=_K8Am2y6zSGrm3fAgMbXxzgspbugJi3uK4_tG8qqGoI,14015
|
25
25
|
risk/network/plot/plotter.py,sha256=eS1vHqvOA2O001Rq7WiDcgqcehJ3fg4OPfvkezH4erw,5771
|
26
|
-
risk/network/plot/utils/colors.py,sha256=
|
26
|
+
risk/network/plot/utils/colors.py,sha256=9zuU2O-Nkpljb1yVGUR_IjqD1y-wH6Bf6Vm1MMVB0Lo,18718
|
27
27
|
risk/network/plot/utils/layout.py,sha256=6o7idoWQnyzujSWOFXQykUvyPy8NuRtJV04TnlbXXBo,3647
|
28
28
|
risk/stats/__init__.py,sha256=WcgoETQ-hS0LQqKRsAMIPtP15xZ-4eul6VUBuUx4Wzc,220
|
29
29
|
risk/stats/hypergeom.py,sha256=oc39f02ViB1vQ-uaDrxG_tzAT6dxQBRjc88EK2EGn78,2282
|
@@ -32,8 +32,8 @@ risk/stats/stats.py,sha256=z8NrhiVj4BzJ250bVLfytpmfC7RzYu7mBuIZD_l0aCA,7222
|
|
32
32
|
risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
|
33
33
|
risk/stats/permutation/permutation.py,sha256=meBNSrbRa9P8WJ54n485l0H7VQJlMSfHqdN4aCKYCtQ,10105
|
34
34
|
risk/stats/permutation/test_functions.py,sha256=lftOude6hee0pyR80HlBD32522JkDoN5hrKQ9VEbuoY,2345
|
35
|
-
risk_network-0.0.
|
36
|
-
risk_network-0.0.
|
37
|
-
risk_network-0.0.
|
38
|
-
risk_network-0.0.
|
39
|
-
risk_network-0.0.
|
35
|
+
risk_network-0.0.9b9.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
|
36
|
+
risk_network-0.0.9b9.dist-info/METADATA,sha256=iBZOFuXgFhOXgRkBH90TC3Fkk7r1iAX6Yq0bPuGjxck,47497
|
37
|
+
risk_network-0.0.9b9.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
38
|
+
risk_network-0.0.9b9.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
|
39
|
+
risk_network-0.0.9b9.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|