-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtfObjToPlt.py
More file actions
executable file
·182 lines (140 loc) · 6.37 KB
/
tfObjToPlt.py
File metadata and controls
executable file
·182 lines (140 loc) · 6.37 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
from tensorboard.backend.event_processing import event_accumulator
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator
from statistics import mean
import csv
from os import listdir
import numpy as np
import matplotlib.pyplot as plt
from shortNames import shortNameDict
from cycler import cycler
wTot = 18 # cm
wTot = wTot*2
nSubFig = 2
w = wTot/(nSubFig*2.54)
h = w*0.75
plt.rcParams['figure.figsize'] = [w, h]
plt.rcParams['lines.linewidth'] = 1.5
plt.rcParams['font.size'] = 10
plt.rcParams['legend.fontsize'] = 12
# plt.rcParams['figure.titlesize'] = 12
linestyle_cycler = (cycler(linestyle=[(0, (5,0)), (0, (1,2)),(0, (4,2)),(0, (4,2,1,2)),(0, (4,2,1,2,1,2)),(0, (1,4)),(0, (8,3)),(0, (8,3,1,3)),(0, (8,3,1,3,1,3)),(0, (15,5))]) + cycler('color', ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']))
plt.rc('axes', prop_cycle=linestyle_cycler)
resultsFilePath="./resultsL2.csv"
outputsPath="./outputs/fwdFacingStep/"
validatorSkip = ["DP5","DP36","DP79","DP86"] # skip data points
# validatorSkip = [] # skip data points
dirSkip = [".hydra", "init", "vtp", "initFC"]
models = listdir(outputsPath)
models.sort()
# models = ["physicsOnly@500k", "dataOnly1800@500k", "data1800PlusPhysicsLambda01@500k", "data1800PlusPhysicsLambda1@500k", "pressureDataPlusPhysicsLambda01@500k", "pressureDataPlusPhysicsLambda1@500k","data1800PlusPhysicsLambda01@100k2pO@500k", "data1800PlusPhysicsLambda1@100k2pO@500k"]
models = ["physicsOnlyFC@500k", "dataOnly1800FC@500k", "data1800PlusPhysicsLambda01FC@500k", "data1800PlusPhysicsLambda1FC@500k", "pressureDataPlusPhysicsLambda01FC@500k", "pressureDataPlusPhysicsLambda1FC@500k"]
with open(resultsFilePath, "w") as resultsFile:
writer = csv.writer(resultsFile, delimiter=",")
firstRow = ["model", "u mean", "u min", "u max", "v mean", "v min", "v max", "p mean", "p min", "p max"]
writer.writerow(firstRow)
plt.figure(1)
plt.title("Validation Error $p_2$")
plt.figure(2)
plt.title("Validation Error $p_1$")
plt.figure(3)
# plt.title("Validation Error $\Delta C_p$")
# plt.title("FNN")
plt.title("FCNN")
for model in models:
# if model in dirSkip or "100k" in model.split("@")[-1] or "300k" in model.split("@")[-1] or '300k' in model.split("@")[-2]:
if model in dirSkip or "100k" in model.split("@")[-1] or "300k" in model.split("@")[-1]:
# if model in dirSkip:
# print("skipping ", model)
continue
print("reading ", model)
log_dir = outputsPath + model
DSP = {}
trueDSPd = {}
USP = {}
trueUSPd = {}
DCp = {}
trueDCp = {}
ea = EventAccumulator(log_dir, size_guidance={event_accumulator.TENSORS: 0})
ea.Reload()
tags = ea.Tags()
n = 0
for tag in tags['tensors']:
if 'Monitors' in tag and not any(element in tag for element in validatorSkip) and not "_design_" in tag:
values = []
steps = []
events = ea.Tensors(tag)
pStep = -1
for event in events:
step = event.step
if step not in steps:
value = event.tensor_proto.float_val[0]
values.append(value)
steps.append(step)
if 'downstreamPressure' in tag:
DP = tag.split("DP")[1].split("_")[0]
trueDSPd[DP] = tag.split("=")[-1]
DSP[DP] = values
l = len(values)
n +=1
if 'upstreamPressure' in tag:
DP = tag.split("DP")[1].split("_")[0]
trueUSPd[DP] = tag.split("=")[-1]
USP[DP] = values
meanUSP = np.zeros(l)
meanDSP = np.zeros(l)
meanDCp = np.zeros(l)
for key in USP.keys():
# print(key + ": ",trueUSPd[key])
npUSP = np.array(USP[key])
# print('npUSP' + ": ",npUSP)
trueUSP = float(trueUSPd[key])
npUSPError = np.abs(npUSP - trueUSP)
npDSP = np.array(DSP[key])
trueDSP = float(trueDSPd[key])
npDSPError = np.abs(npDSP - trueDSP)
DCp = 2*(npUSP-npDSP)
trueDCp = 2*(trueUSP-trueDSP)
# print(key + ": ", trueDCp)
npDCpError = np.abs(DCp-trueDCp)
meanUSP += npUSPError
meanDSP += npDSPError
meanDCp += npDCpError
meanUSP /= n
meanDSP /= n
meanDCp /= n
modelStrSplit = model.split("@")
if len(modelStrSplit) == 3:
label = shortNameDict[modelStrSplit[0]] + ", $S_d=$" + modelStrSplit[1].split("k")[0] + "k" #+ shortNameDict[modelStrSplit[1].split("k")[-1]] #+ "@" + modelStrSplit[-1]
elif len(modelStrSplit) == 2:
label = shortNameDict[modelStrSplit[0]] #+ "@" + modelStrSplit[-1]
label = label.replace('Fully Connected, ', '').replace('Fourier, ', '')
steps = np.array(steps)/1000
plt.figure(1)
plt.plot(steps, meanUSP, label=label)
plt.figure(2)
plt.plot(steps, meanDSP, label=label)
plt.figure(3)
plt.plot(steps, meanDCp, label=label)
for i in range(1,4):
plt.figure(i)
# plt.legend()
plt.yscale("log")
plt.xlabel("Step ($x10^3$)")
# plt.xlabel("Step")
plt.ylabel("MAE $\Delta C_p$")
plt.ylim(0.015, 10)
# pre = 'TEST_'
# pre = 'F_'
pre = 'FC_'
# plt.figure(1)
# plt.savefig(pre + "MaeDSP" + ".png", dpi = 600, bbox_inches='tight')
# plt.figure(2)
# plt.savefig(pre + "MaeUSP" + ".png", dpi = 600, bbox_inches='tight')
# plt.figure(3)
# plt.savefig(pre + "MaeDCp" + ".png", dpi = 600, bbox_inches='tight')
# plt.figure(1)
# plt.savefig(pre + "MaeDSP" + ".eps", format='eps', dpi = 600, bbox_inches='tight')
# plt.figure(2)
# plt.savefig(pre + "MaeUSP" + ".eps", format='eps', dpi = 600, bbox_inches='tight')
plt.figure(3)
plt.savefig(pre + "MaeDCp" + ".eps", format='eps', dpi = 600, bbox_inches='tight')