Mercurial > repos > mzhuang > chess_preprocessor
comparison preprocess_dexela_h5_filesystem.py @ 0:4d2a2268a17a draft
"planemo upload"
author | mzhuang |
---|---|
date | Thu, 23 Sep 2021 21:00:48 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4d2a2268a17a |
---|---|
1 import argparse | |
2 import glob | |
3 import os | |
4 | |
5 import numpy as np | |
6 import time | |
7 from datetime import datetime | |
8 | |
9 from hexrd.imageseries import omega | |
10 import pp_dexela | |
11 #from IPython import embed | |
12 | |
13 # ============================================================================= | |
14 # USER INPUT | |
15 # ============================================================================= | |
16 | |
17 # panel keys to MATCH INSTRUMENT FILE | |
18 panel_keys = ['FF1', 'FF2'] | |
19 panel_opts = dict.fromkeys(panel_keys) | |
20 | |
21 # !!!: hard coded options for each dexela for April 2017 | |
22 panel_opts['FF1'] = [('add-row', 1944), ('add-column', 1296),('flip', 'v'), ] | |
23 panel_opts['FF2'] = [('add-row', 1944), ('add-column', 1296),('flip', 'h'), ] | |
24 | |
25 # ==================== End Inputs (should not need to alter below this line) | |
26 | |
27 | |
28 | |
29 def process_dexelas(file_names, samp_name, scan_number, | |
30 ostart, ostep, num_frames, | |
31 panel_opts, threshold): | |
32 """ | |
33 wrapper for F2 dexela setup | |
34 """ | |
35 ostop = ostart + num_frames*ostep | |
36 omw = omega.OmegaWedges(num_frames) | |
37 omw.addwedge(ostart, ostop, num_frames) | |
38 | |
39 for file_name in file_names: | |
40 for key in panel_keys: | |
41 if key.lower() in file_name: | |
42 ppd = pp_dexela.PP_Dexela( | |
43 file_name, | |
44 omw, | |
45 panel_opts[key], | |
46 panel_id=key, | |
47 frame_start=fstart) | |
48 # embed() | |
49 # ppd=add_missing_pixel_gap(ppd) | |
50 | |
51 output_name = samp_name + '_' + \ | |
52 str(scan_number) + '_' + \ | |
53 file_name.split('/')[-1].split('.')[0] | |
54 ppd.save_processed(output_name, threshold) | |
55 head_tail = os.path.split(file_name) | |
56 if head_tail[0] is not None: | |
57 os.system('cp -p ' + './' + output_name + '* ' + head_tail[0] + ' 2>/dev/null') | |
58 | |
59 if __name__ == '__main__': | |
60 # | |
61 # Run preprocessor | |
62 # | |
63 print("Running preprocessor....") | |
64 parser = argparse.ArgumentParser( | |
65 description="pre-process double Dexela images from F2") | |
66 | |
67 parser.add_argument('base_dir', | |
68 help="raw data path on chess daq", type=str) | |
69 parser.add_argument('expt_name', | |
70 help="experiment name", type=str) | |
71 parser.add_argument('samp_name', | |
72 help="sample name", type=str) | |
73 parser.add_argument('scan_number', | |
74 help="ff scan number", type=int) | |
75 | |
76 parser.add_argument('-n', '--num-frames', | |
77 help="number of frames to read", | |
78 type=int, default=1441) | |
79 parser.add_argument('-s', '--start-frame', | |
80 help="index of first data frame", | |
81 type=int, default=4) | |
82 parser.add_argument('-t', '--threshold', | |
83 help="threshold for frame caches", | |
84 type=int, default=50) | |
85 parser.add_argument('-o', '--ome-start', | |
86 help="start omega", | |
87 type=float, default=0.) | |
88 # parser.add_argument('-d', '--ome-delta', | |
89 # help="delta omega", | |
90 # type=float, default=0.2498265093684941) | |
91 | |
92 parser.add_argument('-e', '--ome-end', | |
93 help="end omega", | |
94 type=float, default=360.) | |
95 | |
96 | |
97 args = parser.parse_args() | |
98 | |
99 # strip args | |
100 data_dir = args.base_dir | |
101 expt_name = args.expt_name | |
102 samp_name = args.samp_name | |
103 scan_number = args.scan_number | |
104 num_frames = args.num_frames | |
105 fstart = args.start_frame | |
106 threshold = args.threshold | |
107 ostart = args.ome_start | |
108 oend = args.ome_end | |
109 ostep = (oend-ostart)/float(num_frames) | |
110 | |
111 print("== Running preprocessor .... processing ") | |
112 now = datetime.now() | |
113 print(now.strftime("%m/%d/%Y %H:%M:%S")) | |
114 | |
115 file_names = glob.glob( | |
116 os.path.join( | |
117 data_dir, | |
118 expt_name, | |
119 samp_name, | |
120 str(scan_number), | |
121 'ff', | |
122 '*.h5') | |
123 ) | |
124 path = os.path.join(data_dir, expt_name, samp_name, str(scan_number), 'ff', '*.h5') | |
125 print("path = " + path) | |
126 for f in file_names: | |
127 print(f) | |
128 | |
129 check_files_exist = [os.path.exists(file_name) for file_name in file_names] | |
130 if not np.all(check_files_exist): | |
131 raise RuntimeError("files don't exist!") | |
132 | |
133 process_dexelas(file_names, samp_name, scan_number, | |
134 ostart, ostep, num_frames, | |
135 panel_opts, threshold) | |
136 now = datetime.now() | |
137 print(now.strftime("%m/%d/%Y %H:%M:%S")) | |
138 print("== End of processing " + " ==") | |
139 print(" ") | |
140 |