risk-network 0.0.11__py3-none-any.whl → 0.0.12__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 (45) hide show
  1. risk/__init__.py +1 -1
  2. risk/annotation/__init__.py +10 -0
  3. risk/{annotations/annotations.py → annotation/annotation.py} +44 -44
  4. risk/{annotations → annotation}/io.py +93 -92
  5. risk/{annotations → annotation}/nltk_setup.py +6 -5
  6. risk/log/__init__.py +1 -1
  7. risk/log/parameters.py +26 -27
  8. risk/neighborhoods/__init__.py +0 -1
  9. risk/neighborhoods/api.py +38 -38
  10. risk/neighborhoods/community.py +33 -4
  11. risk/neighborhoods/domains.py +26 -28
  12. risk/neighborhoods/neighborhoods.py +8 -2
  13. risk/neighborhoods/stats/__init__.py +13 -0
  14. risk/neighborhoods/stats/permutation/__init__.py +6 -0
  15. risk/{stats → neighborhoods/stats}/permutation/permutation.py +24 -21
  16. risk/{stats → neighborhoods/stats}/permutation/test_functions.py +4 -4
  17. risk/{stats/stat_tests.py → neighborhoods/stats/tests.py} +62 -54
  18. risk/network/__init__.py +0 -2
  19. risk/network/graph/__init__.py +0 -2
  20. risk/network/graph/api.py +19 -19
  21. risk/network/graph/graph.py +73 -68
  22. risk/{stats/significance.py → network/graph/stats.py} +2 -2
  23. risk/network/graph/summary.py +12 -13
  24. risk/network/io.py +163 -20
  25. risk/network/plotter/__init__.py +0 -2
  26. risk/network/plotter/api.py +1 -1
  27. risk/network/plotter/canvas.py +36 -36
  28. risk/network/plotter/contour.py +14 -15
  29. risk/network/plotter/labels.py +303 -294
  30. risk/network/plotter/network.py +6 -6
  31. risk/network/plotter/plotter.py +8 -10
  32. risk/network/plotter/utils/colors.py +15 -8
  33. risk/network/plotter/utils/layout.py +3 -3
  34. risk/risk.py +6 -6
  35. risk_network-0.0.12.dist-info/METADATA +122 -0
  36. risk_network-0.0.12.dist-info/RECORD +40 -0
  37. {risk_network-0.0.11.dist-info → risk_network-0.0.12.dist-info}/WHEEL +1 -1
  38. risk/annotations/__init__.py +0 -7
  39. risk/network/geometry.py +0 -150
  40. risk/stats/__init__.py +0 -15
  41. risk/stats/permutation/__init__.py +0 -6
  42. risk_network-0.0.11.dist-info/METADATA +0 -798
  43. risk_network-0.0.11.dist-info/RECORD +0 -41
  44. {risk_network-0.0.11.dist-info → risk_network-0.0.12.dist-info/licenses}/LICENSE +0 -0
  45. {risk_network-0.0.11.dist-info → risk_network-0.0.12.dist-info}/top_level.txt +0 -0
@@ -76,7 +76,7 @@ class Canvas:
76
76
  fig = self.ax.figure
77
77
  # Use a tight layout to ensure that title and subtitle do not overlap with the original plot
78
78
  fig.tight_layout(
79
- rect=[0, 0, 1, 1 - title_space_offset]
79
+ rect=(0, 0, 1, 1 - title_space_offset)
80
80
  ) # Leave space above the plot for title
81
81
 
82
82
  # Plot title if provided
@@ -158,7 +158,7 @@ class Canvas:
158
158
  # Calculate the center and radius of the bounding box around the network
159
159
  center, radius = calculate_bounding_box(node_coordinates)
160
160
  # Adjust the center based on user-defined offsets
161
- adjusted_center = _calculate_adjusted_center(
161
+ adjusted_center = self._calculate_adjusted_center(
162
162
  center, radius, center_offset_x, center_offset_y
163
163
  )
164
164
  # Scale the radius by the scale factor
@@ -250,42 +250,42 @@ class Canvas:
250
250
  fill_alpha=fill_alpha,
251
251
  )
252
252
 
253
+ def _calculate_adjusted_center(
254
+ self,
255
+ center: Tuple[float, float],
256
+ radius: float,
257
+ center_offset_x: float = 0.0,
258
+ center_offset_y: float = 0.0,
259
+ ) -> Tuple[float, float]:
260
+ """Calculate the adjusted center for the network perimeter circle based on user-defined offsets.
253
261
 
254
- def _calculate_adjusted_center(
255
- center: Tuple[float, float],
256
- radius: float,
257
- center_offset_x: float = 0.0,
258
- center_offset_y: float = 0.0,
259
- ) -> Tuple[float, float]:
260
- """Calculate the adjusted center for the network perimeter circle based on user-defined offsets.
261
-
262
- Args:
263
- center (Tuple[float, float]): Original center coordinates of the network graph.
264
- radius (float): Radius of the bounding box around the network.
265
- center_offset_x (float, optional): Horizontal offset as a fraction of the diameter.
266
- Negative values shift the center left, positive values shift it right. Allowed
267
- values are in the range [-1, 1]. Defaults to 0.0.
268
- center_offset_y (float, optional): Vertical offset as a fraction of the diameter.
269
- Negative values shift the center down, positive values shift it up. Allowed
270
- values are in the range [-1, 1]. Defaults to 0.0.
262
+ Args:
263
+ center (Tuple[float, float]): Original center coordinates of the network graph.
264
+ radius (float): Radius of the bounding box around the network.
265
+ center_offset_x (float, optional): Horizontal offset as a fraction of the diameter.
266
+ Negative values shift the center left, positive values shift it right. Allowed
267
+ values are in the range [-1, 1]. Defaults to 0.0.
268
+ center_offset_y (float, optional): Vertical offset as a fraction of the diameter.
269
+ Negative values shift the center down, positive values shift it up. Allowed
270
+ values are in the range [-1, 1]. Defaults to 0.0.
271
271
 
