petal-qc 0.0.2__py3-none-any.whl → 0.0.4__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/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
1
  """petal_qc python module."""
2
- __version__ = "0.0.2"
2
+ __version__ = "0.0.4"
3
3
 
4
4
 
5
5
  def coreMetrology():
@@ -7,6 +7,12 @@ def coreMetrology():
7
7
  from .metrology.coreMetrology import main
8
8
  main()
9
9
 
10
+ def coreThermal():
11
+ """Launches the Core thermal analysis ahd PDB script."""
12
+ from .thermal.coreThermal import main
13
+ main()
14
+
15
+
10
16
  def bustapeReport():
11
17
  """Launches the Core metrology analysis ahd PDB script."""
12
18
  from .BTreport.bustapeReport import main
@@ -130,7 +130,7 @@ def petal_metrology(ifile, options):
130
130
  if options.desy:
131
131
  flatness_data = DataFile.read(ifile, "PetalPlane")
132
132
  else:
133
- flatness_data = DataFile.read(ifile, r"Punto[-|Vision-]\w", "Punto")
133
+ flatness_data = DataFile.read(ifile, r"Punto(-|(Vision-))\d", "Punto")
134
134
  Fmean = np.mean(flatness_data[:, 2])
135
135
  flatness_data[:, 2] -= Fmean
136
136
 
@@ -170,10 +170,10 @@ def petal_metrology(ifile, options):
170
170
  if key == "COPLANARITY_LOCATORS" and not check_spec(val, 0.1):
171
171
  dbOut["comments"].append(
172
172
  "Coplanarity of locators: {:.3f} mm".format(val))
173
- elif key == "PARALLELISM" and not check_spec(abs(val), 0.1):
173
+ elif key == "PARALLELISM" and not check_spec(abs(val), 0.2):
174
174
  dbOut["defects"].append({
175
175
  "name": key,
176
- "description": "Paralelism of locators is {:.3f} mm > 0.100 mm".format(val)
176
+ "description": "Paralelism of locators is {:.3f} mm > 0.200 mm".format(val)
177
177
  })
178
178
  elif key == "OFFSET" and not check_spec(abs(val), 0.100):
179
179
  dbOut["comments"].append("Offset of locator plane w.r.t BT is {:.3f} mm".format(val))
