petal-qc 0.0.0__py3-none-any.whl → 0.0.2__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.

@@ -0,0 +1,366 @@
1
+ #!/usr/bin/env python3
2
+ """GUI for thermal QC of petal cores."""
3
+ import sys
4
+ from pathlib import Path
5
+ from argparse import ArgumentParser
6
+ import json
7
+ import itkdb_gtk
8
+ import itkdb_gtk.ITkDButils
9
+ import itkdb_gtk.dbGtkUtils
10
+ import itkdb_gtk.UploadTest
11
+
12
+
13
+ try:
14
+ import petal_qc
15
+
16
+ except ImportError:
17
+ cwd = Path(__file__).parent.parent.parent
18
+ sys.path.append(cwd.as_posix())
19
+
20
+
21
+ 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
25
+
26
+ import gi
27
+ gi.require_version("Gtk", "3.0")
28
+ from gi.repository import Gtk, GObject, Gio, GLib
29
+
30
+ from petal_qc.thermal.create_core_report import create_report
31
+
32
+ class CoreThermal(itkdb_gtk.dbGtkUtils.ITkDBWindow):
33
+ """Application window."""
34
+
35
+ def __init__(self, params=None, session=None, title="", panel_size=100):
36
+ """Initialization
37
+
38
+ Args:
39
+ params (IRPetalParam, optional): Petal thermal parameters.
40
+ session (itkdb.Client): ITk PDB session.
41
+ title: Window title.
42
+ panel_size: size of message pannel.
43
+ """
44
+ super().__init__(session=session, title=title)
45
+
46
+ self.petal_SN = None
47
+ self.param = params if params else IRPetalParam()
48
+ self.param.add_attachments = True
49
+ self.param.create_golden = False
50
+ self.irbfile = None
51
+ self.folder = None
52
+ self.golden = None
53
+ self.results = None
54
+ self.alternativeID = None
55
+ self.outDB = None
56
+
57
+ # Active button in header
58
+ button = Gtk.Button()
59
+ icon = Gio.ThemedIcon(name="document-send-symbolic")
60
+ image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
61
+ button.add(image)
62
+ button.set_tooltip_text("Click to upload test")
63
+ button.connect("clicked", self.upload_test_gui)
64
+ self.hb.pack_end(button)
65
+
66
+ # JScon edit
67
+ button = Gtk.Button()
68
+ icon = Gio.ThemedIcon(name="accessories-text-editor-symbolic")
69
+ image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
70
+ button.add(image)
71
+ button.set_tooltip_text("Click to see the test data")
72
+ button.connect("clicked", self.show_test_gui)
73
+ self.hb.pack_end(button)
74
+
75
+ # The file chooser
76
+ self.btnData = Gtk.FileChooserButton()
77
+ self.btnData.connect("file-set", self.on_file_set)
78
+
79
+
80
+ # The file chooser
81
+ self.goldenData = Gtk.FileChooserButton()
82
+ self.goldenData.connect("file-set", self.on_golden_set)
83
+
84
+ # The Serial number
85
+ self.SN = itkdb_gtk.dbGtkUtils.TextEntry()
86
+ self.SN.connect("text-changed", self.on_SN_changed)
87
+
88
+ self.run = Gtk.Button(label="Run")
89
+ self.run.connect("clicked", self.create_report)
90
+
91
+ self.btn_state = Gtk.Button(label="Undef")
92
+ self.btn_state.set_name("btnState")
93
+ self.btn_state.connect("clicked", self.show_state)
94
+ self.btn_state.set_tooltip_text("If green all good. Click to see commnets and defects.")
95
+
96
+ # Put the 3 objects in a Grid
97
+ grid = Gtk.Grid(column_spacing=5, row_spacing=5)
98
+ self.mainBox.pack_start(grid, False, True, 0)
99
+
100
+ irow = 0
101
+ grid.attach(Gtk.Label(label="Serial No."), 0, irow, 1, 1)
102
+ grid.attach(self.SN.entry, 1, irow, 1, 1)
103
+ grid.attach(self.btn_state, 3, irow, 1, 1)
104
+
105
+ irow += 1
106
+ grid.attach(Gtk.Label(label="IRB File"), 0, irow, 1, 1)
107
+ grid.attach(self.btnData, 1, irow, 1, 1)
108
+
109
+ self.entryTemp = Gtk.Entry()
110
+ self.entryTemp.set_text("{:.1f}".format(self.param.tco2))
111
+ self.entryTemp.set_tooltip_text("CO2 inlet temperature")
112
+ lbl = Gtk.Label(label="T<sub>CO2</sub>")
113
+ lbl.set_use_markup(True)
114
+ grid.attach(lbl, 2, irow, 1, 1)
115
+ grid.attach(self.entryTemp, 3, irow, 1, 1)
116
+
117
+
118
+ irow += 1
119
+ grid.attach(Gtk.Label(label="Golden File"), 0, 2, 1, 1)
120
+ grid.attach(self.goldenData, 1, 2, 1, 1)
121
+
122
+ self.entryTHrs = Gtk.Entry()
123
+ self.entryTHrs.set_tooltip_text("Temperature threshold.")
124
+ self.entryTHrs.set_text("{:.1f}".format(self.param.thrs))
125
+ lbl = Gtk.Label(label="Threshold")
126
+ grid.attach(lbl, 2, irow, 1, 1)
127
+ grid.attach(self.entryTHrs, 3, irow, 1, 1)
128
+
129
+
130
+ irow += 1
131
+ # the folder option
132
+ self.btnFolder = Gtk.FileChooserButton()
133
+ self.btnFolder.set_tooltip_text("Select folder for all output. If none selected, output in current folder.")
134
+ self.btnFolder.set_action(Gtk.FileChooserAction.SELECT_FOLDER)
135
+ self.btnFolder.connect("file-set", self.on_folder_set)
136
+ if self.param.folder and len(self.param.folder) > 0 :
137
+ ifile = Path(self.param.folder).expanduser().resolve().as_posix()
138
+ self.btnFolder.set_filename(ifile)
139
+
140
+ grid.attach(Gtk.Label(label="Folder"), 0, irow, 1, 1)
141
+ grid.attach(self.btnFolder, 1, irow, 1, 1)
142
+
143
+ self.entryDist = Gtk.Entry()
144
+ self.entryDist.set_text("{}".format(self.param.distance))
145
+ self.entryDist.set_tooltip_text("Distance in contour beteween slices")
146
+ lbl = Gtk.Label(label="Distance")
147
+ grid.attach(lbl, 2, irow, 1, 1)
148
+ grid.attach(self.entryDist, 3, irow, 1, 1)
149
+
150
+
151
+ grid.attach(self.run, 0, 4, 5, 1)
152
+
153
+ self.mainBox.pack_start(self.message_panel.frame, True, True, 0)
154
+
155
+
156
+ def on_file_set(self, *args):
157
+ """File chosen from FileChooser."""
158
+ PSF = self.btnData.get_filename()
159
+ if PSF is None or not Path(PSF).exists():
160
+ itkdb_gtk.dbGtkUtils.complain("Could not find Data File", PSF, parent=self)
161
+ return
162
+
163
+ self.irbfile = PSF
164
+ self.param.files =[PSF,]
165
+
166
+ def on_golden_set(self, *args):
167
+ """File chosen from FileChooser."""
168
+ PSF = self.goldenData.get_filename()
169
+ if PSF is None or not Path(PSF).exists():
170
+ itkdb_gtk.dbGtkUtils.complain("Could not find Golden File", PSF, parent=self)
171
+ return
172
+
173
+ with open(PSF, "r", encoding='utf-8') as fp:
174
+ self.golden = golden_from_json(json.load(fp))
175
+
176
+ self.param.golden = PSF
177
+
178
+ def on_folder_set(self, *args):
179
+ """Folder chosen."""
180
+ F = self.btnFolder.get_filename()
181
+ if F is None or not Path(F).exists():
182
+ itkdb_gtk.dbGtkUtils.complain("Could not find Output folder", F, parent=self)
183
+ return
184
+
185
+ self.folder = F
186
+ self.param.folder = F
187
+
188
+ def on_SN_changed(self, entry, value):
189
+ """New SN given. Ask in PDB,"""
190
+ if len(value) <= 0:
191
+ return None
192
+
193
+
194
+ obj = itkdb_gtk.ITkDButils.get_DB_component(self.session, value)
195
+ if obj is not None:
196
+ entry.set_text(obj["serialNumber"])
197
+ self.alternativeID = obj["alternativeIdentifier"]
198
+
199
+ else:
200
+ itkdb_gtk.dbGtkUtils.complain("Invalid SN", value)
201
+
202
+ def show_state(self, *arg):
203
+ """Shows the status"""
204
+ if self.outDB is None:
205
+ dialog = Gtk.MessageDialog(
206
+ transient_for=self,
207
+ flags=0,
208
+ message_type=Gtk.MessageType.INFO,
209
+ buttons=Gtk.ButtonsType.OK,
210
+ text="State undefined",
211
+ )
212
+ dialog.format_secondary_text(
213
+ "No analysis data available yet."
214
+ )
215
+ dialog.run()
216
+ dialog.destroy()
217
+ return
218
+
219
+ ndef = len(self.outDB["defects"])
220
+ ncomm = len(self.outDB["comments"])
221
+
222
+ if ndef+ncomm == 0:
223
+ dialog = Gtk.MessageDialog(
224
+ transient_for=self,
225
+ flags=0,
226
+ message_type=Gtk.MessageType.INFO,
227
+ buttons=Gtk.ButtonsType.OK,
228
+ text="All good",
229
+ )
230
+ dialog.format_secondary_text(
231
+ "Petal core passed without problems."
232
+ )
233
+ dialog.run()
234
+ dialog.destroy()
235
+ return
236
+
237
+ msg = ""
238
+ if ndef:
239
+ msg += "Defects\n"
240
+ for D in self.outDB["defects"]:
241
+ msg += "{}: {}\n".format(D["name"], D["description"])
242
+
243
+ if ncomm:
244
+ msg += "Comments\n"
245
+ for C in self.outDB["comments"]:
246
+ msg += "{}\n".format(C)
247
+
248
+
249
+ dialog = Gtk.MessageDialog(
250
+ transient_for=self,
251
+ flags=0,
252
+ message_type=Gtk.MessageType.INFO,
253
+ buttons=Gtk.ButtonsType.OK,
254
+ text="Problems found",
255
+ )
256
+
257
+ dialog.format_secondary_text(msg)
258
+ dialog.run()
259
+ dialog.destroy()
260
+
261
+
262
+ def show_test_gui(self, *args):
263
+ """Show test data."""
264
+ if self.outDB is None:
265
+ return
266
+
267
+ values, rc = itkdb_gtk.dbGtkUtils.DictDialog.create_json_data_editor(self.outDB)
268
+ if rc == Gtk.ResponseType.OK:
269
+ self.outDB = values
270
+
271
+ def upload_test_gui(self, *args):
272
+ """Uploads test and attachments."""
273
+ self.upload_test()
274
+
275
+ def upload_test(self):
276
+ """Uploads test and attachments."""
277
+ if self.outDB is None:
278
+ return
279
+ uploadW = itkdb_gtk.UploadTest.UploadTest(self.session, payload=self.outDB)
280
+
281
+ def create_report(self, *args):
282
+ """Creates the thermal report."""
283
+ if self.irbfile is None:
284
+ self.write_message("Missing IRB file\n")
285
+ return
286
+
287
+ self.write_message("Start analysis\n.")
288
+ self.param.out = "{}.json".format(self.alternativeID)
289
+ self.param.alias = self.alternativeID
290
+ self.param.SN = self.SN.get_text()
291
+
292
+ self.param.tco2 = float(self.entryTemp.get_text())
293
+ self.param.distance = int(self.entryDist.get_text())
294
+ self.param.thrs = float(self.entryTHrs.get_text())
295
+ self.param.debug = False
296
+ self.param.report = True
297
+
298
+ self.outDB = create_report(self.param)
299
+ if self.outDB:
300
+ if len(self.outDB["defects"]) > 0:
301
+ itkdb_gtk.dbGtkUtils.set_button_color(self.btn_state, "red", "white")
302
+ self.btn_state.set_label("FAILED")
303
+ elif len(self.outDB["comments"]) > 0:
304
+ itkdb_gtk.dbGtkUtils.set_button_color(self.btn_state, "orange", "white")
305
+ self.btn_state.set_label("PROBLEMS")
306
+ else:
307
+ itkdb_gtk.dbGtkUtils.set_button_color(self.btn_state, "green", "white")
308
+ self.btn_state.set_label("PASSED")
309
+
310
+ def main():
311
+ """Entry point."""
312
+ # Argument parser
313
+ parser = ArgumentParser()
314
+ #parser.add_argument('files', nargs='*', help="Input files")
315
+ parser.add_argument("--nframe", type=int, default=-1, help="Number of frames. (negative means all.")
316
+ parser.add_argument('--frame', type=int, default=-1, help="First frame to start.")
317
+ parser.add_argument("--out", default="core.json", help="Output file name")
318
+ parser.add_argument("--alias", default="", help="Alias")
319
+ parser.add_argument("--SN", default="", help="serial number")
320
+ parser.add_argument("--folder", default=None, help="Folder to store output files. Superseeds folder in --out")
321
+
322
+ IRPetalParam.add_parameters(parser)
323
+
324
+ options = parser.parse_args()
325
+ #if len(options.files) == 0:
326
+ # print("I need an input file")
327
+ # sys.exit()
328
+
329
+ # ITk PDB authentication
330
+ dlg = None
331
+ try:
332
+ # We use here the Gtk GUI
333
+ from itkdb_gtk import ITkDBlogin
334
+ dlg = ITkDBlogin.ITkDBlogin()
335
+ client = dlg.get_client()
336
+
337
+ except Exception:
338
+ # Login with "standard" if the above fails.
339
+ import itkdb
340
+ import getpass
341
+ client = itkdb.Client()
342
+ client.user._access_code1 = getpass.getpass("Access 1: ")
343
+ client.user._access_code2 = getpass.getpass("Access 2: ")
344
+ client.user.authenticate()
345
+ print("Hello {} !".format(client.user.name))
346
+
347
+ CT = CoreThermal(options, session=client, title="Petal Thermal analysis.")
348
+ CT.show_all()
349
+ CT.connect("destroy", Gtk.main_quit)
350
+ CT.write_message("Welcome !")
351
+
352
+ try:
353
+ Gtk.main()
354
+
355
+ except KeyboardInterrupt:
356
+ print("Arrrgggg!!!")
357
+
358
+
359
+ try:
360
+ dlg.die()
361
+
362
+ except Exception:
363
+ print("Bye !")
364
+
365
+ if __name__ == "__main__":
366
+ main()
@@ -9,6 +9,13 @@ from pathlib import Path
9
9
  import dateutil
