petal-qc 0.0.3__py3-none-any.whl → 0.0.5__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.
Potentially problematic release.
This version of petal-qc might be problematic. Click here for more details.
- petal_qc/BTreport/CheckBTtests.py +16 -45
- petal_qc/__init__.py +12 -3
- petal_qc/dashBoard.py +117 -10
- petal_qc/metrology/PetalMetrology.py +97 -56
- petal_qc/metrology/analyze_locking_points.py +4 -4
- petal_qc/metrology/compare_Cores.py +173 -34
- petal_qc/metrology/convert_smartscope.py +95 -12
- petal_qc/metrology/coreMetrology.py +2 -2
- petal_qc/metrology/do_Metrology.py +20 -17
- petal_qc/metrology/petal_flatness.py +8 -3
- petal_qc/test/prepareDESYfiles.py +86 -0
- petal_qc/thermal/IRDataGetter.py +5 -3
- petal_qc/thermal/IRPetal.py +1 -1
- petal_qc/thermal/analyze_IRCore.py +33 -15
- petal_qc/thermal/coreThermal.py +4 -2
- petal_qc/thermal/create_IRCore.py +5 -3
- petal_qc/thermal/create_core_report.py +21 -3
- petal_qc/utils/Geometry.py +8 -3
- {petal_qc-0.0.3.dist-info → petal_qc-0.0.5.dist-info}/METADATA +1 -1
- {petal_qc-0.0.3.dist-info → petal_qc-0.0.5.dist-info}/RECORD +25 -24
- {petal_qc-0.0.3.dist-info → petal_qc-0.0.5.dist-info}/WHEEL +1 -1
- {petal_qc-0.0.3.dist-info → petal_qc-0.0.5.dist-info}/entry_points.txt +2 -0
- /petal_qc/{thermal → test}/test_Graphana.py +0 -0
- /petal_qc/{thermal → test}/test_coreThermal.py +0 -0
- {petal_qc-0.0.3.dist-info → petal_qc-0.0.5.dist-info}/top_level.txt +0 -0
|
@@ -11,22 +11,55 @@ import matplotlib.pyplot as plt
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def get_value(data, value_path):
|
|
14
|
-
"""Get the value."""
|
|
14
|
+
"""Get the value from the path given."""
|
|
15
15
|
a = data
|
|
16
16
|
for k in value_path.split('/'):
|
|
17
17
|
a = a[k]
|
|
18
18
|
|
|
19
19
|
return a
|
|
20
20
|
|
|
21
|
+
def save_figure(fig, fnam, prefix=None, dpi=192):
|
|
22
|
+
"""Saves the figure
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
Args:
|
|
25
|
+
fig (Figure): The figure to save
|
|
26
|
+
fnam (str): The name of the output file
|
|
27
|
+
dpi (int, optional): The Dots por Inch. Defaults to 300.
|
|
28
|
+
"""
|
|
29
|
+
if fnam is not None:
|
|
30
|
+
if prefix:
|
|
31
|
+
P = Path(fnam).expanduser().resolve()
|
|
32
|
+
name = prefix + P.name
|
|
33
|
+
out = P.parent / name
|
|
34
|
+
fnam = out
|
|
35
|
+
|
|
36
|
+
print("out: {}".format(fnam))
|
|
37
|
+
fig.savefig(fnam, dpi=dpi)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def read_data_files(options):
|
|
41
|
+
"""Read the data files.
|
|
42
|
+
|
|
43
|
+
It assumes the data file names are in the format:
|
|
44
|
+
|
|
45
|
+
<AlternativeID>-<side>.json
|
|
46
|
+
|
|
47
|
+
AlternativeID is PPC.nnn side is either front or back.
|
|
48
|
+
|
|
49
|
+
Returns the values for front and back petal tests.
|
|
50
|
+
|
|
51
|
+
The results are a dictionary with the file label as key and the requested
|
|
52
|
+
value, which can be a number of an array.
|
|
53
|
+
|
|
54
|
+
the file labels are also returned.
|
|
55
|
+
|
|
56
|
+
"""
|
|
23
57
|
labels = []
|
|
24
58
|
front = {}
|
|
25
59
|
back = {}
|
|
26
|
-
|
|
60
|
+
|
|
27
61
|
for fnam in options.files:
|
|
28
62
|
ifile = Path(fnam).expanduser().resolve()
|
|
29
|
-
print(ifile.name)
|
|
30
63
|
if not ifile.exists():
|
|
31
64
|
print("File does not exist: ", fnam)
|
|
32
65
|
continue
|
|
@@ -43,54 +76,160 @@ def main(options):
|
|
|
43
76
|
label = tmp[0]
|
|
44
77
|
if not label in labels:
|
|
45
78
|
labels.append(label)
|
|
46
|
-
|
|
47
|
-
is_front = False
|
|
48
|
-
if "front" in tmp[1].lower():
|
|
49
|
-
is_front = True
|
|
50
|
-
|
|
79
|
+
|
|
51
80
|
val = get_value(data, options.value)
|
|
52
|
-
if
|
|
81
|
+
if "front" in tmp[1].lower():
|
|
53
82
|
front[label] = val
|
|
54
83
|
else:
|
|
55
84
|
back[label] = val
|
|
56
85
|
|
|
57
86
|
labels.sort()
|
|
58
|
-
|
|
59
|
-
|
|
87
|
+
|
|
88
|
+
return front, back, labels
|
|
89
|
+
|
|
90
|
+
def draw_deltas(data, keys, fnam=None, title="Front"):
|
|
91
|
+
"""Plot the position deltas."""
|
|
92
|
+
key_table = {"Bot.": "PL01", "Slot": "PL02", "Top": "PL03",
|
|
93
|
+
"Bot-FD01": "PL01-FD01", "Bot-FD02": "PL01-FD02", "FD01-FD02": "FD01-FD02" }
|
|
94
|
+
nfiles = len(data)
|
|
95
|
+
|
|
96
|
+
P = [np.zeros([nfiles, 2]),
|
|
97
|
+
np.zeros([nfiles, 2]),
|
|
98
|
+
np.zeros([nfiles, 2])]
|
|
99
|
+
fig_width = 12.0
|
|
100
|
+
fig_height = 1.2*fig_width/3.0
|
|
101
|
+
fig, ax = plt.subplots(nrows=1, ncols=3, tight_layout=True, figsize=(fig_width, fig_height))
|
|
102
|
+
fig.suptitle(title)
|
|
103
|
+
for i in range(3):
|
|
104
|
+
LBL = [[],[],[]]
|
|
105
|
+
ax[i].set_title(keys[i])
|
|
106
|
+
ax[i].set_aspect('equal', adjustable='box')
|
|
107
|
+
ax[i].set_xlim(-100, 100)
|
|
108
|
+
ax[i].set_ylim(-100, 100)
|
|
109
|
+
circle = plt.Circle((0,0), 50, color="red", alpha=0.25)
|
|
110
|
+
ax[i].add_patch(circle)
|
|
111
|
+
circle = plt.Circle((0,0), 25, color="green", alpha=0.25)
|
|
112
|
+
ax[i].add_patch(circle)
|
|
113
|
+
|
|
114
|
+
ax[i].set_xlabel("X (µm)")
|
|
115
|
+
ax[i].set_ylabel("Y (µm)")
|
|
116
|
+
ax[i].grid()
|
|
117
|
+
|
|
118
|
+
for j, v in enumerate(data.items()):
|
|
119
|
+
label, values = v
|
|
120
|
+
for k in range(3):
|
|
121
|
+
ky = key_table[keys[k]]
|
|
122
|
+
P[k][j, :] = 1000*np.array(values[ky])
|
|
123
|
+
LBL[k].append(label.split('.')[1].lstrip('0'))
|
|
124
|
+
|
|
125
|
+
ax[i].scatter(P[i][:,0], P[i][:,1])
|
|
126
|
+
for j in range(len(LBL[i])):
|
|
127
|
+
ax[i].text(P[i][j,0], P[i][j,1], LBL[i][j]) #, ha='center', va='top')
|
|
128
|
+
|
|
129
|
+
save_figure(fig, fnam, prefix=title)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def show_positions(options):
|
|
133
|
+
"""Make position plots."""
|
|
134
|
+
|
|
135
|
+
if "LOCATION" in options.value:
|
|
136
|
+
keys = ["Bot.", "Slot", "Top"]
|
|
137
|
+
elif "REL_POS" in options.value:
|
|
138
|
+
keys = ["Bot-FD01", "Bot-FD02", "FD01-FD02"]
|
|
139
|
+
else:
|
|
140
|
+
print("Invalid value")
|
|
141
|
+
return
|
|
142
|
+
|
|
143
|
+
front, back, labels = read_data_files(options)
|
|
144
|
+
val_name = options.value.split('/')[-1]
|
|
145
|
+
draw_deltas(front, keys, fnam=options.out, title="{} - Front".format(val_name))
|
|
146
|
+
draw_deltas(back, keys, fnam=options.out, title="{} - Back".format(val_name))
|
|
147
|
+
|
|
148
|
+
plt.show()
|
|
149
|
+
|
|
150
|
+
def show_flatness(options):
|
|
151
|
+
"""Show flatness plots."""
|
|
152
|
+
tick_labels = ["R0", "R1", "R2", "R3S0", "R3S1", "R4S0", "R4S1", "R5S0", "R5S1"]
|
|
153
|
+
cindx = ["Front", "Back"]
|
|
154
|
+
|
|
155
|
+
front, back, labels = read_data_files(options)
|
|
156
|
+
nfiles = len(labels)
|
|
157
|
+
npts = len(tick_labels)
|
|
158
|
+
X = np.array([float(x) for x in range(npts)])
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
fig, ax = plt.subplots(nrows=1, ncols=2, tight_layout=True, figsize=(9., 5.))
|
|
60
162
|
fig.suptitle(options.value)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
163
|
+
|
|
164
|
+
P = [ np.zeros([nfiles, npts]), np.zeros([nfiles, npts]) ]
|
|
165
|
+
y_lim = []
|
|
166
|
+
for i, V in enumerate([front, back]):
|
|
167
|
+
ax[i].set_title(cindx[i])
|
|
168
|
+
ax[i].set_xticks(range(npts), labels=tick_labels)
|
|
169
|
+
ax[i].grid()
|
|
170
|
+
|
|
171
|
+
for lbl in labels:
|
|
172
|
+
ax[i].plot(X, V[lbl], '-', label=lbl)
|
|
173
|
+
|
|
174
|
+
y_lim.append(ax[i].get_ylim())
|
|
175
|
+
|
|
176
|
+
for a in ax:
|
|
177
|
+
a.set_ylim(0, 1.2*max(y_lim[0][1], y_lim[1][1]))
|
|
178
|
+
x_lim = a.get_xlim()
|
|
179
|
+
a.fill_between(x_lim, 0, 0.050, facecolor="darkseagreen", alpha=0.1)
|
|
180
|
+
a.legend(ncol=3, fontsize="x-small")
|
|
181
|
+
|
|
182
|
+
save_figure(fig, options.out, prefix=opts.prefix)
|
|
183
|
+
|
|
184
|
+
def main(options):
|
|
185
|
+
"""Main entry."""
|
|
186
|
+
|
|
187
|
+
if "LOCATION" in options.value or "REL_POS" in options.value:
|
|
188
|
+
show_positions(options)
|
|
189
|
+
|
|
190
|
+
elif "FLATNESS_LOCAL" in options.value:
|
|
191
|
+
show_flatness(options)
|
|
192
|
+
|
|
193
|
+
else:
|
|
194
|
+
front, back, labels = read_data_files(options)
|
|
195
|
+
|
|
196
|
+
labels.sort()
|
|
197
|
+
X = np.arange(0, len(labels))
|
|
198
|
+
fig, ax = plt.subplots(1, 1, tight_layout=True)
|
|
199
|
+
fig.suptitle(options.value)
|
|
200
|
+
ax.set_xticks(range(len(labels)), labels=labels, rotation="vertical")
|
|
201
|
+
ax.grid()
|
|
202
|
+
|
|
203
|
+
vfront = [front[x] for x in labels]
|
|
204
|
+
vback = [back[x] for x in labels]
|
|
205
|
+
ax.plot(X, vfront, '*', label="Front")
|
|
206
|
+
ax.plot(X, vback, 'o', label="Back")
|
|
207
|
+
ax.legend()
|
|
208
|
+
|
|
209
|
+
save_figure(fig, options.out, prefix=options.prefix)
|
|
210
|
+
|
|
73
211
|
plt.show()
|
|
74
|
-
|
|
212
|
+
|
|
75
213
|
|
|
76
214
|
if __name__ == "__main__":
|
|
77
215
|
# Argument parser
|
|
78
216
|
parser = argparse.ArgumentParser()
|
|
79
217
|
parser.add_argument('files', nargs='*', help="Input files")
|
|
80
218
|
parser.add_argument("--value", default=None, help="Value to plot")
|
|
219
|
+
parser.add_argument("--prefix", default=None, help="prefix for out file")
|
|
81
220
|
parser.add_argument("--out", default=None, help="File to store the figure.")
|
|
82
221
|
|
|
83
|
-
|
|
84
|
-
if len(
|
|
222
|
+
opts = parser.parse_args()
|
|
223
|
+
if len(opts.files) == 0:
|
|
85
224
|
print("I need at least one input file")
|
|
86
225
|
sys.exit()
|
|
87
226
|
|
|
88
|
-
|
|
89
|
-
xxx = any(elem in
|
|
227
|
+
elif len(opts.files) == 1:
|
|
228
|
+
xxx = any(elem in opts.files[0] for elem in r"*?")
|
|
90
229
|
if xxx:
|
|
91
|
-
|
|
230
|
+
opts.files = glob.glob(opts.files[0])
|
|
92
231
|
|
|
93
|
-
if
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
main(
|
|
232
|
+
if opts.value[0] == '/':
|
|
233
|
+
opts.value = opts.value[1:]
|
|
234
|
+
opts.value = "results/METROLOGY/" + opts.value
|
|
235
|
+
main(opts)
|
|
@@ -10,15 +10,15 @@ import matplotlib.pyplot as plt
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
from petal_qc.metrology import DataFile
|
|
13
|
-
from .analyze_locking_points import analyze_locking_point_data
|
|
13
|
+
#from .analyze_locking_points import analyze_locking_point_data
|
|
14
14
|
|
|
15
15
|
def get_data_chunck(flist, data_type, ofile):
|
|
16
16
|
"""Get one data type chunk from file
|
|
17
17
|
|
|
18
18
|
Args:
|
|
19
|
-
fname
|
|
20
|
-
data_tyle
|
|
21
|
-
ofile
|
|
19
|
+
fname: input file
|
|
20
|
+
data_tyle: data type
|
|
21
|
+
ofile: file object for output.
|
|
22
22
|
|
|
23
23
|
"""
|
|
24
24
|
rgx = "Step Name:\\s+({}).*?=".format(data_type)
|
|
@@ -41,7 +41,7 @@ def get_data_chunck(flist, data_type, ofile):
|
|
|
41
41
|
ofile.write(txt.group(0)+'\n')
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
def read_smartscope(fnam, ofile, data_type, keep=False
|
|
44
|
+
def read_smartscope(fnam, ofile, data_type, keep=False):
|
|
45
45
|
"""Convert a SmartScope txt file into CVS
|
|
46
46
|
|
|
47
47
|
Args:
|
|
@@ -58,7 +58,11 @@ def read_smartscope(fnam, ofile, data_type, keep=False,):
|
|
|
58
58
|
if isinstance(ofile, io.IOBase):
|
|
59
59
|
fout = ofile
|
|
60
60
|
else:
|
|
61
|
-
|
|
61
|
+
try:
|
|
62
|
+
fout = open(ofile, 'w', encoding="utf-8")
|
|
63
|
+
except TypeError:
|
|
64
|
+
fout = ofile
|
|
65
|
+
|
|
62
66
|
is_file = True
|
|
63
67
|
|
|
64
68
|
if keep:
|
|
@@ -106,7 +110,84 @@ def read_smartscope(fnam, ofile, data_type, keep=False,):
|
|
|
106
110
|
values = [ float(x) for x in items[2:5]]
|
|
107
111
|
fout.write("{:6f}, {:6f}, {:6f}\n".format(values[1], values[0], values[2]))
|
|
108
112
|
|
|
109
|
-
|
|
113
|
+
if is_file:
|
|
114
|
+
fout.close()
|
|
115
|
+
|
|
116
|
+
def get_smarscope_locator_positions(fnam, ofile, data_type, keep=False):
|
|
117
|
+
"""REad DESY 2D file.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
fnam: Input file
|
|
121
|
+
ofile: Output file
|
|
122
|
+
data_type: Label to search
|
|
123
|
+
keep (bool, optional): If tre keep label. Defaults to False.
|
|
124
|
+
"""
|
|
125
|
+
ifile = Path(fnam).expanduser().resolve()
|
|
126
|
+
|
|
127
|
+
is_file = False
|
|
128
|
+
if isinstance(ofile, io.IOBase):
|
|
129
|
+
fout = ofile
|
|
130
|
+
else:
|
|
131
|
+
try:
|
|
132
|
+
fout = open(ofile, 'w', encoding="utf-8")
|
|
133
|
+
except TypeError:
|
|
134
|
+
fout = ofile
|
|
135
|
+
|
|
136
|
+
is_file = True
|
|
137
|
+
|
|
138
|
+
if keep:
|
|
139
|
+
fout.write("X,Y,Z, label\n")
|
|
140
|
+
else:
|
|
141
|
+
fout.write("X,Y,Z\n")
|
|
142
|
+
|
|
143
|
+
rgx = "^Step Name:\\s+(?P<label>{})".format(data_type)
|
|
144
|
+
start = re.compile(rgx, re.DOTALL)
|
|
145
|
+
finder = re.compile("^Finder Name")
|
|
146
|
+
|
|
147
|
+
out = {}
|
|
148
|
+
with open(ifile, 'r', encoding='ISO-8859-1') as fin:
|
|
149
|
+
while True:
|
|
150
|
+
line = fin.readline()
|
|
151
|
+
if not line:
|
|
152
|
+
break
|
|
153
|
+
|
|
154
|
+
r = start.match(line)
|
|
155
|
+
if not r:
|
|
156
|
+
continue
|
|
157
|
+
|
|
158
|
+
label = r.group('label').strip()
|
|
159
|
+
eof = False
|
|
160
|
+
out[label] = [0. for i in range(3)]
|
|
161
|
+
for i in range(3):
|
|
162
|
+
line = fin.readline()
|
|
163
|
+
|
|
164
|
+
while True:
|
|
165
|
+
line = fin.readline().strip()
|
|
166
|
+
if len(line)==0:
|
|
167
|
+
break
|
|
168
|
+
|
|
169
|
+
values = line.split()
|
|
170
|
+
val = float(values[3])
|
|
171
|
+
if values[0] in ["Diame", "Width"]:
|
|
172
|
+
out[label][2] = val
|
|
173
|
+
elif values[0] == "X":
|
|
174
|
+
out[label][1] = val
|
|
175
|
+
elif values[0] == "Y":
|
|
176
|
+
out[label][0] = val
|
|
177
|
+
|
|
178
|
+
lbls = ["BottomPL", "SlotPL", "OversizedPL", "Bottom_Fiducial", "Slot_Fiducial"]
|
|
179
|
+
for L in lbls:
|
|
180
|
+
try:
|
|
181
|
+
V = [float(x) for x in out[L]]
|
|
182
|
+
fout.write("{:.6f}, {:.6f}, {:.6f}".format(V[0], V[1], V[2]))
|
|
183
|
+
if keep:
|
|
184
|
+
fout.write(", {}".format(L))
|
|
185
|
+
fout.write('\n')
|
|
186
|
+
except KeyError:
|
|
187
|
+
continue
|
|
188
|
+
|
|
189
|
+
if is_file:
|
|
190
|
+
fout.close()
|
|
110
191
|
|
|
111
192
|
def do_locking_points(args):
|
|
112
193
|
ifile = args.smartscope_files[0]
|
|
@@ -120,14 +201,14 @@ if __name__ == "__main__":
|
|
|
120
201
|
import argparse
|
|
121
202
|
|
|
122
203
|
parser = argparse.ArgumentParser()
|
|
123
|
-
parser.add_argument("
|
|
204
|
+
parser.add_argument("files", nargs='*',
|
|
124
205
|
help="The SmartScope files to parse")
|
|
125
206
|
parser.add_argument("--label", default="\\w+", help="The label to select")
|
|
126
207
|
parser.add_argument("--out", help="Output CSV file", default="out.csv")
|
|
127
208
|
parser.add_argument("--keep_label", dest="keep", default=False, action="store_true", help="Store label in output")
|
|
128
209
|
|
|
129
210
|
args = parser.parse_args()
|
|
130
|
-
if len(args.
|
|
211
|
+
if len(args.files) == 0:
|
|
131
212
|
print("I need an input file")
|
|
132
213
|
sys.exit()
|
|
133
214
|
|
|
@@ -135,11 +216,13 @@ if __name__ == "__main__":
|
|
|
135
216
|
|
|
136
217
|
# do_locking_points(args)
|
|
137
218
|
|
|
138
|
-
fout = open(Path(args.out).expanduser().resolve(), 'w')
|
|
139
|
-
get_data_chunck(args.smartscope_files, args.label, fout)
|
|
140
|
-
fout.close()
|
|
219
|
+
#fout = open(Path(args.out).expanduser().resolve(), 'w')
|
|
220
|
+
#get_data_chunck(args.smartscope_files, args.label, fout)
|
|
221
|
+
#fout.close()
|
|
141
222
|
|
|
142
223
|
|
|
143
224
|
#read_smartscope(args.smartscope_files[0], args.out, args.label, args.keep)
|
|
144
225
|
|
|
226
|
+
get_smarscope_locator_positions(args.files[0], args.out, args.label)
|
|
227
|
+
|
|
145
228
|
plt.show()
|
|
@@ -16,7 +16,7 @@ import gi
|
|
|
16
16
|
gi.require_version("Gtk", "3.0")
|
|
17
17
|
from gi.repository import Gtk, GObject, Gio, GLib
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
__HELP__ = "https://petal-qc.docs.cern.ch"
|
|
20
20
|
|
|
21
21
|
class CommaSeparatedListAction(Action):
|
|
22
22
|
"""Create a list from the comma sepparated numbers at imput."""
|
|
@@ -41,7 +41,7 @@ class CoreMetrology(itkdb_gtk.dbGtkUtils.ITkDBWindow):
|
|
|
41
41
|
pannel_size: size of message panel.
|
|
42
42
|
|
|
43
43
|
"""
|
|
44
|
-
super().__init__(session=session, title=title)
|
|
44
|
+
super().__init__(session=session, title=title, help=__HELP__)
|
|
45
45
|
|
|
46
46
|
self.data_file = None
|
|
47
47
|
self.folder = None
|
|
@@ -42,13 +42,13 @@ def do_analysis(fnam, prefix, SN, options):
|
|
|
42
42
|
"""Perform analysis of a file.
|
|
43
43
|
|
|
44
44
|
Args:
|
|
45
|
-
fnam
|
|
46
|
-
prefix
|
|
47
|
-
SN
|
|
48
|
-
options
|
|
49
|
-
|
|
45
|
+
fnam: Input data file
|
|
46
|
+
prefix: Prefix telling if it is front or back
|
|
47
|
+
SN: Core serial number
|
|
48
|
+
options: Options.
|
|
49
|
+
|
|
50
50
|
"""
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
is_front = prefix.lower().find("front") >= 0
|
|
53
53
|
print(fnam, prefix)
|
|
54
54
|
options.out = prefix + '.docx'
|
|
@@ -63,10 +63,10 @@ def do_analysis(fnam, prefix, SN, options):
|
|
|
63
63
|
ofile = output_folder(options.folder, prefix + '.json')
|
|
64
64
|
with open(ofile, 'w', encoding='UTF-8') as of:
|
|
65
65
|
json.dump(outDB, of, indent=3)
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
return outDB
|
|
68
68
|
|
|
69
|
-
def
|
|
69
|
+
def analyze_files(ifile, options):
|
|
70
70
|
"""Main entry."""
|
|
71
71
|
with open(ifile, 'r', encoding='UTF-8') as inp:
|
|
72
72
|
|
|
@@ -86,25 +86,25 @@ def main(ifile, options):
|
|
|
86
86
|
|
|
87
87
|
do_analysis(fnam, prefix, SN, options)
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
def main():
|
|
90
|
+
"Main entry."
|
|
91
91
|
parser = ArgumentParser()
|
|
92
92
|
parser.add_argument('files', nargs='*', help="Input files")
|
|
93
|
-
parser.add_argument("--prefix", dest='prefix', default=None)
|
|
94
|
-
parser.add_argument("--SN", dest='SN', default=None)
|
|
93
|
+
parser.add_argument("--prefix", dest='prefix', default=None, help="prefix telling if it is front or back.")
|
|
94
|
+
parser.add_argument("--SN", dest='SN', default=None, help="The petal core Serial Number")
|
|
95
95
|
parser.add_argument("--save", dest='save', action="store_true", default=False)
|
|
96
|
-
parser.add_argument("--desy", dest='desy', action="store_true", default=False)
|
|
96
|
+
parser.add_argument("--desy", dest='desy', action="store_true", default=False, help="True if data is from DESY's SmartScope")
|
|
97
97
|
parser.add_argument("--out", dest="out", default="petal_flatness.docx",
|
|
98
|
-
type=str, help="The output
|
|
98
|
+
type=str, help="The output file name")
|
|
99
99
|
parser.add_argument("--bottom-lp", dest='bLP', action=CommaSeparatedListAction, default=None,
|
|
100
100
|
help="Bottom locking point fiducial coordinates")
|
|
101
101
|
parser.add_argument("--upper-lp", dest='uLP', action=CommaSeparatedListAction, default=None,
|
|
102
102
|
help="upper locking point fiducials coordinates")
|
|
103
103
|
|
|
104
104
|
parser.add_argument("--title", dest="title", default=None,
|
|
105
|
-
type=str, help="Document title")
|
|
105
|
+
type=str, help="Report Document title")
|
|
106
106
|
parser.add_argument("--nbins", dest="nbins", default=25,
|
|
107
|
-
type=int, help="Number of bins")
|
|
107
|
+
type=int, help="Number of bins in the histograms")
|
|
108
108
|
parser.add_argument("--folder", default=None, help="Folder to store output files. Superseeds folder in --out")
|
|
109
109
|
parser.add_argument("--locking_points", action="store_true", default=False)
|
|
110
110
|
|
|
@@ -119,7 +119,10 @@ if __name__ == "__main__":
|
|
|
119
119
|
sys.exit()
|
|
120
120
|
|
|
121
121
|
try:
|
|
122
|
-
|
|
122
|
+
analyze_files(options.files[0], options)
|
|
123
123
|
|
|
124
124
|
except Exception:
|
|
125
125
|
print(traceback.format_exc())
|
|
126
|
+
|
|
127
|
+
if __name__ == "__main__":
|
|
128
|
+
main()
|
|
@@ -162,7 +162,12 @@ def petal_flatness(orig_data, options, document=None):
|
|
|
162
162
|
flatness_func = flatness_LSPL
|
|
163
163
|
F = {}
|
|
164
164
|
for key, val in sensors.items():
|
|
165
|
-
|
|
165
|
+
try:
|
|
166
|
+
F[key] = flatness_func(val)
|
|
167
|
+
except ValueError as E:
|
|
168
|
+
print("*** Error: Petal flatnes: key {}\n{}".format(key, E))
|
|
169
|
+
print(val)
|
|
170
|
+
return TM, avg, Zmean, [-9999, -9999]
|
|
166
171
|
|
|
167
172
|
flatness_all_sensor_area = flatness_func(all_data)
|
|
168
173
|
|
|
@@ -182,7 +187,7 @@ def petal_flatness(orig_data, options, document=None):
|
|
|
182
187
|
outF.extend(values)
|
|
183
188
|
print("{}: {:.3f} {}: {:.3f}".format(lbls[0], values[0], lbls[1], values[1]))
|
|
184
189
|
|
|
185
|
-
print("All sensor area: {:.3f}".format(flatness_all_sensor_area))
|
|
190
|
+
print("All sensor area: {:.3f}".format(1000*flatness_all_sensor_area))
|
|
186
191
|
|
|
187
192
|
# Add table in document
|
|
188
193
|
if document:
|
|
@@ -213,7 +218,7 @@ def petal_flatness(orig_data, options, document=None):
|
|
|
213
218
|
# add allsensor area
|
|
214
219
|
cell = table.add_row().cells
|
|
215
220
|
cell[0].text = "All sensor area"
|
|
216
|
-
cell[1].text = "{:.4f}".format(flatness_all_sensor_area)
|
|
221
|
+
cell[1].text = "{:.4f}".format(flatness_all_sensor_area*1000)
|
|
217
222
|
|
|
218
223
|
return TM, avg, Zmean, outF
|
|
219
224
|
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Prepara input files from DESY RAW."""
|
|
3
|
+
import os
|
|
4
|
+
import fnmatch
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
def all_files(root, patterns='*', single_level=False, yield_folders=False):
|
|
9
|
+
"""A generator that reruns all files in the given folder.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
----
|
|
13
|
+
root (file path): The folder
|
|
14
|
+
patterns (str, optional): The pattern of the files. Defaults to '*'.
|
|
15
|
+
single_level (bool, optional): If true, do not go into sub folders. Defaults to False.
|
|
16
|
+
yield_folders (bool, optional): If True, return folders as well. Defaults to False.
|
|
17
|
+
|
|
18
|
+
Yields
|
|
19
|
+
------
|
|
20
|
+
str: file path name
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
patterns = patterns.split(';')
|
|
24
|
+
for path, subdirs, files in os.walk(root):
|
|
25
|
+
if yield_folders:
|
|
26
|
+
files.extend(subdirs)
|
|
27
|
+
|
|
28
|
+
files.sort()
|
|
29
|
+
for name in files:
|
|
30
|
+
for pattern in patterns:
|
|
31
|
+
if fnmatch.fnmatch(name, pattern):
|
|
32
|
+
yield os.path.join(path, name)
|
|
33
|
+
break
|
|
34
|
+
|
|
35
|
+
if single_level:
|
|
36
|
+
break
|
|
37
|
+
|
|
38
|
+
class PetalCore:
|
|
39
|
+
def __init__(self, front, back):
|
|
40
|
+
self.front = {}
|
|
41
|
+
self.back = {}
|
|
42
|
+
|
|
43
|
+
def main(folder, out_folder):
|
|
44
|
+
"""Main entry point."""
|
|
45
|
+
outF = Path(out_folder).expanduser().resolve()
|
|
46
|
+
if not outF.exists():
|
|
47
|
+
os.mkdir(outF)
|
|
48
|
+
|
|
49
|
+
rgx = re.compile(r"Project Name: (\w+)side_.*AlternativeID=PPC-(\d+)", re.MULTILINE|re.DOTALL)
|
|
50
|
+
petal_cores = {}
|
|
51
|
+
for fnam in all_files(folder, "*.txt"):
|
|
52
|
+
P = Path(fnam).expanduser().resolve()
|
|
53
|
+
with open(fnam, "r", encoding="UTF-8") as ff:
|
|
54
|
+
R = rgx.search(ff.read())
|
|
55
|
+
if R:
|
|
56
|
+
petal_id = "PPC.{}".format(R.group(2))
|
|
57
|
+
side = R.group(1).lower()
|
|
58
|
+
if "_2D_" in P.name:
|
|
59
|
+
test_type = "2D"
|
|
60
|
+
else:
|
|
61
|
+
test_type = "3D"
|
|
62
|
+
|
|
63
|
+
if not petal_id in petal_cores:
|
|
64
|
+
petal_cores[petal_id] = {
|
|
65
|
+
"back":{"2D":None, "3D":None},
|
|
66
|
+
"front":{"2D":None, "3D":None},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
petal_cores[petal_id][side][test_type] = P
|
|
70
|
+
|
|
71
|
+
list_file = open("{}/Desy-cores.txt".format(outF.as_posix()), "w", encoding="UTF-8")
|
|
72
|
+
for petal_id, sides in petal_cores.items():
|
|
73
|
+
for side, values in sides.items():
|
|
74
|
+
oname = "{}/{}-{}.txt".format(outF.as_posix(), petal_id, side)
|
|
75
|
+
list_file.write("{} {}-{} {}\n".format(oname, petal_id, side, petal_id))
|
|
76
|
+
data = ""
|
|
77
|
+
for data_type, fnam in values.items():
|
|
78
|
+
with open(fnam, "r", encoding="UTF-8") as ifile:
|
|
79
|
+
data += ifile.read()
|
|
80
|
+
|
|
81
|
+
with open(oname, "w", encoding="UTF-8") as ofile:
|
|
82
|
+
ofile.write(data)
|
|
83
|
+
|
|
84
|
+
list_file.close()
|
|
85
|
+
if __name__ == "__main__":
|
|
86
|
+
main("/Users/lacasta/Downloads/DESY_Production", "/tmp/desy")
|
petal_qc/thermal/IRDataGetter.py
CHANGED
|
@@ -133,7 +133,8 @@ class IRDataIFIC(IRDataGetter):
|
|
|
133
133
|
super().__init__()
|
|
134
134
|
self.analysis_frame = None
|
|
135
135
|
if HAS_GRAPHANA:
|
|
136
|
-
self.DB = ReadGraphana("localhost")
|
|
136
|
+
#self.DB = ReadGraphana("localhost")
|
|
137
|
+
self.DB = ReadGraphana()
|
|
137
138
|
else:
|
|
138
139
|
self.DB = None
|
|
139
140
|
|
|
@@ -156,9 +157,10 @@ class IRDataIFIC(IRDataGetter):
|
|
|
156
157
|
"""
|
|
157
158
|
irbf.set_concatenate(True)
|
|
158
159
|
frame = self.get_analysis_frame(irbf)
|
|
159
|
-
i_min = self.indx
|
|
160
|
+
i_min = self.indx[-1]
|
|
160
161
|
min_T = np.min(frame[0].image)
|
|
161
|
-
|
|
162
|
+
values = self.get_IR_data(frame[0])
|
|
163
|
+
return min_T, i_min, [values, ]
|
|
162
164
|
|
|
163
165
|
# if len(args) == 0:
|
|
164
166
|
# T_min = -22.0
|
petal_qc/thermal/IRPetal.py
CHANGED
|
@@ -551,7 +551,7 @@ def get_T_profile(data, A, B, npts=10, do_fit=False, npdim=7, debug=False):
|
|
|
551
551
|
fmin.success = True
|
|
552
552
|
break
|
|
553
553
|
|
|
554
|
-
# If
|
|
554
|
+
# If there is a clear minimum within the segment
|
|
555
555
|
if fmin.success and fmin.x[0] > 0 and fmin.x[0] < mx_dist:
|
|
556
556
|
# This should no happen. if minimize returns we should have found
|
|
557
557
|
# at least a valid root.
|