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.

@@ -104,6 +104,7 @@ def find_bus_tapes(session, petal, complain_func=complain):
104
104
  dict: a dict with the bustapes. Key is the BT type.
105
105
  """
106
106
  bt_list = {}
107
+ bt_valid = {}
107
108
  for child in petal["children"]:
108
109
  cstage = "Missing"
109
110
  if child["component"] is None:
@@ -117,14 +118,17 @@ def find_bus_tapes(session, petal, complain_func=complain):
117
118
 
118
119
  # We are left with the bus tapes
119
120
  cobj = session.get('getComponent', json={'component': child["component"]["id"]})
121
+ bt_list[comp_type] = cobj, child['id']
120
122
  cstage = cobj["currentStage"]['code']
121
123
  if cstage != "COMPLETED":
122
124
  complain_func("Bus tape not in final stages", cstage)
123
- continue
125
+ bt_valid[comp_type] = False
126
+
127
+ else:
128
+ bt_valid[comp_type] = True
124
129
 
125
- bt_list[comp_type] = cobj, child['id']
126
130
 
127
- return bt_list
131
+ return bt_list, bt_valid
128
132
 
129
133
 
130
134
  def find_but_tape_tests(session, petal_date, bt_sn, complain_func=complain):
@@ -209,8 +213,14 @@ def BTreport(session, SerialN, complain_func=complain):
209
213
  return None
210
214
 
211
215
  # Loop on children an find bustapes
212
- bt_list = find_bus_tapes(session, petal, complain_func=complain_func)
213
- if len(bt_list) == 0:
216
+ bt_list, bt_valid = find_bus_tapes(session, petal, complain_func=complain_func)
217
+
218
+ nvalid = 0
219
+ for valid in bt_valid.values():
220
+ if valid:
221
+ nvalid += 1
222
+
223
+ if nvalid != 2:
214
224
  complain_func("no valid bustape found", "Either not assembled or in incorrect stage.")
215
225
  return None
216
226
 
@@ -229,7 +239,7 @@ def BTreport(session, SerialN, complain_func=complain):
229
239
  }
230
240
  }
231
241
 
232
- # Check te tests in the bustapes
242
+ # Check the tests in the bustapes
233
243
  ngood = 0
234
244
  ntrouble = 0
235
245
  for bt, cp_id in bt_list.values():
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env python3
2
- from contextlib import redirect_stdout
3
-
2
+ """GUI for the BTtest."""
3
+ import dateutil.parser
4
4
  from itkdb_gtk import ITkDButils
5
5
  from itkdb_gtk import dbGtkUtils
6
6
  from itkdb_gtk import ITkDBlogin
@@ -16,6 +16,8 @@ from gi.repository import Gtk, Gio
16
16
  class BusTapeReport(dbGtkUtils.ITkDBWindow):
17
17
  """Makes a report of bustapes."""
18
18
 
19
+ BUSTAPE, SERIAL_NO, STAGE, DATE, PASSED = range(5)
20
+
19
21
  def __init__(self, session=None, title="", panel_size=100):
20
22
  """Initialization.
21
23
 
@@ -28,7 +30,9 @@ class BusTapeReport(dbGtkUtils.ITkDBWindow):
28
30
  self.petal_SN = None
29
31
  self.alternativeID = None
30
32
  self.outDB = None
31
-
33
+ self.tree = None
34
+ self.petal = None
35
+ self.petal_date = None
32
36
 
33
37
  # Active button in header
34
38
  button = Gtk.Button()
@@ -60,6 +64,10 @@ class BusTapeReport(dbGtkUtils.ITkDBWindow):
60
64
  grid.attach(self.SN.entry, 1, 0, 1, 1)
61
65
 
62
66
 
67
+ # the list of attachments
68
+ self.create_tree_view()
69
+ self.mainBox.pack_start(self.tree, True, True, 5)
70
+
63
71
  self.mainBox.pack_start(self.message_panel.frame, True, True, 0)
64
72
 
65
73
 
@@ -68,6 +76,32 @@ class BusTapeReport(dbGtkUtils.ITkDBWindow):
68
76
  self.hide()
69
77
  self.destroy()
70
78
 