10
10
  import matplotlib.pyplot as plt
11
11
 
12
+ try:
13
+ import petal_qc
14
+
15
+ except ImportError:
16
+ cwd = Path(__file__).parent.parent.parent
17
+ sys.path.append(cwd.as_posix())
18
+
12
19
  from petal_qc.thermal import IRBFile
13
20
  from petal_qc.thermal import IRCore
14
21
  from petal_qc.thermal import IRPetal
@@ -50,15 +57,31 @@ def get_db_date(timestamp=None):
50
57
  return out
51
58
 
52
59
 
60
+ __figures__ = {}
61
+ def get_IRcore_plots():
62
+ """Return global list of figures."""
63
+ return __figures__
64
+
65
+ def clean_figures():
66
+ global __figures__
67
+ for key, fig in __figures__:
68
+ fig.clean()
69
+ plt.close(fig)
70
+
71
+ __figures__ = {}
72
+
53
73
  def create_IR_core(options):
54
74
  """Entry point."""
75
+ global __figures__
76
+ clean_figures()
77
+
55
78
  # Obtain the Data getter.
56
79
  try:
57
80
  getter = IRDataGetter.factory(options.institute, options)
58
81
 
59
82
  except NotImplemented:
60
83
  print("*** Invalid institute name. ***")
