topologicpy 0.4.8__py3-none-any.whl → 0.4.9__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 (79) hide show
  1. topologicpy/Aperture.py +46 -0
  2. topologicpy/Cell.py +1780 -0
  3. topologicpy/CellComplex.py +791 -0
  4. topologicpy/Cluster.py +591 -0
  5. topologicpy/Color.py +157 -0
  6. topologicpy/Context.py +56 -0
  7. topologicpy/DGL.py +2661 -0
  8. topologicpy/Dictionary.py +470 -0
  9. topologicpy/Edge.py +855 -0
  10. topologicpy/EnergyModel.py +1052 -0
  11. topologicpy/Face.py +1810 -0
  12. topologicpy/Graph.py +3526 -0
  13. topologicpy/Graph_Export.py +858 -0
  14. topologicpy/Grid.py +338 -0
  15. topologicpy/Helper.py +182 -0
  16. topologicpy/Honeybee.py +424 -0
  17. topologicpy/Matrix.py +255 -0
  18. topologicpy/Neo4jGraph.py +311 -0
  19. topologicpy/Plotly.py +1396 -0
  20. topologicpy/Polyskel.py +524 -0
  21. topologicpy/Process.py +1368 -0
  22. topologicpy/SQL.py +48 -0
  23. topologicpy/Shell.py +1418 -0
  24. topologicpy/Speckle.py +433 -0
  25. topologicpy/Topology.py +5854 -0
  26. topologicpy/UnitTest.py +29 -0
  27. topologicpy/Vector.py +555 -0
  28. topologicpy/Vertex.py +714 -0
  29. topologicpy/Wire.py +2346 -0
  30. topologicpy/__init__.py +20 -0
  31. topologicpy/bin/linux/topologic/__init__.py +2 -0
  32. topologicpy/bin/linux/topologic/topologic.cpython-310-x86_64-linux-gnu.so +0 -0
  33. topologicpy/bin/linux/topologic/topologic.cpython-311-x86_64-linux-gnu.so +0 -0
  34. topologicpy/bin/linux/topologic/topologic.cpython-38-x86_64-linux-gnu.so +0 -0
  35. topologicpy/bin/linux/topologic/topologic.cpython-39-x86_64-linux-gnu.so +0 -0
  36. topologicpy/bin/linux/topologic.libs/libTKBO-6bdf205d.so.7.7.0 +0 -0
  37. topologicpy/bin/linux/topologic.libs/libTKBRep-2960a069.so.7.7.0 +0 -0
  38. topologicpy/bin/linux/topologic.libs/libTKBool-c44b74bd.so.7.7.0 +0 -0
  39. topologicpy/bin/linux/topologic.libs/libTKFillet-9a670ba0.so.7.7.0 +0 -0
  40. topologicpy/bin/linux/topologic.libs/libTKG2d-8f31849e.so.7.7.0 +0 -0
  41. topologicpy/bin/linux/topologic.libs/libTKG3d-4c6bce57.so.7.7.0 +0 -0
  42. topologicpy/bin/linux/topologic.libs/libTKGeomAlgo-26066fd9.so.7.7.0 +0 -0
  43. topologicpy/bin/linux/topologic.libs/libTKGeomBase-2116cabe.so.7.7.0 +0 -0
  44. topologicpy/bin/linux/topologic.libs/libTKMath-72572fa8.so.7.7.0 +0 -0
  45. topologicpy/bin/linux/topologic.libs/libTKMesh-2a060427.so.7.7.0 +0 -0
  46. topologicpy/bin/linux/topologic.libs/libTKOffset-6cab68ff.so.7.7.0 +0 -0
  47. topologicpy/bin/linux/topologic.libs/libTKPrim-eb1262b3.so.7.7.0 +0 -0
  48. topologicpy/bin/linux/topologic.libs/libTKShHealing-e67e5cc7.so.7.7.0 +0 -0
  49. topologicpy/bin/linux/topologic.libs/libTKTopAlgo-e4c96c33.so.7.7.0 +0 -0
  50. topologicpy/bin/linux/topologic.libs/libTKernel-fb7fe3b7.so.7.7.0 +0 -0
  51. topologicpy/bin/linux/topologic.libs/libgcc_s-32c1665e.so.1 +0 -0
  52. topologicpy/bin/linux/topologic.libs/libstdc++-672d7b41.so.6.0.30 +0 -0
  53. topologicpy/bin/windows/topologic/TKBO-f6b191de.dll +0 -0
  54. topologicpy/bin/windows/topologic/TKBRep-e56a600e.dll +0 -0
  55. topologicpy/bin/windows/topologic/TKBool-7b8d47ae.dll +0 -0
  56. topologicpy/bin/windows/topologic/TKFillet-0ddbf0a8.dll +0 -0
  57. topologicpy/bin/windows/topologic/TKG2d-2e2dee3d.dll +0 -0
  58. topologicpy/bin/windows/topologic/TKG3d-6674513d.dll +0 -0
  59. topologicpy/bin/windows/topologic/TKGeomAlgo-d240e370.dll +0 -0
  60. topologicpy/bin/windows/topologic/TKGeomBase-df87aba5.dll +0 -0
  61. topologicpy/bin/windows/topologic/TKMath-45bd625a.dll +0 -0
  62. topologicpy/bin/windows/topologic/TKMesh-d6e826b1.dll +0 -0
  63. topologicpy/bin/windows/topologic/TKOffset-79b9cc94.dll +0 -0
  64. topologicpy/bin/windows/topologic/TKPrim-aa430a86.dll +0 -0
  65. topologicpy/bin/windows/topologic/TKShHealing-bb48be89.dll +0 -0
  66. topologicpy/bin/windows/topologic/TKTopAlgo-7d0d1e22.dll +0 -0
  67. topologicpy/bin/windows/topologic/TKernel-08c8cfbb.dll +0 -0
  68. topologicpy/bin/windows/topologic/__init__.py +2 -0
  69. topologicpy/bin/windows/topologic/topologic.cp310-win_amd64.pyd +0 -0
  70. topologicpy/bin/windows/topologic/topologic.cp311-win_amd64.pyd +0 -0
  71. topologicpy/bin/windows/topologic/topologic.cp38-win_amd64.pyd +0 -0
  72. topologicpy/bin/windows/topologic/topologic.cp39-win_amd64.pyd +0 -0
  73. {topologicpy-0.4.8.dist-info → topologicpy-0.4.9.dist-info}/METADATA +1 -1
  74. topologicpy-0.4.9.dist-info/RECORD +77 -0
  75. topologicpy-0.4.9.dist-info/top_level.txt +1 -0
  76. topologicpy-0.4.8.dist-info/RECORD +0 -5
  77. topologicpy-0.4.8.dist-info/top_level.txt +0 -1
  78. {topologicpy-0.4.8.dist-info → topologicpy-0.4.9.dist-info}/LICENSE +0 -0
  79. {topologicpy-0.4.8.dist-info → topologicpy-0.4.9.dist-info}/WHEEL +0 -0
