@@ -8,7 +8,7 @@ import CloudMicrophysics.PrecipitationSusceptibility as CMPS
88ENV [" GKSwstype" ] = " nul"
99import ClimaCorePlots, Plots
1010Plots. GRBackend ()
11- using CairoMakie
11+ using CairoMakie, Printf
1212
1313function plot_initial_profiles_comparison (KM; sdm_case = " dry" )
1414 sdm_data = load_sdm_data (sdm_case)
@@ -252,65 +252,53 @@ function plot_animation(nc_data_file; output = "output")
252252 mkpath (path)
253253
254254 ds = NC. NCDataset (joinpath (@__DIR__ , nc_data_file))
255+ profs = ds. group[" profiles" ]
255256
256- t_plt = Array (ds. group[" profiles" ][" t" ])
257- z_plt = Array (ds. group[" profiles" ][" zc" ])
258- q_tot = Array (ds. group[" profiles" ][" q_tot" ])
259- q_liq = Array (ds. group[" profiles" ][" q_liq" ])
260- q_ice = Array (ds. group[" profiles" ][" q_ice" ])
261- q_rai = Array (ds. group[" profiles" ][" q_rai" ])
262- q_sno = Array (ds. group[" profiles" ][" q_sno" ])
263- N_aer = Array (ds. group[" profiles" ][" N_aer" ])
264- N_liq = Array (ds. group[" profiles" ][" N_liq" ])
265- N_rai = Array (ds. group[" profiles" ][" N_rai" ])
266- SN_liq_act = Array (ds. group[" profiles" ][" SN_liq_act" ])
267-
268- function plot_data (data, data_label, max_val, scale, title = " " )
269- return Plots. plot (
270- data * scale,
271- z_plt,
272- xlabel = data_label,
273- ylabel = " z [m]" ,
274- legend = false ,
275- title = title,
276- titlefontsize = 30 ,
277- xlim = [0 , 1.1 * max_val * scale],
278- )
279- end
257+ z_plt = Array (profs[" zc" ])
258+ t_plt = Array (profs[" t" ])
259+ nt = length (t_plt)
260+ ti = Observable (1 ) # time index
280261
281- anim = Plots. @animate for i in 1 : length (t_plt)
262+ kg_to_g = 1e3
263+ m⁻³_to_cm⁻³ = 1e-6
264+ q_tot = Array (profs[" q_tot" ]) .* kg_to_g
265+ q_liq = Array (profs[" q_liq" ]) .* kg_to_g
266+ q_ice = Array (profs[" q_ice" ]) .* kg_to_g
267+ q_rai = Array (profs[" q_rai" ]) .* kg_to_g
268+ q_sno = Array (profs[" q_sno" ]) .* kg_to_g
269+ N_aer = Array (profs[" N_aer" ]) .* m⁻³_to_cm⁻³
270+ N_liq = Array (profs[" N_liq" ]) .* m⁻³_to_cm⁻³
271+ N_rai = Array (profs[" N_rai" ]) .* m⁻³_to_cm⁻³
272+ SN_liq_act = Array (profs[" SN_liq_act" ]) .* m⁻³_to_cm⁻³
282273
283- title = " time = " * string (floor (Int, t_plt[i])) * " [s]"
284- mass_scale = 1e3
285- num_scale = 1e-6
286- p1 = plot_data (q_tot[:, i], " q_tot [g/kg]" , maximum (q_tot), mass_scale)
287- p2 = plot_data (q_liq[:, i], " q_liq [g/kg]" , maximum (q_liq), mass_scale, title)
288- p3 = plot_data (N_liq[:, i], " N_liq [1/cm^3]" , maximum (N_liq), num_scale)
289- p4 = plot_data (q_rai[:, i], " q_rai [g/kg]" , maximum (q_rai), mass_scale)
290- p5 = plot_data (N_rai[:, i], " N_rai [1/cm^3]" , maximum (N_rai), num_scale)
291- p6 = plot_data (q_ice[:, i], " q_ice [g/kg]" , maximum (q_ice), mass_scale)
292- p7 = plot_data (q_sno[:, i], " q_sno [g/kg]" , maximum (q_sno), mass_scale)
293- p8 = plot_data (SN_liq_act[:, i], " Activation [1/cm^3/s]" , maximum (SN_liq_act), num_scale)
274+ close (ds)
294275
295- Plots. plot (
296- p1,
297- p2,
298- p3,
299- p4,
300- p5,
301- p8,
302- p6,
303- p7,
304- size = (1800.0 , 1500.0 ),
305- bottom_margin = 30.0 * Plots. PlotMeasures. px,
306- left_margin = 30.0 * Plots. PlotMeasures. px,
307- top_margin = 30.0 * Plots. PlotMeasures. px,
308- right_margin = 30.0 * Plots. PlotMeasures. px,
309- layout = (3 , 3 ),
310- )
311- end
276+ lims (x) = iszero (x) ? (nothing , nothing ) : ((0 , 1.1 * maximum (x)), nothing )
312277
313- Plots. mp4 (anim, joinpath (path, " animation.mp4" ), fps = 10 )
278+ fig = Figure (size = (1800 , 1500 ))
279+ ax_q_tot = Axis (fig[1 , 1 ]; xlabel = " q_tot [g/kg]" , limits = lims (q_tot), ylabel = " z [m]" )
280+ lines! (ax_q_tot, @lift (q_tot[:, $ ti]), z_plt)
281+ ax_q_liq = Axis (fig[1 , 2 ]; xlabel = " q_liq [g/kg]" , limits = lims (q_liq))
282+ lines! (ax_q_liq, @lift (q_liq[:, $ ti]), z_plt)
283+ ax_N_liq = Axis (fig[1 , 3 ]; xlabel = " N_liq [1/cm^3]" , limits = lims (N_liq))
284+ lines! (ax_N_liq, @lift (N_liq[:, $ ti]), z_plt)
285+ ax_q_rai = Axis (fig[2 , 1 ]; xlabel = " q_rai [g/kg]" , limits = lims (q_rai), ylabel = " z [m]" )
286+ lines! (ax_q_rai, @lift (q_rai[:, $ ti]), z_plt)
287+ ax_N_rai = Axis (fig[2 , 2 ]; xlabel = " N_rai [1/cm^3]" , limits = lims (N_rai))
288+ lines! (ax_N_rai, @lift (N_rai[:, $ ti]), z_plt)
289+ ax_q_ice = Axis (fig[2 , 3 ]; xlabel = " q_ice [g/kg]" , limits = lims (q_ice))
290+ lines! (ax_q_ice, @lift (q_ice[:, $ ti]), z_plt)
291+ ax_q_sno = Axis (fig[3 , 1 ]; xlabel = " q_sno [g/kg]" , limits = lims (q_sno), ylabel = " z [m]" )
292+ lines! (ax_q_sno, @lift (q_sno[:, $ ti]), z_plt)
293+ ax_SN_liq_act = Axis (fig[3 , 2 ]; xlabel = " SN_liq_act [1/cm^3]" , limits = lims (SN_liq_act))
294+ lines! (ax_SN_liq_act, @lift (SN_liq_act[:, $ ti]), z_plt)
295+ axs = contents (fig[:, :])
296+ Label (fig[0 , :], @lift (@sprintf (" time = %d [s]" , t_plt[$ ti])), fontsize = 30 )
297+ linkyaxes! (axs... )
298+
299+ record (fig, joinpath (path, " animation.mp4" ), 1 : nt) do i
300+ ti[] = i
301+ end
314302end
315303
316304function plot_profiles_in_time (nc_data_file; output = " output" , n = 10 )
0 commit comments