Skip to content

Commit 470369d

Browse files
committed
migrate plot_final_aux_profiles to Makie
1 parent bf2b00d commit 470369d

File tree

2 files changed

+92
-104
lines changed

2 files changed

+92
-104
lines changed

test/experiments/KiD_driver/run_KiD_simulation.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ function run_KiD_simulation(::Type{FT}, opts) where {FT}
9999
elseif precipitation_choice == "PrecipitationP3"
100100
cloudy_params = nothing
101101
(; ice_start, _q_flux, _N_flux, _F_rim, _F_liq, _ρ_r_init) = precip.p3_boundary_condition
102-
init = CO.p3_initial_condition.(
103-
FT, kid_params, thermo_params, coord.z;
104-
_q_init = _q_flux, _N_init = _N_flux, _F_rim = _F_rim, _F_liq = _F_liq,
105-
_ρ_r = _ρ_r_init, z_top = FT(opts["z_max"]), ice_start = ice_start,
106-
)
102+
init =
103+
CO.p3_initial_condition.(
104+
FT, kid_params, thermo_params, coord.z;
105+
_q_init = _q_flux, _N_init = _N_flux, _F_rim = _F_rim, _F_liq = _F_liq,
106+
_ρ_r = _ρ_r_init, z_top = FT(opts["z_max"]), ice_start = ice_start,
107+
)
107108
else
108109
cloudy_params = nothing
109110
init = CO.initial_condition_1d.(FT, common_params, kid_params, thermo_params, (ρ_profile,), coord.z)
@@ -139,7 +140,7 @@ function run_KiD_simulation(::Type{FT}, opts) where {FT}
139140
)
140141

141142
# Some basic plots
142-
if opts["plotting_flag"] == true
143+
opts["plotting_flag"] == true && with_theme(theme_minimal()) do
143144
@info "Plotting"
144145
output = joinpath(path, "figures")
145146

test/plotting_utils.jl

Lines changed: 85 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -51,122 +51,109 @@ end
5151

5252
function plot_final_aux_profiles(z_centers, aux, precip; output = "output")
5353

54+
vars = aux.microph_variables
55+
thermo_vars = aux.thermo_variables
56+
5457
path = joinpath(@__DIR__, output)
5558
mkpath(path)
5659

57-
T_end = parent(aux.thermo_variables.T)
58-
q_tot_end = parent(aux.microph_variables.q_tot)
59-
ρ_end = parent(aux.thermo_variables.ρ)
60+
T_end = vec(thermo_vars.T)
61+
q_tot_end = vec(vars.q_tot)
62+
ρ_end = vec(thermo_vars.ρ)
63+
64+
q_liq_end = vec(vars.q_liq)
65+
q_ice_end = vec(vars.q_ice)
6066

61-
q_liq_end = parent(aux.microph_variables.q_liq)
62-
q_ice_end = parent(aux.microph_variables.q_ice)
67+
# Allocate variables
68+
q_rai_end = zero(q_tot_end)
69+
q_sno_end = zero(q_tot_end)
70+
N_aer_end = zero(q_tot_end)
71+
N_liq_end = zero(q_tot_end)
72+
N_rai_end = zero(q_tot_end)
6373

6474
if precip isa CO.Precipitation1M
65-
q_rai_end = parent(aux.microph_variables.q_rai)
66-
q_sno_end = parent(aux.microph_variables.q_sno)
75+
q_rai_end .= vec(vars.q_rai)
76+
q_sno_end .= vec(vars.q_sno)
6777
elseif precip isa CO.Precipitation2M
68-
q_rai_end = parent(aux.microph_variables.q_rai)
69-
q_sno_end = q_tot_end .* 0.0
78+
q_rai_end .= vec(vars.q_rai)
79+
N_aer_end .= vec(vars.N_aer)
80+
N_liq_end .= vec(vars.N_liq)
81+
N_rai_end .= vec(vars.N_rai)
82+
args = (precip.rain_formation, q_liq_end, q_rai_end, ρ_end, N_liq_end)
83+
precip_sus_aut = CMPS.precipitation_susceptibility_autoconversion.(args...)
84+
precip_sus_acc = CMPS.precipitation_susceptibility_accretion.(args...)
85+
d_ln_pp_d_ln_q_liq_aut = getfield.(precip_sus_aut, :d_ln_pp_d_ln_q_liq)
86+
d_ln_pp_d_ln_q_rai_aut = getfield.(precip_sus_aut, :d_ln_pp_d_ln_q_rai)
87+
d_ln_pp_d_ln_q_liq_acc = getfield.(precip_sus_acc, :d_ln_pp_d_ln_q_liq)
88+
d_ln_pp_d_ln_q_rai_acc = getfield.(precip_sus_acc, :d_ln_pp_d_ln_q_rai)
7089
elseif precip isa CO.PrecipitationP3
71-
q_rai_end = parent(aux.microph_variables.q_rai)
72-
q_liqonice_end = parent(aux.microph_variables.q_liqonice)
73-
q_rim_end = parent(aux.microph_variables.q_rim)
74-
B_rim_end = parent(aux.microph_variables.B_rim)
75-
N_ice_end = parent(aux.microph_variables.N_ice)
76-
N_liq_end = parent(aux.microph_variables.N_liq)
77-
N_rai_end = parent(aux.microph_variables.N_rai)
78-
else
79-
q_rai_end = q_tot_end .* 0.0
80-
q_sno_end = q_tot_end .* 0.0
90+
q_rai_end .= vec(vars.q_rai)
91+
N_ice_end .= vec(vars.N_ice)
92+
N_liq_end .= vec(vars.N_liq)
93+
N_rai_end .= vec(vars.N_rai)
94+
# additional variables for P3
95+
q_liqonice_end = vec(vars.q_liqonice)
96+
q_rim_end = vec(vars.q_rim)
97+
B_rim_end = vec(vars.B_rim)
8198
end
8299

