Skip to content

Commit

Permalink
Group plots
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Aug 13, 2021
1 parent dc97b04 commit cf44759
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 15 deletions.
77 changes: 63 additions & 14 deletions integration_tests/utils/compute_mse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,16 @@ function compute_mse_wrapper(
end


function compute_mse(experiment, best_mse, plot_dir; ds_dict, plot_comparison = true, t_start, t_stop)
function compute_mse(
experiment,
best_mse,
plot_dir;
ds_dict,
plot_comparison = true,
group_figs = true,
t_start,
t_stop,
)

ds_scampy = haskey(ds_dict, :ds_scampy) ? ds_dict[:ds_scampy] : nothing
ds_tc_main = haskey(ds_dict, :ds_tc_main) ? ds_dict[:ds_tc_main] : nothing
Expand Down Expand Up @@ -187,6 +196,9 @@ function compute_mse(experiment, best_mse, plot_dir; ds_dict, plot_comparison =
data_scales_tcc = []
data_scales_tcm = []
pycles_weight = []
plots_dict = Dict()
plots_dict["profiles"] = Dict()
plots_dict["contours"] = Dict()
for tc_var in keys(best_mse)

# Only compare fields defined for var_map_les
Expand All @@ -206,7 +218,7 @@ function compute_mse(experiment, best_mse, plot_dir; ds_dict, plot_comparison =
data_tcm_arr = get_data(ds_tc_main, tc_var)'
data_tcc_arr = get_data(ds_tc, tc_var)'
data_scm_arr = get_data(ds_scampy, scm_var)'
@info " Data sizes (les,scm,tcc,tcm): $(size(data_les_arr)), $(size(data_scm_arr)), $(size(data_tcc_arr)), $(size(data_tcm_arr))"
# @info " Data sizes (les,scm,tcc,tcm): $(size(data_les_arr)), $(size(data_scm_arr)), $(size(data_tcc_arr)), $(size(data_tcm_arr))"
# Scale the data for comparison
push!(pycles_weight, "1")

Expand Down Expand Up @@ -268,9 +280,8 @@ function compute_mse(experiment, best_mse, plot_dir; ds_dict, plot_comparison =
label = "TC.jl (main)",
)
end
Plots.plot!(data_tcc_cont_mapped, z_tcc ./ 10^3, xlabel = tc_var, ylabel = "z [km]", label = "TC.jl")
@info " Saving $(joinpath(plot_dir, "$tc_var.png"))"
Plots.savefig(joinpath(plot_dir, "profile_$tc_var.png"))
plots_dict["profiles"][tc_var] =
Plots.plot!(data_tcc_cont_mapped, z_tcc ./ 10^3, xlabel = tc_var, ylabel = "z [km]", label = "TC.jl")

if tc_var == "updraft_thetal"
# TODO: remove this if-else when artifacts are updated
Expand All @@ -288,40 +299,36 @@ function compute_mse(experiment, best_mse, plot_dir; ds_dict, plot_comparison =
time_scm,
z_scm,
data_scm_arr';
xlabel = tc_var,
ylabel = "height (m)",
c = :viridis,
clims = clims,
title = "SCAMPy",
title = "$tc_var (SCAMPy)",
)
if have_tc_main
p2 = Plots.contourf(
time_tcc,
z_tcc,
data_tcm_arr';
xlabel = tc_var,
ylabel = "height (m)",
c = :viridis,
clims = clims,
title = "TC.jl (main)",
title = "$tc_var (TC.jl main)",
)
end
p3 = Plots.contourf(
time_tcc,
z_tcc,
data_tcc_arr';
xlabel = tc_var,
ylabel = "height (m)",
c = :viridis,
clims = clims,
title = have_tc_main ? "TC.jl (PR)" : "TC.jl",
title = have_tc_main ? "$tc_var (TC.jl PR)" : "$tc_var (TC.jl)",
)
if have_tc_main
Plots.plot(p1, p2, p3; layout = (3, 1), size = (400, 600))
plots_dict["contours"][tc_var] = Plots.plot(p1, p2, p3; layout = (3, 1), size = (300, 600))
else
Plots.plot(p1, p3; layout = (2, 1))
plots_dict["contours"][tc_var] = Plots.plot(p1, p3; layout = (2, 1), size = (300, 600))
end
Plots.savefig(joinpath(plot_dir, "contours_" * tc_var * ".png"))
end

# Compute mean squared error (mse)
Expand All @@ -334,6 +341,8 @@ function compute_mse(experiment, best_mse, plot_dir; ds_dict, plot_comparison =
push!(table_best_mse, best_mse[tc_var])
end

save_plots(plot_dir, plots_dict; group_figs = group_figs)

# Tabulate output
header = [
"Variable" "Variable" "Weight" "Data scale" "Data scale" "MSE" "MSE" "MSE"
Expand Down Expand Up @@ -368,6 +377,46 @@ function compute_mse(experiment, best_mse, plot_dir; ds_dict, plot_comparison =
return mse
end

function save_plots(plot_dir, plots_dict; group_figs = true)
if group_figs
width_to_height_ratio = 23 / 10
s = 1000
n_cols = 3

vars_to_skip =
["thetal_mean", "updraft_thetal", "u_mean", "v_mean", "qt_mean", "updraft_qt", "temperature_mean"]

all_contours = plots_dict["contours"]
filter!(p -> !occursin("var", p.first), all_contours) # skip higher order moment contours
filter!(p -> !any(map(x -> occursin(x, p.first), vars_to_skip)), all_contours)
all_contours = values(all_contours)
n_plots = length(all_contours)
n_rows = ceil(Int, n_plots / n_cols)
@info " Saving $(joinpath(plot_dir, "contours.png"))"
Plots.plot(
all_contours...;
layout = n_plots,
size = (width_to_height_ratio * s, s),
framestyle = :box,
margin = 20 * Plots.PlotMeasures.px,
)
Plots.savefig(joinpath(plot_dir, "contours.png"))

all_profiles = values(plots_dict["profiles"])
n_plots = length(all_profiles)
n_rows = ceil(Int, n_plots / n_cols)
@info " Saving $(joinpath(plot_dir, "profiles.png"))"
Plots.plot(
all_profiles...;
layout = n_plots,
size = (width_to_height_ratio * s, s),
framestyle = :box,
margin = 20 * Plots.PlotMeasures.px,
)
Plots.savefig(joinpath(plot_dir, "profiles.png"))
end
end

sufficient_mse(computed_mse, best_mse) = computed_mse <= best_mse + sqrt(eps())

function test_mse(computed_mse, best_mse, key)
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/utils/variable_map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var_map_les(::Val{:updraft_area}) = "updraft_fraction"
var_map_les(::Val{:updraft_w}) = "updraft_w"
var_map_les(::Val{:updraft_qt}) = "updraft_qt"
var_map_les(::Val{:updraft_ql}) = "updraft_ql"
var_map_les(::Val{:updraft_qr}) = "updraft_ql"
var_map_les(::Val{:updraft_qr}) = "updraft_qr"
var_map_les(::Val{:updraft_thetal}) = "updraft_thetali"
var_map_les(::Val{:tke_mean}) = "tke_mean"
var_map_les(::Val{:thetal_mean}) = "thetali_mean"
Expand Down

0 comments on commit cf44759

Please sign in to comment.