-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
321 lines (271 loc) · 9.34 KB
/
Copy pathdata.py
File metadata and controls
321 lines (271 loc) · 9.34 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/usr/bin/env python3
"""
Summary plots
"""
import sys
import math
import pandas as pd
import matplotlib.pyplot as plt
STEADY_STATE_FRACTION = 0.30
PUBLICATION_MODE = True
def apply_publication_style():
if not PUBLICATION_MODE:
return
plt.rcParams.update({
"font.size": 14,
"axes.titlesize": 15,
"axes.labelsize": 14,
"xtick.labelsize": 12,
"ytick.labelsize": 12,
"legend.fontsize": 12,
"figure.titlesize": 15,
"lines.linewidth": 1.8,
})
def ivantsov_2d(P):
try:
import mpmath as mp
except Exception:
return None
if P <= 0.0:
return 0.0
s = mp.sqrt(P)
return float(mp.sqrt(mp.pi * P) * mp.e**P * mp.erfc(s))
def clean_series(s):
s = pd.to_numeric(s, errors="coerce")
s = s.replace([math.inf, -math.inf], math.nan)
return s
def trim_startup(df, vel_col=None):
out = df.copy()
if vel_col is not None and vel_col in out.columns:
v = clean_series(out[vel_col])
vmax = v.max(skipna=True)
if pd.notna(vmax) and vmax > 0.0:
keep = v >= 0.02 * vmax
if keep.any():
first = keep.idxmax()
return out.loc[first:].reset_index(drop=True)
return out
def col_lookup(df, name):
lname = name.lower()
for c in df.columns:
if c.lower() == lname:
return c
return None
def col_any(df, *names):
for n in names:
c = col_lookup(df, n)
if c is not None:
return c
return None
def print_series_summary(label, s):
vals = clean_series(s)
vals = vals[vals.notna()]
if len(vals) == 0:
return
mean = vals.mean()
std = vals.std()
print(f"{label:<20s}: {mean:.5f} ± {std:.5f}")
def new_figure():
plt.figure(figsize=(7.2, 5.2))
def plot_ca_series(ax, x, y, label="CA", color="tab:blue", marker="o"):
"""Helper to consistently plot CA data with visible points only."""
m = x.notna() & y.notna()
if not m.any():
return
ax.plot(
x[m], y[m],
marker=marker,
linestyle="None",
markersize=5.5,
markeredgecolor="k",
markeredgewidth=0.6,
label=label,
color=color
)
def main():
if len(sys.argv) < 2:
print("Usage: python data3.py data.csv")
return 2
apply_publication_style()
path = sys.argv[1]
df = pd.read_csv(path)
df.columns = [c.strip() for c in df.columns]
c_time = col_lookup(df, "time(s)")
c_vel = col_lookup(df, "vel(um/s)")
c_ucool = col_lookup(df, "undercoolavg(degC)")
c_rad = col_lookup(df, "radiusKGT(um)")
c_sol = col_any(df, "solcap", "DFRZ")
c_p = col_lookup(df, "peclet")
c_om = (col_lookup(df, "Omega") or col_lookup(df, "OmegaCA"))
c_omkgt = (col_lookup(df, "OmegaKGT") or
col_lookup(df, "OmegaKGT(2D)") or
col_lookup(df, "OmegaKGT(3D)"))
c_dtkgt = col_lookup(df, "DTKGT(degC)")
c_cl = col_lookup(df, "Clstar(wt%)")
c_theta = col_lookup(df, "thetaBOX(deg)")
sol_label = "SOLCAP" if col_lookup(df, "solcap") else "DFRZ"
required = [c_time, c_vel, c_ucool, c_rad, c_sol, c_p, c_om]
if any(c is None for c in required):
print("Missing one or more required lean CSV columns.")
return 1
df = df.sort_values(c_time).reset_index(drop=True)
df_trim = trim_startup(df, c_vel)
# 1. Omega vs Peclet (with clear CA points)
x = clean_series(df_trim[c_p])
y = clean_series(df_trim[c_om])
if x.notna().any() and y.notna().any():
new_figure()
ax = plt.gca()
plot_ca_series(ax, x, y, label="CA data", color="tab:blue")
# Ivantsov reference
try:
pmin = float(max(1.0e-6, x[x > 0].min()))
pmax = float(max(pmin * 1.001, x.max()))
lpmin = math.log(pmin)
lpmax = math.log(pmax)
curve_p = []
curve_o = []
for i in range(200):
a = i / 199.0
pp = math.exp(lpmin + a * (lpmax - lpmin))
vv = ivantsov_2d(pp)
if vv is not None:
curve_p.append(pp)
curve_o.append(vv)
if curve_p:
plt.plot(curve_p, curve_o, label="2-D Ivantsov", color="tab:orange", linewidth=2.2)
except Exception:
pass
plt.xlabel("Peclet number, P = V R / (2 D)")
plt.ylabel("Supersaturation, Omega")
plt.title("Omega vs Peclet")
plt.legend()
plt.grid(True)
plt.tight_layout()
# 2. Supersaturation vs time
x = clean_series(df_trim[c_time])
y = clean_series(df_trim[c_om])
if x.notna().any() and y.notna().any():
new_figure()
ax = plt.gca()
plot_ca_series(ax, x, y, label="CA", color="tab:blue")
if c_omkgt is not None:
y2 = clean_series(df_trim[c_omkgt])
m2 = x.notna() & y2.notna()
if m2.any():
plt.plot(x[m2], y2[m2], label="KGT", color="tab:orange", linewidth=2.0)
plt.xlabel("Time (s)")
plt.ylabel("Supersaturation, Omega")
plt.title("Supersaturation vs time")
plt.legend()
plt.grid(True)
plt.tight_layout()
# 3. Velocity vs time
x = clean_series(df_trim[c_time])
y = clean_series(df_trim[c_vel])
if x.notna().any() and y.notna().any():
new_figure()
ax = plt.gca()
plot_ca_series(ax, x, y, label="CA velocity", color="tab:blue")
plt.xlabel("Time (s)")
plt.ylabel("Velocity (um/s)")
plt.title("Tip velocity vs time")
plt.grid(True)
plt.tight_layout()
# 4. Undercooling vs time
x = clean_series(df_trim[c_time])
y = clean_series(df_trim[c_ucool])
if x.notna().any() and y.notna().any():
new_figure()
ax = plt.gca()
plot_ca_series(ax, x, y, label="CA", color="tab:blue")
if c_dtkgt is not None:
y2 = clean_series(df_trim[c_dtkgt])
m2 = x.notna() & y2.notna()
if m2.any():
plt.plot(x[m2], y2[m2], label="KGT", color="tab:orange", linewidth=2.0)
plt.xlabel("Time (s)")
plt.ylabel("Undercooling (degC)")
plt.title("Tip undercooling vs time")
plt.legend()
plt.grid(True)
plt.tight_layout()
# 5. KGT radius vs time
x = clean_series(df_trim[c_time])
y = clean_series(df_trim[c_rad])
if x.notna().any() and y.notna().any():
new_figure()
ax = plt.gca()
plot_ca_series(ax, x, y, label="CA", color="tab:blue")
plt.xlabel("Time (s)")
plt.ylabel("KGT tip radius (um)")
plt.title("KGT tip radius vs time")
plt.grid(True)
plt.tight_layout()
# 6. SOLCAP vs time
x = clean_series(df_trim[c_time])
y = clean_series(df_trim[c_sol])
if x.notna().any() and y.notna().any():
new_figure()
ax = plt.gca()
plot_ca_series(ax, x, y, label="CA", color="tab:blue")
plt.xlabel("Time (s)")
plt.ylabel(sol_label)
plt.title(f"{sol_label} vs time")
plt.grid(True)
plt.tight_layout()
# Optional: Interface composition
if c_cl is not None:
x = clean_series(df_trim[c_time])
y = clean_series(df_trim[c_cl])
if x.notna().any() and y.notna().any():
new_figure()
ax = plt.gca()
plot_ca_series(ax, x, y, label="CA", color="tab:blue")
plt.xlabel("Time (s)")
plt.ylabel("Clstar (wt%)")
plt.title("Interface liquid composition vs time")
plt.grid(True)
plt.tight_layout()
# Optional: BOX orientation
if c_theta is not None:
x = clean_series(df_trim[c_time])
y = clean_series(df_trim[c_theta])
if x.notna().any() and y.notna().any():
new_figure()
ax = plt.gca()
plot_ca_series(ax, x, y, label="CA", color="tab:blue")
plt.xlabel("Time (s)")
plt.ylabel("thetaBOX (deg)")
plt.title("BOX orientation vs time")
plt.grid(True)
plt.tight_layout()
# Steady-state summary
n = len(df_trim)
if n > 10:
i0 = int((1.0 - STEADY_STATE_FRACTION) * n)
df_ss = df_trim.iloc[i0:].copy()
print()
print("===============================================")
print("LEAN CSV STEADY-STATE SUMMARY")
print("===============================================")
print(f"Points used : {len(df_ss)}")
print_series_summary("Velocity (um/s)", df_ss[c_vel])
print_series_summary("Undercooling (degC)", df_ss[c_ucool])
print_series_summary("RadiusKGT (um)", df_ss[c_rad])
print_series_summary("SOLCAP", df_ss[c_sol])
print_series_summary("Peclet", df_ss[c_p])
print_series_summary("Omega", df_ss[c_om])
if c_omkgt is not None:
print_series_summary("OmegaKGT", df_ss[c_omkgt])
if c_dtkgt is not None:
print_series_summary("DTKGT (degC)", df_ss[c_dtkgt])
if c_cl is not None:
print_series_summary("Clstar (wt%)", df_ss[c_cl])
if c_theta is not None:
print_series_summary("thetaBOX (deg)", df_ss[c_theta])
print("===============================================")
plt.show()
return 0
if __name__ == "__main__":
raise SystemExit(main())