79
+ def create_tree_view(self):
80
+ """Creates the Tree vvew"""
81
+ model = Gtk.ListStore(str, str, str, str, bool)
82
+ self.tree = Gtk.TreeView(model=model)
83
+
84
+ renderer = Gtk.CellRendererText()
85
+ column = Gtk.TreeViewColumn("Tape", renderer, text=BusTapeReport.BUSTAPE)
86
+ self.tree.append_column(column)
87
+
88
+ renderer = Gtk.CellRendererText()
89
+ column = Gtk.TreeViewColumn("SN", renderer, text=BusTapeReport.SERIAL_NO)
90
+ self.tree.append_column(column)
91
+
92
+ renderer = Gtk.CellRendererText()
93
+ column = Gtk.TreeViewColumn("Stage", renderer, text=BusTapeReport.STAGE)
94
+ self.tree.append_column(column)
95
+
96
+ renderer = Gtk.CellRendererText()
97
+ column = Gtk.TreeViewColumn("Test Date", renderer, text=BusTapeReport.DATE)
98
+ self.tree.append_column(column)
99
+
100
+ renderer = Gtk.CellRendererText()
101
+ column = Gtk.TreeViewColumn("Passed", renderer, text=BusTapeReport.PASSED)
102
+ self.tree.append_column(column)
103
+
104
+
71
105
  def on_SN_changed(self, entry, value):
72
106
  """New SN given. Ask in PDB,"""
73
107
  if len(value) <= 0:
@@ -76,19 +110,54 @@ class BusTapeReport(dbGtkUtils.ITkDBWindow):
76
110
 
77
111
  obj = ITkDButils.get_DB_component(self.session, value)
78
112
  if obj is not None:
79
- entry.set_text(obj["serialNumber"])
80
- self.alternativeID = obj["alternativeIdentifier"]
113
+ if self.check_petal(obj):
114
+ entry.set_text(obj["serialNumber"])
115
+ self.alternativeID = obj["alternativeIdentifier"]
116
+ self.petal = obj
117
+ self.petal_date = dateutil.parser.parse(self.petal["stateTs"])
118
+
119
+ self.query_db()
81
120
 
82
121
  else:
83
122
  dbGtkUtils.complain("Invalid SN", value)
84
123
 
124
+ def check_petal(self, petal):
125
+ """Check that the petal is a good one."""
126
+ comp_type = CheckBTtests.get_type(petal)
127
+ if comp_type != "CORE_AVS":
128
+ dbGtkUtils.complain("This is not a petal coree", comp_type)
129
+ return False
130
+
131
+ # Check that the petal core is in the proper stage.
132
+ stage = petal["currentStage"]['code']
133
+ if stage != "AT_QC_SITE":
134
+ dbGtkUtils.complain("Petal core is not at QC_SITE", "Current stage: {}".format(stage))
135
+ return False
136
+
137
+ return True
85
138
  def query_db(self, *args):
86
139
  """Search petal and bustapes."""
87
- SN = self.SN.get_text()
88
- if SN is None or len(SN)==0:
89
- dbGtkUtils.complain("Invalid Serial Number", "Wrong value: {}".format(SN))
140
+ if self.petal is None:
90
141
  return
91
-
142
+
143
+ model = Gtk.ListStore(str, str, str, str, bool)
144
+ self.tree = Gtk.TreeView(model=model)
145
+
146
+ # Loop on children an find bustapes
147
+ bt_list, bt_valid = CheckBTtests.find_bus_tapes(self.session,
148
+ self.petal,
149
+ complain_func=dbGtkUtils.complain)
150
+
151
+ for btype, item in bt_list.items():
152
+ bt_sn = item[0]["serialNumber"]
153
+ cstage = item[0]["currentStage"]['code']
154
+ bt_tests = CheckBTtests.find_but_tape_tests(self.session,
155
+ self.petal_date,
156
+ bt_sn,
157
+ complain_func=dbGtkUtils.complain)
158
+
159
+ values = [btype, child_sn, cstage]
160
+
92
161
  self.outDB = CheckBTtests.BTreport(self.session, SN, complain_func=dbGtkUtils.complain)
93
162
 
94
163
  if self.outDB is None:
petal_qc/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
1
  """petal_qc python module."""
2
- __version__ = "0.0.0"
2
+ __version__ = "0.0.2"
3
3
 
