topologicpy 0.8.43__py3-none-any.whl → 0.8.45__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.
- topologicpy/Color.py +37 -1
- topologicpy/Graph.py +265 -95
- topologicpy/Topology.py +13 -9
- topologicpy/version.py +1 -1
- {topologicpy-0.8.43.dist-info → topologicpy-0.8.45.dist-info}/METADATA +1 -1
- {topologicpy-0.8.43.dist-info → topologicpy-0.8.45.dist-info}/RECORD +9 -9
- {topologicpy-0.8.43.dist-info → topologicpy-0.8.45.dist-info}/WHEEL +0 -0
- {topologicpy-0.8.43.dist-info → topologicpy-0.8.45.dist-info}/licenses/LICENSE +0 -0
- {topologicpy-0.8.43.dist-info → topologicpy-0.8.45.dist-info}/top_level.txt +0 -0
topologicpy/Color.py
CHANGED
@@ -19,6 +19,40 @@ import math
|
|
19
19
|
|
20
20
|
class Color:
|
21
21
|
|
22
|
+
def AddHex(*colors):
|
23
|
+
"""
|
24
|
+
Adds the input hexadecimal color codes channel-wise, clipping each channel to a max of 255.
|
25
|
+
|
26
|
+
Parameters
|
27
|
+
----------
|
28
|
+
colors : *list or str
|
29
|
+
The input list of hexadecimal colors.
|
30
|
+
|
31
|
+
Returns
|
32
|
+
-------
|
33
|
+
str
|
34
|
+
The resulting hex color after addition (e.g., "#FF88FF").
|
35
|
+
"""
|
36
|
+
import inspect
|
37
|
+
from topologicpy.Helper import Helper
|
38
|
+
|
39
|
+
def add(hex1, hex2):
|
40
|
+
# Remove "#" if present
|
41
|
+
hex1 = hex1.lstrip('#')
|
42
|
+
hex2 = hex2.lstrip('#')
|
43
|
+
|
44
|
+
# Convert to RGB integers
|
45
|
+
r1, g1, b1 = int(hex1[0:2], 16), int(hex1[2:4], 16), int(hex1[4:6], 16)
|
46
|
+
r2, g2, b2 = int(hex2[0:2], 16), int(hex2[2:4], 16), int(hex2[4:6], 16)
|
47
|
+
|
48
|
+
# Add each channel, clip to 255
|
49
|
+
r = min(r1 + r2, 255)
|
50
|
+
g = min(g1 + g2, 255)
|
51
|
+
b = min(b1 + b2, 255)
|
52
|
+
|
53
|
+
# Return as hex string
|
54
|
+
return f"#{r:02X}{g:02X}{b:02X}"
|
55
|
+
|
22
56
|
@staticmethod
|
23
57
|
def AnyToHex(color):
|
24
58
|
"""
|
@@ -35,6 +69,8 @@ class Color:
|
|
35
69
|
A hexadecimal color string in the format '#RRGGBB'.
|
36
70
|
"""
|
37
71
|
return_hex = None
|
72
|
+
if isinstance(color, list) and all(isinstance(item, str) for item in color):
|
73
|
+
return Color.Average(color)
|
38
74
|
if isinstance(color, list):
|
39
75
|
if len(color) == 4: # Probably CMYK
|
40
76
|
if all(0 <= x <= 1 for x in color[:4]):
|
@@ -56,7 +92,7 @@ class Color:
|
|
56
92
|
return return_hex.upper()
|
57
93
|
|
58
94
|
@staticmethod
|
59
|
-
def
|
95
|
+
def Average(*colors, silent: bool = False):
|
60
96
|
"""
|
61
97
|
Averages the input list of hex colors.
|
62
98
|
|
topologicpy/Graph.py
CHANGED
@@ -4575,6 +4575,56 @@ class Graph:
|
|
4575
4575
|
edges = [e for e in edges if Topology.IsInstance(e, "Edge")]
|
4576
4576
|
return topologic.Graph.ByVerticesEdges(vertices, edges) # Hook to Core
|
4577
4577
|
|
4578
|
+
@staticmethod
|
4579
|
+
def Choice(graph, method: str = "vertex", weightKey="length", normalize: bool = False, nxCompatible: bool = False, key: str = "choice", colorKey="ch_color", colorScale="viridis", mantissa: int = 6, tolerance: float = 0.001, silent: bool = False):
|
4580
|
+
"""
|
4581
|
+
This is an alias method for Graph.BetweenessCentrality. Returns the choice (Betweeness Centrality) of the input graph. The order of the returned list is the same as the order of vertices/edges. See https://en.wikipedia.org/wiki/Betweenness_centrality.
|
4582
|
+
|
4583
|
+
Parameters
|
4584
|
+
----------
|
4585
|
+
graph : topologic_core.Graph
|
4586
|
+
The input graph.
|
4587
|
+
method : str , optional
|
4588
|
+
The method of computing the betweenness centrality. The options are "vertex" or "edge". The default is "vertex".
|
4589
|
+
weightKey : str , optional
|
4590
|
+
If specified, the value in the connected edges' dictionary specified by the weightKey string will be aggregated to calculate
|
4591
|
+
the shortest path. If a numeric value cannot be retrieved from an edge, a value of 1 is used instead.
|
4592
|
+
This is used in weighted graphs. if weightKey is set to "Length" or "Distance", the length of the edge will be used as its weight.
|
4593
|
+
normalize : bool , optional
|
4594
|
+
If set to True, the values are normalized to be in the range 0 to 1. Otherwise they are not. The default is False.
|
4595
|
+
nxCompatible : bool , optional
|
4596
|
+
If set to True, and normalize input parameter is also set to True, the values are set to be identical to NetworkX values. Otherwise, they are normalized between 0 and 1. The default is False.
|
4597
|
+
key : str , optional
|
4598
|
+
The desired dictionary key under which to store the betweenness centrality score. The default is "betweenness_centrality".
|
4599
|
+
colorKey : str , optional
|
4600
|
+
The desired dictionary key under which to store the betweenness centrality color. The default is "betweenness_centrality".
|
4601
|
+
colorScale : str , optional
|
4602
|
+
The desired type of plotly color scales to use (e.g. "viridis", "plasma"). The default is "viridis". For a full list of names, see https://plotly.com/python/builtin-colorscales/.
|
4603
|
+
In addition to these, three color-blind friendly scales are included. These are "protanopia", "deuteranopia", and "tritanopia" for red, green, and blue colorblindness respectively.
|
4604
|
+
mantissa : int , optional
|
4605
|
+
The desired length of the mantissa. The default is 6.
|
4606
|
+
tolerance : float , optional
|
4607
|
+
The desired tolerance. The default is 0.0001.
|
4608
|
+
|
4609
|
+
Returns
|
4610
|
+
-------
|
4611
|
+
list
|
4612
|
+
The choice (betweenness centrality) of the input list of vertices within the input graph. The values are in the range 0 to 1.
|
4613
|
+
|
4614
|
+
"""
|
4615
|
+
return Graph.BetweennessCentrality(graph,
|
4616
|
+
method=method,
|
4617
|
+
weightKey=weightKey,
|
4618
|
+
normalize=normalize,
|
4619
|
+
nxCompatible=nxCompatible,
|
4620
|
+
key=key,
|
4621
|
+
colorKey=colorKey,
|
4622
|
+
colorScale=colorScale,
|
4623
|
+
mantissa=mantissa,
|
4624
|
+
tolerance=tolerance,
|
4625
|
+
silent=silent)
|
4626
|
+
|
4627
|
+
|
4578
4628
|
@staticmethod
|
4579
4629
|
def ChromaticNumber(graph, maxColors: int = 3, silent: bool = False):
|
4580
4630
|
"""
|
@@ -5427,94 +5477,159 @@ class Graph:
|
|
5427
5477
|
graph = Graph.RemoveVertex(graph,ev, tolerance=tolerance)
|
5428
5478
|
return graph
|
5429
5479
|
|
5480
|
+
|
5430
5481
|
@staticmethod
|
5431
|
-
def ClosenessCentrality(
|
5482
|
+
def ClosenessCentrality(
|
5483
|
+
graph,
|
5484
|
+
weightKey: str = "length",
|
5485
|
+
normalize: bool = False,
|
5486
|
+
nxCompatible: bool = True,
|
5487
|
+
key: str = "closeness_centrality",
|
5488
|
+
colorKey: str = "cc_color",
|
5489
|
+
colorScale: str = "viridis",
|
5490
|
+
mantissa: int = 6,
|
5491
|
+
tolerance: float = 0.0001,
|
5492
|
+
silent: bool = False
|
5493
|
+
):
|
5432
5494
|
"""
|
5433
|
-
|
5495
|
+
Returns the closeness centrality of the input graph. The order of the returned
|
5496
|
+
list matches the order of Graph.Vertices(graph).
|
5497
|
+
See: https://en.wikipedia.org/wiki/Closeness_centrality
|
5434
5498
|
|
5435
5499
|
Parameters
|
5436
5500
|
----------
|
5437
5501
|
graph : topologic_core.Graph
|
5438
5502
|
The input graph.
|
5439
5503
|
weightKey : str , optional
|
5440
|
-
If specified,
|
5441
|
-
|
5442
|
-
|
5504
|
+
If specified, this edge attribute will be used as the distance weight when
|
5505
|
+
computing shortest paths. If set to a name containing "Length" or "Distance",
|
5506
|
+
it will be mapped to "length".
|
5507
|
+
Note: Graph.NetworkXGraph automatically provides a "length" attribute on all edges.
|
5443
5508
|
normalize : bool , optional
|
5444
|
-
If
|
5509
|
+
If True, the returned values are rescaled to [0, 1]. Otherwise raw values
|
5510
|
+
from NetworkX (optionally using the improved formula) are returned.
|
5445
5511
|
nxCompatible : bool , optional
|
5446
|
-
If
|
5447
|
-
For single
|
5512
|
+
If True, use NetworkX's wf_improved scaling (Wasserman and Faust).
|
5513
|
+
For single-component graphs it matches the original formula.
|
5448
5514
|
key : str , optional
|
5449
|
-
The
|
5515
|
+
The dictionary key under which to store the closeness centrality score.
|
5450
5516
|
colorKey : str , optional
|
5451
|
-
The
|
5517
|
+
The dictionary key under which to store a color derived from the score.
|
5452
5518
|
colorScale : str , optional
|
5453
|
-
|
5454
|
-
In addition to these, three color-blind friendly scales are included. These are "protanopia", "deuteranopia", and "tritanopia" for red, green, and blue colorblindness respectively.
|
5519
|
+
Plotly color scale name (e.g., "viridis", "plasma").
|
5455
5520
|
mantissa : int , optional
|
5456
5521
|
The desired length of the mantissa. The default is 6.
|
5457
5522
|
tolerance : float , optional
|
5458
5523
|
The desired tolerance. The default is 0.0001.
|
5524
|
+
silent : bool , optional
|
5525
|
+
If set to True, error and warning messages are suppressed. The default is False.
|
5459
5526
|
|
5460
5527
|
Returns
|
5461
5528
|
-------
|
5462
|
-
list
|
5463
|
-
|
5464
|
-
|
5529
|
+
list[float]
|
5530
|
+
Closeness centrality values for vertices in the same order as Graph.Vertices(graph).
|
5465
5531
|
"""
|
5466
5532
|
import warnings
|
5467
|
-
|
5468
5533
|
try:
|
5469
5534
|
import networkx as nx
|
5470
|
-
except:
|
5471
|
-
|
5472
|
-
|
5473
|
-
|
5474
|
-
|
5475
|
-
|
5476
|
-
try:
|
5477
|
-
import networkx as nx
|
5478
|
-
print("Graph.ClosenessCentrality - Infromation: networkx library installed correctly.")
|
5479
|
-
except:
|
5480
|
-
warnings.warn("Graph.ClosenessCentrality - Error: Could not import networkx. Please try to install networkx manually. Returning None.")
|
5481
|
-
return None
|
5482
|
-
|
5535
|
+
except Exception as e:
|
5536
|
+
warnings.warn(
|
5537
|
+
f"Graph.ClosenessCentrality - Error: networkx is required but not installed ({e}). Returning None."
|
5538
|
+
)
|
5539
|
+
return None
|
5540
|
+
|
5483
5541
|
from topologicpy.Dictionary import Dictionary
|
5484
5542
|
from topologicpy.Color import Color
|
5485
5543
|
from topologicpy.Topology import Topology
|
5486
5544
|
from topologicpy.Helper import Helper
|
5487
5545
|
|
5546
|
+
# Topology.IsInstance is case-insensitive, so a single call is sufficient.
|
5488
5547
|
if not Topology.IsInstance(graph, "graph"):
|
5489
5548
|
if not silent:
|
5490
|
-
print("Graph.ClosenessCentrality - Error: The input
|
5549
|
+
print("Graph.ClosenessCentrality - Error: The input is not a valid Graph. Returning None.")
|
5491
5550
|
return None
|
5492
|
-
|
5493
|
-
if
|
5494
|
-
if
|
5551
|
+
vertices = Graph.Vertices(graph)
|
5552
|
+
if len(vertices) == 0:
|
5553
|
+
if not silent:
|
5554
|
+
print("Graph.ClosenessCentrality - Warning: Graph has no vertices. Returning [].")
|
5555
|
+
return []
|
5556
|
+
|
5557
|
+
# Normalize the weight key semantics
|
5558
|
+
distance_attr = None
|
5559
|
+
if isinstance(weightKey, str) and weightKey:
|
5560
|
+
if ("len" in weightKey.lower()) or ("dis" in weightKey.lower()):
|
5495
5561
|
weightKey = "length"
|
5562
|
+
distance_attr = weightKey
|
5563
|
+
|
5564
|
+
# Build the NX graph
|
5496
5565
|
nx_graph = Graph.NetworkXGraph(graph)
|
5497
|
-
|
5498
|
-
|
5499
|
-
|
5500
|
-
if
|
5501
|
-
|
5502
|
-
|
5566
|
+
|
5567
|
+
# Graph.NetworkXGraph automatically adds "length" to all edges.
|
5568
|
+
# So if distance_attr == "length", we trust it and skip per-edge checks.
|
5569
|
+
if distance_attr and distance_attr != "length":
|
5570
|
+
# For any non-"length" custom attribute, verify presence; else fall back unweighted.
|
5571
|
+
attr_missing = any(
|
5572
|
+
(distance_attr not in data) or (data[distance_attr] is None)
|
5573
|
+
for _, _, data in nx_graph.edges(data=True)
|
5574
|
+
)
|
5575
|
+
if attr_missing:
|
5576
|
+
if not silent:
|
5577
|
+
print("Graph.ClosenessCentrality - Warning: The specified edge attribute was not found on all edges. Falling back to unweighted closeness.")
|
5578
|
+
distance_arg = None
|
5503
5579
|
else:
|
5504
|
-
|
5505
|
-
min_value = 0
|
5506
|
-
max_value = 1
|
5580
|
+
distance_arg = distance_attr
|
5507
5581
|
else:
|
5508
|
-
|
5509
|
-
|
5582
|
+
# Use "length" directly or unweighted if distance_attr is falsy.
|
5583
|
+
distance_arg = distance_attr if distance_attr else None
|
5510
5584
|
|
5511
|
-
|
5585
|
+
# Compute centrality (dict keyed by NetworkX nodes)
|
5586
|
+
try:
|
5587
|
+
cc_dict = nx.closeness_centrality(nx_graph, distance=distance_arg, wf_improved=nxCompatible)
|
5588
|
+
except Exception as e:
|
5589
|
+
if not silent:
|
5590
|
+
print(f"Graph.ClosenessCentrality - Error: NetworkX failed to compute centrality ({e}). Returning None.")
|
5591
|
+
return None
|
5592
|
+
|
5593
|
+
# NetworkX vertex ids are in the same numerice order as the list of vertices starting from 0.
|
5594
|
+
raw_values = []
|
5595
|
+
for i, v in enumerate(vertices):
|
5596
|
+
try:
|
5597
|
+
raw_values.append(float(cc_dict.get(i, 0.0)))
|
5598
|
+
except Exception:
|
5599
|
+
if not silent:
|
5600
|
+
print(f,"Graph.ClosenessCentrality - Warning: Could not retrieve score for vertex {i}. Assigning a Zero (0).")
|
5601
|
+
raw_values.append(0.0)
|
5602
|
+
|
5603
|
+
# Optional normalization ONLY once, then rounding once at the end
|
5604
|
+
values_for_return = Helper.Normalize(raw_values) if normalize else raw_values
|
5605
|
+
|
5606
|
+
# Values for color scaling should reflect the displayed numbers
|
5607
|
+
color_values = values_for_return
|
5608
|
+
|
5609
|
+
# Single rounding at the end for return values
|
5610
|
+
if mantissa is not None and mantissa >= 0:
|
5611
|
+
values_for_return = [round(v, mantissa) for v in values_for_return]
|
5612
|
+
|
5613
|
+
# Prepare color mapping range, guarding equal-range case
|
5614
|
+
if color_values:
|
5615
|
+
min_value = min(color_values)
|
5616
|
+
max_value = max(color_values)
|
5617
|
+
else:
|
5618
|
+
min_value, max_value = 0.0, 1.0
|
5619
|
+
|
5620
|
+
if abs(max_value - min_value) < tolerance:
|
5621
|
+
max_value = min_value + tolerance
|
5622
|
+
|
5623
|
+
# Annotate vertices with score and color
|
5624
|
+
for i, value in enumerate(color_values):
|
5512
5625
|
d = Topology.Dictionary(vertices[i])
|
5513
|
-
|
5514
|
-
|
5626
|
+
color_hex = Color.AnyToHex(
|
5627
|
+
Color.ByValueInRange(value, minValue=min_value, maxValue=max_value, colorScale=colorScale)
|
5628
|
+
)
|
5629
|
+
d = Dictionary.SetValuesAtKeys(d, [key, colorKey], [values_for_return[i], color_hex])
|
5515
5630
|
vertices[i] = Topology.SetDictionary(vertices[i], d)
|
5516
5631
|
|
5517
|
-
return
|
5632
|
+
return values_for_return
|
5518
5633
|
|
5519
5634
|
@staticmethod
|
5520
5635
|
def Community(graph, key: str = "partition", mantissa: int = 6, tolerance: float = 0.0001, silent: bool = False):
|
@@ -5684,7 +5799,7 @@ class Graph:
|
|
5684
5799
|
@staticmethod
|
5685
5800
|
def Connectivity(graph, vertices=None, weightKey: str = None, normalize: bool = False, key: str = "connectivity", colorKey: str = "cn_color", colorScale="Viridis", mantissa: int = 6, tolerance = 0.0001, silent = False):
|
5686
5801
|
"""
|
5687
|
-
Return the connectivity measure of the input list of vertices within the input graph. The order of the returned list is the same as the order of the input list of vertices. If no vertices are specified, the connectivity of all the vertices in the input graph is computed. See https://www.spacesyntax.online/term/connectivity/.
|
5802
|
+
This is an alias method for Graph.DegreeCentrality. Return the connectivity measure of the input list of vertices within the input graph. The order of the returned list is the same as the order of the input list of vertices. If no vertices are specified, the connectivity of all the vertices in the input graph is computed. See https://www.spacesyntax.online/term/connectivity/.
|
5688
5803
|
|
5689
5804
|
Parameters
|
5690
5805
|
----------
|
@@ -5718,38 +5833,17 @@ class Graph:
|
|
5718
5833
|
The connectivity score of the input list of vertices within the input graph. The values are in the range 0 to 1 if normalized.
|
5719
5834
|
|
5720
5835
|
"""
|
5721
|
-
|
5722
|
-
|
5723
|
-
|
5724
|
-
|
5725
|
-
|
5726
|
-
|
5727
|
-
|
5728
|
-
|
5729
|
-
|
5730
|
-
|
5731
|
-
if vertices == None:
|
5732
|
-
vertices = Graph.Vertices(graph)
|
5733
|
-
values = [Graph.VertexDegree(graph, v, weightKey=weightKey, mantissa=mantissa, tolerance=tolerance, silent=silent) for v in vertices]
|
5734
|
-
values = [round(v, mantissa) for v in values]
|
5735
|
-
if normalize == True:
|
5736
|
-
if mantissa > 0:
|
5737
|
-
values = [round(v, mantissa) for v in Helper.Normalize(values)]
|
5738
|
-
else:
|
5739
|
-
values = Helper.Normalize(values)
|
5740
|
-
min_value = 0
|
5741
|
-
max_value = 1
|
5742
|
-
else:
|
5743
|
-
min_value = min(values)
|
5744
|
-
max_value = max(values)
|
5836
|
+
return Graph.DegreeCentrality(graph=graph,
|
5837
|
+
vertices=vertices,
|
5838
|
+
weightKey=weightKey,
|
5839
|
+
normalize=normalize,
|
5840
|
+
key="connectivity",
|
5841
|
+
colorKey=colorKey,
|
5842
|
+
colorScale=colorScale,
|
5843
|
+
mantissa=mantissa,
|
5844
|
+
tolerance=tolerance,
|
5845
|
+
silent=silent)
|
5745
5846
|
|
5746
|
-
for i, value in enumerate(values):
|
5747
|
-
color = Color.AnyToHex(Color.ByValueInRange(value, minValue=min_value, maxValue=max_value, colorScale=colorScale))
|
5748
|
-
d = Topology.Dictionary(vertices[i])
|
5749
|
-
d = Dictionary.SetValuesAtKeys(d, [key, colorKey], [value, color])
|
5750
|
-
v = Topology.SetDictionary(vertices[i], d)
|
5751
|
-
return values
|
5752
|
-
|
5753
5847
|
@staticmethod
|
5754
5848
|
def ContainsEdge(graph, edge, tolerance=0.0001):
|
5755
5849
|
"""
|
@@ -5884,7 +5978,7 @@ class Graph:
|
|
5884
5978
|
tolerance: float = 0.001,
|
5885
5979
|
silent: bool = False):
|
5886
5980
|
"""
|
5887
|
-
|
5981
|
+
Returns the degree centrality of the input graph. The order of the returned list is the same as the order of vertices. See https://en.wikipedia.org/wiki/Degree_centrality.
|
5888
5982
|
|
5889
5983
|
Parameters
|
5890
5984
|
----------
|
@@ -5911,30 +6005,42 @@ class Graph:
|
|
5911
6005
|
Returns
|
5912
6006
|
-------
|
5913
6007
|
list
|
5914
|
-
The
|
6008
|
+
The degree centrality of the input list of vertices within the input graph. The values are in the range 0 to 1.
|
5915
6009
|
|
5916
6010
|
"""
|
5917
6011
|
|
5918
|
-
from topologicpy.Dictionary import Dictionary
|
5919
|
-
from topologicpy.Color import Color
|
5920
6012
|
from topologicpy.Topology import Topology
|
6013
|
+
from topologicpy.Dictionary import Dictionary
|
5921
6014
|
from topologicpy.Helper import Helper
|
6015
|
+
from topologicpy.Color import Color
|
5922
6016
|
|
5923
|
-
if not Topology.IsInstance(graph, "
|
6017
|
+
if not Topology.IsInstance(graph, "Graph"):
|
5924
6018
|
if not silent:
|
5925
6019
|
print("Graph.DegreeCentrality - Error: The input graph is not a valid graph. Returning None.")
|
5926
6020
|
return None
|
6021
|
+
if vertices == None:
|
6022
|
+
vertices = Graph.Vertices(graph)
|
6023
|
+
values = [Graph.VertexDegree(graph, v, weightKey=weightKey, mantissa=mantissa, tolerance=tolerance, silent=silent) for v in vertices]
|
6024
|
+
if normalize == True:
|
6025
|
+
if mantissa > 0:
|
6026
|
+
values = [round(v, mantissa) for v in Helper.Normalize(values)]
|
6027
|
+
else:
|
6028
|
+
values = Helper.Normalize(values)
|
6029
|
+
min_value = 0
|
6030
|
+
max_value = 1
|
6031
|
+
else:
|
6032
|
+
min_value = min(values)
|
6033
|
+
max_value = max(values)
|
6034
|
+
|
6035
|
+
if abs(max_value - min_value) < tolerance:
|
6036
|
+
max_value = min_value + tolerance
|
5927
6037
|
|
5928
|
-
|
5929
|
-
|
5930
|
-
|
5931
|
-
|
5932
|
-
|
5933
|
-
|
5934
|
-
colorScale=colorScale,
|
5935
|
-
mantissa=mantissa,
|
5936
|
-
tolerance=tolerance,
|
5937
|
-
silent=silent)
|
6038
|
+
for i, value in enumerate(values):
|
6039
|
+
color = Color.AnyToHex(Color.ByValueInRange(value, minValue=min_value, maxValue=max_value, colorScale=colorScale))
|
6040
|
+
d = Topology.Dictionary(vertices[i])
|
6041
|
+
d = Dictionary.SetValuesAtKeys(d, [key, colorKey], [value, color])
|
6042
|
+
v = Topology.SetDictionary(vertices[i], d)
|
6043
|
+
return values
|
5938
6044
|
|
5939
6045
|
@staticmethod
|
5940
6046
|
def DegreeMatrix(graph):
|
@@ -9442,6 +9548,70 @@ class Graph:
|
|
9442
9548
|
incoming_vertices.append(Graph.NearestVertex(graph, sv))
|
9443
9549
|
return incoming_vertices
|
9444
9550
|
|
9551
|
+
@staticmethod
|
9552
|
+
def Integration(
|
9553
|
+
graph,
|
9554
|
+
weightKey: str = "length",
|
9555
|
+
normalize: bool = False,
|
9556
|
+
nxCompatible: bool = True,
|
9557
|
+
key: str = "integration",
|
9558
|
+
colorKey: str = "in_color",
|
9559
|
+
colorScale: str = "viridis",
|
9560
|
+
mantissa: int = 6,
|
9561
|
+
tolerance: float = 0.0001,
|
9562
|
+
silent: bool = False
|
9563
|
+
):
|
9564
|
+
"""
|
9565
|
+
This is an alias method for Graph.ClosenessCentrality. Returns the integration (closeness centrality) of the input graph. The order of the returned
|
9566
|
+
list matches the order of Graph.Vertices(graph).
|
9567
|
+
See: https://en.wikipedia.org/wiki/Closeness_centrality
|
9568
|
+
|
9569
|
+
Parameters
|
9570
|
+
----------
|
9571
|
+
graph : topologic_core.Graph
|
9572
|
+
The input graph.
|
9573
|
+
weightKey : str , optional
|
9574
|
+
If specified, this edge attribute will be used as the distance weight when
|
9575
|
+
computing shortest paths. If set to a name containing "Length" or "Distance",
|
9576
|
+
it will be mapped to "length".
|
9577
|
+
Note: Graph.NetworkXGraph automatically provides a "length" attribute on all edges.
|
9578
|
+
normalize : bool , optional
|
9579
|
+
If True, the returned values are rescaled to [0, 1]. Otherwise raw values
|
9580
|
+
from NetworkX (optionally using the improved formula) are returned.
|
9581
|
+
nxCompatible : bool , optional
|
9582
|
+
If True, use NetworkX's wf_improved scaling (Wasserman and Faust).
|
9583
|
+
For single-component graphs it matches the original formula.
|
9584
|
+
key : str , optional
|
9585
|
+
The dictionary key under which to store the closeness centrality score.
|
9586
|
+
colorKey : str , optional
|
9587
|
+
The dictionary key under which to store a color derived from the score.
|
9588
|
+
colorScale : str , optional
|
9589
|
+
Plotly color scale name (e.g., "viridis", "plasma").
|
9590
|
+
mantissa : int , optional
|
9591
|
+
The desired length of the mantissa. The default is 6.
|
9592
|
+
tolerance : float , optional
|
9593
|
+
The desired tolerance. The default is 0.0001.
|
9594
|
+
silent : bool , optional
|
9595
|
+
If set to True, error and warning messages are suppressed. The default is False.
|
9596
|
+
|
9597
|
+
Returns
|
9598
|
+
-------
|
9599
|
+
list[float]
|
9600
|
+
Integration (closeness centrality) values for vertices in the same order as Graph.Vertices(graph).
|
9601
|
+
"""
|
9602
|
+
return Graph.ClosenessCentrality(
|
9603
|
+
graph,
|
9604
|
+
weightKey=weightKey,
|
9605
|
+
normalize=normalize,
|
9606
|
+
nxCompatible=nxCompatible,
|
9607
|
+
key=key,
|
9608
|
+
colorKey=colorKey,
|
9609
|
+
colorScale=colorScale,
|
9610
|
+
mantissa=mantissa,
|
9611
|
+
tolerance=tolerance,
|
9612
|
+
silent=silent
|
9613
|
+
)
|
9614
|
+
|
9445
9615
|
@staticmethod
|
9446
9616
|
def IsBipartite(graph, tolerance=0.0001):
|
9447
9617
|
"""
|
topologicpy/Topology.py
CHANGED
@@ -944,7 +944,7 @@ class Topology():
|
|
944
944
|
|
945
945
|
|
946
946
|
@staticmethod
|
947
|
-
def Inherit(targets, sources, keys: list = None, tolerance: float = 0.0001, silent: bool = False):
|
947
|
+
def Inherit(targets, sources, keys: list = None, exclusive: bool = True, tolerance: float = 0.0001, silent: bool = False):
|
948
948
|
"""
|
949
949
|
Transfers dictionary information from topologiesB to topologiesA based on co-location of internal vertices.
|
950
950
|
|
@@ -954,6 +954,8 @@ class Topology():
|
|
954
954
|
The list of target topologies that will inherit the dictionaries.
|
955
955
|
sources : list of topologic_core. Topology
|
956
956
|
The list of source topologies from which to inherit dictionary information.
|
957
|
+
exclusive : bool , optional
|
958
|
+
If set to True, a target will inherit information only from the first eligible source. The default is True.
|
957
959
|
tolerance : float , optional
|
958
960
|
The desired tolerance. The default is 0.0001.
|
959
961
|
silent : bool , optional
|
@@ -983,17 +985,19 @@ class Topology():
|
|
983
985
|
iv = Topology.InternalVertex(top_a, tolerance=tolerance, silent=silent)
|
984
986
|
d_a = Topology.Dictionary(top_a, silent=silent)
|
985
987
|
found = False
|
986
|
-
for top_b in topologies_b:
|
988
|
+
for j, top_b in enumerate(topologies_b):
|
987
989
|
if Vertex.IsInternal(iv, top_b, tolerance=tolerance, silent=silent):
|
988
990
|
d_b = Topology.Dictionary(top_b)
|
989
991
|
if isinstance(keys, list):
|
990
992
|
values = Dictionary.ValuesAtKeys(d_b, keys, silent=silent)
|
991
|
-
d_c = Dictionary.
|
993
|
+
d_c = Dictionary.ByKeysValues(keys, values)
|
994
|
+
d_a = Dictionary.ByMergedDictionaries(d_a, d_c, silent=silent)
|
992
995
|
else:
|
993
|
-
|
994
|
-
top_a = Topology.SetDictionary(top_a,
|
996
|
+
d_a = Dictionary.ByMergedDictionaries(d_a, d_b, silent=silent)
|
997
|
+
top_a = Topology.SetDictionary(top_a, d_a, silent=silent)
|
995
998
|
found = True
|
996
|
-
|
999
|
+
if exclusive:
|
1000
|
+
break
|
997
1001
|
if found == False:
|
998
1002
|
if not silent:
|
999
1003
|
print("Topology.Inherit - Warning: Could not find a source for target number: "+str(i+1)+". Consider increasing the tolerance value.")
|
@@ -4432,9 +4436,9 @@ class Topology():
|
|
4432
4436
|
if not silent:
|
4433
4437
|
print("Topology.Explode - Error: the input axes parameter is not a valid string. Returning None.")
|
4434
4438
|
return None
|
4435
|
-
if Topology.IsInstance(topology, "Topology"):
|
4436
|
-
|
4437
|
-
|
4439
|
+
# if Topology.IsInstance(topology, "Topology"):
|
4440
|
+
# # Hack to fix a weird bug that seems to be a problem with OCCT memory handling.
|
4441
|
+
# topology = Topology.ByJSONString(Topology.JSONString([topology]))[0]
|
4438
4442
|
axes = axes.lower()
|
4439
4443
|
x_flag = "x" in axes
|
4440
4444
|
y_flag = "y" in axes
|
topologicpy/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = '0.8.
|
1
|
+
__version__ = '0.8.45'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: topologicpy
|
3
|
-
Version: 0.8.
|
3
|
+
Version: 0.8.45
|
4
4
|
Summary: An AI-Powered Spatial Modelling and Analysis Software Library for Architecture, Engineering, and Construction.
|
5
5
|
Author-email: Wassim Jabi <wassim.jabi@gmail.com>
|
6
6
|
License: AGPL v3 License
|
@@ -5,14 +5,14 @@ topologicpy/CSG.py,sha256=uDkOSmc8m1V_k7T3UCerODhOSyYNO4FRDzoOqt0kEt8,15590
|
|
5
5
|
topologicpy/Cell.py,sha256=M4Xv4gabSgtKYYA-Wh0lgYEbRNRVF9zr4DYejOXJc-4,176278
|
6
6
|
topologicpy/CellComplex.py,sha256=c2B3mF1c3iwOfT-V0JWt9qNcFdd6DPR0aBOE2UnZTn4,61165
|
7
7
|
topologicpy/Cluster.py,sha256=wvfMAx6aPrSAt5nQ4--KnqD4EK9MGjch6Dg985WF7JQ,58748
|
8
|
-
topologicpy/Color.py,sha256=
|
8
|
+
topologicpy/Color.py,sha256=OTtXo9htNuOqZaZZpfK5BoLsJFJssauk3jbHzIBnWx8,24518
|
9
9
|
topologicpy/Context.py,sha256=G3CwMvN8Jw2rnQRwB-n4MaQq_wLS0vPimbXKwsdMJ80,3055
|
10
10
|
topologicpy/DGL.py,sha256=HQXy9iDnrvWGDxaBfe5pRbweQ2zLBvAf6UdjfhKkQYI,139041
|
11
11
|
topologicpy/Dictionary.py,sha256=sPskW5bopbDzLz6MGKm8lN_OeyeAgsqdLvwwNcG0J3g,44690
|
12
12
|
topologicpy/Edge.py,sha256=dLoAPuRKbjVg_dzloTgjRnQyv_05U9nfrtLO3tqyuys,74167
|
13
13
|
topologicpy/EnergyModel.py,sha256=Pyb28gDDwhzlQIH0xqAygqS0P3SJxWyyV7OWS_AAfRs,53856
|
14
14
|
topologicpy/Face.py,sha256=pN1fssyDLYWf1vU0NOBRx69DaUL958wRSxT-7VBCuCg,203184
|
15
|
-
topologicpy/Graph.py,sha256=
|
15
|
+
topologicpy/Graph.py,sha256=Qwc8SfAzoWGj_Op77QNyIVRx2iL79NJOkhO4Uu_xogE,655808
|
16
16
|
topologicpy/Grid.py,sha256=EbI2NcYhQDpD5mItd7A1Lpr8Puuf87vZPWuoh7_gChQ,18483
|
17
17
|
topologicpy/Helper.py,sha256=qEsE4yaboEGW94q9lFCff0I_JwwTTQnDAFXw006yHaQ,31203
|
18
18
|
topologicpy/Honeybee.py,sha256=yctkwfdupKnp7bAOjP1Z4YaYpRrWoMEb4gz9Z5zaWwE,21751
|
@@ -25,14 +25,14 @@ topologicpy/ShapeGrammar.py,sha256=UVb8VPwVKd6V3zDTNzpBecQPgYo1EjSsS10XJ8k5YcI,2
|
|
25
25
|
topologicpy/Shell.py,sha256=fx0WTndC8blkvWe38nKsJsI_AmklOA0qsjU0gbZp4b4,90501
|
26
26
|
topologicpy/Speckle.py,sha256=-eiTqJugd7pHiHpD3pDUcDO6CGhVyPV14HFRzaqEoaw,18187
|
27
27
|
topologicpy/Sun.py,sha256=_VBBAUIDhvpkp72JBZlv7k9qx9jYubm3yM56UZ1Nc6c,36837
|
28
|
-
topologicpy/Topology.py,sha256
|
28
|
+
topologicpy/Topology.py,sha256=-9hsN1PSvhH7qDo1HXjd545xteRZZY7-fxtxoBtU1Tw,471584
|
29
29
|
topologicpy/Vector.py,sha256=X12eqskn28bdB7sLY1EZhq3noPYzPbNEgHPb4a959ss,42302
|
30
30
|
topologicpy/Vertex.py,sha256=RlGQnxQSb_kAus3tJgXd-v-Ptubtt09PQPA9IMwfXmI,84835
|
31
31
|
topologicpy/Wire.py,sha256=sJE8qwqYOomvN3snMWmj2P2-Sq25ul_OQ95YFz6DFUw,230553
|
32
32
|
topologicpy/__init__.py,sha256=RMftibjgAnHB1vdL-muo71RwMS4972JCxHuRHOlU428,928
|
33
|
-
topologicpy/version.py,sha256=
|
34
|
-
topologicpy-0.8.
|
35
|
-
topologicpy-0.8.
|
36
|
-
topologicpy-0.8.
|
37
|
-
topologicpy-0.8.
|
38
|
-
topologicpy-0.8.
|
33
|
+
topologicpy/version.py,sha256=gbj_9V6jOG2ld32r54uMjnVmRZWWapq9d0kXO6shk_E,23
|
34
|
+
topologicpy-0.8.45.dist-info/licenses/LICENSE,sha256=FK0vJ73LuE8PYJAn7LutsReWR47-Ooovw2dnRe5yV6Q,681
|
35
|
+
topologicpy-0.8.45.dist-info/METADATA,sha256=wbkQITLteNvtJg6ctFuuwYjzLn3S-RC-_UhqZ9BWQzI,10535
|
36
|
+
topologicpy-0.8.45.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
37
|
+
topologicpy-0.8.45.dist-info/top_level.txt,sha256=J30bDzW92Ob7hw3zA8V34Jlp-vvsfIkGzkr8sqvb4Uw,12
|
38
|
+
topologicpy-0.8.45.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|