-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateTrainingAndTestData.py
67 lines (55 loc) · 2.09 KB
/
createTrainingAndTestData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import random
from scraperTools import getDataFromFile, saveDataToFile
from tensorflow.keras.preprocessing.text import one_hot as one_hot_text
from tensorflow import one_hot
import numpy as np
random.seed("a")
net_vocab_size = 250
max_net_char_len = 8
maxLayers = 32 + 2
def extractPads(shapes):
padsList = []
for shape in shapes:
if "PAD" in shape:
padsList.append(compressPadData(shape["PAD"]))
elif "LIB" in shape:
padsList = padsList + extractPads(shape["LIB"])
return padsList
def compressPadData(pad):
# padTypes = {"RECT": [1, 0, 0],"OVAL":[0, 1, 0], "ELLIPSE":[0, 0, 1], "POLYGON": [0, 0, 0]}
padCompressed = dict()
padCompressed["pos"] = [pad['x'],pad['y']]
padCompressed["size"] = [pad['width'], pad['height']]
padCompressed["layer"] = pad['layer']
padCompressed["net"] = pad['net']
# padCompressed[4] = padTypes[pad["type"]]
# padCompressed[5] = pad['rot']
return padCompressed
def extractRouteElements(shapes):
routeList = []
copperLayers = [1,2] + list(range(21,52 + 1))
for shape in shapes:
if "TRACK" in shape:
if int(shape["TRACK"]["layer"]) in copperLayers:
routeList = routeList + compressRouteData(shape["TRACK"])
# elif "VIA" in shape: # TODO Consider VIAs
# routeList.append(compressRouteData(shape["VIA"]))
elif "LIB" in shape:
routeList = routeList + extractRouteElements(shape["LIB"])
return routeList
def compressRouteData(route):
#assumes route is track
routeList = []
lastPoint = route["points"][0]
for point in route["points"][1:]: #takes each pair of points, so skips first
routeCompressed = [None]*7
routeCompressed[0] = route["width"]
routeCompressed[1] = route["layer"]
routeCompressed[2] = route["net"]
routeCompressed[3] = point[0]
routeCompressed[4] = point[1]
routeCompressed[5] = lastPoint[0]
routeCompressed[6] = lastPoint[1]
routeList.append(routeCompressed)
lastPoint = point
return routeList