4
4
 
5
5
  def coreMetrology():
petal_qc/dashBoard.py ADDED
@@ -0,0 +1,21 @@
1
+ """Test dashboard."""
2
+ import sys
3
+
4
+ try:
5
+ import petal_qc
6
+
7
+ except ImportError:
8
+ from pathlib import Path
9
+ cwd = Path(__file__).parent.parent
10
+ sys.path.append(cwd.as_posix())
11
+
12
+ from itkdb_gtk import dbGtkUtils
13
+ from itkdb_gtk import GetShipments
14
+ from itkdb_gtk import PetalReceptionTests
15
+ from itkdb_gtk import ITkDBlogin
16
+ from itkdb_gtk import CreateShipments
17
+ from itkdb_gtk import UploadTest
18
+ from itkdb_gtk import UploadMultipleTests
19
+ from itkdb_gtk import GlueWeight
20
+ from itkdb_gtk import UploadModuleIV
21
+ from itkdb_gtk import WireBondGui
@@ -3,11 +3,11 @@
3
3
  from pathlib import Path
4
4
  from argparse import Action
5
5
  from argparse import ArgumentParser
6
- import itkdb_gtk.ITkDButils
7
- import itkdb_gtk.dbGtkUtils
8
- import numpy as np
9
6
  from contextlib import redirect_stdout
7
+ import numpy as np
10
8
  import itkdb_gtk
9
+ import itkdb_gtk.ITkDButils
10
+ import itkdb_gtk.dbGtkUtils
11
11
  import itkdb_gtk.UploadTest
12
12
 
13
13
  from petal_qc.metrology.do_Metrology import do_analysis
@@ -147,6 +147,7 @@ class CoreMetrology(itkdb_gtk.dbGtkUtils.ITkDBWindow):
147
147
 
148
148
  self.mainBox.pack_start(self.message_panel.frame, True, True, 0)
149
149
 
150
+
150
151
  def quit(self, *args):
151
152
  """Quits the application."""
152
153
  self.hide()
@@ -333,6 +334,20 @@ class CoreMetrology(itkdb_gtk.dbGtkUtils.ITkDBWindow):
333
334
  uploadW = itkdb_gtk.UploadTest.UploadTest(self.session, payload=self.outDB)
334
335
 
335
336
 
337
+ class CoreMetrologyOptions(object):
338
+ """Dummy options"""
339
+ def __init__(self):
340
+ self.files = []
341
+ self.SN = None
342
+ self.desy = False
343
+ self.folder = None
344
+ self.prefix = None
345
+ self.locking_points = None
346
+ self.title = None
347
+ self.nbins = 25
348
+ self.label = "\\w+"
349
+ self.type = "Punto"
350
+
336
351
  def main():
337
352
  """Entry point."""
338
353
  parser = ArgumentParser()
@@ -12,6 +12,7 @@ import os
12
12
  import pickle
13
13
  import struct
14
14
  import sys
15
+ from argparse import ArgumentParser
15
16
  from collections.abc import Iterable
16
17
  from pathlib import Path
17
18
 
@@ -719,13 +720,12 @@ def open_file(fname):
719
720
  return irbf
720
721
 
721
722
 
722
- if __name__ == "__main__":
723
+ def main():
723
724
  """Example of use of IRBFile.
724
725
 
725
- Shows all the images in a file.
726
+ Shows all the images in a file.
726
727
 
727
728
  """
728
- from argparse import ArgumentParser
729
729
  parser = ArgumentParser()
730
730
  parser.add_argument('files', nargs='*', help="Input files")
731
731
  parser.add_argument("--save", action="store_true",
@@ -743,7 +743,8 @@ if __name__ == "__main__":
743
743
  fig = None
744
744
  nimg = 0
745
745
  ratio = -1
746
- for img in IRfile.images():
746
+ for ximg in IRfile.images():
747
+ img = ximg[0]
747
748
  tmin = np.min(img.image)
748
749
  print("Tmin {:1f} - {}x{}".format(tmin, img.width, img.height))
749
750
  if ratio < 0:
@@ -766,3 +767,6 @@ if __name__ == "__main__":
766
767
  plt.pause(0.00001)
767
768
 
768
769
  plt.show()
770
+
771
+ if __name__ == "__main__":
772
+ main()
@@ -41,6 +41,7 @@ class IRCore(object):
41
41
  self.files = []
42
42
  self.results = [] if results is None else results # list of AnalysisResults. One per side
43
43
  self.golden = [] # list of Golden results. One per side.
44
+ self.inlet = -9999
44
45
 
45
46
  def set_files(self, files):
46
47
  """Set the input files."""
@@ -1,11 +1,29 @@
1
1
  """Encapsulates different data structure at DESY and IFIC.
2
2
  """
3
+ import sys
4
+ from pathlib import Path
5
+ import numpy as np
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())
3
13
 
