petal-qc 0.0.0__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.

Files changed (51) hide show
  1. petal_qc/BTreport/CheckBTtests.py +321 -0
  2. petal_qc/BTreport/__init__.py +0 -0
  3. petal_qc/BTreport/bustapeReport.py +144 -0
  4. petal_qc/__init__.py +14 -0
  5. petal_qc/metrology/Cluster.py +90 -0
  6. petal_qc/metrology/DataFile.py +47 -0
  7. petal_qc/metrology/PetalMetrology.py +327 -0
  8. petal_qc/metrology/__init__.py +0 -0
  9. petal_qc/metrology/all2csv.py +57 -0
  10. petal_qc/metrology/analyze_locking_points.py +597 -0
  11. petal_qc/metrology/cold_noise.py +106 -0
  12. petal_qc/metrology/comparisonTable.py +59 -0
  13. petal_qc/metrology/convert_mitutoyo.py +175 -0
  14. petal_qc/metrology/convert_smartscope.py +145 -0
  15. petal_qc/metrology/coreMetrology.py +402 -0
  16. petal_qc/metrology/data2csv.py +63 -0
  17. petal_qc/metrology/do_Metrology.py +117 -0
  18. petal_qc/metrology/flatness4nigel.py +157 -0
  19. petal_qc/metrology/gtkutils.py +120 -0
  20. petal_qc/metrology/petal_flatness.py +353 -0
  21. petal_qc/metrology/show_data_file.py +118 -0
  22. petal_qc/metrology/testSummary.py +37 -0
  23. petal_qc/metrology/test_paralelism.py +71 -0
  24. petal_qc/thermal/CSVImage.py +69 -0
  25. petal_qc/thermal/DebugPlot.py +76 -0
  26. petal_qc/thermal/IRBFile.py +768 -0
  27. petal_qc/thermal/IRCore.py +110 -0
  28. petal_qc/thermal/IRDataGetter.py +359 -0
  29. petal_qc/thermal/IRPetal.py +1338 -0
  30. petal_qc/thermal/IRPetalParam.py +71 -0
  31. petal_qc/thermal/PetalColorMaps.py +62 -0
  32. petal_qc/thermal/Petal_IR_Analysis.py +142 -0
  33. petal_qc/thermal/PipeFit.py +598 -0
  34. petal_qc/thermal/__init__.py +0 -0
  35. petal_qc/thermal/analyze_IRCore.py +417 -0
  36. petal_qc/thermal/contours.py +378 -0
  37. petal_qc/thermal/create_IRCore.py +185 -0
  38. petal_qc/thermal/pipe_read.py +182 -0
  39. petal_qc/thermal/show_IR_petal.py +420 -0
  40. petal_qc/utils/Geometry.py +756 -0
  41. petal_qc/utils/Progress.py +182 -0
  42. petal_qc/utils/__init__.py +0 -0
  43. petal_qc/utils/all_files.py +35 -0
  44. petal_qc/utils/docx_utils.py +186 -0
  45. petal_qc/utils/fit_utils.py +188 -0
  46. petal_qc/utils/utils.py +180 -0
  47. petal_qc-0.0.0.dist-info/METADATA +29 -0
  48. petal_qc-0.0.0.dist-info/RECORD +51 -0
  49. petal_qc-0.0.0.dist-info/WHEEL +5 -0
  50. petal_qc-0.0.0.dist-info/entry_points.txt +3 -0
  51. petal_qc-0.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env python3
