topologicpy 0.6.2__py3-none-any.whl → 0.7.0__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/Aperture.py +12 -13
- topologicpy/Cell.py +234 -210
- topologicpy/CellComplex.py +130 -118
- topologicpy/Cluster.py +108 -91
- topologicpy/Context.py +11 -7
- topologicpy/DGL.py +1 -1
- topologicpy/Dictionary.py +55 -65
- topologicpy/Edge.py +185 -148
- topologicpy/EnergyModel.py +23 -24
- topologicpy/Face.py +512 -313
- topologicpy/Graph.py +439 -351
- topologicpy/Grid.py +40 -43
- topologicpy/Honeybee.py +1 -1
- topologicpy/Matrix.py +28 -27
- topologicpy/Neo4j.py +5 -5
- topologicpy/Plotly.py +169 -53
- topologicpy/Shell.py +160 -145
- topologicpy/Sun.py +17 -13
- topologicpy/Topology.py +534 -766
- topologicpy/Vector.py +4 -3
- topologicpy/Vertex.py +145 -126
- topologicpy/Wire.py +542 -325
- topologicpy/version.py +1 -1
- {topologicpy-0.6.2.dist-info → topologicpy-0.7.0.dist-info}/METADATA +1 -1
- topologicpy-0.7.0.dist-info/RECORD +33 -0
- topologicpy-0.6.2.dist-info/RECORD +0 -33
- {topologicpy-0.6.2.dist-info → topologicpy-0.7.0.dist-info}/LICENSE +0 -0
- {topologicpy-0.6.2.dist-info → topologicpy-0.7.0.dist-info}/WHEEL +0 -0
- {topologicpy-0.6.2.dist-info → topologicpy-0.7.0.dist-info}/top_level.txt +0 -0
topologicpy/Plotly.py
CHANGED
@@ -14,40 +14,11 @@
|
|
14
14
|
# You should have received a copy of the GNU Affero General Public License along with
|
15
15
|
# this program. If not, see <https://www.gnu.org/licenses/>.
|
16
16
|
|
17
|
-
import topologicpy
|
18
17
|
import topologic_core as topologic
|
19
18
|
|
20
|
-
from topologicpy.Wire import Wire
|
21
|
-
from topologicpy.Face import Face
|
22
19
|
import os
|
23
20
|
import warnings
|
24
21
|
|
25
|
-
try:
|
26
|
-
import numpy as np
|
27
|
-
except:
|
28
|
-
print("Plotly - Installing required numpy library.")
|
29
|
-
try:
|
30
|
-
os.system("pip install numpy")
|
31
|
-
except:
|
32
|
-
os.system("pip install numpy --user")
|
33
|
-
try:
|
34
|
-
import numpy as np
|
35
|
-
except:
|
36
|
-
warnings.warn("Plotly - Error: Could not import numpy.")
|
37
|
-
|
38
|
-
try:
|
39
|
-
import pandas as pd
|
40
|
-
except:
|
41
|
-
print("Plotly - Installing required pandas library.")
|
42
|
-
try:
|
43
|
-
os.system("pip install pandas")
|
44
|
-
except:
|
45
|
-
os.system("pip install pandas --user")
|
46
|
-
try:
|
47
|
-
import pandas as pd
|
48
|
-
except:
|
49
|
-
warnings.warn("Plotly - Error: Could not import pandas.")
|
50
|
-
|
51
22
|
try:
|
52
23
|
import plotly
|
53
24
|
import plotly.graph_objects as go
|
@@ -93,6 +64,7 @@ class Plotly:
|
|
93
64
|
The units used in the color bar. The default is ""
|
94
65
|
colorScale : str , optional
|
95
66
|
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/.
|
67
|
+
In addition to these, three color-blind friendly scales are included. These are "protanopia", "deuteranopia", and "tritanopia" for red, green, and blue colorblindness respectively.
|
96
68
|
mantissa : int , optional
|
97
69
|
The desired length of the mantissa for the values listed on the color bar. The default is 6.
|
98
70
|
Returns
|
@@ -121,7 +93,7 @@ class Plotly:
|
|
121
93
|
showlegend=False,
|
122
94
|
marker=dict(
|
123
95
|
size=0,
|
124
|
-
colorscale=colorScale, # choose the colorscale
|
96
|
+
colorscale=Plotly.ColorScale(colorScale), # choose the colorscale
|
125
97
|
cmin=minValue,
|
126
98
|
cmax=maxValue,
|
127
99
|
color=['rgba(0,0,0,0)'],
|
@@ -202,7 +174,58 @@ class Plotly:
|
|
202
174
|
"violet","wheat","white",
|
203
175
|
"whitesmoke","yellow","yellowgreen"]
|
204
176
|
|
205
|
-
|
177
|
+
@staticmethod
|
178
|
+
def ColorScale(colorScale: str = "viridis"):
|
179
|
+
|
180
|
+
# Colors recommended by various sources for color-blind-friendly palettes
|
181
|
+
protanopia_colors = [
|
182
|
+
"#E69F00", # orange
|
183
|
+
"#56B4E9", # sky blue
|
184
|
+
"#009E73", # bluish green
|
185
|
+
"#F0E442", # yellow
|
186
|
+
"#0072B2", # blue
|
187
|
+
"#D55E00", # vermillion
|
188
|
+
"#CC79A7", # reddish purple
|
189
|
+
]
|
190
|
+
|
191
|
+
deuteranopia_colors = [
|
192
|
+
"#377EB8", # blue
|
193
|
+
"#FF7F00", # orange
|
194
|
+
"#4DAF4A", # green
|
195
|
+
"#F781BF", # pink
|
196
|
+
"#A65628", # brown
|
197
|
+
"#984EA3", # purple
|
198
|
+
"#999999", # grey
|
199
|
+
]
|
200
|
+
|
201
|
+
tritanopia_colors = [
|
202
|
+
"#E69F00", # orange
|
203
|
+
"#56B4E9", # sky blue
|
204
|
+
"#009E73", # bluish green
|
205
|
+
"#F0E442", # yellow
|
206
|
+
"#0072B2", # blue
|
207
|
+
"#D55E00", # vermillion
|
208
|
+
"#CC79A7", # reddish purple
|
209
|
+
]
|
210
|
+
|
211
|
+
# Create colorscales for Plotly
|
212
|
+
def create_colorscale(colors):
|
213
|
+
colorscale = []
|
214
|
+
num_colors = len(colors)
|
215
|
+
for i, color in enumerate(colors):
|
216
|
+
position = i / (num_colors - 1)
|
217
|
+
colorscale.append((position, color))
|
218
|
+
return colorscale
|
219
|
+
|
220
|
+
if "prota" in colorScale.lower():
|
221
|
+
return create_colorscale(protanopia_colors)
|
222
|
+
elif "deutera" in colorScale.lower():
|
223
|
+
return create_colorscale(deuteranopia_colors)
|
224
|
+
elif "trita"in colorScale.lower():
|
225
|
+
return create_colorscale(tritanopia_colors)
|
226
|
+
else:
|
227
|
+
return colorScale
|
228
|
+
|
206
229
|
@staticmethod
|
207
230
|
def DataByDGL(data, labels):
|
208
231
|
"""
|
@@ -222,6 +245,20 @@ class Plotly:
|
|
222
245
|
|
223
246
|
"""
|
224
247
|
|
248
|
+
try:
|
249
|
+
import pandas as pd
|
250
|
+
except:
|
251
|
+
print("Plotly - Installing required pandas library.")
|
252
|
+
try:
|
253
|
+
os.system("pip install pandas")
|
254
|
+
except:
|
255
|
+
os.system("pip install pandas --user")
|
256
|
+
try:
|
257
|
+
import pandas as pd
|
258
|
+
except:
|
259
|
+
warnings.warn("Plotly.DataByDGL - Error: Could not import pandas. Please install the pandas library manually. Returning None")
|
260
|
+
return None
|
261
|
+
|
225
262
|
if isinstance(data[labels[0]][0], int):
|
226
263
|
xAxis_list = list(range(1, data[labels[0]][0]+1))
|
227
264
|
else:
|
@@ -241,7 +278,7 @@ class Plotly:
|
|
241
278
|
|
242
279
|
Parameters
|
243
280
|
----------
|
244
|
-
graph :
|
281
|
+
graph : topologic_core.Graph
|
245
282
|
The input graph.
|
246
283
|
vertexColor : str , optional
|
247
284
|
The desired color of the output vertices. This can be any plotly color string and may be specified as:
|
@@ -298,7 +335,7 @@ class Plotly:
|
|
298
335
|
from topologicpy.Graph import Graph
|
299
336
|
import plotly.graph_objs as go
|
300
337
|
|
301
|
-
if not
|
338
|
+
if not Topology.IsInstance(graph, "Graph"):
|
302
339
|
return None
|
303
340
|
v_labels = []
|
304
341
|
v_groupList = []
|
@@ -352,7 +389,7 @@ class Plotly:
|
|
352
389
|
marker=dict(symbol='circle',
|
353
390
|
size=vertexSize,
|
354
391
|
color=v_groupList,
|
355
|
-
colorscale=colorScale,
|
392
|
+
colorscale=Plotly.ColorScale(colorScale),
|
356
393
|
line=dict(color=edgeColor, width=0.5)
|
357
394
|
),
|
358
395
|
text=v_labels,
|
@@ -448,13 +485,13 @@ class Plotly:
|
|
448
485
|
faceMinGroup=None, faceMaxGroup=None,
|
449
486
|
showFaceLegend=False, faceLegendLabel="Topology Faces", faceLegendRank=3,
|
450
487
|
faceLegendGroup=3,
|
451
|
-
intensityKey=None, intensities=[], colorScale="
|
488
|
+
intensityKey=None, intensities=[], colorScale="viridis", mantissa=6, tolerance=0.0001):
|
452
489
|
"""
|
453
490
|
Creates plotly face, edge, and vertex data.
|
454
491
|
|
455
492
|
Parameters
|
456
493
|
----------
|
457
|
-
topology :
|
494
|
+
topology : topologic_core.Topology
|
458
495
|
The input topology. This must contain faces and or edges.
|
459
496
|
|
460
497
|
showVertices : bool , optional
|
@@ -737,7 +774,7 @@ class Plotly:
|
|
737
774
|
def faceData(vertices, faces, dictionaries=None, color="#FAFAFA",
|
738
775
|
opacity=0.5, labelKey=None, groupKey=None,
|
739
776
|
minGroup=None, maxGroup=None, groups=[], legendLabel="Topology Faces",
|
740
|
-
legendGroup=3, legendRank=3, showLegend=True, intensities=None, colorScale="
|
777
|
+
legendGroup=3, legendRank=3, showLegend=True, intensities=None, colorScale="viridis"):
|
741
778
|
x = []
|
742
779
|
y = []
|
743
780
|
z = []
|
@@ -820,7 +857,7 @@ class Plotly:
|
|
820
857
|
legendrank = legendRank,
|
821
858
|
color = color,
|
822
859
|
facecolor = groupList,
|
823
|
-
colorscale = colorScale,
|
860
|
+
colorscale = Plotly.ColorScale(colorScale),
|
824
861
|
cmin = 0,
|
825
862
|
cmax = 1,
|
826
863
|
intensity = intensities,
|
@@ -834,11 +871,13 @@ class Plotly:
|
|
834
871
|
)
|
835
872
|
return fData
|
836
873
|
|
874
|
+
from topologicpy.Face import Face
|
837
875
|
from topologicpy.Cluster import Cluster
|
838
876
|
from topologicpy.Topology import Topology
|
839
877
|
from topologicpy.Dictionary import Dictionary
|
840
878
|
from time import time
|
841
|
-
|
879
|
+
|
880
|
+
if not Topology.IsInstance(topology, "Topology"):
|
842
881
|
return None
|
843
882
|
|
844
883
|
intensityList = []
|
@@ -846,7 +885,7 @@ class Plotly:
|
|
846
885
|
data = []
|
847
886
|
v_list = []
|
848
887
|
|
849
|
-
if
|
888
|
+
if Topology.Type(topology) == Topology.TypeID("Vertex"):
|
850
889
|
tp_vertices = [topology]
|
851
890
|
else:
|
852
891
|
tp_vertices = Topology.Vertices(topology)
|
@@ -902,8 +941,8 @@ class Plotly:
|
|
902
941
|
vertices.append([tp_v.X(), tp_v.Y(), tp_v.Z()])
|
903
942
|
data.append(vertexData(vertices, dictionaries=v_dictionaries, color=vertexColor, size=vertexSize, labelKey=vertexLabelKey, groupKey=vertexGroupKey, minGroup=vertexMinGroup, maxGroup=vertexMaxGroup, groups=vertexGroups, legendLabel=vertexLegendLabel, legendGroup=vertexLegendGroup, legendRank=vertexLegendRank, showLegend=showVertexLegend, colorScale=colorScale))
|
904
943
|
|
905
|
-
if showEdges and
|
906
|
-
if
|
944
|
+
if showEdges and Topology.Type(topology) > Topology.TypeID("Vertex"):
|
945
|
+
if Topology.Type(topology) == Topology.TypeID("Edge"):
|
907
946
|
tp_edges = [topology]
|
908
947
|
else:
|
909
948
|
tp_edges = Topology.Edges(topology)
|
@@ -918,8 +957,8 @@ class Plotly:
|
|
918
957
|
edges = geo['edges']
|
919
958
|
data.append(edgeData(vertices, edges, dictionaries=e_dictionaries, color=edgeColor, width=edgeWidth, labelKey=edgeLabelKey, groupKey=edgeGroupKey, minGroup=edgeMinGroup, maxGroup=edgeMaxGroup, groups=edgeGroups, legendLabel=edgeLegendLabel, legendGroup=edgeLegendGroup, legendRank=edgeLegendRank, showLegend=showEdgeLegend, colorScale=colorScale))
|
920
959
|
|
921
|
-
if showFaces and
|
922
|
-
if
|
960
|
+
if showFaces and Topology.Type(topology) >= Topology.TypeID("Face"):
|
961
|
+
if Topology.IsInstance(topology, "Face"):
|
923
962
|
tp_faces = [topology]
|
924
963
|
else:
|
925
964
|
tp_faces = Topology.Faces(topology)
|
@@ -934,7 +973,7 @@ class Plotly:
|
|
934
973
|
#ibList = [Wire.RemoveCollinearEdges(ib) for ib in ibList]
|
935
974
|
#ibList = [ib for ib in ibList if not ib == None]
|
936
975
|
#new_f = Face.ByWires(eb, ibList, silent=False)
|
937
|
-
#if
|
976
|
+
#if Topology.IsInstance(new_f, "Face"):
|
938
977
|
#if faceLabelKey or faceGroupKey:
|
939
978
|
#d = Topology.Dictionary(tp_faces[i])
|
940
979
|
#keys = Dictionary.Keys(d)
|
@@ -973,7 +1012,7 @@ class Plotly:
|
|
973
1012
|
width=950,
|
974
1013
|
height=500,
|
975
1014
|
showScale = True,
|
976
|
-
colorScale='
|
1015
|
+
colorScale='viridis',
|
977
1016
|
colorSamples=10,
|
978
1017
|
backgroundColor='rgba(0,0,0,0)',
|
979
1018
|
marginLeft=0,
|
@@ -1027,6 +1066,20 @@ class Plotly:
|
|
1027
1066
|
The desired bottom margin in pixels. The default is 0.
|
1028
1067
|
|
1029
1068
|
"""
|
1069
|
+
try:
|
1070
|
+
import numpy as np
|
1071
|
+
except:
|
1072
|
+
print("Plotly.FigureByConfusionMatrix - Installing required numpy library.")
|
1073
|
+
try:
|
1074
|
+
os.system("pip install numpy")
|
1075
|
+
except:
|
1076
|
+
os.system("pip install numpy --user")
|
1077
|
+
try:
|
1078
|
+
import numpy as np
|
1079
|
+
except:
|
1080
|
+
warnings.warn("Plotly.FigureByConfusionMatrix - Error: Could not import numpy. Please install numpy manually. Returning None.")
|
1081
|
+
return None
|
1082
|
+
|
1030
1083
|
if not isinstance(matrix, list) and not isinstance(matrix, np.ndarray):
|
1031
1084
|
print("Plotly.FigureByConfusionMatrix - Error: The input matrix is not of the correct type. Returning None.")
|
1032
1085
|
return None
|
@@ -1040,7 +1093,7 @@ class Plotly:
|
|
1040
1093
|
width=width,
|
1041
1094
|
height=height,
|
1042
1095
|
showScale=showScale,
|
1043
|
-
colorScale=colorScale,
|
1096
|
+
colorScale=Plotly.ColorScale(colorScale),
|
1044
1097
|
colorSamples=colorSamples,
|
1045
1098
|
backgroundColor=backgroundColor,
|
1046
1099
|
marginLeft=marginLeft,
|
@@ -1126,6 +1179,20 @@ class Plotly:
|
|
1126
1179
|
import plotly.graph_objects as go
|
1127
1180
|
import plotly.express as px
|
1128
1181
|
|
1182
|
+
try:
|
1183
|
+
import numpy as np
|
1184
|
+
except:
|
1185
|
+
print("Plotly.FigureByMatrix - Installing required numpy library.")
|
1186
|
+
try:
|
1187
|
+
os.system("pip install numpy")
|
1188
|
+
except:
|
1189
|
+
os.system("pip install numpy --user")
|
1190
|
+
try:
|
1191
|
+
import numpy as np
|
1192
|
+
except:
|
1193
|
+
warnings.warn("Plotly.FigureByMatrix - Error: Could not import numpy. Please install numpy manually. Returning None.")
|
1194
|
+
return None
|
1195
|
+
|
1129
1196
|
if not isinstance(matrix, list) and not isinstance(matrix, np.ndarray):
|
1130
1197
|
print("Plotly.FigureByMatrix - Error: The input matrix is not of the correct type. Returning None.")
|
1131
1198
|
return None
|
@@ -1134,7 +1201,7 @@ class Plotly:
|
|
1134
1201
|
|
1135
1202
|
if isinstance(matrix, list):
|
1136
1203
|
matrix = np.array(matrix)
|
1137
|
-
colors = px.colors.sample_colorscale(colorScale, [n/(colorSamples -1) for n in range(colorSamples)])
|
1204
|
+
colors = px.colors.sample_colorscale(Plotly.ColorScale(colorScale), [n/(colorSamples -1) for n in range(colorSamples)])
|
1138
1205
|
|
1139
1206
|
if not xCategories:
|
1140
1207
|
xCategories = [x for x in range(len(matrix[0]))]
|
@@ -1471,6 +1538,21 @@ class Plotly:
|
|
1471
1538
|
"""
|
1472
1539
|
|
1473
1540
|
import plotly.express as px
|
1541
|
+
|
1542
|
+
try:
|
1543
|
+
import pandas as pd
|
1544
|
+
except:
|
1545
|
+
print("Plotly.FigureByPieChart - Installing required pandas library.")
|
1546
|
+
try:
|
1547
|
+
os.system("pip install pandas")
|
1548
|
+
except:
|
1549
|
+
os.system("pip install pandas --user")
|
1550
|
+
try:
|
1551
|
+
import pandas as pd
|
1552
|
+
except:
|
1553
|
+
warnings.warn("Plotly.FigureByPieChart - Error: Could not import pandas. Please install the pandas library manually. Returning None")
|
1554
|
+
return None
|
1555
|
+
|
1474
1556
|
dlist = list(map(list, zip(*data)))
|
1475
1557
|
df = pd.DataFrame(dlist, columns=data['names'])
|
1476
1558
|
fig = px.pie(df, values=values, names=names)
|
@@ -1502,13 +1584,13 @@ class Plotly:
|
|
1502
1584
|
marginLeft=0, marginRight=0, marginTop=20, marginBottom=0, showScale=False,
|
1503
1585
|
|
1504
1586
|
cbValues=[], cbTicks=5, cbX=-0.15, cbWidth=15, cbOutlineWidth=0, cbTitle="",
|
1505
|
-
cbSubTitle="", cbUnits="", colorScale="
|
1587
|
+
cbSubTitle="", cbUnits="", colorScale="viridis", mantissa=6, tolerance=0.0001):
|
1506
1588
|
"""
|
1507
1589
|
Creates a figure from the input topology.
|
1508
1590
|
|
1509
1591
|
Parameters
|
1510
1592
|
----------
|
1511
|
-
topology :
|
1593
|
+
topology : topologic_core.Topology
|
1512
1594
|
The input topology. This must contain faces and or edges.
|
1513
1595
|
|
1514
1596
|
showVertices : bool , optional
|
@@ -1669,7 +1751,9 @@ class Plotly:
|
|
1669
1751
|
Plotly figure
|
1670
1752
|
|
1671
1753
|
"""
|
1672
|
-
|
1754
|
+
from topologicpy.Topology import Topology
|
1755
|
+
|
1756
|
+
if not Topology.IsInstance(topology, "Topology"):
|
1673
1757
|
print("Plotly.FigureByTopology - Error: the input topology is not a valid topology. Returning None.")
|
1674
1758
|
return None
|
1675
1759
|
data = Plotly.DataByTopology(topology=topology,
|
@@ -1923,7 +2007,7 @@ class Plotly:
|
|
1923
2007
|
return figure
|
1924
2008
|
|
1925
2009
|
@staticmethod
|
1926
|
-
def Show(figure, camera=[-1.25, -1.25, 1.25], center=[0, 0, 0], up=[0, 0, 1], renderer=
|
2010
|
+
def Show(figure, camera=[-1.25, -1.25, 1.25], center=[0, 0, 0], up=[0, 0, 1], renderer=None, projection="perspective"):
|
1927
2011
|
"""
|
1928
2012
|
Shows the input figure.
|
1929
2013
|
|
@@ -1938,7 +2022,7 @@ class Plotly:
|
|
1938
2022
|
up : list , optional
|
1939
2023
|
The desired up vector. The default is [0, 0, 1].
|
1940
2024
|
renderer : str , optional
|
1941
|
-
The desired
|
2025
|
+
The desired renderer. See Plotly.Renderers(). If set to None, the code will attempt to discover the most suitable renderer. The default is None.
|
1942
2026
|
projection : str, optional
|
1943
2027
|
The desired type of projection. The options are "orthographic" or "perspective". It is case insensitive. The default is "perspective"
|
1944
2028
|
|
@@ -1954,6 +2038,8 @@ class Plotly:
|
|
1954
2038
|
if not isinstance(figure, plotly.graph_objs._figure.Figure):
|
1955
2039
|
print("Plotly.Show - Error: The input is not a figure. Returning None.")
|
1956
2040
|
return None
|
2041
|
+
if renderer == None:
|
2042
|
+
renderer = Plotly.Renderer()
|
1957
2043
|
if not renderer.lower() in Plotly.Renderers():
|
1958
2044
|
print("Plotly.Show - Error: The input renderer is not in the approved list of renderers. Returning None.")
|
1959
2045
|
return None
|
@@ -1965,6 +2051,36 @@ class Plotly:
|
|
1965
2051
|
figure.show(renderer=renderer)
|
1966
2052
|
return None
|
1967
2053
|
|
2054
|
+
@staticmethod
|
2055
|
+
def Renderer():
|
2056
|
+
"""
|
2057
|
+
Return the renderer most suitable for the environment in which the script is running.
|
2058
|
+
|
2059
|
+
Parameters
|
2060
|
+
----------
|
2061
|
+
|
2062
|
+
Returns
|
2063
|
+
-------
|
2064
|
+
str
|
2065
|
+
The most suitable renderer type for the environment in which the script is running.
|
2066
|
+
Currently, this is limited to:
|
2067
|
+
- "vscode" if running in Visual Studio Code
|
2068
|
+
- "colab" if running in Google Colab
|
2069
|
+
- "iframe" if running in jupyter notebook or jupyterlab
|
2070
|
+
- "browser" if running in anything else
|
2071
|
+
"""
|
2072
|
+
import sys
|
2073
|
+
import os
|
2074
|
+
|
2075
|
+
if 'VSCODE_PID' in os.environ:
|
2076
|
+
return 'vscode'
|
2077
|
+
elif "google.colab" in sys.modules:
|
2078
|
+
return "colab"
|
2079
|
+
elif "ipykernel" in sys.modules:
|
2080
|
+
return "iframe" #works for jupyter notebook and jupyterlab
|
2081
|
+
else:
|
2082
|
+
return "browser"
|
2083
|
+
|
1968
2084
|
@staticmethod
|
1969
2085
|
def Renderers():
|
1970
2086
|
"""
|