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,59 @@
1
+ #!/usr/bin/env python3
2
+ """Create a table from a set of PDB JSon files."""
3
+
4
+ import sys
5
+ import json
6
+ import openpyxl as xl
7
+ from openpyxl.worksheet.cell_range import CellRange
8
+ from pathlib import Path
9
+
10
+
11
+ def comparisonTable(files, options):
12
+ """Creqt3 the table."""
13
+ wb = xl.Workbook()
14
+ ws = wb.active
15
+
16
+ dir(ws)
17
+
18
+ firstC = ["All", "R0", "R1", "R2", "R3_0", "R3_1", "R4_0", "R4_1", "R5_0", "R5_1"]
19
+ for i, lbl in enumerate(firstC):
20
+ ws.cell(row=3+i, column=1).value = lbl
21
+
22
+ for i, ifile in enumerate(files):
23
+ P = Path(ifile).expanduser().resolve()
24
+ print(P.stem)
25
+ petal, side = P.stem.split('_')
26
+ with open(P, "r") as inp:
27
+ Js = json.load(inp)
28
+ if len(Js["results"]["METROLOGY_FRONT"]):
29
+ Js = Js["results"]["METROLOGY_FRONT"]
30
+ else:
31
+ Js = Js["results"]["METROLOGY_BACK"]
32
+
33
+ if i % 2 == 0:
34
+ ws.cell(row=1, column=i+2).value = petal
35
+
36
+ ws.cell(row=2, column=i+2).value = side
37
+ ws.cell(row=3, column=i+2).value = Js["FLATNESS_GLOBAL"]
38
+ ws.cell(row=3, column=i+2).number_format = '0.000'
39
+ for j, v in enumerate(Js["FLATNESS_LOCAL"]):
40
+ cell = ws.cell(row=4+j, column=i+2)
41
+ cell.value = v
42
+ cell.number_format = '0.000'
43
+
44
+ wb.save(options.out)
45
+
46
+
47
+ if __name__ == "__main__":
48
+ from argparse import ArgumentParser
49
+ parser = ArgumentParser()
50
+ parser.add_argument('files', nargs='*', help="Input files")
51
+ parser.add_argument("--out", default="table.xlsx")
52
+
53
+ options = parser.parse_args()
54
+ if len(options.files) == 0:
55
+ print(sys.argv[0])
56
+ print("I need an input file")
57
+ sys.exit()
58
+
59
+ comparisonTable(options.files, options)
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/env python3
2
+ """Convert mitutoyo output into CSV."""
3
+ import argparse
4
+ import fnmatch
5
+ import io
6
+ import os
7
+ import re
8
+ import sys
9
+ from pathlib import Path
10
+
11
+
12
+ def all_files(root, patterns='*', single_level=False, yield_folders=False):
13
+ """A generator that reruns all files in the given folder.
14
+
15
+ Args:
16
+ ----
17
+ root (file path): The folder
18
+ patterns (str, optional): The pattern of the files. Defaults to '*'.
19
+ single_level (bool, optional): If true, do not go into sub folders. Defaults to False.
20
+ yield_folders (bool, optional): If True, return folders as well. Defaults to False.
21
+
22
+ Yields
23
+ ------
24
+ str: file path name
25
+
26
+ """
27
+ patterns = patterns.split(';')
28
+ for path, subdirs, files in os.walk(root):
29
+ if yield_folders:
30
+ files.extend(subdirs)
31
+
32
+ files.sort()
33
+ for name in files:
34
+ for pattern in patterns:
35
+ if fnmatch.fnmatch(name, pattern):
36
+ yield os.path.join(path, name)
37
+ break
38
+
39
+ if single_level:
40
+ break
41
+
42
+
43
+ def mitutoyo2cvs(infiles, ofile, label='\\w+', data_type="Punto", keep=False, fill=-1):
44
+ """Converts a Mityutoyo ASCII file to csv.
45
+
46
+ Stores the X, Y and Z coordinates in the objects defined by object with
47
+ label matching the input.
48
+
49
+ Args:
50
+ ----
51
+ infiles: List of input files
52
+ ofile: Output file
53
+ label (optional): label of the objects to convert. Defaults to '\w+'.
54
+ data_type (optional): Type of objects. Defaults to "Punto".
55
+ keep (optional): keep the label in the output table. Defaults to False.
56
+ fill (optional): if given, fill CVS lines to have up to fill items
57
+
58
+ """
59
+ # print("^{}:\\s+({})".format(type, label))
60
+ rgx = "^({}):\\s+({})".format(data_type, label)
61
+ start = re.compile(rgx, re.DOTALL)
62
+
63
+ is_file = False
64
+ if isinstance(ofile, io.IOBase):
65
+ fout = ofile
66
+ else:
67
+ try:
68
+ fout = open(ofile, 'w', encoding="utf-8")
69
+ except TypeError:
70
+ fout = ofile
71
+
72
+ is_file = True
73
+
74
+ if keep:
75
+ fout.write("X,Y,Z, label\n")
76
+ else:
77
+ fout.write("X,Y,Z\n")
78
+
79
+ for fnam in infiles:
80
+ ifile = Path(fnam).expanduser().resolve()
81
+ fin = open(ifile, 'r', encoding='ISO-8859-1')
82
+
83
+ for line in fin:
84
+ line = line.replace("C�rculo", "Círculo") \
85
+ .replace("L�nea", "Linea") \
86
+ .replace("�ngulo", "Ángulo") \
87
+ .replace("Di�metro", "Diámetero")
88
+ r = start.match(line)
89
+ if r:
90
+ the_type = r.group(1)
91
+ the_label = r.group(2)
92
+
93
+ else:
94
+ continue
95
+
96
+ line_data = []
97
+ while True:
98
+ ss = fin.readline()
99
+ if len(ss)==0 or ss[0] == '\n':
100
+ break
101
+
102
+ dd = [s.strip().replace(',', '.') for s in ss.split('=')]
103
+ try:
104
+ line_data.append(float(dd[1]))
105
+ except IndexError:
106
+ print("Incomplete data line.")
107
+ print(ss)
108
+ print(dd)
109
+
110
+ if fill > 0:
111
+ while len(line_data) < fill:
112
+ line_data.append(0.0)
113
+
114
+ slin = ','.join([str(v) for v in line_data])
115
+ fout.write(slin)
116
+ if keep:
117
+ fout.write(",{}\n".format(the_label))
118
+ else:
119
+ fout.write('\n')
120
+
121
+ fin.close()
122
+
123
+ if is_file:
124
+ fout.close()
125
+
126
+
127
+ def convert_all_in_folder(indir, outdir, patterns='*', label='\\w+', data_type="Punto"):
128
+ """Call mitutoyo2cvs to all files in folder and store them in outpuit folder.
129
+
130
+ Args:
131
+ ----
132
+ indir: input folder
133
+ outdir: output folder
134
+ patterns (optional): ';' separted list of file patterns to match. Defaults to '*'.
135
+ label (optional): see mitutoyo2cvs. Defaults to '\w+'.
136
+ data_type (optional): see mitutoyo2cvs. Defaults to "Punto".
137
+
138
+ """
139
+ idir = ifile = Path(indir).expanduser().resolve()
140
+ if not idir.exists():
141
+ raise ValueError("Input folder does not exist.")
142
+
143
+ odir = ifile = Path(outdir).expanduser().resolve()
144
+
145
+ for ipath in all_files(idir, patterns=patterns):
146
+ ifile = Path(ipath)
147
+ oname = ifile.stem + '.csv'
148
+ fdir = ifile.parent.relative_to(idir)
149
+ fdir = Path.joinpath(odir, fdir)
150
+ if not fdir.exists():
151
+
152
+ Path.mkdir(fdir, parents=True)
153
+
154
+ ofile = Path.joinpath(fdir, oname)
155
+ mitutoyo2cvs([ifile], ofile, label, data_type)
156
+ print(ifile)
157
+ print(ofile)
158
+ print('.')
159
+
160
+
161
+ if __name__ == "__main__":
162
+ parser = argparse.ArgumentParser()
163
+ parser.add_argument("mitutoyo_files", nargs='*',
164
+ help="The Mitutoyo file to parse")
165
+ parser.add_argument("--label", default="\\w+", help="The label to select")
166
+ parser.add_argument("--type", default="Punto", help="The class to select")
167
+ parser.add_argument("--out", help="Outout CSV file", default="out.csv")
168
+ parser.add_argument("--keep_label", dest="keep", default=False, action="store_true", help="Store label in output")
169
+
170
+ args = parser.parse_args()
171
+ if len(args.mitutoyo_files) == 0:
172
+ print("I need an input file")
173
+ sys.exit()
174
+
175
+ mitutoyo2cvs(args.mitutoyo_files, args.out, args.label, args.type, args.keep)
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env python3
2
+ """Convert mitutoyo output into CSV."""
3
+ import io
4
+ import re
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ import numpy as np
9
+ import matplotlib.pyplot as plt
10
+
11
+
12
+ from petal_qc.metrology import DataFile
13
+ from .analyze_locking_points import analyze_locking_point_data
14
+
15
+ def get_data_chunck(flist, data_type, ofile):
16
+ """Get one data type chunk from file
17
+
18
+ Args:
19
+ fname (): input file
20
+ data_tyle (): data type
21
+ ofile (): file object for output.
22
+
23
+ """
24
+ rgx = "Step Name:\\s+({}).*?=".format(data_type)
25
+ print("Regex: {}\n".format(rgx))
26
+ start = re.compile(rgx, re.DOTALL)
27
+
28
+ for fname in flist:
29
+ ifile = Path(fname).expanduser().resolve()
30
+ print(ifile)
31
+ ss = None
32
+ with open(ifile, 'r', encoding='ISO-8859-1') as fin:
33
+ ss = fin.read()
34
+
35
+ if not ss:
36
+ return
37
+
38
+ for txt in start.finditer(ss):
39
+ print(txt.group(1))
40
+ if ofile:
41
+ ofile.write(txt.group(0)+'\n')
42
+
43
+
44
+ def read_smartscope(fnam, ofile, data_type, keep=False,):
45
+ """Convert a SmartScope txt file into CVS
46
+
47
+ Args:
48
+ fnam: Input file pat
49
+ ofile: Output file
50
+ data_type: Data label in file
51
+ keep (optional): keep the label in the output table. Defaults to False.
52
+
53
+ """
54
+ ifile = Path(fnam).expanduser().resolve()
55
+ fin = open(ifile, 'r', encoding='ISO-8859-1')
56
+
57
+ is_file = False
58
+ if isinstance(ofile, io.IOBase):
59
+ fout = ofile
60
+ else:
61
+ fout = open(ofile, 'w')
62
+ is_file = True
63
+
64
+ if keep:
65
+ fout.write("X,Y,Z, label\n")
66
+ else:
67
+ fout.write("X,Y,Z\n")
68
+
69
+ rgx = "^Step Name:\\s+{}".format(data_type)
70
+ start = re.compile(rgx, re.DOTALL)
71
+ finder = re.compile("^Finder Name")
72
+
73
+ while True:
74
+ line = fin.readline()
75
+ if not line:
76
+ break
77
+
78
+ r = start.match(line)
79
+ if not r:
80
+ continue
81
+
82
+ eof = False
83
+ while True:
84
+ line = fin.readline()
85
+ if not line:
86
+ eof = True
87
+ break
88
+
89
+ r = finder.match(line)
90
+ if r:
91
+ break
92
+
93
+ # Read the header line and to the numbers
94
+ while not eof:
95
+ line = fin.readline()
96
+ if not line:
97
+ break
98
+
99
+ if line[0] == '-':
100
+ continue
101
+
102
+ if line[0] == "=":
103
+ break
104
+
105
+ items = line.split()
106
+ values = [ float(x) for x in items[2:5]]
107
+ fout.write("{:6f}, {:6f}, {:6f}\n".format(values[1], values[0], values[2]))
108
+
109
+ fout.close()
110
+
111
+ def do_locking_points(args):
112
+ ifile = args.smartscope_files[0]
113
+ flatness_data = DataFile.read(ifile, "PetalPlane")
114
+ locator_data = DataFile.read(ifile, ".*_FineFlatness")
115
+
116
+ data = np.concatenate((flatness_data, locator_data))
117
+ analyze_locking_point_data(data, document=None, nbins=50, plane_fit=True)
118
+
119
+ if __name__ == "__main__":
120
+ import argparse
121
+
122
+ parser = argparse.ArgumentParser()
123
+ parser.add_argument("smartscope_files", nargs='*',
124
+ help="The SmartScope files to parse")
125
+ parser.add_argument("--label", default="\\w+", help="The label to select")
126
+ parser.add_argument("--out", help="Output CSV file", default="out.csv")
127
+ parser.add_argument("--keep_label", dest="keep", default=False, action="store_true", help="Store label in output")
128
+
129
+ args = parser.parse_args()
130
+ if len(args.smartscope_files) == 0:
131
+ print("I need an input file")
132
+ sys.exit()
133
+
134
+
135
+
136
+ # do_locking_points(args)
137
+
138
+ fout = open(Path(args.out).expanduser().resolve(), 'w')
139
+ get_data_chunck(args.smartscope_files, args.label, fout)
140
+ fout.close()
141
+
142
+
143
+ #read_smartscope(args.smartscope_files[0], args.out, args.label, args.keep)
144
+
145
+ plt.show()