From e96f111110d3afc7d191a97f1360c0d638b84b7b Mon Sep 17 00:00:00 2001 From: Haakon Ludvig Langeland Ervik <45243236+haakon-e@users.noreply.github.com> Date: Wed, 16 Jul 2025 12:49:36 -0700 Subject: [PATCH] migrate plot_initial_profiles_comparison to Makie --- test/data_utils.jl | 44 ---------------- .../initial_profile_test.jl | 4 +- test/plotting_utils.jl | 50 +++++++++---------- 3 files changed, 28 insertions(+), 70 deletions(-) diff --git a/test/data_utils.jl b/test/data_utils.jl index c8aaf652..5bb2ac83 100644 --- a/test/data_utils.jl +++ b/test/data_utils.jl @@ -1,47 +1,3 @@ -using Plots - -""" - Create plots comparing the Julia & PySDM vertical profiles -""" -function plot_comparison(KM; sdm_case = "dry", name = "dry") - sdm_data = load_sdm_data(sdm_case) - path = joinpath(@__DIR__, "output") - mkpath(path) - - fig_name = string(name, "_init_profile.png") - - p1 = Plots.plot(KM.q_vap, KM.z_centers, label = "KM", xlabel = "q_vap [g/kg]", ylabel = "z [m]") - Plots.plot!(p1, sdm_data.qv_sdm, sdm_data.z_sdm, label = "SDM") - - p2 = Plots.plot(KM.ρ, KM.z_centers, label = "KM ρ_tot", xlabel = "ρ [kg/m3]", ylabel = "z [m]") - Plots.plot!(p2, sdm_data.rho_sdm, sdm_data.z_sdm, label = "SDM ρ") - - p3 = Plots.plot(KM.θ_dry, KM.z_centers, label = "KM", xlabel = "θ_dry [K]", ylabel = "z [m]") - Plots.plot!(p3, sdm_data.thetad_sdm, sdm_data.z_sdm, label = "SDM") - - p4 = Plots.plot(KM.T, KM.z_centers, label = "KM", xlabel = "T [K]", ylabel = "z [m]") - Plots.plot!(p4, sdm_data.T_sdm, sdm_data.z_sdm, label = "SDM") - - p5 = Plots.plot(KM.p ./ 100, KM.z_centers, label = "KM", xlabel = "p [hPa]", ylabel = "z [m]") - Plots.plot!(p5, sdm_data.P_sdm ./ 100, sdm_data.z_sdm, label = "SDM") - - p6 = Plots.plot(KM.q_liq, KM.z_centers, label = "KM", xlabel = "q_liq [g/kg]", ylabel = "z [m]") - Plots.plot!(p6, sdm_data.ql_sdm, sdm_data.z_sdm, label = "SDM") - - p = Plots.plot( - p1, - p2, - p3, - p4, - p5, - p6, - size = (1200.0, 750.0), - bottom_margin = 40.0 * Plots.PlotMeasures.px, - left_margin = 80.0 * Plots.PlotMeasures.px, - ) - Plots.png(p, joinpath(path, fig_name)) -end - """ Load the statically-stored PySDM profiles """ diff --git a/test/initial_condition_tests/initial_profile_test.jl b/test/initial_condition_tests/initial_profile_test.jl index 1eb6733c..e831245b 100644 --- a/test/initial_condition_tests/initial_profile_test.jl +++ b/test/initial_condition_tests/initial_profile_test.jl @@ -115,7 +115,9 @@ function compare_profiles(; is_dry_flag::Bool) @test all(isapprox(KM_θ_dry(z_test), SD_θ_dry(z_test), rtol = 1e-6)) end - plot_initial_profiles_comparison(KM_data, sdm_case = sdm_case) + with_theme(theme_minimal()) do + plot_initial_profiles_comparison(KM_data, sdm_case = sdm_case) + end end compare_profiles(is_dry_flag = true) diff --git a/test/plotting_utils.jl b/test/plotting_utils.jl index de8581a8..08a6258f 100644 --- a/test/plotting_utils.jl +++ b/test/plotting_utils.jl @@ -15,38 +15,38 @@ function plot_initial_profiles_comparison(KM; sdm_case = "dry") path = joinpath(@__DIR__, "initial_condition_tests/output_init_profiles") mkpath(path) - fig_name = string(sdm_case, "_init_profile.png") + fig = Figure(; size = (1200, 750)) + z = vec(KM.z_centers) - p1 = Plots.plot(KM.q_vap, KM.z_centers, label = "KM", xlabel = "q_vap [g/kg]", ylabel = "z [m]") - Plots.plot!(p1, sdm_data.qv_sdm, sdm_data.z_sdm, label = "SDM") + ax = Axis(fig[1, 1]; xlabel = "q_vap [g/kg]", ylabel = "z [m]") + lines!(vec(KM.q_vap), z, label = "KM") + lines!(vec(sdm_data.qv_sdm), sdm_data.z_sdm, label = "SDM") - p2 = Plots.plot(KM.ρ, KM.z_centers, label = "KM ρ_tot", xlabel = "ρ [kg/m3]", ylabel = "z [m]") - Plots.plot!(p2, sdm_data.rho_sdm, sdm_data.z_sdm, label = "SDM ρ") + ax = Axis(fig[1, 2]; xlabel = "ρ [kg/m3]") + lines!(vec(KM.ρ), z, label = "KM") + lines!(vec(sdm_data.rho_sdm), sdm_data.z_sdm, label = "SDM") - p3 = Plots.plot(KM.θ_dry, KM.z_centers, label = "KM", xlabel = "θ_dry [K]", ylabel = "z [m]") - Plots.plot!(p3, sdm_data.thetad_sdm, sdm_data.z_sdm, label = "SDM") + ax = Axis(fig[1, 3]; xlabel = "θ_dry [K]") + lines!(vec(KM.θ_dry), z, label = "KM") + lines!(vec(sdm_data.thetad_sdm), sdm_data.z_sdm, label = "SDM") - p4 = Plots.plot(KM.T, KM.z_centers, label = "KM", xlabel = "T [K]", ylabel = "z [m]") - Plots.plot!(p4, sdm_data.T_sdm, sdm_data.z_sdm, label = "SDM") + ax = Axis(fig[2, 1]; xlabel = "T [K]", ylabel = "z [m]") + lines!(vec(KM.T), z, label = "KM") + lines!(vec(sdm_data.T_sdm), sdm_data.z_sdm, label = "SDM") - p5 = Plots.plot(KM.p ./ 100, KM.z_centers, label = "KM", xlabel = "p [hPa]", ylabel = "z [m]") - Plots.plot!(p5, sdm_data.P_sdm ./ 100, sdm_data.z_sdm, label = "SDM") + ax = Axis(fig[2, 2]; xlabel = "p [hPa]") + lines!(vec(KM.p ./ 100), z, label = "KM") + lines!(vec(sdm_data.P_sdm ./ 100), sdm_data.z_sdm, label = "SDM") - p6 = Plots.plot(KM.q_liq, KM.z_centers, label = "KM", xlabel = "q_liq [g/kg]", ylabel = "z [m]") - Plots.plot!(p6, sdm_data.ql_sdm, sdm_data.z_sdm, label = "SDM") + ax = Axis(fig[2, 3]; xlabel = "q_liq [g/kg]") + lines!(vec(KM.q_liq), z, label = "KM") + lines!(vec(sdm_data.ql_sdm), sdm_data.z_sdm, label = "SDM") - p = Plots.plot( - p1, - p2, - p3, - p4, - p5, - p6, - size = (1200.0, 750.0), - bottom_margin = 40.0 * Plots.PlotMeasures.px, - left_margin = 80.0 * Plots.PlotMeasures.px, - ) - Plots.png(p, joinpath(path, fig_name)) + axs = contents(fig[:, :]) + axislegend.(axs) + linkyaxes!(axs...) + + save(joinpath(path, "$(sdm_case)_init_profile.png"), fig) end function plot_final_aux_profiles(z_centers, aux, precip; output = "output")