4
14
 
5
- import numpy as np
6
15
  from petal_qc.thermal import IRPetal
7
16
  from petal_qc.thermal import Petal_IR_Analysis
8
17
 
18
+ HAS_GRAPHANA = False
19
+ try:
20
+ from petal_qc.utils.readGraphana import ReadGraphana
21
+ HAS_GRAPHANA = True
22
+
23
+ except ImportError:
24
+ HAS_GRAPHANA = False
25
+
26
+
9
27
 
10
28
  class IRDataGetter(object):
11
29
  """BAse class defining the interface."""
@@ -101,6 +119,10 @@ class IRDataGetter(object):
101
119
  """Get the frame where we want to perform the analysis."""
102
120
  return None
103
121
 
122
+ def get_inlet_temperature(self):
123
+ """REturn the inlet temperature."""
124
+ return -9999
125
+
104
126
 
105
127
  class IRDataIFIC(IRDataGetter):
106
128
  """Gets data for IFIC analysis."""
@@ -108,6 +130,11 @@ class IRDataIFIC(IRDataGetter):
108
130
  def __init__(self) -> None:
109
131
  """Initialization."""
110
132
  super().__init__()
133
+ self.analysis_frame = None
134
+ if HAS_GRAPHANA:
135
+ self.DB = ReadGraphana("localhost")
136
+ else:
137
+ self.DB = None
111
138
 
112
139
  def find_reference_image(self, irbf, *args, **kargs):
113
140
  """Find first image in sequence with T < T_min.
@@ -236,7 +263,19 @@ class IRDataIFIC(IRDataGetter):
236
263
  min_T.append(np.min(img[0].image))
237
264
 
238
265
  indx = IRDataIFIC.find_minimum(min_T)
239
- return [irbf.getImage(indx[-1])]
266
+ self.analysis_frame = [irbf.getImage(indx[-1])]
267
+ return self.analysis_frame
268
+
269
+ def get_inlet_temperature(self):
270
+ """REturn the inlet temperature."""
271
+ if self.DB:
272
+ img = self.analysis_frame[0]
273
+ val = self.DB.get_temperature(img.timestamp, 10)
274
+ return val
275
+
276
+ else:
277
+ return -9999
278
+
240
279
 
241
280
 
242
281
  class IRDataDESY(IRDataGetter):
@@ -13,6 +13,13 @@ from scipy import ndimage
13
13
  from scipy.optimize import minimize
14
14
  from skimage import measure
15
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
+
16
23
  from petal_qc.thermal import contours
17
24
  from petal_qc.thermal import CSVImage
18
25
  from petal_qc.thermal import DebugPlot
@@ -1212,7 +1219,7 @@ def get_image_from_irb(irbf, frame, thrs):
1212
1219
  """
1213
1220
  img = None
1214
1221
  i_min = frame
1215
- if irbf.n_images() == 0:
1222
+ if irbf.nimages == 0:
1216
1223
  print("Input file does not contain images.")
1217
1224
 
1218
1225
  else:
@@ -1246,12 +1253,12 @@ def read_image(fnam, frame=-1, thrs=-20):
1246
1253
  ifile = Path(fnam).expanduser().resolve()
1247
1254
  if not ifile.exists():
1248
1255
  print("Input file does not exist.")
1249
- return None
1256
+ return None, None
1250
1257
 
1251
1258
  suffix = ifile.suffix.lower()
1252
- img = None
1259
+ img = None, None
1253
1260
  if suffix == ".csv":
1254
- img = CSVImage.CSVImage(ifile)
1261
+ img = CSVImage.CSVImage(ifile), 0
1255
1262
 
