risk-network 0.0.8b3__py3-none-any.whl → 0.0.8b4__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.py +112 -37
- {risk_network-0.0.8b3.dist-info → risk_network-0.0.8b4.dist-info}/METADATA +1 -1
- {risk_network-0.0.8b3.dist-info → risk_network-0.0.8b4.dist-info}/RECORD +7 -7
- {risk_network-0.0.8b3.dist-info → risk_network-0.0.8b4.dist-info}/LICENSE +0 -0
- {risk_network-0.0.8b3.dist-info → risk_network-0.0.8b4.dist-info}/WHEEL +0 -0
- {risk_network-0.0.8b3.dist-info → risk_network-0.0.8b4.dist-info}/top_level.txt +0 -0
risk/__init__.py
CHANGED
risk/network/plot.py
CHANGED
@@ -705,10 +705,10 @@ class NetworkPlotter:
|
|
705
705
|
arrow_base_shrink (float, optional): Distance between the text and the base of the arrow. Defaults to 0.0.
|
706
706
|
arrow_tip_shrink (float, optional): Distance between the arrow tip and the centroid. Defaults to 0.0.
|
707
707
|
max_labels (int, optional): Maximum number of labels to plot. Defaults to None (no limit).
|
708
|
-
max_label_lines (int, optional): Maximum number of lines in a label. Defaults to None (no limit).
|
709
708
|
min_label_lines (int, optional): Minimum number of lines in a label. Defaults to 1.
|
710
|
-
|
709
|
+
max_label_lines (int, optional): Maximum number of lines in a label. Defaults to None (no limit).
|
711
710
|
min_chars_per_line (int, optional): Minimum number of characters in a line to display. Defaults to 1.
|
711
|
+
max_chars_per_line (int, optional): Maximum number of characters in a line to display. Defaults to None (no limit).
|
712
712
|
words_to_omit (list, optional): List of words to omit from the labels. Defaults to None.
|
713
713
|
overlay_ids (bool, optional): Whether to overlay domain IDs in the center of the centroids. Defaults to False.
|
714
714
|
ids_to_keep (list, tuple, np.ndarray, or None, optional): IDs of domains that must be labeled. To discover domain IDs,
|
@@ -761,11 +761,11 @@ class NetworkPlotter:
|
|
761
761
|
if words_to_omit:
|
762
762
|
words_to_omit = set(word.lower() for word in words_to_omit)
|
763
763
|
|
764
|
-
# Calculate the center and radius of the network
|
765
|
-
|
764
|
+
# Calculate the center and radius of domains to position labels around the network
|
765
|
+
domain_id_to_centroid_map = {}
|
766
766
|
for domain_id, node_ids in self.graph.domain_id_to_node_ids_map.items():
|
767
767
|
if node_ids: # Skip if the domain has no nodes
|
768
|
-
|
768
|
+
domain_id_to_centroid_map[domain_id] = self._calculate_domain_centroid(node_ids)
|
769
769
|
|
770
770
|
# Initialize dictionaries and lists for valid indices
|
771
771
|
valid_indices = [] # List of valid indices to plot colors and arrows
|
@@ -775,8 +775,8 @@ class NetworkPlotter:
|
|
775
775
|
if ids_to_keep:
|
776
776
|
# Process the ids_to_keep first INPLACE
|
777
777
|
self._process_ids_to_keep(
|
778
|
+
domain_id_to_centroid_map=domain_id_to_centroid_map,
|
778
779
|
ids_to_keep=ids_to_keep,
|
779
|
-
domain_centroids=domain_centroids,
|
780
780
|
ids_to_replace=ids_to_replace,
|
781
781
|
words_to_omit=words_to_omit,
|
782
782
|
max_labels=max_labels,
|
@@ -796,7 +796,7 @@ class NetworkPlotter:
|
|
796
796
|
# Process remaining domains INPLACE to fill in additional labels, if there are slots left
|
797
797
|
if remaining_labels and remaining_labels > 0:
|
798
798
|
self._process_remaining_domains(
|
799
|
-
|
799
|
+
domain_id_to_centroid_map=domain_id_to_centroid_map,
|
800
800
|
ids_to_keep=ids_to_keep,
|
801
801
|
ids_to_replace=ids_to_replace,
|
802
802
|
words_to_omit=words_to_omit,
|
@@ -977,8 +977,8 @@ class NetworkPlotter:
|
|
977
977
|
|
978
978
|
def _process_ids_to_keep(
|
979
979
|
self,
|
980
|
+
domain_id_to_centroid_map: Dict[str, np.ndarray],
|
980
981
|
ids_to_keep: Union[List[str], Tuple[str], np.ndarray],
|
981
|
-
domain_centroids: Dict[str, np.ndarray],
|
982
982
|
ids_to_replace: Union[Dict[str, str], None],
|
983
983
|
words_to_omit: Union[List[str], None],
|
984
984
|
max_labels: Union[int, None],
|
@@ -993,8 +993,8 @@ class NetworkPlotter:
|
|
993
993
|
"""Process the ids_to_keep, apply filtering, and store valid domain centroids and terms.
|
994
994
|
|
995
995
|
Args:
|
996
|
+
domain_id_to_centroid_map (dict): Mapping of domain IDs to their centroids.
|
996
997
|
ids_to_keep (list, tuple, or np.ndarray, optional): IDs of domains that must be labeled.
|
997
|
-
domain_centroids (dict): Mapping of domains to their centroids.
|
998
998
|
ids_to_replace (dict, optional): A dictionary mapping domain IDs to custom labels. Defaults to None.
|
999
999
|
words_to_omit (list, optional): List of words to omit from the labels. Defaults to None.
|
1000
1000
|
max_labels (int, optional): Maximum number of labels allowed.
|
@@ -1020,25 +1020,30 @@ class NetworkPlotter:
|
|
1020
1020
|
|
1021
1021
|
# Process each domain in ids_to_keep
|
1022
1022
|
for domain in ids_to_keep:
|
1023
|
-
if
|
1024
|
-
|
1023
|
+
if (
|
1024
|
+
domain in self.graph.domain_id_to_domain_terms_map
|
1025
|
+
and domain in domain_id_to_centroid_map
|
1026
|
+
):
|
1027
|
+
domain_centroid = domain_id_to_centroid_map[domain]
|
1028
|
+
# No need to filter the domain terms if it is in ids_to_keep
|
1029
|
+
_ = self._validate_and_update_domain(
|
1025
1030
|
domain=domain,
|
1031
|
+
domain_centroid=domain_centroid,
|
1032
|
+
domain_id_to_centroid_map=domain_id_to_centroid_map,
|
1026
1033
|
ids_to_replace=ids_to_replace,
|
1027
1034
|
words_to_omit=words_to_omit,
|
1035
|
+
min_label_lines=min_label_lines,
|
1028
1036
|
max_label_lines=max_label_lines,
|
1029
1037
|
min_chars_per_line=min_chars_per_line,
|
1030
1038
|
max_chars_per_line=max_chars_per_line,
|
1039
|
+
filtered_domain_centroids=filtered_domain_centroids,
|
1040
|
+
filtered_domain_terms=filtered_domain_terms,
|
1041
|
+
valid_indices=valid_indices,
|
1031
1042
|
)
|
1032
|
-
num_domain_lines = len(domain_terms.split(TERM_DELIMITER))
|
1033
|
-
# Check if the number of lines in the label is greater than or equal to the minimum
|
1034
|
-
if num_domain_lines >= min_label_lines:
|
1035
|
-
filtered_domain_terms[domain] = domain_terms
|
1036
|
-
filtered_domain_centroids[domain] = domain_centroids[domain]
|
1037
|
-
valid_indices.append(list(domain_centroids.keys()).index(domain))
|
1038
1043
|
|
1039
1044
|
def _process_remaining_domains(
|
1040
1045
|
self,
|
1041
|
-
|
1046
|
+
domain_id_to_centroid_map: Dict[str, np.ndarray],
|
1042
1047
|
ids_to_keep: Union[List[str], Tuple[str], np.ndarray],
|
1043
1048
|
ids_to_replace: Union[Dict[str, str], None],
|
1044
1049
|
words_to_omit: Union[List[str], None],
|
@@ -1054,7 +1059,7 @@ class NetworkPlotter:
|
|
1054
1059
|
"""Process remaining domains to fill in additional labels, respecting the remaining_labels limit.
|
1055
1060
|
|
1056
1061
|
Args:
|
1057
|
-
|
1062
|
+
domain_id_to_centroid_map (dict): Mapping of domain IDs to their centroids.
|
1058
1063
|
ids_to_keep (list, tuple, or np.ndarray, optional): IDs of domains that must be labeled.
|
1059
1064
|
ids_to_replace (dict, optional): A dictionary mapping domain IDs to custom labels. Defaults to None.
|
1060
1065
|
words_to_omit (list, optional): List of words to omit from the labels. Defaults to None.
|
@@ -1066,13 +1071,16 @@ class NetworkPlotter:
|
|
1066
1071
|
filtered_domain_centroids (dict): Dictionary to store filtered domain centroids (output).
|
1067
1072
|
filtered_domain_terms (dict): Dictionary to store filtered domain terms (output).
|
1068
1073
|
valid_indices (list): List to store valid indices (output).
|
1074
|
+
|
1075
|
+
Note:
|
1076
|
+
The `filtered_domain_centroids`, `filtered_domain_terms`, and `valid_indices` are modified in-place.
|
1069
1077
|
"""
|
1070
1078
|
# Counter to track how many labels have been created
|
1071
1079
|
label_count = 0
|
1072
1080
|
# Collect domains not in ids_to_keep
|
1073
1081
|
remaining_domains = {
|
1074
1082
|
domain: centroid
|
1075
|
-
for domain, centroid in
|
1083
|
+
for domain, centroid in domain_id_to_centroid_map.items()
|
1076
1084
|
if domain not in ids_to_keep and not pd.isna(domain)
|
1077
1085
|
}
|
1078
1086
|
|
@@ -1112,26 +1120,89 @@ class NetworkPlotter:
|
|
1112
1120
|
|
1113
1121
|
# Process the selected domains and add to filtered lists
|
1114
1122
|
for domain in selected_domains:
|
1115
|
-
|
1116
|
-
|
1123
|
+
domain_centroid = remaining_domains[domain]
|
1124
|
+
is_domain_valid = self._validate_and_update_domain(
|
1117
1125
|
domain=domain,
|
1126
|
+
domain_centroid=domain_centroid,
|
1127
|
+
domain_id_to_centroid_map=domain_id_to_centroid_map,
|
1118
1128
|
ids_to_replace=ids_to_replace,
|
1119
1129
|
words_to_omit=words_to_omit,
|
1130
|
+
min_label_lines=min_label_lines,
|
1120
1131
|
max_label_lines=max_label_lines,
|
1121
1132
|
min_chars_per_line=min_chars_per_line,
|
1122
1133
|
max_chars_per_line=max_chars_per_line,
|
1134
|
+
filtered_domain_centroids=filtered_domain_centroids,
|
1135
|
+
filtered_domain_terms=filtered_domain_terms,
|
1136
|
+
valid_indices=valid_indices,
|
1123
1137
|
)
|
1124
|
-
|
1125
|
-
|
1126
|
-
if num_domain_lines >= min_label_lines:
|
1127
|
-
filtered_domain_centroids[domain] = centroid
|
1128
|
-
filtered_domain_terms[domain] = domain_terms
|
1129
|
-
valid_indices.append(list(domain_centroids.keys()).index(domain))
|
1130
|
-
|
1138
|
+
# Increment the label count if the domain is valid
|
1139
|
+
if is_domain_valid:
|
1131
1140
|
label_count += 1
|
1132
1141
|
if label_count >= remaining_labels:
|
1133
1142
|
break
|
1134
1143
|
|
1144
|
+
def _validate_and_update_domain(
|
1145
|
+
self,
|
1146
|
+
domain: str,
|
1147
|
+
domain_centroid: np.ndarray,
|
1148
|
+
domain_id_to_centroid_map: Dict[str, np.ndarray],
|
1149
|
+
ids_to_replace: Union[Dict[str, str], None],
|
1150
|
+
words_to_omit: Union[List[str], None],
|
1151
|
+
min_label_lines: int,
|
1152
|
+
max_label_lines: int,
|
1153
|
+
min_chars_per_line: int,
|
1154
|
+
max_chars_per_line: int,
|
1155
|
+
filtered_domain_centroids: Dict[str, np.ndarray],
|
1156
|
+
filtered_domain_terms: Dict[str, str],
|
1157
|
+
valid_indices: List[int],
|
1158
|
+
) -> bool:
|
1159
|
+
"""Validate and process the domain terms, updating relevant dictionaries if valid.
|
1160
|
+
|
1161
|
+
Args:
|
1162
|
+
domain (str): Domain ID to process.
|
1163
|
+
domain_centroid (np.ndarray): Centroid position of the domain.
|
1164
|
+
domain_id_to_centroid_map (dict): Mapping of domain IDs to their centroids.
|
1165
|
+
ids_to_replace (Union[Dict[str, str], None]): A dictionary mapping domain IDs to custom labels.
|
1166
|
+
words_to_omit (Union[List[str], None]): List of words to omit from the labels.
|
1167
|
+
min_label_lines (int): Minimum number of lines required in a label.
|
1168
|
+
max_label_lines (int): Maximum number of lines allowed in a label.
|
1169
|
+
min_chars_per_line (int): Minimum number of characters allowed per line.
|
1170
|
+
max_chars_per_line (int): Maximum number of characters allowed per line.
|
1171
|
+
filtered_domain_centroids (Dict[str, np.ndarray]): Dictionary to store valid domain centroids.
|
1172
|
+
filtered_domain_terms (Dict[str, str]): Dictionary to store valid domain terms.
|
1173
|
+
valid_indices (List[int]): List of valid domain indices.
|
1174
|
+
|
1175
|
+
Returns:
|
1176
|
+
bool: True if the domain is valid and added to the filtered dictionaries, False otherwise.
|
1177
|
+
|
1178
|
+
Note:
|
1179
|
+
The `filtered_domain_centroids`, `filtered_domain_terms`, and `valid_indices` are modified in-place.
|
1180
|
+
"""
|
1181
|
+
# Process the domain terms
|
1182
|
+
domain_terms = self._process_terms(
|
1183
|
+
domain=domain,
|
1184
|
+
ids_to_replace=ids_to_replace,
|
1185
|
+
words_to_omit=words_to_omit,
|
1186
|
+
max_label_lines=max_label_lines,
|
1187
|
+
min_chars_per_line=min_chars_per_line,
|
1188
|
+
max_chars_per_line=max_chars_per_line,
|
1189
|
+
)
|
1190
|
+
# If domain_terms is empty, skip further processing
|
1191
|
+
if not domain_terms:
|
1192
|
+
return False
|
1193
|
+
|
1194
|
+
# Split the terms by TERM_DELIMITER and count the number of lines
|
1195
|
+
num_domain_lines = len(domain_terms.split(TERM_DELIMITER))
|
1196
|
+
# Check if the number of lines is greater than or equal to the minimum
|
1197
|
+
if num_domain_lines >= min_label_lines:
|
1198
|
+
filtered_domain_centroids[domain] = domain_centroid
|
1199
|
+
filtered_domain_terms[domain] = domain_terms
|
1200
|
+
# Add the index of the domain to the valid indices list
|
1201
|
+
valid_indices.append(list(domain_id_to_centroid_map.keys()).index(domain))
|
1202
|
+
return True
|
1203
|
+
|
1204
|
+
return False
|
1205
|
+
|
1135
1206
|
def _process_terms(
|
1136
1207
|
self,
|
1137
1208
|
domain: str,
|
@@ -1152,7 +1223,7 @@ class NetworkPlotter:
|
|
1152
1223
|
max_chars_per_line (int): Maximum number of characters in a line to display.
|
1153
1224
|
|
1154
1225
|
Returns:
|
1155
|
-
|
1226
|
+
str: Processed terms separated by TERM_DELIMITER, with words combined if necessary to fit within constraints.
|
1156
1227
|
"""
|
1157
1228
|
# Handle ids_to_replace logic
|
1158
1229
|
if ids_to_replace and domain in ids_to_replace:
|
@@ -1487,13 +1558,13 @@ def _calculate_bounding_box(
|
|
1487
1558
|
return center, radius
|
1488
1559
|
|
1489
1560
|
|
1490
|
-
def _combine_words(words: List[str],
|
1491
|
-
"""Combine words to fit within the
|
1492
|
-
and separate the final output by
|
1561
|
+
def _combine_words(words: List[str], max_chars_per_line: int, max_label_lines: int) -> str:
|
1562
|
+
"""Combine words to fit within the max_chars_per_line and max_label_lines constraints,
|
1563
|
+
and separate the final output by TERM_DELIMITER for plotting.
|
1493
1564
|
|
1494
1565
|
Args:
|
1495
1566
|
words (List[str]): List of words to combine.
|
1496
|
-
|
1567
|
+
max_chars_per_line (int): Maximum number of characters in a line to display.
|
1497
1568
|
max_label_lines (int): Maximum number of lines in a label.
|
1498
1569
|
|
1499
1570
|
Returns:
|
@@ -1510,14 +1581,18 @@ def _combine_words(words: List[str], max_length: int, max_label_lines: int) -> s
|
|
1510
1581
|
# Try to combine more words if possible, and ensure the combination fits within max_length
|
1511
1582
|
for j in range(i + 1, len(words_batch)):
|
1512
1583
|
next_word = words_batch[j]
|
1513
|
-
|
1584
|
+
# Ensure that the combined word fits within the max_chars_per_line limit
|
1585
|
+
if len(combined_word) + len(next_word) + 1 <= max_chars_per_line: # +1 for space
|
1514
1586
|
combined_word = f"{combined_word} {next_word}"
|
1515
1587
|
i += 1 # Move past the combined word
|
1516
1588
|
else:
|
1517
1589
|
break # Stop combining if the length is exceeded
|
1518
1590
|
|
1519
|
-
|
1520
|
-
|
1591
|
+
# Add the combined word only if it fits within the max_chars_per_line limit
|
1592
|
+
if len(combined_word) <= max_chars_per_line:
|
1593
|
+
combined_lines.append(combined_word) # Add the combined word
|
1594
|
+
# Move to the next word
|
1595
|
+
i += 1
|
1521
1596
|
|
1522
1597
|
# Stop if we've reached the max_label_lines limit
|
1523
1598
|
if len(combined_lines) >= max_label_lines:
|
@@ -1,4 +1,4 @@
|
|
1
|
-
risk/__init__.py,sha256=
|
1
|
+
risk/__init__.py,sha256=NEb1vT_sWtAGA_9YQ9jcZiU201G2LaBvb6-ayyoBAro,112
|
2
2
|
risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
|
3
3
|
risk/risk.py,sha256=FaQhDCBZxZSAXJsScH0rSbjjCTNZA5vgf9rJj1GHW44,20924
|
4
4
|
risk/annotations/__init__.py,sha256=vUpVvMRE5if01Ic8QY6M2Ae3EFGJHdugEe9PdEkAW4Y,138
|
@@ -15,7 +15,7 @@ risk/network/__init__.py,sha256=iEPeJdZfqp0toxtbElryB8jbz9_t_k4QQ3iDvKE8C_0,126
|
|
15
15
|
risk/network/geometry.py,sha256=H1yGVVqgbfpzBzJwEheDLfvGLSA284jGQQTn612L4Vc,6759
|
16
16
|
risk/network/graph.py,sha256=EwD4-1THC5YNdP6PY01Oe35k2QYYqtZpxWraPVH6wa4,16426
|
17
17
|
risk/network/io.py,sha256=kY7HqmL3wa1NnqHu61_G8IpT21qpBijpAZ4ixmsseJA,22911
|
18
|
-
risk/network/plot.py,sha256=
|
18
|
+
risk/network/plot.py,sha256=_Z2OSNJM6vBhpwfKUwU9IGRvIbr9uZVZzaEXwfyVa9M,81981
|
19
19
|
risk/stats/__init__.py,sha256=WcgoETQ-hS0LQqKRsAMIPtP15xZ-4eul6VUBuUx4Wzc,220
|
20
20
|
risk/stats/hypergeom.py,sha256=o6Qnj31gCAKxr2uQirXrbv7XvdDJGEq69MFW-ubx_hA,2272
|
21
21
|
risk/stats/poisson.py,sha256=8x9hB4DCukq4gNIlIKO-c_jYG1-BTwTX53oLauFyfj8,1793
|
@@ -23,8 +23,8 @@ risk/stats/stats.py,sha256=kvShov-94W6ffgDUTb522vB9hDJQSyTsYif_UIaFfSM,7059
|
|
23
23
|
risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
|
24
24
|
risk/stats/permutation/permutation.py,sha256=D84Rcpt6iTQniK0PfQGcw9bLcHbMt9p-ARcurUnIXZQ,10095
|
25
25
|
risk/stats/permutation/test_functions.py,sha256=lftOude6hee0pyR80HlBD32522JkDoN5hrKQ9VEbuoY,2345
|
26
|
-
risk_network-0.0.
|
27
|
-
risk_network-0.0.
|
28
|
-
risk_network-0.0.
|
29
|
-
risk_network-0.0.
|
30
|
-
risk_network-0.0.
|
26
|
+
risk_network-0.0.8b4.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
|
27
|
+
risk_network-0.0.8b4.dist-info/METADATA,sha256=wHiueFpwYZzcIRfiMlHztT4GHhZDxFTGKUuTPfXz7Jo,47450
|
28
|
+
risk_network-0.0.8b4.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
29
|
+
risk_network-0.0.8b4.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
|
30
|
+
risk_network-0.0.8b4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|