-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhops4_fparam_example.py.in
More file actions
86 lines (72 loc) · 2.89 KB
/
Copy pathhops4_fparam_example.py.in
File metadata and controls
86 lines (72 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!@PY_EXE@
#
# demo for HOPS4 fringe data retrieval using python interface
# which shows how to access each of the fringe files in a directory, pull out the
# fringe result data and format the results as a table with pandas
#
import pyMHO_Containers
import pandas as pd
import os
import sys
import argparse
def extract_data(file_data):
trimmed_fparam = dict()
if file_data != None:
n_obj = file_data.get_nobjects()
obj_info = file_data.get_object_id_list()
uuid = ""
for object_record in obj_info:
if "shortname" in object_record:
sname = object_record["shortname"]
#plot data is stored in 'tags' object
if sname == "tags":
uuid = object_record["object_uuid"]
if uuid != "":
tags_data = file_data.get_object(object_record["object_uuid"] )
if "parameters" in tags_data:
param = tags_data["parameters"]
fparam = param["fringe"]
for k,v in fparam.items():
#we only want to extract scalar values
#for our table, so exclude lists
if not isinstance(v, list):
trimmed_fparam[k] = v
return trimmed_fparam
def get_fringe_file_info(scan_store, name):
scan_store.load_fringe(name)
file_data = scan_store.get_fringe_data(name)
return extract_data(file_data)
def main():
parser = argparse.ArgumentParser(
prog='hops4_fparam_example.py', \
description='''Example utility demo on how to extract fringe parameters from a list of fringe files and construct a table''' \
)
parser.add_argument("filenames", nargs="+", default="", help='the list of fringe files to be processed')
parser.add_argument('-o', '--output-filename', dest='output_filename', help='specify the table output filename', default='./out.csv')
args = parser.parse_args()
ffiles = args.filenames
output = args.output_filename
fparams = list()
for ffile in ffiles:
#figure out the corresponding scan directory
scan_dir, basename = os.path.split( os.path.abspath(ffile) );
scan_store = pyMHO_Containers.MHO_PyScanStoreInterface()
scan_store.set_directory(scan_dir)
scan_store.initialize()
if scan_store.is_valid():
fringes = scan_store.get_fringe_list()
for fr in fringes:
if fr == basename:
ex_params = get_fringe_file_info(scan_store, basename)
ex_params["file"] = basename
fparams.append(ex_params)
df = pd.DataFrame(fparams)
print(df)
#save output file as csv
df.to_csv(output, index=False)
if __name__ == '__main__':
main()
sys.exit(0)
#
# eof
#