61
- return
84
+ return None
62
85
 
63
86
  # Set parameters from command line
64
87
  params = IRPetal.IRPetalParam(options)
@@ -76,8 +99,9 @@ def create_IR_core(options):
76
99
  min_T, i_min, values = getter.find_reference_image(irbf, params.thrs, nframes=10)
77
100
  print("Image size: {} x {}".format(values[0].shape[0], values[0].shape[1]))
78
101
 
79
- if options.debug:
80
- Petal_IR_Analysis.show_2D_image(values)
102
+ if options.debug or options.report:
103
+ fig, ax = Petal_IR_Analysis.show_2D_image(values)
104
+ __figures__["original"] = fig
81
105
 
82
106
  except LookupError as e:
83
107
  print(e)
@@ -99,8 +123,9 @@ def create_IR_core(options):
99
123
  pipe_order[i] = pipe_type
100
124
  PF = PipeFit.PipeFit(pipe_type)
101
125
  R = PF.fit_ex(pipes[i], factor=getter.factor)
102
- if options.debug:
103
- PF.plot()
126
+ if options.debug or options.report:
127
+ fig, _ =PF.plot()
128
+ __figures__["fit_{}".format(i)] = fig
104
129
 
105
130
  transforms[pipe_type] = R
106
131
  fitter[pipe_type] = PF