83-
if precip isa CO.Precipitation2M
84-
N_aer_end = parent(aux.microph_variables.N_aer)
85-
N_liq_end = parent(aux.microph_variables.N_liq)
86-
N_rai_end = parent(aux.microph_variables.N_rai)
87-
else
88-
N_aer_end = q_tot_end .* 0.0
89-
N_liq_end = q_tot_end .* 0.0
90-
N_rai_end = q_tot_end .* 0.0
91-
end
100+
kg_to_g = 1e3
101+
m⁻³_to_cm⁻³ = 1e-6
92102

93-
p1 = Plots.plot(q_tot_end .* 1e3, z_centers, xlabel = "q_tot [g/kg]", ylabel = "z [m]")
94-
p2 = Plots.plot(q_liq_end .* 1e3, z_centers, xlabel = "q_liq [g/kg]", ylabel = "z [m]")
95-
p3 = Plots.plot(q_ice_end .* 1e3, z_centers, xlabel = "q_ice [g/kg]", ylabel = "z [m]")
96-
p4 = Plots.plot(T_end, z_centers, xlabel = "T [K]", ylabel = "z [m]")
97-
p5 = Plots.plot(q_rai_end .* 1e3, z_centers, xlabel = "q_rai [g/kg]", ylabel = "z [m]")
103+
fig = Figure(size = (1800, 1200))
104+
ax = Axis(fig[1, 1]; xlabel = "q_tot [g/kg]", ylabel = "z [m]")
105+
lines!(q_tot_end .* kg_to_g, z_centers)
106+
107+
ax = Axis(fig[1, 2]; xlabel = "q_liq [g/kg]")
108+
lines!(q_liq_end .* kg_to_g, z_centers)
109+
110+
ax = Axis(fig[1, 3]; xlabel = "q_ice [g/kg]")
111+
lines!(q_ice_end .* kg_to_g, z_centers)
112+
113+
ax = Axis(fig[1, 4]; xlabel = "T [K]")
114+
lines!(T_end, z_centers)
115+
116+
ax = Axis(fig[2, 1]; xlabel = "q_rai [g/kg]", ylabel = "z [m]")
117+
lines!(q_rai_end .* kg_to_g, z_centers)
98118