@@ -303,7 +303,7 @@ def analyze_locking_point_data(orig_data, nbins=50, plane_fit=True, cut=3, docum
303
303
  max_par = -9999
304
304
  for i in range(3):
305
305
  pts = M[iloc_indx[i], 2] + 0.435
306
- _, _, band = get_min_max(pts)
306
+ vmin, vmax, band = get_min_max(pts)
307
307
  avg_pts = np.mean(pts)
308
308
  if abs(avg_pts) > max_par:
309
309
  max_par = abs(avg_pts)
@@ -312,8 +312,6 @@ def analyze_locking_point_data(orig_data, nbins=50, plane_fit=True, cut=3, docum
312
312
  print("Loc par. {} - {:.3f} avg: {:.3f}".format(i, band, avg_pts))
313
313
  ax.hist(pts, bins=xaxis, label="Avg {:.3f} band {:.3f} mm".format(avg_pts, band))
314
314
 
315
- parallelism = max_avg
316
-
317
315
  ax.legend(loc='upper left')
318
316
  y_lim = ax.get_ylim()
319
317
  ax.fill_between([-0.100, 0.100], y_lim[0], y_lim[1], facecolor="grey", alpha=0.1)
@@ -330,7 +328,7 @@ def analyze_locking_point_data(orig_data, nbins=50, plane_fit=True, cut=3, docum
330
328
 
331
329
  outDB["PARALLELISM"] = parallelism
332
330
  outDB["OFFSET"] = mean_dist
333
- print("Paralelism test: {:.4f}.\n{}".format(parallelism, txt))
331
+ print("Parallelism test: {:.4f}.\n{}".format(parallelism, txt))
334
332
  if document:
335
333
  txt = """To study parallelism, we subtract -0.435 mm to the Z values. \
336
334
  This is the nominal position of locator points. \
@@ -0,0 +1,232 @@
1
+ #!/usr/bin/env python3
2
+ """Compare quantities."""
3
+
4
+ import sys
5
+ import argparse
6
+ import glob
7
+ import json
8
+ from pathlib import Path
9
+ import numpy as np
10
+ import matplotlib.pyplot as plt
11
+
12
+
13
+ def get_value(data, value_path):
14
+ """Get the value from the path given."""
15
+ a = data
16
+ for k in value_path.split('/'):
17
+ a = a[k]
18
+
19
+ return a
20
+
21
+ def save_figure(fig, fnam, prefix=None, dpi=192):
22
+ """Saves the figure
23
+
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
+ """
57
+ labels = []
58
+ front = {}
59
+ back = {}
60
+
61
+ for fnam in options.files:
62
+ ifile = Path(fnam).expanduser().resolve()
63
+ print(ifile.name)
64
+ if not ifile.exists():
65
+ print("File does not exist: ", fnam)
66
+ continue
67
+
68
+ data = None
69
+ with open(ifile, 'r', encoding="UTF-8") as fp:
70
+ data = json.load(fp)
71
+
72
+ if data is None:
73
+ print("Problems reading ", fnam)
74
+ continue
75
+
76
+ tmp = ifile.name.split('-')
77
+ label = tmp[0]
78
+ if not label in labels:
79
+ labels.append(label)
80
+
81
+ val = get_value(data, options.value)
82
+ if "front" in tmp[1].lower():
83
+ front[label] = val
84
+ else:
85
+ back[label] = val
86
+
87
+ labels.sort()
88
+
89
+ return front, back, labels
90
+
91
+ def draw_deltas(data, keys, fnam=None, title="Front"):
92
+ """Plot the position deltas."""
93
+ key_table = {"Bot.": "PL01", "Slot": "PL02", "Top": "PL03",
94
+ "Bot-FD01": "PL01-FD01", "Bot-FD02": "PL01-FD02", "FD01-FD02": "FD01-FD02" }
95
+ nfiles = len(data)
96
+
97
+ P = [np.zeros([nfiles, 2]),
98
+ np.zeros([nfiles, 2]),
99
+ np.zeros([nfiles, 2])]
100
+
101
+ fig_width = 12.0
102
+ fig_height = 1.2*fig_width/3.0
103
+ fig, ax = plt.subplots(nrows=1, ncols=3, tight_layout=True, figsize=(fig_width, fig_height))
104
+ fig.suptitle(title)
105
+ for i in range(3):
106
+ ax[i].set_title(keys[i])
107
+ ax[i].set_aspect('equal', adjustable='box')
108
+ ax[i].set_xlim(-100, 100)
109
+ ax[i].set_ylim(-100, 100)
110
+ circle = plt.Circle((0,0), 50, color="red", alpha=0.25)
111
+ ax[i].add_patch(circle)
112
+ circle = plt.Circle((0,0), 25, color="green", alpha=0.25)
113
+ ax[i].add_patch(circle)
114
+
115
+ ax[i].set_xlabel("X (µm)")
116
+ ax[i].set_ylabel("Y (µm)")
117
+ ax[i].grid()
118
+
119
+ for j, v in enumerate(data.items()):
120
+ label, values = v
121
+ for k in range(3):
122
+ ky = key_table[keys[k]]
123
+ P[k][j, :] = 1000*np.array(values[ky])
124
+
125
+ ax[i].scatter(P[i][:,0], P[i][:,1])
126
+
127
+ save_figure(fig, fnam, prefix=title)
128
+
129
+
130
+ def show_positions(options):
131
+ """Make position plots."""
132
+
133
+ if "LOCATION" in options.value:
134
+ keys = ["Bot.", "Slot", "Top"]
135
+ elif "REL_POS" in options.value:
136
+ keys = ["Bot-FD01", "Bot-FD02", "FD01-FD02"]
137
+ else:
138
+ print("Invalid value")
139
+ return
140
+
141
+ front, back, labels = read_data_files(options)
142
+ val_name = options.value.split('/')[-1]
143
+ draw_deltas(front, keys, fnam=options.out, title="{} - Front".format(val_name))
144
+ draw_deltas(back, keys, fnam=options.out, title="{} - Back".format(val_name))
145
+
146
+ plt.show()
147
+
148
+ def show_flatness(options):
149
+ """Show flatness plots."""
150
+ tick_labels = ["R0", "R1", "R2", "R3S0", "R3S1", "R4S0", "R4S1", "R5S0", "R5S1"]
151
+ cindx = ["Front", "Back"]
152
+
153
+ front, back, labels = read_data_files(options)
154
+ nfiles = len(labels)
155
+ npts = len(tick_labels)
156
+ X = np.array([float(x) for x in range(npts)])
157
+
158
+
159
+ fig, ax = plt.subplots(nrows=1, ncols=2, tight_layout=True, figsize=(9., 5.))
160
+ fig.suptitle(options.value)
161
+
162
+ P = [ np.zeros([nfiles, npts]), np.zeros([nfiles, npts]) ]
163
+ y_lim = []
164
+ for i, V in enumerate([front, back]):
165
+ ax[i].set_title(cindx[i])
166
+ ax[i].set_xticks(range(npts), labels=tick_labels)
167
+ ax[i].grid()
168
+
169
+ for lbl in labels:
170
+ ax[i].plot(X, V[lbl], '-', label=lbl)
171
+
172
+ y_lim.append(ax[i].get_ylim())
173
+
174
+ for a in ax:
175
+ a.set_ylim(0, 1.2*max(y_lim[0][1], y_lim[1][1]))
176
+ a.legend(ncol=3, fontsize="x-small")
177
+
178
+ save_figure(fig, options.out, prefix="zzz-")
179
+
180
+ def main(options):
181
+ """Main entry."""
182
+
183
+ if "LOCATION" in options.value or "REL_POS" in options.value:
184
+ show_positions(options)
185
+ return
186
+
187
+ if "FLATNESS_LOCAL" in options.value:
188
+ show_flatness(options)
189
+ return
190
+
191
+
192
+ front, back, labels = read_data_files(options)
193
+
194
+ labels.sort()
195
+ X = np.arange(0, len(labels))
196
+ fig, ax = plt.subplots(1, 1, tight_layout=True)
197
+ fig.suptitle(options.value)
198
+ ax.set_xticks(range(len(labels)), labels=labels)
199
+ ax.grid()
200
+
201
+ vfront = [front[x] for x in labels]
202
+ vback = [back[x] for x in labels]
203
+ ax.plot(X, vfront, '*', label="Front")
204
+ ax.plot(X, vback, 'o', label="Back")
205
+ ax.legend()
206
+
207
+ save_figure(fig, options.out)
208
+
209
+ plt.show()
210
+
211
+
212
+ if __name__ == "__main__":
213
+ # Argument parser
214
+ parser = argparse.ArgumentParser()
215
+ parser.add_argument('files', nargs='*', help="Input files")
216
+ parser.add_argument("--value", default=None, help="Value to plot")
217
+ parser.add_argument("--out", default=None, help="File to store the figure.")
218
+
219
+ opts = parser.parse_args()
220
+ if len(opts.files) == 0:
221
+ print("I need at least one input file")
222
+ sys.exit()
223
+
224
+ if len(opts.files) == 1:
225
+ xxx = any(elem in opts.files[0] for elem in r"*?")
226
+ if xxx:
227
+ opts.files = glob.glob(opts.files[0])
228
+
229
+ if opts.value[0] == '/':
230
+ opts.value = opts.value[1:]
231
+ opts.value = "results/METROLOGY/" + opts.value
232
+ main(opts)
@@ -14,6 +14,14 @@ from argparse import Action
14
14
  from argparse import ArgumentParser
15
15
  from pathlib import Path
16
16
  import numpy as np
17
+
18
+ try:
19
+ import petal_qc
20
+
21
+ except ImportError:
22
+ cwd = Path(__file__).parent.parent.parent
23
+ sys.path.append(cwd.as_posix())
24
+
17
25
  from petal_qc.utils.utils import output_folder
18
26
 
19
27
  from petal_qc.metrology.PetalMetrology import petal_metrology
@@ -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
- F[key] = flatness_func(val)
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:
@@ -3,6 +3,7 @@
3
3
  import sys
4
4
  from pathlib import Path
5
5
  import datetime
6
+ import numpy as np
6
7
  try:
7
8
  import petal_qc
8
9
 
@@ -16,15 +17,21 @@ from petal_qc.thermal.IRPetalParam import IRPetalParam
16
17
  from petal_qc.thermal import IRBFile
17
18
 
18
19
 
20
+
19
21
  options = IRPetalParam()
20
- options.files = ["/Users/lacasta/tmp/thermal/PPC.007.irb"]
22
+ options.files = [Path("~/tmp/thermal/PPC.008.irb").expanduser().resolve()]
21
23
  getter = IRDataGetter.factory(options.institute, options)
22
24
  DB = ReadGraphana("localhost")
23
25
  irbf = IRBFile.open_file(options.files)
24
26
 
25
27
  frames = getter.get_analysis_frame(irbf)
26
28
  print(frames[0].timestamp)
27
- the_time = datetime.fromtimestamp(timestamp, timezone.utc)
28
- val = DB.get_temperature(frames[0].timestamp, 10)
29
-
30
- print(val)
29
+ the_time = frames[0].timestamp
30
+ try:
31
+ X, val = DB.get_temperature(the_time, 5)
32
+ for x, y in zip(X, val):
33
+ print("{} - {:.1f}".format(x, y))
34
+
35
+ print("{:.1f}".format(np.min(val)))
36
+ except ValueError as e:
37
+ print(e)
@@ -690,7 +690,7 @@ def open_file(fname):
690
690
  fname: Path of input file or list of files.
691
691
 
692
692
  """
693
- irb = None
693
+ irbf = None
694
694
  if is_iterable(fname):
695
695
  # we assume it is a list of IRB files...
696
696
  try:
@@ -31,6 +31,7 @@ class IRDataGetter(object):
31
31
  def __init__(self):
32
32
  """Initialization."""
33
33
  self.factor = 1
34
+ self.indx = -1
34
35
  return
35
36
 
36
37
  @staticmethod
@@ -132,7 +133,8 @@ class IRDataIFIC(IRDataGetter):
132
133
  super().__init__()
133
134
  self.analysis_frame = None
134
135
  if HAS_GRAPHANA:
135
- self.DB = ReadGraphana("localhost")
136
+ #self.DB = ReadGraphana("localhost")
137
+ self.DB = ReadGraphana()
136
138
  else:
137
139
  self.DB = None
138
140
 
@@ -153,18 +155,25 @@ class IRDataIFIC(IRDataGetter):
153
155
 
154
156
 
155
157
  """
156
- if len(args) == 0:
157
- T_min = -22.0
158
- else:
159
- T_min = args[0]
160
-
161
158
  irbf.set_concatenate(True)
162
- min_T, i_min, ref_img = IRPetal.find_reference_image(irbf, T_min)
163
- values = self.get_IR_data(ref_img)
164
- self.factor = values.shape[0]/640
165
-
159
+ frame = self.get_analysis_frame(irbf)
160
+ i_min = self.indx[-1]
161
+ min_T = np.min(frame[0].image)
162
+ values = self.get_IR_data(frame[0])
166
163
  return min_T, i_min, [values, ]
167
164
 
165
+ # if len(args) == 0:
166
+ # T_min = -22.0
167
+ # else:
168
+ # T_min = args[0]
169
+ #
170
+ # irbf.set_concatenate(True)
171
+ # min_T, i_min, ref_img = IRPetal.find_reference_image(irbf, T_min)
172
+ # values = self.get_IR_data(ref_img)
173
+ # self.factor = values.shape[0]/640
174
+ #
175
+ # return min_T, i_min, [values, ]
176
+
168
177
  def get_IR_data(self, image, **kargs):
169
178
  """Get the data from the image in the proper orientation.
170
179
 
@@ -262,16 +271,16 @@ class IRDataIFIC(IRDataGetter):
262
271
  for img in irbf.images():
263
272
  min_T.append(np.min(img[0].image))
264
273
 
265
- indx = IRDataIFIC.find_minimum(min_T)
266
- self.analysis_frame = [irbf.getImage(indx[-1])]
274
+ self.indx = IRDataIFIC.find_minimum(min_T)
275
+ self.analysis_frame = [irbf.getImage(self.indx[-1])]
267
276
  return self.analysis_frame
268
277
 
269
278
  def get_inlet_temperature(self):
270
279
  """REturn the inlet temperature."""
271
280
  if self.DB:
272
281
  img = self.analysis_frame[0]
273
- val = self.DB.get_temperature(img.timestamp, 10)
274
- return val
282
+ X, T = self.DB.get_temperature(img.timestamp, 1)
283
+ return np.min(T)
275
284
 
276
285
  else:
277
286
  return -9999
@@ -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 the re is aclear minimum within the segment
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.
@@ -12,6 +12,7 @@ import numpy as np
12
12
  from scipy.interpolate import CubicSpline
13
13
  from petal_qc.utils.utils import find_file
14
14
  from petal_qc.utils.utils import output_folder
15
+ import petal_qc.utils.docx_utils as docx_utils
15
16
 
16
17
  from petal_qc.thermal import IRCore
17
18
  from petal_qc.thermal import Petal_IR_Analysis
@@ -33,6 +34,23 @@ def get_names(files):
33
34
  names.append(ifile.stem)
34
35
  return names
35
36
 
37
+ def add_figures_to_doc(doc, figures, name=None):
38
+ """Add figures to doc.
39
+
40
+ Args:
41
+ doc (Document): Document
42
+ figures (list): List of figures.
43
+
44
+ """
45
+ if doc is None or len(figures)==0:
46
+ return
47
+
48
+ if name:
49
+ doc.add_heading(name, level=1)
50
+
51
+ for F in figures:
52
+ doc.add_picture(F, True, 12, caption=F._suptitle.get_text())
53
+
36
54
 
37
55
  class GoldenAxis(object):
38
56
  """Get best X path."""
@@ -293,10 +311,11 @@ def show_golden_average(golden, results, value):
293
311
  for i in range(2):
294
312
  ax[i].set_xticks(range(10), labels=tick_labels)
295
313
 
314
+ G = golden[iside]
296
315
  for R in results:
297
316
  RS = R.results[iside]
298
317
  Y = getattr(RS, value)
299
- gY = getattr(golden[iside], value)
318
+ gY = getattr(G, value)
300
319
  O = getattr(R.golden[iside], value) - gY
301
320
  if value.find("path") >= 0:
302
321
  X = RS.path_length
@@ -381,6 +400,7 @@ def analyze_petal_cores(files, golden, options):
381
400
 
382
401
  """
383
402
  output = []
403
+ cores = []
384
404
  names = get_names(files)
385
405
  for i, ifile in enumerate(files):
386
406
  ifile = find_file(options.folder, ifile)
@@ -397,6 +417,7 @@ def analyze_petal_cores(files, golden, options):
397
417
  print("+++ File {} does not have component serial number.")
398
418
  continue
399
419
 
420
+ cores.append(core)
400
421
  out = [{}, {}]
401
422
  for iside in range(2):
402
423
  for val in ("path_temp", "sensor_avg", "sensor_std"):
@@ -463,7 +484,7 @@ def analyze_petal_cores(files, golden, options):
463
484
 
464
485
  output.append(dbOut)
465
486
 
466
- return output
487
+ return output, cores
467
488
 
468
489
  def analyze_IRCore(options, show=True):
469
490
  """Main entry."""
@@ -499,7 +520,31 @@ def analyze_IRCore(options, show=True):
499
520
  for i, Jside in enumerate(J):
500
521
  golden[i].from_json(Jside)
501
522
 
502
- output = analyze_petal_cores(options.files, golden, options)
523
+ output, cores = analyze_petal_cores(options.files, golden, options)
524
+
525
+ if show or options.report:
526
+ for C in cores:
527
+ get_golden_axis(C, golden)
528
+
529
+ if options.report:
530
+ document = docx_utils.Document()
531
+ document.add_page_numbers()
532
+ document.styles['Normal'].font.name = "Calibri"
533
+ document.add_heading("Comparing to Golden", 0)
534
+ else:
535
+ document = None
536
+
537
+ F = show_golden_average(golden, cores, "path_temp")
538
+ add_figures_to_doc(document, F, "Temperature along pipe")
539
+ F = show_golden_average(golden, cores, "path_spread")
540
+ add_figures_to_doc(document, F, "Spread along pipe")
541
+ F = show_golden_average(golden, cores, "sensor_avg")
542
+ add_figures_to_doc(document, F, "Sensor avg")
543
+ F = show_golden_average(golden, cores, "sensor_std")
544
+ add_figures_to_doc(document, F, "Sendor std")
545
+
546
+ if document:
547
+ document.save("Compare-to-Golden.docx")
503
548
 
504
549
  if show:
505
550
  plt.show()
@@ -4,6 +4,8 @@ import sys
4
4
  from pathlib import Path
5
5
  from argparse import ArgumentParser
6
6
  import json
7
+ import numpy as np
8
+
7
9
  import itkdb_gtk
8
10
  import itkdb_gtk.ITkDButils
9
11
  import itkdb_gtk.dbGtkUtils
@@ -19,9 +21,11 @@ except ImportError:
19
21
 
20
22
 
21
23
  from petal_qc.thermal.IRPetalParam import IRPetalParam
22
- from petal_qc.thermal.create_IRCore import create_IR_core
23
- from petal_qc.thermal.analyze_IRCore import analyze_IRCore, golden_from_json, get_golden_axis, plot_profile_and_golden
24
- from petal_qc.utils.utils import output_folder
24
+ from petal_qc.thermal import IRBFile
25
+ from petal_qc.thermal.IRDataGetter import IRDataGetter
26
+
27
+ from petal_qc.thermal.analyze_IRCore import golden_from_json
28
+ from petal_qc.utils.readGraphana import ReadGraphana
25
29
 
26
30
  import gi
27
31
  gi.require_version("Gtk", "3.0")
@@ -162,6 +166,19 @@ class CoreThermal(itkdb_gtk.dbGtkUtils.ITkDBWindow):
162
166
 
163
167
  self.irbfile = PSF
164
168
  self.param.files =[PSF,]
169
+
170
+ #DB = ReadGraphana("localhost")
171
+ DB = ReadGraphana()
172
+ irbf = IRBFile.open_file(self.irbfile)
173
+ getter = IRDataGetter.factory(self.param.institute, self.param)
174
+ frames = getter.get_analysis_frame(irbf)
175
+ try:
176
+ X, val = DB.get_temperature(frames[0].timestamp, 3)
177
+ inlet = np.min(val)
178
+ self.entryTemp.set_text("{:.1f}".format(inlet))
179
+
180
+ except ValueError:
181
+ pass
165
182
 
166
183
  def on_golden_set(self, *args):
167
184
  """File chosen from FileChooser."""
@@ -7,6 +7,7 @@ from datetime import datetime
7
7
  from pathlib import Path
8
8
 
9
9
  import dateutil
10
+ import numpy as np
10
11
  import matplotlib.pyplot as plt
11
12
 
12
13
  try:
@@ -23,6 +24,7 @@ from petal_qc.thermal import Petal_IR_Analysis
23
24
  from petal_qc.thermal import PipeFit
24
25
  from petal_qc.thermal.IRDataGetter import IRDataGetter
25
26
  from petal_qc.thermal.IRPetalParam import IRPetalParam
27
+ from petal_qc.utils.readGraphana import ReadGraphana
26
28
  from petal_qc.utils.utils import output_folder
27
29
 
28
30
 
@@ -70,6 +72,30 @@ def clean_figures():
70
72
 
71
73
  __figures__ = {}
72
74
 
75
+ def get_inlet_temp(irbf, param):
76
+ """Gets the value of the inlet temperature from Graphana."""
77
+
78
+ print("# Getting the Inlet temperature. Contacting Graphana...")
79
+ out = -9999
80
+ getter = IRDataGetter.factory(param.institute, param)
81
+ #DB = ReadGraphana("localhost")
82
+ DB = ReadGraphana()
83
+ frames = getter.get_analysis_frame(irbf)
84
+ the_time = frames[0].timestamp
85
+ try:
86
+ X, val = DB.get_temperature(the_time, 5)
87
+ for x, y in zip(X, val):
88
+ print("{} - {:.1f}".format(x, y))
89
+
90
+ imin = np.argmin(val)
91
+ out = val[imin]
92
+ print("{}: T_co2 = {:.1f}".format(X[imin], out))
93
+
94
+ except ValueError:
95
+ out = -9999
96
+
97
+ return out
98
+
73
99
  def create_IR_core(options):
74
100
  """Entry point."""
75
101
  global __figures__
@@ -83,13 +109,25 @@ def create_IR_core(options):
83
109
  print("*** Invalid institute name. ***")
84
110
  return None
85
111
 
86
- # Set parameters from command line
87
- params = IRPetal.IRPetalParam(options)
88
- params.debug = False
89
-
90
112
  # Open the sequence file
91
113
  print("## ", options.files)
92
114
  irbf = IRBFile.open_file(options.files)
115
+ if irbf is None:
116
+ print("Could not fine input file: {}".format(options.files))
117
+ return
118
+
119
+ if options.tco2 <= -999:
120
+ out = get_inlet_temp(irbf, options)
121
+ if out <= -999:
122
+ print("### Cannot get Tcos. Setting to default.")
123
+ P = IRPetalParam()
124
+ out = P.tco2
125
+
126
+ options.tco2 = out
127
+
128
+ # Set parameters from command line
129
+ params = IRPetal.IRPetalParam(options)
130
+ params.debug = False
93
131
 
94
132
  # FInd first image below the threshold or the corresponding frame
95
133
  # We will use the pipe obtained from here as the reference
@@ -153,7 +191,7 @@ def create_IR_core(options):
153
191
 
154
192
  # get the framea from where extract the data
155
193
  # reorder if needed
156
- frames = getter.get_analysis_frame(irbf)
194
+ frames = getter.get_analysis_frame(irbf)
157
195
  if pipe_order[0]:
158
196
  tmp = frames[0]
159
197
  frames[0] = frames[1]
@@ -82,11 +82,15 @@ def create_report(options):
82
82
  document.add_heading('Temperature along path', level=1)
83
83
  document.add_picture(figures[0], True, 12, caption="Petal core .vs. Golden (side 0).")
84
84
  document.add_picture(figures[0], True, 12, caption="Petal core .vs. Golden (side 1).")
85
+ for F in figures:
86
+ plt.close(F)
85
87
 
86
88
  figures = plot_profile_and_golden(golden, core, "sensor_avg")
87
89
  document.add_heading('Average Temperatur on sensors areas.', level=1)
88
90
  document.add_picture(figures[0], True, 12, caption="Sensors .vs. Golden (side 0).")
89
91
  document.add_picture(figures[0], True, 12, caption="Sensors .vs. Golden (side 1).")
92
+ for F in figures:
93
+ plt.close(F)
90
94
 
91
95
  ofile = utils.output_folder(options.folder, "{}-thermal.docx".format(options.SN))
92
96
  document.save(ofile)
@@ -31,31 +31,34 @@ class ReadGraphana(object):
31
31
  if not isinstance(the_time, datetime.datetime):
32
32
  the_time = parse(the_time)
33
33
 
34
- td = datetime.timedelta(minutes=window/2)
35
- t1 = the_time - td # datetime.datetime(year=2024, month=5, day=22, hour=15)
36
- t2 = the_time + td #datetime.datetime(year=2024, month=5, day=23, hour=15)
34
+ wnd = int(window/2.0+0.5)
35
+ td = datetime.timedelta(minutes=wnd)
36
+ t1 = the_time - td
37
+ t2 = the_time + td
37
38
 
38
39
  measure="Temp"
39
40
  setup="MARTA_APP|MARTA_tt06"
40
41
  query = "select location,value from {measure} where (location =~ /.*{location}*/ and time>'{t1}' and time < '{t2}') group by \"location\"".format(
41
42
  measure=measure,
42
43
  location=setup,
43
- t1=t1.isoformat()+'Z',
44
- t2=t2.isoformat()+'Z')
44
+ t1=t1.astimezone(datetime.UTC).isoformat(),
45
+ t2=t2.astimezone(datetime.UTC).isoformat()
46
+ )
45
47
 
46
48
  ss = self.client.query(query)
47
49
  nitems = 0
48
50
  for s in ss:
51
+
49
52
  nitems += len(s)
50
53
 
51
54
  if nitems==0:
52
55
  raise ValueError(("No data found"))
53
56
 
54
57
  T = []
58
+ X = []
55
59
  for s in ss:
56
60
  for v in s:
57
61
  T.append(v['value'])
62
+ X.append(v['time'])
58
63
 
59
-
60
- val = np.mean(T)
61
- return val
64
+ return X, T
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: petal_qc
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: A collection of scripts for Petal CORE QC.
5
5
  Author-email: Carlos Lacasta <carlos.lacasta@cern.ch>
6
6
  Project-URL: Homepage, https://gitlab.cern.ch/atlas-itk/sw/db/itk-pdb-gtk-gui-utils
@@ -1,59 +1,60 @@
1
- petal_qc/__init__.py,sha256=qgmsBfB_EW96gEoFQLrZhf2KsTrIy3KffxsjNF_Cy5I,337
1
+ petal_qc/__init__.py,sha256=VpC-IsQnxbgzAmtAY_kKTvTlAtU1gruWo2LAL5oOFY0,472
2
2
  petal_qc/dashBoard.py,sha256=aPugRYhCcAzEBPrCyh8A8QKYaB4Q-_T1q3r5A3J2eog,553
3
3
  petal_qc/BTreport/CheckBTtests.py,sha256=4hNP1V-zcFBN5UvWVbx9nAmittF8Jmb5J17L33t68Eg,9086
4
4
  petal_qc/BTreport/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  petal_qc/BTreport/bustapeReport.py,sha256=c5VERxPm6BOgW_yN9O_bEPmCYpuwZ_Yt_I2sMVAp0-I,6895
6
6
  petal_qc/metrology/Cluster.py,sha256=UtZ5q1EFb8f3qC0hEYBbhRg2pPbW_28aJX2EEMu00Ho,2105
7
7
  petal_qc/metrology/DataFile.py,sha256=PbFqy3-WSj69epV5EjhHc1GKhA8I74FmJYOXUjN0V20,1367
8
- petal_qc/metrology/PetalMetrology.py,sha256=H4MwuQ2QxP_Td9KtMly_-osXT1owigzC7QlmRub7oRo,11886
8
+ petal_qc/metrology/PetalMetrology.py,sha256=dzy--gvmF-xzTFI_MGn2oJWNaVMsBLBSwoZ1dLnAHfc,11888
9
9
  petal_qc/metrology/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  petal_qc/metrology/all2csv.py,sha256=KTgEGaediylwkGN7gyWyQqUjU0f9FOa3xF4z1W38EcU,1569
11
- petal_qc/metrology/analyze_locking_points.py,sha256=AD5DRlZDpgzZS8sUwuUnzwws4BtJZrNtsJ-IWG6xvcQ,20539
11
+ petal_qc/metrology/analyze_locking_points.py,sha256=FjLte9VgxVMfR-b1DlViWDsa2vl3ZKfCCptyibEjBUY,20519
12
12
  petal_qc/metrology/cold_noise.py,sha256=PuTaQ73WrQCJdE9ezS4UFmA3atwCuvM0ZsUOYu1ZIBw,3106
13
+ petal_qc/metrology/compare_Cores.py,sha256=A3_Zqd7K5G93bShWFA7NK0Xob3Zin9WSwfGUMpCitNY,6485
13
14
  petal_qc/metrology/comparisonTable.py,sha256=6Zmh-x0ahs28ZJQuHMrIiRcblUmTN1_-1otFSRNMPds,1743
14
15
  petal_qc/metrology/convert_mitutoyo.py,sha256=HdXQzFL5y7r8qXDzti91VItDQ-y6D9rEAYknn4yHwBs,5449
15
16
  petal_qc/metrology/convert_smartscope.py,sha256=es3PoUd5d5rpHebgwsS9nrc3uuy9uFKOQ00ZdU5XHQ0,3836
16
17
  petal_qc/metrology/coreMetrology.py,sha256=L_uoxq8ObmmiMSx41gFCdpQnalR-HgaVUPHzhDYsDiE,13610
17
18
  petal_qc/metrology/data2csv.py,sha256=2ttMSmfGLPIaOqZGima2dH6sdnSRAFTHlEbSOfW5ebA,1809
18
- petal_qc/metrology/do_Metrology.py,sha256=4tbZJfJYXY8QVLiG5_2pThNPzyuqbC3s8xhFdQfC1TU,3977
19
+ petal_qc/metrology/do_Metrology.py,sha256=zPryMgu46fmCyuAGtRGs2yqh0OSxnkSo9bsJMxQ80PU,4107
19
20
  petal_qc/metrology/flatness4nigel.py,sha256=SUHwn6pCEUWQV_62-_9-VKrmUdL4gVQcSA3aTtYq958,4071
20
21
  petal_qc/metrology/gtkutils.py,sha256=1pOTxiE2EZR9zNNNT5cOetga_4NG9DzLaqQPI4c1EzE,3372
21
- petal_qc/metrology/petal_flatness.py,sha256=MH3ZlSildLokYnjERQG28qqLg3LL8C6rFLT8VbEI_BA,11190
22
+ petal_qc/metrology/petal_flatness.py,sha256=-TuCndiCTwvIKaSb9oIMmtyy2qVv_WCY3Arq5qRxegk,11390
22
23
  petal_qc/metrology/show_data_file.py,sha256=yZPcmMy-1EWWySiBBx0hNB3tPVh19bTr0PDaXSyIF4c,4057
23
24
  petal_qc/metrology/testSummary.py,sha256=0BhcEd1BPz2Mbonzi8nyZOzNSzpUqowBFNl5cVutqsk,994
24
25
  petal_qc/metrology/test_paralelism.py,sha256=_j__OdUwdXWM494_9HpGPuPHixMwwVphCcvHEfzWi_k,1981
26
+ petal_qc/test/test_Graphana.py,sha256=fXcqHzgrfZGjSF-WoMLl96G97XjXVnynHYC-5rKw_-c,1032
27
+ petal_qc/test/test_coreThermal.py,sha256=YRPK3DGG7Tz66K4Kka3euXgUDzW_JlIqSYicMBhb96E,1516
25
28
  petal_qc/thermal/CSVImage.py,sha256=Vt2kYmUsZWkQvxcF8fDda3HO1Rb29kPQHnEoHFCqWYo,2038
26
29
  petal_qc/thermal/DebugPlot.py,sha256=OmREFwNDAKgoObDmcgHrB4d8m3bf2znfsKVGsb5rBGQ,2119
27
- petal_qc/thermal/IRBFile.py,sha256=gudyAMwYjBtfXhx-Kxbott9Lpbnfm4oKnizIE5vrkoE,22270
30
+ petal_qc/thermal/IRBFile.py,sha256=yScjQrAeB9dnNNO-6_8S34vzrtme0F6y3kwYahMKDxc,22271
28
31
  petal_qc/thermal/IRCore.py,sha256=y79YEQrq4q2hSdmYbOF7jjEA-wy50Qun0g_AmrRUmls,3056
29
- petal_qc/thermal/IRDataGetter.py,sha256=cT20apD0xN9VCKY01yXQTx9cV1Pk4xjVy3sXR3ROHGQ,10580
30
- petal_qc/thermal/IRPetal.py,sha256=8H1ltpahzJavM65De8OTSedvilXQkr3LkV8mRnTDhLQ,38334
32
+ petal_qc/thermal/IRDataGetter.py,sha256=5z9kUo5is-D6Cc2B7w8e588RzhUaRsDRRBRvz9ggqh4,10925
33
+ petal_qc/thermal/IRPetal.py,sha256=5QGGnfxt7QTqEmtqF6o8Kgvtu_FB4wGNH3CVSU4TlIk,38334
31
34
  petal_qc/thermal/IRPetalParam.py,sha256=hrQ9FevzWctvBVHeQ71G0WzllVEa5rYkJom2ezfFYHc,3674
32
35
  petal_qc/thermal/PetalColorMaps.py,sha256=6CvJHzRdojLHu3BROYSekHw8g_BJ1lJ_edyhovTIydU,3831
33
36
  petal_qc/thermal/Petal_IR_Analysis.py,sha256=8Deh_bJ5B7DdaUV18saboF7fXZ_8Bt1vkUlsk5RqVeo,3910
34
37
  petal_qc/thermal/PipeFit.py,sha256=bipXxJGxrwlgbrFv8WJA1Ds7Kj4oUwEyqTIswpgni9o,17214
35
38
  petal_qc/thermal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
- petal_qc/thermal/analyze_IRCore.py,sha256=6qV8q4yEJxB1hkhXi-SozI3fZXMh9zNHnwfjvpI380k,18086
39
+ petal_qc/thermal/analyze_IRCore.py,sha256=lJsADO4ZisESpJLA97MR9oIbdMKzwlZj9vD6WWj64pg,19577
37
40
  petal_qc/thermal/contours.py,sha256=ampCKm4byZYKb_4eJFjIkdFIl2bqVXD2mV13d2XUWlw,8244
38
- petal_qc/thermal/coreThermal.py,sha256=q1e_8e19TPL3EeJzJKiMo04-nIdXAU6b_XSJNuF-zGU,12320
39
- petal_qc/thermal/create_IRCore.py,sha256=3J6vj1xyjtwoe2OdHv8LbjTgo4I_vaiw_05DWidY9v4,6206
40
- petal_qc/thermal/create_core_report.py,sha256=x3yx4CxbPARmLHqjpt5-yNZELRiHadEOufMpDFNEr5g,4239
41
+ petal_qc/thermal/coreThermal.py,sha256=e7LLuRU5hhPWMTowNlID7A2JmB7hszclX4POlfCND9s,12794
42
+ petal_qc/thermal/create_IRCore.py,sha256=mnAmDTF_t3AMOA7Wv19yXT1IX4oFCgfHwHpdnamZvmI,7311
43
+ petal_qc/thermal/create_core_report.py,sha256=zCZtTR6ouHRVZQAen_PutCvvDwHE5aSwq95sIv-8htM,4325
41
44
  petal_qc/thermal/pipe_back.npz,sha256=yooZuVYtHU541HcV6Gh_5B0BqdYAVEvYAuVvMMSY7Jc,3632
42
45
  petal_qc/thermal/pipe_front.npz,sha256=DuwruG9C2Z1rLigqWMApY4Orsf1SGUQGKy0Yan8Bk8A,3697
43
46
  petal_qc/thermal/pipe_read.py,sha256=HrAtEbf8pMhJDETzkevodiTbuprIOh4yHv6PzpRoz7Q,5040
44
47
  petal_qc/thermal/show_IR_petal.py,sha256=vKb8wm9Y7erAdCb93ODREv2qfSexNMfJpV-67wfOhBw,13159
45
- petal_qc/thermal/test_Graphana.py,sha256=lr3JYC8XwwsZLfhGK2M1swOiIvDUTf5IYc6pqxZyCSA,878
46
- petal_qc/thermal/test_coreThermal.py,sha256=YRPK3DGG7Tz66K4Kka3euXgUDzW_JlIqSYicMBhb96E,1516
47
48
  petal_qc/utils/Geometry.py,sha256=XwA_aojk880N-jC1_bnMYFK0bcD-L96JPS81NUerJf0,19765
48
49
  petal_qc/utils/Progress.py,sha256=gCti4n2xfCcOTlAff5GchabGE5BCwavvDZYYKdbEsXU,4064
49
50
  petal_qc/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
51
  petal_qc/utils/all_files.py,sha256=4ja_DkbTYPY3gUPBAZq0p7KB9lnXZx-OCnpTHg9tm4I,1044
51
52
  petal_qc/utils/docx_utils.py,sha256=Eye16PF8W0mPBVdQvgFKWxPYV7-hzBgANPDZtUEjzf8,5805
52
53
  petal_qc/utils/fit_utils.py,sha256=3KUGWpBMV-bVDkQHWBigXot8chOpjAVBJ5H5b5dbdjk,5349
53
- petal_qc/utils/readGraphana.py,sha256=-l1iVazszGOgH2oUYAbjaIyxUvM8G4Bzoar491tsWjg,1862
54
+ petal_qc/utils/readGraphana.py,sha256=Ljr3PSkkTw-A8SRfMa77n7RO7ogLewwDy9dkflzKh2M,1869
54
55
  petal_qc/utils/utils.py,sha256=CqCsNIcEg6FQb3DN70tmqeLVLlQqsRfDzhfGevlnfBc,4035
55
- petal_qc-0.0.2.dist-info/METADATA,sha256=SPjkEowJUpsvFQv4FEoQ60BmJzg7Fj_zILlVDf0e2oo,943
56
- petal_qc-0.0.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
57
- petal_qc-0.0.2.dist-info/entry_points.txt,sha256=ZsBmzA1gRvZSe4ZKcxlo0b-RBjySccqBhL6g_CJhNaM,92
58
- petal_qc-0.0.2.dist-info/top_level.txt,sha256=CCo1Xe6kLS79PruhsB6bk2CuL9VFtNdNpgJjYUs4jk4,9
59
- petal_qc-0.0.2.dist-info/RECORD,,
56
+ petal_qc-0.0.4.dist-info/METADATA,sha256=j4X7tTTdxbyK1rzZIo9GMcHCjFSm08Ec8wH3rnvVe7I,943
57
+ petal_qc-0.0.4.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
58
+ petal_qc-0.0.4.dist-info/entry_points.txt,sha256=tkGC458t1_yVr9OHFE1KtJmGQ2wqsbK8WkPWxru4jFk,127
59
+ petal_qc-0.0.4.dist-info/top_level.txt,sha256=CCo1Xe6kLS79PruhsB6bk2CuL9VFtNdNpgJjYUs4jk4,9
60
+ petal_qc-0.0.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (70.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,3 +1,4 @@
1
1
  [gui_scripts]
2
2
  bustapeReport = petal_qc:bustapeReport
3
3
  coreMetrology = petal_qc:coreMetrology
4
+ coreThermal = petal_qc:coreThermal
File without changes