@@ -128,7 +153,7 @@ def create_IR_core(options):
128
153
 
129
154
  # get the framea from where extract the data
130
155
  # reorder if needed
131
- frames = getter.get_analysis_frame(irbf)
156
+ frames = getter.get_analysis_frame(irbf)
132
157
  if pipe_order[0]:
133
158
  tmp = frames[0]
134
159
  frames[0] = frames[1]
@@ -154,12 +179,14 @@ def create_IR_core(options):
154
179
 
155
180
  # Check if we are given an output folder
156
181
  ofile = output_folder(options.folder, options.out)
157
- with open(ofile, "w") as ofile:
182
+ with open(ofile, "w", encoding="utf-8") as ofile:
158
183
  core.to_json(ofile)
159
184
 
160
185
  if options.debug:
161
186
  plt.show()
162
187
 
188
+ return core
189
+
163
190
 
164
191
  if __name__ == "__main__":
165
192
  from argparse import ArgumentParser
@@ -169,7 +196,6 @@ if __name__ == "__main__":
169
196
  parser.add_argument('files', nargs='*', help="Input files")
170
197
  parser.add_argument("--nframe", type=int, default=-1, help="Number of frames. (negative means all.")
171
198
  parser.add_argument('--frame', type=int, default=-1, help="First frame to start.")