1256
1263
  elif suffix == ".irb":
1257
1264
  irbf = IRBFile.IRBFile(ifile)
@@ -1274,12 +1281,12 @@ def main(fnam, options):
1274
1281
  params.debug = False
1275
1282
 
1276
1283
  print("Open file")
1277
- img = read_image(fnam, options.frame, options.thrs)
1284
+ img, _ = read_image(fnam, options.frame, options.thrs)
1278
1285
  if img is None:
1279
1286
  sys.exit()
1280
1287
 
1281
1288
  # Show original Image
1282
- fig, ax = plt.subplots(1, 1, dpi=300)
1289
+ fig, ax = plt.subplots(1, 1)
1283
1290
  values = get_IR_data(img, False)
1284
1291
  min_T = np.min(values)
1285
1292
  fig.suptitle("Original image - Temp. {:.1f}".format(min_T))
@@ -1290,7 +1297,7 @@ def main(fnam, options):
1290
1297
  # Show rotated image
1291
1298
  values = get_IR_data(img, True)
1292
1299
  min_T = np.min(values)
1293
- fig, ax = plt.subplots(1, 1, dpi=300)
1300
+ fig, ax = plt.subplots(1, 1)
1294
1301
  fig.suptitle("Rotated image - Temp. {:.1f}".format(min_T))
1295
1302
  pcm = ax.imshow(values, origin='lower', cmap="jet")
1296
1303
  fig.colorbar(pcm, ax=ax)
@@ -13,7 +13,8 @@ class IRPetalParam(object):
13
13
 