@@ -0,0 +1,858 @@
1
+ '''
2
+ @staticmethod
3
+ def adjacentVertices(graph, vertex):
4
+ vertices = []
5
+ _ = graph.AdjacentVertices(vertex, vertices)
6
+ return list(vertices)
7
+
8
+ @staticmethod
9
+ def vertexIndex(vertex, vertices):
10
+ for i in range(len(vertices)):
11
+ if topologic.Topology.IsSame(vertex, vertices[i]):
12
+ return i
13
+ return None
14
+
15
+ @staticmethod
16
+ def ExportToCSV(graph_list, graph_label_list, graphs_file_path,
17
+ edges_file_path, nodes_file_path, graph_id_header,
18
+ graph_label_header, graph_num_nodes_header,
19
+ edge_src_header, edge_dst_header, node_label_header,
20
+ node_label_key, default_node_label, overwrite):
21
+ """
22
+ Description
23
+ -----------
24
+ Creates a vertex at the coordinates specified by the x, y, z inputs.
25
+
26
+ Parameters
27
+ ----------
28
+ graph_list : TYPE
29
+ DESCRIPTION.
30
+ graph_label_list : TYPE
31
+ DESCRIPTION.
32
+ graphs_file_path : TYPE
33
+ DESCRIPTION.
34
+ edges_file_path : TYPE
35
+ DESCRIPTION.
36
+ nodes_file_path : TYPE
37
+ DESCRIPTION.
38
+ graph_id_header : TYPE
39
+ DESCRIPTION.
40
+ graph_label_header : TYPE
41
+ DESCRIPTION.
42
+ graph_num_nodes_header : TYPE
43
+ DESCRIPTION.
44
+ edge_src_header : TYPE
45
+ DESCRIPTION.
46
+ edge_dst_header : TYPE
47
+ DESCRIPTION.
48
+ node_label_header : TYPE
49
+ DESCRIPTION.
50
+ node_label_key : TYPE
51
+ DESCRIPTION.
52
+ default_node_label : TYPE
53
+ DESCRIPTION.
54
+ overwrite : TYPE
55
+ DESCRIPTION.
56
+
57
+ Returns
58
+ -------
59
+ bool
60
+ DESCRIPTION.
61
+
62
+ """
63
+ # graph_list, \
64
+ # graph_label_list, \
65
+ # graphs_file_path, \
66
+ # edges_file_path, \
67
+ # nodes_file_path, \
68
+ # graph_id_header, \
69
+ # graph_label_header, \
70
+ # graph_num_nodes_header, \
71
+ # edge_src_header, \
72
+ # edge_dst_header, \
73
+ # node_label_header, \
74
+ # node_label_key, \
75
+ # default_node_label, \
76
+ # overwrite = item
77
+
78
+ if not isinstance(graph_list, list):
79
+ graph_list = [graph_list]
80
+ for graph_index, graph in enumerate(graph_list):
81
+ graph_label = graph_label_list[graph_index]
82
+ # Export Graph Properties
83
+ vertices = Graph.graphVertices(graph)
84
+ graph_num_nodes = len(vertices)
85
+ if overwrite == False:
86
+ graphs = pd.read_csv(graphs_file_path)
87
+ max_id = max(list(graphs[graph_id_header]))
88
+ graph_id = max_id + graph_index + 1
89
+ else:
90
+ graph_id = graph_index
91
+ data = [[graph_id], [graph_label], [graph_num_nodes]]
92
+ data = Replication.iterate(data)
93
+ data = Replication.transposeList(data)
94
+ df = pd.DataFrame(data, columns= [graph_id_header, graph_label_header, graph_num_nodes_header])
95
+ if overwrite == False:
96
+ df.to_csv(graphs_file_path, mode='a', index = False, header=False)
97
+ else:
98
+ if graph_index == 0:
99
+ df.to_csv(graphs_file_path, mode='w+', index = False, header=True)
100
+ else:
101
+ df.to_csv(graphs_file_path, mode='a', index = False, header=False)
102
+
103
+ # Export Edge Properties
104
+ edge_src = []
105
+ edge_dst = []
106
+ edge_graph_id = [] #Repetitive list of graph_id for each edge
107
+ node_graph_id = [] #Repetitive list of graph_id for each vertex/node
108
+ node_labels = []
109
+ x_list = []
110
+ y_list = []
111
+ z_list = []
112
+ node_data = []
113
+ node_columns = [graph_id_header, node_label_header, "X", "Y", "Z"]
114
+ # All keys should be the same for all vertices, so we can get them from the first vertex
115
+ d = vertices[0].GetDictionary()
116
+ keys = d.Keys()
117
+ for key in keys:
118
+ if key != node_label_key: #We have already saved that in its own column
119
+ node_columns.append(key)
120
+ for i, v in enumerate(vertices):
121
+ # Might as well get the node labels since we are iterating through the vertices
122
+ d = v.GetDictionary()
123
+ vLabel = Dictionary.DictionaryValueAtKey(d, node_label_key)
124
+ if not(vLabel):
125
+ vLabel = default_node_label
126
+ single_node_data = [graph_id, vLabel, round(float(v.X()),5), round(float(v.Y()),5), round(float(v.Z()),5)]
127
+ keys = d.Keys()
128
+ for key in keys:
129
+ if key != node_label_key and (key in node_columns):
130
+ value = Dictionary.DictionaryValueAtKey(d, key)
131
+ if not value:
132
+ value = 'None'
133
+ single_node_data.append(value)
134
+ node_data.append(single_node_data)
135
+ av = Graph.adjacentVertices(graph, v)
136
+ for k in range(len(av)):
137
+ vi = Graph.vertexIndex(av[k], vertices)
138
+ edge_graph_id.append(graph_id)
139
+ edge_src.append(i)
140
+ edge_dst.append(vi)
141
+ data = [edge_graph_id, edge_src, edge_dst]
142
+ data = Replication.iterate(data)
143
+ data = Replication.transposeList(data)
144
+ df = pd.DataFrame(data, columns= [graph_id_header, edge_src_header, edge_dst_header])
145
+ if overwrite == False:
146
+ df.to_csv(edges_file_path, mode='a', index = False, header=False)
147
+ else:
148
+ if graph_index == 0:
149
+ df.to_csv(edges_file_path, mode='w+', index = False, header=True)
150
+ else:
151
+ df.to_csv(edges_file_path, mode='a', index = False, header=False)
152
+
153
+ # Export Node Properties
154
+ df = pd.DataFrame(node_data, columns= node_columns)
155
+
156
+ if overwrite == False:
157
+ df.to_csv(nodes_file_path, mode='a', index = False, header=False)
158
+ else:
159
+ if graph_index == 0:
160
+ df.to_csv(nodes_file_path, mode='w+', index = False, header=True)
161
+ else:
162
+ df.to_csv(nodes_file_path, mode='a', index = False, header=False)
163
+ return True
164
+
165
+
166
+ @staticmethod
167
+ def ExportToCSV_NC(graph_list, graph_label_list, graphs_folder_path,
168
+ node_label_key, node_features_keys, default_node_label, edge_label_key,
169
+ edge_features_keys, default_edge_label,
170
+ train_ratio, test_ratio, validate_ratio,
171
+ overwrite):
172
+ """
173
+ Description
174
+ -----------
175
+ Creates a vertex at the coordinates specified by the x, y, z inputs.
176
+
177
+ Parameters
178
+ ----------
179
+ graph_list : TYPE
180
+ DESCRIPTION.
181
+ graph_label_list : TYPE
182
+ DESCRIPTION.
183
+ graphs_folder_path : TYPE
184
+ DESCRIPTION.
185
+ node_label_key : TYPE
186
+ DESCRIPTION.
187
+ node_features_keys : TYPE
188
+ DESCRIPTION.
189
+ default_node_label : TYPE
190
+ DESCRIPTION.
191
+ edge_label_key : TYPE
192
+ DESCRIPTION.
193
+ edge_features_keys : TYPE
194
+ DESCRIPTION.
195
+ default_edge_label : TYPE
196
+ DESCRIPTION.
197
+ train_ratio : TYPE
198
+ DESCRIPTION.
199
+ test_ratio : TYPE
200
+ DESCRIPTION.
201
+ validate_ratio : TYPE
202
+ DESCRIPTION.
203
+ overwrite : TYPE
204
+ DESCRIPTION.
205
+
206
+ Returns
207
+ -------
208
+ TYPE
209
+ DESCRIPTION.
210
+
211
+ """
212
+ # graph_list, \
213
+ # graph_label_list, \
214
+ # graphs_folder_path, \
215
+ # node_label_key, \
216
+ # node_features_keys, \
217
+ # default_node_label, \
218
+ # edge_label_key, \
219
+ # edge_features_keys, \
220
+ # default_edge_label, \
221
+ # train_ratio, \
222
+ # test_ratio, \
223
+ # validate_ratio, \
224
+ # overwrite = item
225
+
226
+ def graphVertices(graph):
227
+ import random
228
+ vertices = []
229
+ if graph:
230
+ try:
231
+ _ = graph.Vertices(vertices)
232
+ except:
233
+ print("ERROR: (Topologic>Graph.Vertices) operation failed. Returning None.")
234
+ vertices = None
235
+ if vertices:
236
+ return random.sample(vertices, len(vertices))
237
+ else:
238
+ return []
239
+
240
+ assert (train_ratio+test_ratio+validate_ratio > 0.99), "GraphExportToCSV_NC - Error: Train_Test_Validate ratios do not add up to 1."
241
+
242
+ if not isinstance(graph_list, list):
243
+ graph_list = [graph_list]
244
+ for graph_index, graph in enumerate(graph_list):
245
+ graph_label = graph_label_list[graph_index]
246
+ # Export Graph Properties
247
+ vertices = graphVertices(graph)
248
+ train_max = math.floor(float(len(vertices))*train_ratio)
249
+ test_max = math.floor(float(len(vertices))*test_ratio)
250
+ validate_max = len(vertices) - train_max - test_max
251
+ graph_num_nodes = len(vertices)
252
+ if overwrite == False:
253
+ graphs = pd.read_csv(os.path.join(graphs_folder_path,"graphs.csv"))
254
+ max_id = max(list(graphs["graph_id"]))
255
+ graph_id = max_id + graph_index + 1
256
+ else:
257
+ graph_id = graph_index
258
+ data = [[graph_id], [graph_label], [graph_num_nodes]]
259
+ data = Replication.iterate(data)
260
+ data = Replication.transposeList(data)
261
+ df = pd.DataFrame(data, columns= ["graph_id", "label", "num_nodes"])
262
+ if overwrite == False:
263
+ df.to_csv(os.path.join(graphs_folder_path, "graphs.csv"), mode='a', index = False, header=False)
264
+ else:
265
+ if graph_index == 0:
266
+ df.to_csv(os.path.join(graphs_folder_path, "graphs.csv"), mode='w+', index = False, header=True)
267
+ else:
268
+ df.to_csv(os.path.join(graphs_folder_path, "graphs.csv"), mode='a', index = False, header=False)
269
+
270
+ # Export Edge Properties
271
+ edge_graph_id = [] #Repetitive list of graph_id for each edge
272
+ edge_src = []
273
+ edge_dst = []
274
+ edge_lab = []
275
+ edge_feat = []
276
+ node_graph_id = [] #Repetitive list of graph_id for each vertex/node
277
+ node_labels = []
278
+ x_list = []
279
+ y_list = []
280
+ z_list = []
281
+ node_data = []
282
+ node_columns = ["graph_id", "node_id","label", "train_mask","val_mask","test_mask","feat", "X", "Y", "Z"]
283
+ # All keys should be the same for all vertices, so we can get them from the first vertex
284
+ d = vertices[0].GetDictionary()
285
+ '''
286
+ keys = d.Keys()
287
+ for key in keys:
288
+ if key != node_label_key: #We have already saved that in its own column
289
+ node_columns.append(key)
290
+ '''
291
+ train = 0
292
+ test = 0
293
+ validate = 0
294
+
295
+ for i, v in enumerate(vertices):
296
+ if train < train_max:
297
+ train_mask = True
298
+ test_mask = False
299
+ validate_mask = False
300
+ train = train + 1
301
+ elif test < test_max:
302
+ train_mask = False
303
+ test_mask = True
304
+ validate_mask = False
305
+ test = test + 1
306
+ elif validate < validate_max:
307
+ train_mask = False
308
+ test_mask = False
309
+ validate_mask = True
310
+ validate = validate + 1
311
+ else:
312
+ train_mask = True
313
+ test_mask = False
314
+ validate_mask = False
315
+ train = train + 1
316
+ # Might as well get the node labels since we are iterating through the vertices
317
+ d = v.GetDictionary()
318
+ vLabel = Dictionary.DictionaryValueAtKey(d, node_label_key)
319
+ if not(vLabel):
320
+ vLabel = default_node_label
321
+ # Might as well get the features since we are iterating through the vertices
322
+ features = ""
323
+ node_features_keys = Replication.flatten(node_features_keys)
324
+ for node_feature_key in node_features_keys:
325
+ if len(features) > 0:
326
+ features = features + ","+ str(round(float(Dictionary.DictionaryValueAtKey(d, node_feature_key)),5))
327
+ else:
328
+ features = str(round(float(Dictionary.DictionaryValueAtKey(d, node_feature_key)),5))
329
+ single_node_data = [graph_id, i, vLabel, train_mask, validate_mask, test_mask, features, round(float(v.X()),5), round(float(v.Y()),5), round(float(v.Z()),5)]
330
+ '''
331
+ keys = d.Keys()
332
+ for key in keys:
333
+ if key != node_label_key and (key in node_columns):
334
+ value = DictionaryValueAtKey.processItem([d, key])
335
+ if not value:
336
+ value = 'None'
337
+ single_node_data.append(value)
338
+ '''
339
+ node_data.append(single_node_data)
340
+ av = Graph.adjacentVertices(graph, v)
341
+ for k in range(len(av)):
342
+ vi = Graph.vertexIndex(av[k], vertices)
343
+ edge_graph_id.append(graph_id)
344
+ edge_src.append(i)
345
+ edge_dst.append(vi)
346
+ edge = graph.Edge(v, av[k], 0.0001)
347
+ ed = edge.GetDictionary()
348
+ edge_label = Dictionary.DictionaryValueAtKey(d, edge_label_key)
349
+ if not(edge_label):
350
+ edge_label = default_edge_label
351
+ edge_lab.append(edge_label)
352
+ edge_features = ""
353
+ edge_features_keys = Replication.flatten(edge_features_keys)
354
+ for edge_feature_key in edge_features_keys:
355
+ if len(edge_features) > 0:
356
+ edge_features = edge_features + ","+ str(round(float(Dictionary.DictionaryValueAtKey(ed, edge_feature_key)),5))
357
+ else:
358
+ edge_features = str(round(float(Dictionary.DictionaryValueAtKey(ed, edge_feature_key)),5))
359
+ edge_feat.append(edge_features)
360
+ data = [edge_graph_id, edge_src, edge_dst, edge_lab, edge_feat]
361
+ data = Replication.iterate(data)
362
+ data = Replication.transposeList(data)
363
+ df = pd.DataFrame(data, columns= ["graph_id", "src_id", "dst_id", "label", "feat"])
364
+ if overwrite == False:
365
+ df.to_csv(os.path.join(graphs_folder_path, "edges.csv"), mode='a', index = False, header=False)
366
+ else:
367
+ if graph_index == 0:
368
+ df.to_csv(os.path.join(graphs_folder_path, "edges.csv"), mode='w+', index = False, header=True)
369
+ else:
370
+ df.to_csv(os.path.join(graphs_folder_path, "edges.csv"), mode='a', index = False, header=False)
371
+
372
+ # Export Node Properties
373
+ df = pd.DataFrame(node_data, columns= node_columns)
374
+
375
+ if overwrite == False:
376
+ df.to_csv(os.path.join(graphs_folder_path, "nodes.csv"), mode='a', index = False, header=False)
377
+ else:
378
+ if graph_index == 0:
379
+ df.to_csv(os.path.join(graphs_folder_path, "nodes.csv"), mode='w+', index = False, header=True)
380
+ else:
381
+ df.to_csv(os.path.join(graphs_folder_path, "nodes.csv"), mode='a', index = False, header=False)
382
+ # Write out the meta.yaml file
383
+ yaml_file = open(os.path.join(graphs_folder_path,"meta.yaml"), "w")
384
+ yaml_file.write('dataset_name: topologic_dataset\nedge_data:\n- file_name: edges.csv\nnode_data:\n- file_name: nodes.csv\ngraph_data:\n file_name: graphs.csv')
385
+ yaml_file.close()
386
+ return True
387
+
388
+ @staticmethod
389
+ def ExportToCSVGC(graph_list, graph_label_list, graphs_file_path, edges_file_path,
390
+ nodes_file_path, graph_id_header, graph_label_header, graph_num_nodes_header,
391
+ edge_src_header, edge_dst_header, node_label_header, node_label_key, default_node_label, overwrite):
392
+ """
393
+ Description
394
+ -----------
395
+ Creates a vertex at the coordinates specified by the x, y, z inputs.
396
+
397
+ Parameters
398
+ ----------
399
+ graph_list : TYPE
400
+ DESCRIPTION.
401
+ graph_label_list : TYPE
402
+ DESCRIPTION.
403
+ graphs_file_path : TYPE
404
+ DESCRIPTION.
405
+ edges_file_path : TYPE
406
+ DESCRIPTION.
407
+ nodes_file_path : TYPE
408
+ DESCRIPTION.
409
+ graph_id_header : TYPE
410
+ DESCRIPTION.
411
+ graph_label_header : TYPE
412
+ DESCRIPTION.
413
+ graph_num_nodes_header : TYPE
414
+ DESCRIPTION.
415
+ edge_src_header : TYPE
416
+ DESCRIPTION.
417
+ edge_dst_header : TYPE
418
+ DESCRIPTION.
419
+ node_label_header : TYPE
420
+ DESCRIPTION.
421
+ node_label_key : TYPE
422
+ DESCRIPTION.
423
+ default_node_label : TYPE
424
+ DESCRIPTION.
425
+ overwrite : TYPE
426
+ DESCRIPTION.
427
+
428
+ Returns
429
+ -------
430
+ bool
431
+ DESCRIPTION.
432
+
433
+ """
434
+ # graph_list, \
435
+ # graph_label_list, \
436
+ # graphs_file_path, \
437
+ # edges_file_path, \
438
+ # nodes_file_path, \
439
+ # graph_id_header, \
440
+ # graph_label_header, \
441
+ # graph_num_nodes_header, \
442
+ # edge_src_header, \
443
+ # edge_dst_header, \
444
+ # node_label_header, \
445
+ # node_label_key, \
446
+ # default_node_label, \
447
+ # overwrite = item
448
+
449
+ if not isinstance(graph_list, list):
450
+ graph_list = [graph_list]
451
+ for graph_index, graph in enumerate(graph_list):
452
+ graph_label = graph_label_list[graph_index]
453
+ # Export Graph Properties
454
+ vertices = Graph.graphVertices(graph)
455
+ graph_num_nodes = len(vertices)
456
+ if overwrite == False:
457
+ graphs = pd.read_csv(graphs_file_path)
458
+ max_id = max(list(graphs[graph_id_header]))
459
+ graph_id = max_id + graph_index + 1
460
+ else:
461
+ graph_id = graph_index
462
+ data = [[graph_id], [graph_label], [graph_num_nodes]]
463
+ data = Replication.iterate(data)
464
+ data = Replication.transposeList(data)
465
+ df = pd.DataFrame(data, columns= [graph_id_header, graph_label_header, graph_num_nodes_header])
466
+ if overwrite == False:
467
+ df.to_csv(graphs_file_path, mode='a', index = False, header=False)
468
+ else:
469
+ if graph_index == 0:
470
+ df.to_csv(graphs_file_path, mode='w+', index = False, header=True)
471
+ else:
472
+ df.to_csv(graphs_file_path, mode='a', index = False, header=False)
473
+
474
+ # Export Edge Properties
475
+ edge_src = []
476
+ edge_dst = []
477
+ edge_graph_id = [] #Repetitive list of graph_id for each edge
478
+ node_graph_id = [] #Repetitive list of graph_id for each vertex/node
479
+ node_labels = []
480
+ x_list = []
481
+ y_list = []
482
+ z_list = []
483
+ node_data = []
484
+ node_columns = [graph_id_header, node_label_header, "X", "Y", "Z"]
485
+ # All keys should be the same for all vertices, so we can get them from the first vertex
486
+ d = vertices[0].GetDictionary()
487
+ keys = d.Keys()
488
+ for key in keys:
489
+ if key != node_label_key: #We have already saved that in its own column
490
+ node_columns.append(key)
491
+ for i, v in enumerate(vertices):
492
+ # Might as well get the node labels since we are iterating through the vertices
493
+ d = v.GetDictionary()
494
+ vLabel = Dictionary.DictionaryValueAtKey(d, node_label_key)
495
+ if not(vLabel):
496
+ vLabel = default_node_label
497
+ single_node_data = [graph_id, vLabel, round(float(v.X()),5), round(float(v.Y()),5), round(float(v.Z()),5)]
498
+ keys = d.Keys()
499
+ for key in keys:
500
+ if key != node_label_key and (key in node_columns):
501
+ value = Dictionary.DictionaryValueAtKey(d, key)
502
+ if not value:
503
+ value = 'None'
504
+ single_node_data.append(value)
505
+ node_data.append(single_node_data)
506
+ av = Graph.adjacentVertices(graph, v)
507
+ for k in range(len(av)):
508
+ vi = Graph.vertexIndex(av[k], vertices)
509
+ edge_graph_id.append(graph_id)
510
+ edge_src.append(i)
511
+ edge_dst.append(vi)
512
+ data = [edge_graph_id, edge_src, edge_dst]
513
+ data = Replication.iterate(data)
514
+ data = Replication.transposeList(data)
515
+ df = pd.DataFrame(data, columns= [graph_id_header, edge_src_header, edge_dst_header])
516
+ if overwrite == False:
517
+ df.to_csv(edges_file_path, mode='a', index = False, header=False)
518
+ else:
519
+ if graph_index == 0:
520
+ df.to_csv(edges_file_path, mode='w+', index = False, header=True)
521
+ else:
522
+ df.to_csv(edges_file_path, mode='a', index = False, header=False)
523
+
524
+ # Export Node Properties
525
+ df = pd.DataFrame(node_data, columns= node_columns)
526
+
527
+ if overwrite == False:
528
+ df.to_csv(nodes_file_path, mode='a', index = False, header=False)
529
+ else:
530
+ if graph_index == 0:
531
+ df.to_csv(nodes_file_path, mode='w+', index = False, header=True)
532
+ else:
533
+ df.to_csv(nodes_file_path, mode='a', index = False, header=False)
534
+ return True
535
+
536
+ @staticmethod
537
+ def ExportToCSVNC(graph_list, graph_label_list, graphs_folder_path, graph_id_header,
538
+ graph_label_header, graph_num_nodes_header, edge_src_header, edge_dst_header,
539
+ node_label_header, node_label_key, node_features_keys, default_node_label, overwrite):
540
+ """
541
+ Description
542
+ -----------
543
+ Creates a vertex at the coordinates specified by the x, y, z inputs.
544
+
545
+ Parameters
546
+ ----------
547
+ graph_list : TYPE
548
+ DESCRIPTION.
549
+ graph_label_list : TYPE
550
+ DESCRIPTION.
551
+ graphs_folder_path : TYPE
552
+ DESCRIPTION.
553
+ graph_id_header : TYPE
554
+ DESCRIPTION.
555
+ graph_label_header : TYPE
556
+ DESCRIPTION.
557
+ graph_num_nodes_header : TYPE
558
+ DESCRIPTION.
559
+ edge_src_header : TYPE
560
+ DESCRIPTION.
561
+ edge_dst_header : TYPE
562
+ DESCRIPTION.
563
+ node_label_header : TYPE
564
+ DESCRIPTION.
565
+ node_label_key : TYPE
566
+ DESCRIPTION.
567
+ node_features_keys : TYPE
568
+ DESCRIPTION.
569
+ default_node_label : TYPE
570
+ DESCRIPTION.
571
+ overwrite : TYPE
572
+ DESCRIPTION.
573
+
574
+ Returns
575
+ -------
576
+ bool
577
+ DESCRIPTION.
578
+
579
+ """
580
+ # graph_list, \
581
+ # graph_label_list, \
582
+ # graphs_folder_path, \
583
+ # graph_id_header, \
584
+ # graph_label_header, \
585
+ # graph_num_nodes_header, \
586
+ # edge_src_header, \
587
+ # edge_dst_header, \
588
+ # node_label_header, \
589
+ # node_label_key, \
590
+ # node_features_keys, \
591
+ # default_node_label, \
592
+ # overwrite = item
593
+
594
+ if not isinstance(graph_list, list):
595
+ graph_list = [graph_list]
596
+ for graph_index, graph in enumerate(graph_list):
597
+ graph_label = graph_label_list[graph_index]
598
+ # Export Graph Properties
599
+ vertices = Graph.graphVertices(graph)
600
+ graph_num_nodes = len(vertices)
601
+ if overwrite == False:
602
+ graphs = pd.read_csv(graphs_folder_path)
603
+ max_id = max(list(graphs[graph_id_header]))
604
+ graph_id = max_id + graph_index + 1
605
+ else:
606
+ graph_id = graph_index
607
+ data = [[graph_id], [graph_label], [graph_num_nodes]]
608
+ data = Replication.iterate(data)
609
+ data = Replication.transposeList(data)
610
+ df = pd.DataFrame(data, columns= [graph_id_header, graph_label_header, graph_num_nodes_header])
611
+ if overwrite == False:
612
+ df.to_csv(os.path.join(graphs_folder_path, "graphs.csv"), mode='a', index = False, header=False)
613
+ else:
614
+ if graph_index == 0:
615
+ df.to_csv(os.path.join(graphs_folder_path, "graphs.csv"), mode='w+', index = False, header=True)
616
+ else:
617
+ df.to_csv(os.path.join(graphs_folder_path, "graphs.csv"), mode='a', index = False, header=False)
618
+
619
+ # Export Edge Properties
620
+ edge_src = []
621
+ edge_dst = []
622
+ edge_graph_id = [] #Repetitive list of graph_id for each edge
623
+ node_graph_id = [] #Repetitive list of graph_id for each vertex/node
624
+ node_labels = []
625
+ x_list = []
626
+ y_list = []
627
+ z_list = []
628
+ node_data = []
629
+ node_columns = [graph_id_header, node_label_header, "feat", "X", "Y", "Z"]
630
+ # All keys should be the same for all vertices, so we can get them from the first vertex
631
+ d = vertices[0].GetDictionary()
632
+ keys = d.Keys()
633
+ for key in keys:
634
+ if key != node_label_key: #We have already saved that in its own column
635
+ node_columns.append(key)
636
+ for i, v in enumerate(vertices):
637
+ # Might as well get the node labels since we are iterating through the vertices
638
+ d = v.GetDictionary()
639
+ vLabel = Dictionary.DictionaryValueAtKey(d, node_label_key)
640
+ if not(vLabel):
641
+ vLabel = default_node_label
642
+ # Might as well get the features since we are iterating through the vertices
643
+ features = ""
644
+ for node_feature_key in node_features_keys:
645
+ if len(features) > 0:
646
+ features = features + ","+ str(round(float(Dictionary.DictionaryValueAtKey(d, node_feature_key)),5))
647
+ else:
648
+ features = str(round(float(Dictionary.DictionaryValueAtKey(d, node_feature_key)),5))
649
+ single_node_data = [graph_id, vLabel, features, round(float(v.X()),5), round(float(v.Y()),5), round(float(v.Z()),5)]
650
+ keys = d.Keys()
651
+ for key in keys:
652
+ if key != node_label_key and (key in node_columns):
653
+ value = Dictionary.DictionaryValueAtKey(d, key)
654
+ if not value:
655
+ value = 'None'
656
+ single_node_data.append(value)
657
+ node_data.append(single_node_data)
658
+ av = Graph.adjacentVertices(graph, v)
659
+ for k in range(len(av)):
660
+ vi = Graph.vertexIndex(av[k], vertices)
661
+ edge_graph_id.append(graph_id)
662
+ edge_src.append(i)
663
+ edge_dst.append(vi)
664
+ data = [edge_graph_id, edge_src, edge_dst]
665
+ data = Replication.iterate(data)
666
+ data = Replication.transposeList(data)
667
+ df = pd.DataFrame(data, columns= [graph_id_header, edge_src_header, edge_dst_header])
668
+ if overwrite == False:
669
+ df.to_csv(os.path.join(graphs_folder_path, "edges.csv"), mode='a', index = False, header=False)
670
+ else:
671
+ if graph_index == 0:
672
+ df.to_csv(os.path.join(graphs_folder_path, "edges.csv"), mode='w+', index = False, header=True)
673
+ else:
674
+ df.to_csv(os.path.join(graphs_folder_path, "edges.csv"), mode='a', index = False, header=False)
675
+
676
+ # Export Node Properties
677
+ df = pd.DataFrame(node_data, columns= node_columns)
678
+
679
+ if overwrite == False:
680
+ df.to_csv(nodes_file_path, mode='a', index = False, header=False)
681
+ else:
682
+ if graph_index == 0:
683
+ df.to_csv(os.path.join(graphs_folder_path, "nodes.csv"), mode='w+', index = False, header=True)
684
+ else:
685
+ df.to_csv(os.path.join(graphs_folder_path, "nodes.csv"), mode='a', index = False, header=False)
686
+ return True
687
+
688
+ @staticmethod
689
+ def ExportToDGCNN(graph, graph_label, key, default_vertex_label, filepath, overwrite):
690
+ """
691
+ Description
692
+ -----------
693
+ Creates a vertex at the coordinates specified by the x, y, z inputs.
694
+
695
+ Parameters
696
+ ----------
697
+ graph : TYPE
698
+ DESCRIPTION.
699
+ graph_label : TYPE
700
+ DESCRIPTION.
701
+ key : TYPE
702
+ DESCRIPTION.
703
+ default_vertex_label : TYPE
704
+ DESCRIPTION.
705
+ filepath : TYPE
706
+ DESCRIPTION.
707
+ overwrite : TYPE
708
+ DESCRIPTION.
709
+
710
+ Returns
711
+ -------
712
+ bool
713
+ DESCRIPTION.
714
+
715
+ """
716
+ # graph, graph_label, key, default_vertex_label, filepath, overwrite = item
717
+ vertices = Graph.graphVertices(graph)
718
+ new_lines = []
719
+ new_lines.append("\n"+str(len(vertices))+" "+str(graph_label))
720
+ for j in range(len(vertices)):
721
+ d = vertices[j].GetDictionary()
722
+ vLabel = Dictionary.DictionaryValueAtKey(d, key)
723
+ if not(vLabel):
724
+ vLabel = default_vertex_label
725
+ av = Graph.adjacentVertices(graph, vertices[j])
726
+ line = "\n"+str(vLabel)+" "+ str(len(av))+" "
727
+ for k in range(len(av)):
728
+ vi = Graph.vertexIndex(av[k], vertices)
729
+ line = line+str(vi)+" "
730
+ new_lines.append(line)
731
+ # Make sure the file extension is .txt
732
+ ext = filepath[len(filepath)-4:len(filepath)]
733
+ if ext.lower() != ".txt":
734
+ filepath = filepath+".txt"
735
+ old_lines = ["1"]
736
+ if overwrite == False:
737
+ with open(filepath) as f:
738
+ old_lines = f.readlines()
739
+ if len(old_lines):
740
+ if old_lines[0] != "":
741
+ old_lines[0] = str(int(old_lines[0])+1)+"\n"
742
+ else:
743
+ old_lines[0] = "1"
744
+ lines = old_lines+new_lines
745
+ with open(filepath, "w") as f:
746
+ f.writelines(lines)
747
+ return True
748
+ '''
749
+ @staticmethod
750
+ def VerticesAtKeyValue(vertexList, key, value):
751
+ """
752
+ Description
753
+ -----------
754
+ Creates a vertex at the coordinates specified by the x, y, z inputs.
755
+
756
+ Parameters
757
+ ----------
758
+ vertexList : TYPE
759
+ DESCRIPTION.
760
+ key : TYPE
761
+ DESCRIPTION.
762
+ value : TYPE
763
+ DESCRIPTION.
764
+
765
+ Returns
766
+ -------
767
+ returnVertices : TYPE
768
+ DESCRIPTION.
769
+
770
+ """
771
+ # key = item[0]
772
+ # value = item[1]
773
+
774
+ def listAttributeValues(listAttribute):
775
+ listAttributes = listAttribute.ListValue()
776
+ returnList = []
777
+ for attr in listAttributes:
778
+ if isinstance(attr, IntAttribute):
779
+ returnList.append(attr.IntValue())
780
+ elif isinstance(attr, DoubleAttribute):
781
+ returnList.append(attr.DoubleValue())
782
+ elif isinstance(attr, StringAttribute):
783
+ returnList.append(attr.StringValue())
784
+ return returnList
785
+
786
+ def valueAtKey(item, key):
787
+ try:
788
+ attr = item.ValueAtKey(key)
789
+ except:
790
+ raise Exception("Dictionary.ValueAtKey - Error: Could not retrieve a Value at the specified key ("+key+")")
791
+ if isinstance(attr, topologic.IntAttribute):
792
+ return (attr.IntValue())
793
+ elif isinstance(attr, topologic.DoubleAttribute):
794
+ return (attr.DoubleValue())
795
+ elif isinstance(attr, topologic.StringAttribute):
796
+ return (attr.StringValue())
797
+ elif isinstance(attr, topologic.ListAttribute):
798
+ return (listAttributeValues(attr))
799
+ else:
800
+ return None
801
+
802
+ if isinstance(value, list):
803
+ value.sort()
804
+ returnVertices = []
805
+ for aVertex in vertexList:
806
+ d = aVertex.GetDictionary()
807
+ v = valueAtKey(d, key)
808
+ if isinstance(v, list):
809
+ v.sort()
810
+ if str(v) == str(value):
811
+ returnVertices.append(aVertex)
812
+ return returnVertices
813
+
814
+ @staticmethod
815
+ def VisibilityGraph(cluster):
816
+ """
817
+ Description
818
+ -----------
819
+ Creates a vertex at the coordinates specified by the x, y, z inputs.
820
+
821
+ Parameters
822
+ ----------
823
+ cluster : TYPE
824
+ DESCRIPTION.
825
+
826
+ Returns
827
+ -------
828
+ graph : TYPE
829
+ DESCRIPTION.
830
+
831
+ """
832
+ wires = []
833
+ _ = cluster.Wires(None, wires)
834
+ polys = []
835
+ for aWire in wires:
836
+ vertices = []
837
+ _ = aWire.Vertices(None, vertices)
838
+ poly = []
839
+ for v in vertices:
840
+ p = vg.Point(round(v.X(),4),round(v.Y(),4), 0)
841
+ poly.append(p)
842
+ polys.append(poly)
843
+ g = vg.VisGraph()
844
+ g.build(polys)
845
+ tpEdges = []
846
+ vgEdges = g.visgraph.get_edges()
847
+ for vgEdge in vgEdges:
848
+ sv = topologic.Vertex.ByCoordinates(vgEdge.p1.x, vgEdge.p1.y,0)
849
+ ev = topologic.Vertex.ByCoordinates(vgEdge.p2.x, vgEdge.p2.y,0)
850
+ tpEdges.append(topologic.Edge.ByStartVertexEndVertex(sv, ev))
851
+ tpVertices = []
852
+ vgPoints = g.visgraph.get_points()
853
+ for vgPoint in vgPoints:
854
+ v = topologic.Vertex.ByCoordinates(vgPoint.x, vgPoint.y,0)
855
+ tpVertices.append(v)
856
+ graph = topologic.Graph(tpVertices, tpEdges)
857
+ return graph
858
+