172
- parser.add_argument("--tco2", default=0, type=float, help="CO2 inlet temperature.")
173
199
  parser.add_argument("--out", default="core.json", help="Output file name")
174
200
  parser.add_argument("--alias", default="", help="Alias")
175
201
  parser.add_argument("--SN", default="", help="serial number")
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env python3
2
+ """Creates the report of a core."""
3
+
4
+ import math
5
+ import sys
6
+ import json
7
+ from argparse import ArgumentParser
8
+ from pathlib import Path
9
+
10
+ import matplotlib.path as mplPath
11
+ import matplotlib.pyplot as plt
12
+ import numpy as np
13
+
14
+
15
+ try:
16
+ import petal_qc
17
+
18
+ except ImportError:
19
+ cwd = Path(__file__).parent.parent.parent
20
+ sys.path.append(cwd.as_posix())
21
+
22
+ from petal_qc.thermal.IRPetalParam import IRPetalParam
23
+ from petal_qc.thermal.create_IRCore import create_IR_core, get_IRcore_plots
24
+ from petal_qc.thermal.analyze_IRCore import analyze_IRCore, golden_from_json, get_golden_axis, plot_profile_and_golden
25
+
26
+ import petal_qc.utils.docx_utils as docx_utils
27
+ import petal_qc.utils.utils as utils
28
+
29
+
30
+
31
+ def create_report(options):
32
+ """Create a writen report.
33
+ """
34
+ ifile = Path(options.files[0]).expanduser().resolve()
35
+ if not ifile.exists():
36
+ print("input file {} does not exist.".format(ifile))
37
+ return
38
+
39
+ goldenFile = Path(options.golden).expanduser().resolve()
40
+ if not goldenFile.exists():
41
+ print("I need a golden file.")
42
+
43
+ with open(goldenFile, "r", encoding='utf-8') as fp:
44
+ golden = golden_from_json(json.load(fp))
45
+
46
+
47
+
48
+ document = docx_utils.Document()
49
+ document.add_page_numbers()
50
+ document.styles['Normal'].font.name = "Calibri"
51
+ document.add_heading(options.SN, 0)
52
+
53
+ P = document.add_paragraph(ifile.name, "Subtitle")
54
+ P.alignment = docx_utils.paragraph_align_center()
55
+
56
+ P = document.add_paragraph("Golden: {}".format(goldenFile.name), "Subtitle")
57
+ P.alignment = docx_utils.paragraph_align_center()
58
+
59
+
60
+ core = create_IR_core(options)
61
+
62
+ figures = get_IRcore_plots()
63
+ document.add_heading('Original image', level=1)
64
+ document.add_picture(figures["original"], True, 14, caption="Original Thermal image.")
65
+
66
+ document.add_heading('Result of Pipe Fit', level=1)
67
+ document.add_picture(figures["fit_0"], True, 10, caption="Size 0 fit.")
68
+ document.add_picture(figures["fit_1"], True, 10, caption="Size 1 fit.")
69
+
70
+ options.add_attachments = True
71
+ options.create_golden = False
72
+
73
+ options.files[0] = utils.output_folder(options.folder, options.out)
74
+ options.out = None
75
+ out = analyze_IRCore(options, show=False)
76
+ outDB = out[0] if len(out) else None
77
+ options.files = []
78
+
79
+ get_golden_axis(core, golden)
80
+
81
+ figures = plot_profile_and_golden(golden, core, "path_temp")
82
+ document.add_heading('Temperature along path', level=1)
83
+ document.add_picture(figures[0], True, 12, caption="Petal core .vs. Golden (side 0).")
84
+ document.add_picture(figures[0], True, 12, caption="Petal core .vs. Golden (side 1).")
85
+
86
+ figures = plot_profile_and_golden(golden, core, "sensor_avg")
87
+ document.add_heading('Average Temperatur on sensors areas.', level=1)
88
+ document.add_picture(figures[0], True, 12, caption="Sensors .vs. Golden (side 0).")
89
+ document.add_picture(figures[0], True, 12, caption="Sensors .vs. Golden (side 1).")
90
+
91
+ ofile = utils.output_folder(options.folder, "{}-thermal.docx".format(options.SN))
92
+ document.save(ofile)
93
+
94
+ return outDB
95
+
96
+ if __name__ == "__main__":
97
+ P = IRPetalParam()
98
+ parser = ArgumentParser()
99
+ parser.add_argument('files', nargs='*', help="Input files")
100
+ parser.add_argument("--orig", action="store_true", default=False, help="plot the original image")
101
+ parser.add_argument('--frame', default=-1, type=int, help="Frame to analize")
102
+ parser.add_argument("--out", default="core.json", help="Output file name")
103
+ parser.add_argument("--alias", default="", help="Alias")
104
+ parser.add_argument("--SN", default="", help="serial number")
105
+ parser.add_argument("--folder", default=None, help="Folder to store output files. Superseeds folder in --out")
106
+ parser.add_argument("--add_attachments", action="store_true", default=False, help="If true add the attachments section os DB file.")
107
+ parser.add_argument("--golden", default=None, help="The golden to compare width")
108
+
109
+
110
+ IRPetalParam.add_parameters(parser)
111
+
112
+ options = parser.parse_args()
113
+
114
+ if len(options.files) == 0:
115
+ print("I need an input file")
116
+ sys.exit()
117
+ else:
118
+ ifile = options.files[0]
119
+
120
+ options.debug = False
121
+ options.report = True
122
+ create_report(options)
Binary file
Binary file
@@ -12,6 +12,14 @@ from pathlib import PurePath
12
12
  import matplotlib.pyplot as plt