14
14
  """
15
15
  self.institute = 'IFIC' # Either IFIC or DESY to treat the different files
16
- self.thrs = -20.0 # the threshold
16
+ self.thrs = -22.0 # the threshold
17
+ self.tco2 = -35.0 # Inlet temperature
17
18
  self.gauss_size = 15 # Radius of gausian filtering
18
19
  self.grad_sigma = 2.5 # Sigma of grading calculation
19
20
  self.distance = 5 # Distance in contour between slices
@@ -25,6 +26,7 @@ class IRPetalParam(object):
25
26
  self.do_fit = True # True to fit the segment points.
26
27
  self.rotate = True # Rotate to have a vertical petal in mirror image
27
28
  self.debug = False # To debug
29
+ self.report = False #
28
30
 
29
31
  if values is not None:
30
32
  self.set_values(values)
@@ -58,6 +60,7 @@ class IRPetalParam(object):
58
60
  default=P.institute,
59
61
  help="Either IFIC or DESY to treat the different files")
60
62
  parser.add_argument("--thrs", type=float, default=P.thrs, help="Temperature threshold")
63
+ parser.add_argument("--tco2", type=float, default=P.tco2, help="CO2 Inlet temperature")
61
64
  parser.add_argument("--gauss_size", type=int, default=P.gauss_size, help="Radius of gausian filtering")
62
65
  parser.add_argument("--distance", type=float, default=P.distance, help="Distance in contour beteween slices")
63
66
  parser.add_argument("--npoints", type=int, default=P.npoints, help="Number of points per segment")
@@ -69,3 +72,4 @@ class IRPetalParam(object):
69
72
  parser.add_argument("--contour_smooth", type=float, default=P.contour_smooth,
70
73
  help="Value to smooth contour")
71
74
  parser.add_argument("--debug", action="store_true", default=False, help="Show additional information.")
75
+ parser.add_argument("--report", action="store_true", default=False, help="True if figures kept for the report.")
@@ -511,6 +511,7 @@ class PipeFit(object):
511
511
  ax.legend()
512
512
  plt.draw()
513
513
  plt.pause(0.0001)
514
+ return fig, ax
514
515
 
515
516
 
516
517
  def main(data_file, opts):
@@ -162,6 +162,106 @@ def create_golden_average(files, options):
162
162
 
163
163
  return golden, result_list
164
164
 
165
+ def golden_from_json(js_golden):
166
+ """Converst a JSon golden into a Golden object."""
167
+ golden = [Petal_IR_Analysis.AnalysisResult() for i in range(2)]
168
+ for i, G in enumerate(golden):
169
+ G.path_length = np.array(js_golden[i]["path_length"])
170
+ G.path_temp = np.array(js_golden[i]["path_temp"])
171
+ G.path_spread = np.array(js_golden[i]["path_spread"])
172
+ G.sensor_avg = np.array(js_golden[i]["sensor_avg"])
173
+ G.sensor_std = np.array(js_golden[i]["sensor_std"])
174
+
175
+ return golden
176
+
177
+ def get_golden_axis(R, golden):
178
+ """Compute result on golden points."""
179
+ xvalues = [ [x for x in golden[i].path_length] for i in range(2) ]
180
+ R.golden = []
181
+ for iside in range(2):
182
+ G = Petal_IR_Analysis.AnalysisResult()
183
+ splnT = CubicSpline(R.results[iside].path_length, R.results[iside].path_temp)
184
+ splnS = CubicSpline(R.results[iside].path_length, R.results[iside].path_spread)
185
+ G.path_length = np.array(xvalues[iside])
186
+ G.path_temp = np.array([splnT(x) for x in G.path_length])
187
+ G.path_spread = np.array([splnS(x) for x in G.path_length])
188
+ G.sensor_avg = np.array(R.results[iside].sensor_avg)
189
+ G.sensor_std = np.array(R.results[iside].sensor_std)
190
+ R.golden.append(G)
191
+
192
+
193
+ def plot_profile_and_golden(golden, core, value):
194
+ """Plot petal core and golden average.
195
+
196
+ Args:
197
+ ----
198
+ resuls: results from create_golden_average
199
+ golden: golden values (from create_golgen_average)
200
+ value: value to show, ej path_temp, path_spread, sensor_avg, sensor_std
201
+
202
+ """
203
+ tick_labels = ["R0", "R1", "R2", "R3", "R3", "R4", "R4", "R5", "R5", "EoS"]
204
+ figures = []
205
+ factor = 1.0
206
+ if value.find("sensor") >= 0:
207
+ factor = 2.0
208
+
209
+ # Get acceptance band
210
+ band = get_acceptance_band()
211
+
212
+ for iside in range(2):
213
+ fig, ax = plt.subplots(2, 1, tight_layout=True, gridspec_kw={'height_ratios': (0.66, 0.34)})
214
+ figures.append(fig)
215
+ fig.suptitle("Petal core .vs. Golden for {} - side {}.".format(value, iside))
216
+ for a in ax:
217
+ a.grid()
218
+
219
+ if value.find("path") < 0:
220
+ for i in range(2):
221
+ ax[i].set_xticks(range(10), labels=tick_labels)
222
+
223
+ RS = core.results[iside]
224
+ # convert to golden X
225
+ # TODO: get X, Y from petal core. Move golden to this X axis and draw differences.
226
+ # This only happens for the "_path" values, not for the sensors.
227
+ if value.find("path") >= 0:
228
+ X = RS.path_length
229
+ Y = getattr(RS, value)
230
+ spln = CubicSpline(golden[iside].path_length, getattr(golden[iside], value))
231
+ gY = np.array([spln(x) for x in X])
232
+ else:
233
+ X = np.array([float(x) for x in range(10)])
234
+ Y = getattr(RS, value)
235
+ gY = getattr(golden[iside], value)
236
+
237
+ delta = Y - gY
238
+ ax[0].plot(X, Y, '-', label=core.aliasID, linewidth=1)
239
+ ax[1].plot(X, delta, '-', label=core.aliasID, linewidth=1)
240
+
241
+ # Draw golden line
242
+ ax[0].plot(X, gY, '-', label="Golden", linewidth=4, alpha=0.4, color="black")
243
+
244
+ Tmean = np.mean(Y)
245
+ Tband = factor*abs(Tmean)/3
246
+
247
+ ax[0].legend(ncol=3, fontsize="x-small")
248
+ ax[0].set_title("T$_{prof}$ values")
249
+ if value.find("temp") >= 0 or value.find("_avg") >= 0:
250
+ ax[0].set_ylim(Tmean-Tband, Tmean+Tband)
251
+ ax[0].fill_between(X, gY + band, gY - band,
252
+ facecolor="yellow", alpha=0.25,
253
+ label="Acceptance band")
254
+
255
+ ax[1].fill_between(X, band, -band,
256
+ facecolor="yellow", alpha=0.25,
257
+ label="Acceptance band")
258
+
259
+ ax[1].legend(ncol=4, fontsize="x-small")
260
+ ax[1].set_title("T$_{prof}$ - Golden avg.")
261
+ if value.find("temp") >= 0 or value.find("_avg") >= 0:
262
+ ax[1].set_ylim(-Tband, Tband)
263
+
264
+ return figures
165
265
 
166
266
  def show_golden_average(golden, results, value):
167
267
  """Create golden average.