272
- Returns:
273
- Tuple[float, float]: Adjusted center coordinates after applying the offsets.
272
+ Returns:
273
+ Tuple[float, float]: Adjusted center coordinates after applying the offsets.
274
274
 
275
- Raises:
276
- ValueError: If the center offsets are outside the valid range [-1, 1].
277
- """
278
- # Flip the y-axis to match the plot orientation
279
- flipped_center_offset_y = -center_offset_y
280
- # Validate the center offsets
281
- if not -1 <= center_offset_x <= 1:
282
- raise ValueError("Horizontal center offset must be in the range [-1, 1].")
283
- if not -1 <= center_offset_y <= 1:
284
- raise ValueError("Vertical center offset must be in the range [-1, 1].")
275
+ Raises:
276
+ ValueError: If the center offsets are outside the valid range [-1, 1].
277
+ """
278
+ # Flip the y-axis to match the plot orientation
279
+ flipped_center_offset_y = -center_offset_y
280
+ # Validate the center offsets
281
+ if not -1 <= center_offset_x <= 1:
282
+ raise ValueError("Horizontal center offset must be in the range [-1, 1].")
283
+ if not -1 <= center_offset_y <= 1:
284
+ raise ValueError("Vertical center offset must be in the range [-1, 1].")
285
285
 
286
- # Calculate adjusted center by applying offset fractions of the diameter
287
- adjusted_center_x = center[0] + (center_offset_x * radius * 2)
288
- adjusted_center_y = center[1] + (flipped_center_offset_y * radius * 2)
286
+ # Calculate adjusted center by applying offset fractions of the diameter
287
+ adjusted_center_x = center[0] + (center_offset_x * radius * 2)
288
+ adjusted_center_y = center[1] + (flipped_center_offset_y * radius * 2)
289
289
 
290
- # Return the adjusted center coordinates
291
- return adjusted_center_x, adjusted_center_y
290
+ # Return the adjusted center coordinates
291
+ return adjusted_center_x, adjusted_center_y
@@ -11,7 +11,7 @@ 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 params, logger
14
+ from risk.log import logger, params
15
15
  from risk.network.graph.graph import Graph
16
16
  from risk.network.plotter.utils.colors import get_annotated_domain_colors, to_rgba
17
17
 
@@ -213,7 +213,7 @@ class Contour:
213
213
  ]
214
214
  z = kde(np.vstack([x.ravel(), y.ravel()])).reshape(x.shape)
215
215
  # Check if the KDE forms a single connected component
216
- connected = _is_connected(z)
216
+ connected = self._is_connected(z)
217
217
  if not connected:
218
218
  bandwidth += 0.05 # Increase bandwidth slightly and retry
219
219
  except linalg.LinAlgError:
@@ -282,8 +282,8 @@ class Contour:
282
282
  scale_factor: float = 1.0,
283
283
  ids_to_colors: Union[Dict[int, Any], None] = None,
284
284
  random_seed: int = 888,
285
- ) -> np.ndarray:
286
- """Get colors for the contours based on node annotations or a specified colormap.
285
+ ) -> List[Tuple]:
286
+ """Get colors for the contours based on node annotation or a specified colormap.
287
287
 
288
288
  Args:
289
289
  cmap (str, optional): Name of the colormap to use for generating contour colors. Defaults to "gist_rainbow".
@@ -301,7 +301,7 @@ class Contour:
301
301
  random_seed (int, optional): Seed for random number generation to ensure reproducibility. Defaults to 888.
302
302
 
303
303
  Returns:
304
- np.ndarray: Array of RGBA colors for contour annotations.
304
+ List[Tuple]: List of RGBA colors for the contours, one for each domain in the network graph.
305
305
  """
306
306
  return get_annotated_domain_colors(
307
307
  graph=self.graph,
@@ -316,15 +316,14 @@ class Contour:
316
316
  random_seed=random_seed,
317
317
  )
318
318
 
319
+ def _is_connected(self, z: np.ndarray) -> bool:
320
+ """Determine if a thresholded grid represents a single, connected component.
319
321
 
320
- def _is_connected(z: np.ndarray) -> bool:
321
- """Determine if a thresholded grid represents a single, connected component.
322
-
323
- Args:
324
- z (np.ndarray): A binary grid where the component connectivity is evaluated.
322
+ Args:
323
+ z (np.ndarray): A binary grid where the component connectivity is evaluated.
325
324
 
326
- Returns:
327
- bool: True if the grid represents a single connected component, False otherwise.
328
- """
329
- _, num_features = label(z)
330
- return num_features == 1 # Return True if only one connected component is found
325
+ Returns:
326
+ bool: True if the grid represents a single connected component, False otherwise.
327
+ """
328
+ _, num_features = label(z)
329
+ return num_features == 1 # Return True if only one connected component is found