-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDAFD_CMD.py
187 lines (163 loc) · 5.12 KB
/
DAFD_CMD.py
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/python3
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import os
from DAFD.bin.DAFD_Interface import DAFD_Interface
from DAFD.tolerance_study.TolHelper import TolHelper
from DAFD.metrics_study.MetricHelper import MetricHelper
import pandas as pd
di = DAFD_Interface()
constraints = {}
desired_vals = {}
features = {}
stage = -1
tolerance_test = False
sort_by = None
flow_stability = False
versatility = False
with open(os.path.dirname(os.path.abspath(__file__)) + "/" + "DAFD/cmd_inputs.txt","r") as f:
for line in f:
line = line.strip()
if line == "CONSTRAINTS":
stage=0
continue
elif line == "DESIRED_VALS":
stage=1
continue
elif line == "FORWARD":
stage=2
continue
elif line == "TOLERANCE":
tolerance_test=True
try:
tolerance = float(line.split("=")[1])
except:
tolerance = 10
continue
elif line == "FLOW_STABILITY":
flow_stability=True
continue
elif line == "VERSATILITY":
versatility=True
continue
elif line == "SORT_BY":
sort_by = line.split("=")[1]
continue
if stage == 0:
param_name = line.split("=")[0]
param_pair = line.split("=")[1].split(":")
if param_name=="regime":
wanted_constraint=float(param_pair[0])
constraints[param_name] = wanted_constraint
else:
wanted_constraint = (float(param_pair[0]), float(param_pair[1]))
constraints[param_name] = wanted_constraint
if stage == 1:
param_name = line.split("=")[0]
param_val = float(line.split("=")[1])
desired_vals[param_name] = param_val
if stage == 2:
param_name = line.split("=")[0]
param_val = float(line.split("=")[1])
features[param_name] = param_val
if flow_stability or versatility:
if sort_by is None:
if flow_stability:
sort_by = "flow_stability"
else:
sort_by = "overall_versatility"
reg_str = ""
if "versatility" in sort_by:
try:
if constraints["regime"] == 1:
reg_str = "dripping"
else:
reg_str = "jetting"
except:
reg_str = "all"
sort_by = reg_str + "_" + sort_by.split("_")[0] + "_" + "score"
if stage == 2:
fwd_results = di.runForward(features)
result_str = "BEGIN:"
for x in di.MH.get_instance().output_headers:
result_str += str(fwd_results[x]) + "|"
result_str += str(fwd_results["regime"]) + "|"
result_str += str(fwd_results["oil_rate"]) + "|"
result_str += str(fwd_results["water_rate"]) + "|"
result_str += str(fwd_results["inferred_droplet_size"]) + "|"
print(result_str)
if flow_stability or versatility:
results = features.copy()
results.update(fwd_results)
if fwd_results["regime"] == 1:
reg_str = "Dripping"
else:
reg_str = "Jetting"
MetHelper = MetricHelper(results, di=di)
MetHelper.run_all_flow_stability()
MetHelper.run_all_versatility()
results.update(MetHelper.versatility_results)
results.update({"flow_stability":MetHelper.point_flow_stability})
report_info = {
"regime": reg_str,
"results_df": pd.DataFrame([results]),
"sort_by": sort_by
}
report_info["feature_denormalized"] = MetHelper.features_denormalized
MetHelper.generate_report(report_info)
else:
if flow_stability or versatility:
results = di.runInterpQM(desired_vals, constraints.copy())
for i, result in enumerate(results):
MetHelper = MetricHelper(result, di=di)
MetHelper.run_all_flow_stability()
results[i]["flow_stability"] = MetHelper.point_flow_stability
MetHelper.run_all_versatility()
results[i].update(MetHelper.versatility_results)
results[i].update(di.runForward(result))
results_df = pd.DataFrame(results)
results_df.sort_values(by=sort_by, ascending=False, inplace=True)
report_info = {
"regime": reg_str,
"results_df": results_df,
"sort_by": sort_by
}
MetHelper = MetricHelper(results_df.to_dict(orient="records")[0], di=di)
MetHelper.run_all_flow_stability()
MetHelper.run_all_versatility()
report_info["feature_denormalized"] = MetHelper.features_denormalized
rev_results = results_df.to_dict(orient="records")[0]
fwd_results = di.runForward(rev_results)
import datetime
date = datetime.datetime.today().isoformat()[:16]
size = int(fwd_results["droplet_size"])
rate = int(rev_results["generation_rate"])
filepath = f"{date}_{size}um_{rate}Hz.csv"
filepath = filepath.replace(":", "_")
results_df.to_csv(filepath)
results_df.to_csv(filepath)
MetHelper.generate_report(report_info)
else:
rev_results = di.runInterp(desired_vals, constraints)
fwd_results = di.runForward(rev_results)
result_str = "BEGIN:"
for x in di.MH.get_instance().input_headers:
result_str += str(rev_results[x]) + "|"
result_str += str(rev_results["point_source"]) + "|"
for x in di.MH.get_instance().output_headers:
result_str += str(fwd_results[x]) + "|"
result_str += str(fwd_results["regime"]) + "|"
result_str += str(fwd_results["oil_rate"]) + "|"
result_str += str(fwd_results["water_rate"]) + "|"
result_str += str(fwd_results["inferred_droplet_size"]) + "|"
print(result_str)
if tolerance_test:
if stage == 1:
tol_features = rev_results.copy()
del tol_features["point_source"]
else:
tol_features = features
TH = TolHelper(tol_features, di=di, tolerance=tolerance)
TH.run_all()
TH.plot_all()
TH.generate_report()