99119
if precip isa CO.PrecipitationP3
100-
p6 = Plots.plot(N_ice_end .* 1e-6, z_centers, xlabel = "N_ice [1/cm3]", ylabel = "z [m]")
101-
p11 = Plots.plot(N_ice_end .* 1e-6, z_centers, xlabel = "N_ice [1/cm3]", ylabel = "z [m]")
102-
p12 = Plots.plot(q_liqonice_end .* 1e3, z_centers, xlabel = "q_liqonice [g/kg]", ylabel = "z [m]")
103-
p13 = Plots.plot(q_rim_end .* 1e3, z_centers, xlabel = "q_rim [g/kg]", ylabel = "z [m]")
104-
p14 = Plots.plot(B_rim_end, z_centers, xlabel = "B_rim [-]", ylabel = "z [m]")
105-
p = Plots.plot(
106-
p1,
107-
p2,
108-
p3,
109-
p4,
110-
p5,
111-
p6,
112-
p11,
113-
p12,
114-
p13,
115-
p14,
116-
size = (1800.0, 1200.0),
117-
bottom_margin = 40.0 * Plots.PlotMeasures.px,
118-
left_margin = 80.0 * Plots.PlotMeasures.px,
119-
layout = (2, 5),
120-
)
121-
Plots.png(p, joinpath(path, "final_aux_profiles.png"))
120+
ax = Axis(fig[2, 2]; xlabel = "N_ice [1/cm³]")
121+
lines!(N_ice_end .* m⁻³_to_cm⁻³, z_centers)
122+
123+
ax = Axis(fig[2, 3]; xlabel = "q_liqonice [g/kg]")
124+
lines!(q_liqonice_end .* kg_to_g, z_centers)
125+
126+
ax = Axis(fig[2, 4]; xlabel = "q_rim [g/kg]")
127+
lines!(q_rim_end .* kg_to_g, z_centers)
128+
129+
ax = Axis(fig[3, 1]; xlabel = "B_rim [-]", ylabel = "z [m]")
130+
lines!(B_rim_end, z_centers)
122131
else
123-
p6 = Plots.plot(q_sno_end .* 1e3, z_centers, xlabel = "q_sno [g/kg]", ylabel = "z [m]")
124-
p8 = Plots.plot(N_aer_end .* 1e-6, z_centers, xlabel = "N_aer [1/cm3]", ylabel = "z [m]")
125-
p9 = Plots.plot(N_liq_end .* 1e-6, z_centers, xlabel = "N_liq [1/cm3]", ylabel = "z [m]")
126-
p10 = Plots.plot(N_rai_end .* 1e-6, z_centers, xlabel = "N_rai [1/cm3]", ylabel = "z [m]")
132+
ax = Axis(fig[2, 2]; xlabel = "q_sno [g/kg]")
133+
lines!(q_sno_end .* kg_to_g, z_centers)
134+
135+
ax = Axis(fig[2, 3]; xlabel = "N_aer [1/cm³]")
136+
lines!(N_aer_end .* m⁻³_to_cm⁻³, z_centers)
137+
138+
ax = Axis(fig[2, 4]; xlabel = "N_liq [1/cm³]")
139+
lines!(N_liq_end .* m⁻³_to_cm⁻³, z_centers)
127140

128-
p7 = Plots.plot(xlabel = "precipitation susceptibility", ylabel = "z [m]")
141+
ax = Axis(fig[3, 1]; xlabel = "N_rai [1/cm³]", ylabel = "z [m]")
142+
lines!(N_rai_end .* m⁻³_to_cm⁻³, z_centers)
143+
144+
ax = Axis(fig[3, 2]; xlabel = "precipitation susceptibility", ylabel = "z [m]")
129145
if precip isa CO.Precipitation2M
130-
N_liq_end = parent(aux.microph_variables.N_liq)
131-
precip_sus_aut =
132-
CMPS.precipitation_susceptibility_autoconversion.(
133-
Ref(precip.rain_formation),
134-
q_liq_end,
135-
q_rai_end,
136-
ρ_end,
137-
N_liq_end,
138-
)
139-
precip_sus_acc =
140-
CMPS.precipitation_susceptibility_accretion.(
141-
Ref(precip.rain_formation),
142-
q_liq_end,
143-
q_rai_end,
144-
ρ_end,
145-
N_liq_end,
146-
)
147-
Plots.plot!([r.d_ln_pp_d_ln_q_liq for r in precip_sus_aut], z_centers, label = "aut, q_liq", color = :red)
148-
Plots.plot!([r.d_ln_pp_d_ln_q_rai for r in precip_sus_aut], z_centers, label = "aut, q_rai", color = :brown)
149-
Plots.plot!([r.d_ln_pp_d_ln_q_liq for r in precip_sus_acc], z_centers, label = "acc, q_liq", color = :blue)
150-
Plots.plot!([r.d_ln_pp_d_ln_q_rai for r in precip_sus_acc], z_centers, label = "acc, q_rai", color = :green)
151-
Plots.plot!(legend = :outerright)
146+
lines!(d_ln_pp_d_ln_q_liq_aut, z_centers, label = "aut, q_liq", color = :red)
147+
lines!(d_ln_pp_d_ln_q_rai_aut, z_centers, label = "aut, q_rai", color = :brown)
148+
lines!(d_ln_pp_d_ln_q_liq_acc, z_centers, label = "acc, q_liq", color = :blue)
149+
lines!(d_ln_pp_d_ln_q_rai_acc, z_centers, label = "acc, q_rai", color = :green)
150+
axislegend(ax, position = :top)
152151
end
153-
p = Plots.plot(
154-
p1,
155-
p2,
156-
p3,
157-
p4,
158-
p5,
159-
p6,
160-
p7,
161-
p8,
162-
p9,
163-
p10,
164-
size = (1800.0, 1200.0),
165-
bottom_margin = 40.0 * Plots.PlotMeasures.px,
166-
left_margin = 80.0 * Plots.PlotMeasures.px,
167-
)
168-
Plots.png(p, joinpath(path, "final_aux_profiles.png"))
169152
end
153+
axs = contents(fig[:, :])
154+
linkyaxes!(axs...)
155+
save(joinpath(path, "final_aux_profiles.png"), fig)
156+
nothing
170157
end
171158

172159
function plot_animation_p3(z_centers, solver, aux, moisture, precip, K1D, output = plot_folder)

0 commit comments

Comments
 (0)