Skip to content

Commit 68e15dd

Browse files
Split energy plot to time and frequency (#42)
* split energy plot to time and frequency * plot histogram as lines for energy * fix formatting * split energy evolution and histogram * update axis limits in plot histogram --------- Co-authored-by: SCiarella <[email protected]>
1 parent eaeff3a commit 68e15dd

File tree

3 files changed

+138
-3
lines changed

3 files changed

+138
-3
lines changed

benchmark.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ end
1111
basedir = haskey(ENV, "DEEPDIP") ? ENV["DEEPDIP"] : @__DIR__
1212
outdir = joinpath(basedir, "output", "kolmogorov")
1313
confdir = joinpath(basedir, "configs/local")
14-
confdir = joinpath(basedir, "configs/snellius")
14+
#confdir = joinpath(basedir, "configs/snellius")
1515
@warn "Using configuration files from $confdir"
1616
compdir = joinpath(outdir, "comparison")
1717
ispath(compdir) || mkpath(compdir)
@@ -113,10 +113,15 @@ plot_labels = Dict(
113113
ylabel = "Face-average",
114114
),
115115
:energy_evolution => (
116-
title = "Energy evolution for different configurations",
116+
title = "Energy evolution for different configurations",
117117
xlabel = "t",
118118
ylabel = "E(t)",
119119
),
120+
:energy_evolution_hist => (
121+
title = "Energy histogram for different configurations",
122+
xlabel = "frequency",
123+
ylabel = "E(t)",
124+
),
120125
:energy_spectra => (
121126
title = "Energy spectra",
122127
),
@@ -228,6 +233,11 @@ for key in keys(plot_labels)
228233
outdir, closure_name, nles, Φ, data_index, ax, color, PLOT_STYLES
229234
)
230235