13
13
  import matplotlib.ticker as ticker
14
14
  import numpy as np
15
+
16
+ try:
17
+ import petal_qc
18
+
19
+ except ImportError:
20
+ cwd = Path(__file__).parent.parent.parent
21
+ sys.path.append(cwd.as_posix())
22
+
15
23
  from petal_qc.thermal import contours
16
24
  from petal_qc.thermal import IRBFile
17
25
  from petal_qc.thermal import IRPetal
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env python3
2
+ """Test the connection with graphana to get the value at the peak."""
3
+ import sys
4
+ from pathlib import Path
5
+ import datetime
6
+ try:
7
+ import petal_qc
8
+
9
+ except ImportError:
10
+ cwd = Path(__file__).parent.parent.parent
11
+ sys.path.append(cwd.as_posix())
12
+
13
+ from petal_qc.utils.readGraphana import ReadGraphana
14
+ from petal_qc.thermal.IRDataGetter import IRDataGetter
15
+ from petal_qc.thermal.IRPetalParam import IRPetalParam
16
+ from petal_qc.thermal import IRBFile
17
+
18
+
19
+ options = IRPetalParam()
20
+ options.files = ["/Users/lacasta/tmp/thermal/PPC.007.irb"]
21
+ getter = IRDataGetter.factory(options.institute, options)
22
+ DB = ReadGraphana("localhost")
23
+ irbf = IRBFile.open_file(options.files)
24
+
25
+ frames = getter.get_analysis_frame(irbf)
26
+ 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)
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env python3
2
+ """Probando."""
3
+ import sys
4
+ import json
5
+ from pathlib import Path
6
+
7
+ try:
8
+ import petal_qc
9
+
10
+ except ImportError:
11
+ cwd = Path(__file__).parent.parent.parent
12
+ sys.path.append(cwd.as_posix())
13
+
14
+
15
+ import numpy as np
16
+ import matplotlib.pyplot as plt
17
+
18
+ from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas
19
+ from matplotlib.backends.backend_gtk3 import NavigationToolbar2GTK3 as NavigationToolbar
20
+
21
+ import petal_qc
22
+ from petal_qc.thermal.IRPetalParam import IRPetalParam
23
+ from petal_qc.thermal.create_IRCore import create_IR_core
24
+ from petal_qc.thermal.analyze_IRCore import analyze_IRCore, golden_from_json, get_golden_axis, plot_profile_and_golden
25
+ from petal_qc.utils.utils import output_folder
26
+
27
+
28
+ irbFile="/private/tmp/thermal/PPB08.irb"
29
+ goldenFIle = "/private/tmp/thermal/golden-PPB.json"
30
+ outFolder = "/private/tmp/thermal"
31
+
32
+ param = IRPetalParam()
33
+ param.alias = "PPB_008"
34
+ param.SN = "20USEBC1000028"
35
+ param.tco2 = -31.7
36
+ param.out = "{}.json".format(param.alias)
37
+ param.files = [irbFile, ]
38
+ param.golden = goldenFIle
39
+ param.folder = outFolder
40
+ param.create_golden = False
41
+ param.add_attachments = True
42
+
43
+ with open(goldenFIle, "r", encoding='utf-8') as fp:
44
+ golden = golden_from_json(json.load(fp))
45
+
46
+ core = create_IR_core(param)
47
+
48
+ param.files[0] = output_folder(outFolder, param.out)
49
+ param.out = None
50
+ out = analyze_IRCore(param)
51
+ outDB = out[0] if len(out) else None
52
+ param.files = []
53
+
54
+ get_golden_axis(core, golden)
55
+
56
+ plot_profile_and_golden(golden, core, "path_temp")
57
+
58
+ plt.show()