@@ -174,7 +274,7 @@ def show_golden_average(golden, results, value):
174
274
 
175
275
  """
176
276
  tick_labels = ["R0", "R1", "R2", "R3", "R3", "R4", "R4", "R5", "R5", "EoS"]
177
-
277
+ figures = []
178
278
  factor = 1.0
179
279
  if value.find("sensor") >= 0:
180
280
  factor = 2.0
@@ -184,6 +284,7 @@ def show_golden_average(golden, results, value):
184
284
 
185
285
  for iside in range(2):
186
286
  fig, ax = plt.subplots(2, 1, tight_layout=True, gridspec_kw={'height_ratios': (0.66, 0.34)}, figsize=(7, 6))
287
+ figures.append(fig)
187
288
  fig.suptitle("Golden average for {} - side {}.".format(value, iside))
188
289
  for a in ax:
189
290
  a.grid()
@@ -231,6 +332,7 @@ def show_golden_average(golden, results, value):
231
332
  if value.find("temp") >= 0 or value.find("_avg") >= 0:
232
333
  ax[1].set_ylim(-Tband, Tband)
233
334
 
335
+ return figures
234
336
 
235
337
  def compare_golden(core, golden, value):
236
338
  """Comapres petal core with golden average.
@@ -270,12 +372,15 @@ def analyze_petal_cores(files, golden, options):
270
372
  """Create golden average.
271
373
 
272
374
  Args:
273
- ----
274
375
  files (list): List of input files
275
376
  golden: the golden object
276
377
  options: other options.
277
378
 
379
+ Return:
380
+ array with JSon objects corresponding to the PDB test.
381
+
278
382
  """
383
+ output = []
279
384
  names = get_names(files)
280
385
  for i, ifile in enumerate(files):
281
386
  ifile = find_file(options.folder, ifile)
@@ -352,13 +457,17 @@ def analyze_petal_cores(files, golden, options):
352
457
 
353
458
  # Check if we are given an output folder
354
459
  ofile = output_folder(options.folder, ofile)
355
- with open(ofile, 'w') as fp:
460
+ with open(ofile, 'w', encoding="UTF-8") as fp:
356
461
  print("writing {}".format(ofile))
357
462
  json.dump(dbOut, fp, indent=3, cls=IRCore.NumpyArrayEncoder)
358
463
 
464
+ output.append(dbOut)
359
465
 
360
- def analyze_IRCore(options):
466
+ return output
467
+
468
+ def analyze_IRCore(options, show=True):
361
469
  """Main entry."""
470
+ output = None
362
471
  if options.create_golden:
363
472
  golden, results = create_golden_average(options.files, options)
364
473
  if options.out is None:
@@ -390,9 +499,12 @@ def analyze_IRCore(options):
390
499
  for i, Jside in enumerate(J):
391
500
  golden[i].from_json(Jside)
392
501
 
393
- analyze_petal_cores(options.files, golden, options)
502
+ output = analyze_petal_cores(options.files, golden, options)
503
+
504
+ if show:
505
+ plt.show()
394
506
 
395
- plt.show()
507
+ return output
396
508
 
397
509
 
398
510
  if __name__ == "__main__":
@@ -406,6 +518,8 @@ if __name__ == "__main__":
406
518
  parser.add_argument("--golden", default=None, help="The golden to compare width")
407
519
  parser.add_argument("--prefix", default="golden", help="Prefix for figures")
408
520
  parser.add_argument("--debug", action="store_true", default=False, help="Set to debug")
521
+ parser.add_argument("--report", action="store_true", default=False, help="Set to produce plots for report")
522
+
409
523
  parser.add_argument("--out", default=None, help="File to store Golden.")
410
524
  parser.add_argument("--folder", default=None, help="Folder to store output files. Superseeds folder in --out")
411
525