236+
elseif key == :energy_evolution_hist
237+
plot_energy_evolution_hist(
238+
outdir, closure_name, nles, Φ, data_index, ax, color, PLOT_STYLES
239+
)
240+
231241
elseif key== :energy_spectra
232242
num_of_models = length(list_confs)
233243
plot_energy_spectra(

src/Benchmark.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export _convert_to_single_index,
103103
plot_posteriori_traininghistory,
104104
plot_divergence,
105105
plot_energy_evolution,
106+
plot_energy_evolution_hist,
106107
plot_energy_spectra,
107108
plot_training_time,
108109
plot_inference_time,

src/plots.jl

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,25 @@ function plot_divergence(outdir, closure_name, nles, Φ, data_index, ax, color,
191191
ax.yscale = log10
192192
end
193193

194+
function _plot_histogram(ax, data, label, color, linestyle, linewidth)
195+
hist_data = hist!(ax, [p[2] for p in data]; bins = 10, color = (:transparent, 0.0))
196+
centers = hist_data.plots[1][1][]
197+
x_values = [p[2] for p in centers] # x-values are frequencies
198+
y_values = [p[1] for p in centers] # y-values are bin centers
199+
lines!(
200+
ax,
201+
x_values,
202+
y_values,
203+
label = label,
204+
linestyle = linestyle,
205+
linewidth = linewidth,
206+
color = color,
207+
)
208+
209+
# update axis limits
210+
ax = _update_ax_limits(ax, x_values, y_values)
211+
end
212+
194213
function plot_energy_evolution(
195214
outdir,
196215
closure_name,
@@ -209,7 +228,6 @@ function plot_energy_evolution(
209228
end
210229
energyhistory = namedtupleload(energy_dir).energyhistory;
211230

212-
# add No closure only once
213231
if closure_name == "INS_ref"
214232
label = "No closure "
215233
if _missing_label(ax, label) && haskey(energyhistory, Symbol("nomodel"))
@@ -273,6 +291,7 @@ function plot_energy_evolution(
273291
end
274292

275293
label = Φ isa FaceAverage ? "FA" : "VA"
294+
# prior
276295
lines!(
277296
ax,
278297
energyhistory.model_prior[data_index];
@@ -281,6 +300,7 @@ function plot_energy_evolution(
281300
linewidth = PLOT_STYLES[:prior].linewidth,
282301
color = color, # dont change this color
283302
)
303+
# post
284304
lines!(
285305
ax,
286306
energyhistory.model_post[data_index];
@@ -294,6 +314,110 @@ function plot_energy_evolution(
294314
x_values = [point[1] for v in values(energyhistory) for point in v[data_index]]
295315
y_values = [point[2] for v in values(energyhistory) for point in v[data_index]]
296316
ax = _update_ax_limits(ax, x_values, y_values)
317+
318+
end
319+
320+
function plot_energy_evolution_hist(
321+
outdir,
322+
closure_name,
323+
nles,
324+
Φ,
325+
data_index,
326+
ax,
327+
color,
328+
PLOT_STYLES,
329+
)
330+
# Load learned parameters
331+
energy_dir = joinpath(outdir, closure_name, "history.jld2")
332+
if !ispath(energy_dir)
333+
@warn "Energy history not found in $energy_dir"
334+
return
335+
end
336+
energyhistory = namedtupleload(energy_dir).energyhistory;
337+
338+
if closure_name == "INS_ref"
339+
label = "No closure "
340+
if _missing_label(ax, label) && haskey(energyhistory, Symbol("nomodel"))
341+
_plot_histogram(
342+
ax,
343+
energyhistory.nomodel[data_index],
344+
label,
345+
PLOT_STYLES[:no_closure].color,
346+
PLOT_STYLES[:no_closure].linestyle,
347+
PLOT_STYLES[:no_closure].linewidth,
348+
)
349+
end
350+
# add reference only once
351+
label = "Reference"
352+
if _missing_label(ax, label) && haskey(energyhistory, Symbol("ref"))
353+
_plot_histogram(
354+
ax,
355+
energyhistory.ref[data_index],
356+
label,
357+
PLOT_STYLES[:reference].color,
358+
PLOT_STYLES[:reference].linestyle,
359+
PLOT_STYLES[:reference].linewidth,
360+
)
361+
end
362+
end
363+
364+
if closure_name == "cnn_1"
365+
label = "No closure (projected dyn)"
366+
if _missing_label(ax, label) && haskey(energyhistory, Symbol("nomodel"))
367+
_plot_histogram(
368+
ax,
369+
energyhistory.nomodel[data_index],
370+
label,
371+
PLOT_STYLES[:no_closure_proj].color,
372+
PLOT_STYLES[:no_closure_proj].linestyle,
373+
PLOT_STYLES[:no_closure_proj].linewidth,
374+
)
375+
end
376+
label = "Reference (projected dyn)"
377+
if _missing_label(ax, label) && haskey(energyhistory, Symbol("ref"))
378+
_plot_histogram(
379+
ax,
380+
energyhistory.ref[data_index],
381+
label,
382+
PLOT_STYLES[:reference_proj].color,
383+
PLOT_STYLES[:reference_proj].linestyle,
384+
PLOT_STYLES[:reference_proj].linewidth,
385+
)
386+
end
387+
end
388+
389+
if haskey(energyhistory, Symbol("smag"))
390+
_plot_histogram(
391+
ax,
392+
energyhistory.smag[data_index],
393+
"$closure_name (smag) (n = $nles)",
394+
PLOT_STYLES[:smag].color,
395+
PLOT_STYLES[:smag].linestyle,
396+
PLOT_STYLES[:smag].linewidth,
397+
)
398+
end
399+
400+
label = Φ isa FaceAverage ? "FA" : "VA"
401+
# prior
402+
_plot_histogram(
403+
ax,
404+
energyhistory.model_prior[data_index],
405+
"$closure_name (prior) (n = $nles, $label)",
406+
color,
407+
PLOT_STYLES[:prior].linestyle,
408+
PLOT_STYLES[:prior].linewidth,
409+
)
410+
411+
# post
412+
_plot_histogram(
413+
ax,
414+
energyhistory.model_post[data_index],
415+
"$closure_name (post) (n = $nles, $label)",
416+
color,
417+
PLOT_STYLES[:post].linestyle,
418+
PLOT_STYLES[:post].linewidth,
419+
)
420+
297421
end
298422

299423
function _get_spectra(setup, u)

0 commit comments

Comments
 (0)