2
+ """Show data file."""
3
+ import sys
4
+ from argparse import ArgumentParser
5
+ from pathlib import Path
6
+
7
+ import matplotlib.pyplot as plt
8
+ import numpy as np
9
+
10
+ from petal_qc.metrology import DataFile
11
+ from petal_qc.utils.Geometry import fit_plane
12
+ from petal_qc.utils.Geometry import project_to_plane
13
+ from petal_qc.utils.Geometry import remove_outliers_indx
14
+
15
+
16
+ DEFAULT_VIEW, TOP_VIEW, FRONT_VIEW = range(0, 3)
17
+
18
+
19
+ def show_data(data, title, view=DEFAULT_VIEW, nbins=50, out_file=None, log_axis=False, surf=False, color_bar=True):
20
+ """Show the data.
21
+
22
+ PLot a 3D scatter and the Z distribution.
23
+ """
24
+ fig = plt.figure(figsize=[10, 5])
25
+ fig.suptitle(title)
26
+ fig.subplots_adjust(left=0.0, right=1.)
27
+ ax = fig.add_subplot(1, 2, 1, projection='3d')
28
+ if view == TOP_VIEW:
29
+ ax.view_init(azim=-90, elev=90)
30
+ elif view == FRONT_VIEW:
31
+ ax.view_init(azim=-90, elev=0)
32
+
33
+ Z = data[:, 2]
34
+ if surf:
35
+ _surf = ax.plot_trisurf(data[:, 0], data[:, 1], Z, cmap=plt.cm.jet, edgecolor="black", linewidths=0.2)
36
+ else:
37
+ _surf = ax.scatter(data[:, 0], data[:, 1], Z, c=Z, marker='.', cmap=plt.cm.jet)
38
+
39
+ ax.set_xlabel("X")
40
+ ax.set_ylabel("Y")
41
+ ax.set_zlabel("Z")
42
+
43
+ if color_bar:
44
+ fig.colorbar(_surf, shrink=0.5, aspect=5, location="left")
45
+
46
+ ax = fig.add_subplot(1, 2, 2)
47
+ n, *_ = ax.hist(Z, bins=nbins)
48
+ if log_axis:
49
+ plt.yscale("log")
50
+
51
+ if out_file is not None:
52
+ plt.savefig(out_file, dpi=300)
53
+
54
+ return fig
55
+
56
+
57
+ def show_data_file(fnam, options):
58
+ """Plot points in data file."""
59
+ data = DataFile.read(fnam, label=options.label, type=options.type)
60
+
61
+ if options.outliers:
62
+ indx = remove_outliers_indx(data[:, 2])
63
+ data = data[indx]
64
+
65
+ if options.fit_plane:
66
+ data, *_ = fit_plane(data)
67
+
68
+ # the plane
69
+ if options.zplane != sys.float_info.max:
70
+ zd = data[:, 2]
71
+ cond = np.where((abs(zd-options.zplane) < options.splane))
72
+ plane, V, M, L = fit_plane(data[cond])
73
+ data = project_to_plane(data, V, M)
74
+ show_data(plane, "{} - plane".format(fnam.name))
75
+
76
+ show_data(data, fnam.name, log_axis=options.log)
77
+
78
+ if options.fit:
79
+ zd = data[:, 2]
80
+ indx = np.where((abs(zd-options.zfit) < options.sfit))[0]
81
+ Y = data[indx, 2]
82
+ X = data[indx, 0:2]
83
+ coeff = np.polynomial.chebyshev.chebfit(X, Y, 2)
84
+ print(coeff)
85
+
86
+ plt.show()
87
+
88
+
89
+ if __name__ == "__main__":
90
+ parser = ArgumentParser()
91
+ parser.add_argument('files', nargs='*', help="Input files")
92
+ parser.add_argument("--Z-plane", dest='zplane', type=float,
93
+ default=sys.float_info.max, help="Estimated value plate Z plane")
94
+ parser.add_argument("--W-plane", dest='splane', type=float,
95
+ default=0.2, help="Estimated width in Z pf points in plale")
96
+ parser.add_argument("--fit", dest='fit', action="store_true", default=False)
97
+ parser.add_argument("--fit-plane", dest='fit_plane', action="store_true", default=False,
98
+ help="If set, make first a plane fit projection.")
99
+ parser.add_argument("--log", dest='log', action="store_true", default=False, help="Log Y axis")
100
+
101
+ parser.add_argument("--Z-fit", dest='zfit', type=float,
102
+ default=sys.float_info.max, help="Estimated value plate Z plane")
103
+ parser.add_argument("--W-fit", dest='sfit', type=float,
104
+ default=0.2, help="Estimated width in Z pf points in plale")
105
+ parser.add_argument("--remove-outliers", dest="outliers",
106
+ help="Remove Outliers", default=False, action="store_true")
107
+
108
+ # This is to convert a CMM file
109
+ parser.add_argument("--label", default="\\w+", help="The label to select")
110
+ parser.add_argument("--type", default="Punto", help="The class to select")
111
+
112
+ options = parser.parse_args()
113
+ if len(options.files) == 0:
114
+ print("I need an input file")
115
+ sys.exit()
116
+
117
+ fnam = Path(options.files[0]).expanduser().resolve()
118
+ show_data_file(fnam, options)
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env python3
2
+ """Read JSon files an produces a summary."""
3
+
4
+ import sys
5
+ import json
6
+ from pathlib import Path
7
+
8
+
9
+ def testSummary(files, options):
10
+ """PRoduces the summary."""
11
+ ofile = open(Path(options.out).expanduser().resolve(), "w")
12
+ for i, ifile in enumerate(files):
13
+ P = Path(ifile).expanduser().resolve()
14
+ ofile.write(P.stem + '\n')
15
+
16
+ with open(P, "r") as inp:
17
+ Js = json.load(inp)
18
+
19
+ for D in Js["defects"]:
20
+ ofile.write("{}: {}\n".format(D["name"], D["description"]))
21
+
22
+ ofile.write("\n")
23
+
24
+
25
+ if __name__ == "__main__":
26
+ from argparse import ArgumentParser
27
+ parser = ArgumentParser()
28
+ parser.add_argument('files', nargs='*', help="Input files")
29
+ parser.add_argument("--out", default="testSummary.txt")
30
+
31
+ options = parser.parse_args()
32
+ if len(options.files) == 0:
33
+ print(sys.argv[0])
34
+ print("I need an input file")
35
+ sys.exit()
36
+
37
+ testSummary(options.files, options)
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env python3
2
+ """Test Paralelism."""
3
+ import sys
4
+ import traceback
5
+ from argparse import ArgumentParser
6
+ from pathlib import Path
7
+
8
+ import numpy as np
9
+ import matplotlib.pyplot as plt
10
+
11
+ import DataFile
12
+ from analyze_locking_points import analyze_locking_point_data
13
+
14
+
15
+ def do_paralelism(ifile, options):
16
+ """Calculate paralelism locator-core
17
+
18
+ Args:
19
+ ----
20
+ files (): Input files
21
+ options (): Options.
22
+
23
+ """
24
+ ifile = Path(ifile).expanduser().resolve()
25
+ if not ifile.exists():
26
+ print("input file {} does not exist.".format(ifile))
27
+ return
28
+
29
+ # Do petal flatness analysis
30
+ Zmean = 0
31
+ if options.desy:
32
+ flatness_data = DataFile.read(ifile, "PetalPlane")
33
+ else:
34
+ flatness_data = DataFile.read(ifile, r"Punto[-|Vision-]\w", "Punto")
35
+ Zmean = np.mean(flatness_data[:, 2])
36
+ flatness_data -= Zmean
37
+
38
+ # Do locator flatness analysis
39
+ TM = None # TODO: fix this
40
+ if options.desy:
41
+ locator_data = DataFile.read(ifile, ".*_FineFlatness")
42
+ else:
43
+ locator_data = DataFile.read(ifile, "PuntoLocator", "Punto")
44
+ locator_data -= Zmean
45
+
46
+ data = np.concatenate((flatness_data, locator_data))
47
+ out = analyze_locking_point_data(data, nbins=options.nbins, cut=4, plane_fit=True)
48
+
49
+ for key, val in out.items():
50
+ print("{:10} -> {}".format(key, val))
51
+
52
+
53
+ if __name__ == "__main__":
54
+ parser = ArgumentParser()
55
+ parser.add_argument('files', nargs='*', help="Input files")
56
+ parser.add_argument("--desy", dest='desy', action="store_true", default=False)
57
+ parser.add_argument("--nbins", dest="nbins", default=25,
58
+ type=int, help="Number of bins")
59
+
60
+ options = parser.parse_args()
61
+ if len(options.files) == 0:
62
+ print(sys.argv[0])
63
+ print("I need an input file")
64
+ sys.exit()
65
+
66
+ try:
67
+ do_paralelism(options.files[0], options)
68
+ plt.show()
69
+
70
+ except Exception:
71
+ print(traceback.format_exc())
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env python3
2
+ """Get Thenal Image from CSV file."""
3
+ import datetime
4
+ import sys
5
+
6
+ import matplotlib.pyplot as plt
7
+ import numpy as np
8
+
9
+
10
+ class CSVImage(object):
11
+ """Read an image from CSV file."""
12
+
13
+ def __init__(self, ifile):
14
+ """Initialize."""
15
+ config = open(ifile, "rb")
16
+ in_data = False
17
+ i = 0
18
+ for line in config:
19
+ if not in_data:
20
+ if b'ImageWidth' in line:
21
+ ip = line.find(b'=')+1
22
+ self.width = int(line[ip:])
23
+
24
+ elif b'ImageHeight' in line:
25
+ ip = line.find(b'=')+1
26
+ self.height = int(line[ip:])
27
+
28
+ elif b'RecDate' in line:
29
+ recDate = line[line.find(b'=')+1:].strip()
30
+
31
+ elif b'RecTime' in line:
32
+ recTime = line[line.find(b'=')+1:].strip()
33
+
34
+ elif b'[Data]' in line:
35
+ recDate = recDate + b' ' + recTime
36
+ self.timestamp = datetime.datetime.strptime(recDate.decode('ascii'), "%d.%m.%Y %H:%M:%S", )
37
+ self.image = np.zeros([self.height, self.width])
38
+ in_data = True
39
+
40
+ else:
41
+ if len(line):
42
+ numbers = line.replace(b',', b'.').split(b';')
43
+ row = np.array([float(x) for x in numbers])
44
+ self.image[i, :] = row
45
+ i = i + 1
46
+
47
+ self.image = np.flipud(self.image)
48
+
49
+ def get_data(self):
50
+ """Return the image."""
51
+ return self.image
52
+
53
+
54
+ if __name__ == "__main__":
55
+ try:
56
+ fnam = sys.argv[1]
57
+ except IndexError:
58
+ print("I need an input file")
59
+ # sys.exit()
60
+ fnam = "/private/tmp/minus35.csv"
61
+
62
+ img = CSVImage(fnam)
63
+ print("{}x{}\n".format(img.width, img.height))
64
+ fig = plt.figure(figsize=(img.width/128, img.height/128))
65
+ fig.suptitle("CSVimage")
66
+ plt.imshow(img.get_data(), origin='lower', cmap="jet")
67
+ plt.colorbar()
68
+ plt.tight_layout()
69
+ plt.show()
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/envp python3
2
+ """Class encapsulating debug plots."""
3
+ import matplotlib.pyplot as plt
4
+
5
+
6
+ class DebugPlot(object):
7
+ """Handles debugging figures and plots."""
8
+
9
+ def __init__(self):
10
+ """Initialization."""
11
+ self.ax = {}
12
+ self.fig = {}
13
+ n_fig = 0
14
+
15
+ def setup_debug(self, f_id, nrow=1, ncol=1, is_3d=False, fig_kw={}):
16
+ """Prepare debug figure with given identifier.
17
+
18
+ Args:
19
+ ----
20
+ f_id (): Identifier. Use it later to get the figure associated.
21
+ nrow (int, optional): Number of rows. Defaults to 1.
22
+ ncol (int, optional): Number of columns. Defaults to 1.
23
+ is_3d (boolean): if True prepares a 3D figure.
24
+ fig_kw: rest of keywords for plt.subplots or figure.
25
+
26
+ """
27
+ if f_id not in self.ax:
28
+ if is_3d:
29
+ fig = plt.figure(tight_layout=True, **fig_kw)
30
+ ax = fig.add_subplot(1, 1, 1, projection='3d')
31
+ else:
32
+ fig, ax = plt.subplots(nrow, ncol, tight_layout=True, **fig_kw)
33
+
34
+ self.ax[f_id] = ax
35
+ self.fig[f_id] = fig
36
+
37
+ def get_ax(self, f_id):
38
+ """Return the axes associated to f_id."""
39
+ return self.ax[f_id]
40
+
41
+ def get_fig(self, f_id):
42
+ """Return the Figure associated to f_id."""
43
+ return self.fig[f_id]
44
+
45
+ def plot(self, f_id, *args):
46
+ """Plot in axes associated to f_id."""
47
+ if f_id not in self.ax:
48
+ return
49
+
50
+ self.ax[f_id].clear()
51
+ self.ax[f_id].plot(*args)
52
+ plt.draw()
53
+ plt.pause(0.001)
54
+
55
+ def plotx(self, f_id, *args):
56
+ """Draws."""
57
+ if f_id not in self.ax:
58
+ return
59
+
60
+ self.ax[f_id].plot(*args)
61
+ plt.draw()
62
+ plt.pause(0.001)
63
+
64
+ def set_title(self, f_id, title):
65
+ """Set title to axes."""
66
+ if f_id not in self.ax:
67
+ return
68
+
69
+ self.ax[f_id].set_title(title)
70
+
71
+ def savefig(self, f_id, fname, **kwargs):
72
+ """Saves the figure."""
73
+ if f_id not in self.ax:
74
+ return
75
+
76
+ self.fig[f_id].savefig(fname, **kwargs)