@@ -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,60 +252,50 @@ 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- 
267-     function  plot_data (data, data_label, max_val, title =  " "  )
268-         return  Plots. plot (
269-             data,
270-             z_plt,
271-             xlabel =  data_label,
272-             ylabel =  " z [m]"  ,
273-             legend =  false ,
274-             title =  title,
275-             titlefontsize =  30 ,
276-             xlim =  [0 , 1.1  *  max_val],
277-         )
278-     end 
257+     z_plt =  Array (profs[" zc"  ])
258+     t_plt =  Array (profs[" t"  ])
259+     nt =  length (t_plt)
260+     ti =  Observable (1 )  #  time index
279261
280-     anim =  Plots. @animate  for  i in  1 : length (t_plt)
281- 
282-         title =  " time = "   *  string (floor (Int, t_plt[i])) *  "  [s]" 
283-         p1 =  plot_data (q_tot[:, i] .*  1e3 , " q_tot [g/kg]"  , maximum (q_tot))
284-         p2 =  plot_data (q_liq[:, i] .*  1e3 , " q_liq [g/kg]"  , maximum (q_liq), title)
285-         p3 =  plot_data (N_liq[:, i] .*  1e6 , " N_liq [1/cm^3]"  , maximum (N_liq))
286-         p4 =  plot_data (q_rai[:, i] .*  1e3 , " q_rai [g/kg]"  , maximum (q_rai))
287-         p5 =  plot_data (N_rai[:, i] .*  1e6 , " N_rai [1/cm^3]"  , maximum (N_rai))
288-         p6 =  plot_data (q_ice[:, i] .*  1e3 , " q_ice [g/kg]"  , maximum (q_ice))
289-         p7 =  plot_data (q_sno[:, i] .*  1e3 , " q_sno [g/kg]"  , maximum (q_sno))
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+ 
273+     close (ds)
274+ 
275+     lims (x) =  iszero (x) ?  (nothing , nothing ) :  ((0 , 1.1  *  maximum (x)), nothing )
276+ 
277+     fig =  Figure (size =  (1800 , 1500 ))
278+     ax_q_tot =  Axis (fig[1 , 1 ]; xlabel =  " q_tot [g/kg]"  , limits =  lims (q_tot), ylabel =  " z [m]"  )
279+     lines! (ax_q_tot, @lift (q_tot[:, $ ti]), z_plt)
280+     ax_q_liq =  Axis (fig[1 , 2 ]; xlabel =  " q_liq [g/kg]"  , limits =  lims (q_liq))
281+     lines! (ax_q_liq, @lift (q_liq[:, $ ti]), z_plt)
282+     ax_N_liq =  Axis (fig[1 , 3 ]; xlabel =  " N_liq [1/cm^3]"  , limits =  lims (N_liq))
283+     lines! (ax_N_liq, @lift (N_liq[:, $ ti]), z_plt)
284+     ax_q_rai =  Axis (fig[2 , 1 ]; xlabel =  " q_rai [g/kg]"  , limits =  lims (q_rai), ylabel =  " z [m]"  )
285+     lines! (ax_q_rai, @lift (q_rai[:, $ ti]), z_plt)
286+     ax_N_rai =  Axis (fig[2 , 2 ]; xlabel =  " N_rai [1/cm^3]"  , limits =  lims (N_rai))
287+     lines! (ax_N_rai, @lift (N_rai[:, $ ti]), z_plt)
288+     ax_q_ice =  Axis (fig[2 , 3 ]; xlabel =  " q_ice [g/kg]"  , limits =  lims (q_ice))
289+     lines! (ax_q_ice, @lift (q_ice[:, $ ti]), z_plt)
290+     ax_q_sno =  Axis (fig[3 , 1 ]; xlabel =  " q_sno [g/kg]"  , limits =  lims (q_sno), ylabel =  " z [m]"  )
291+     lines! (ax_q_sno, @lift (q_sno[:, $ ti]), z_plt)
292+     axs =  contents (fig[:, :])
293+     Label (fig[0 , :], @lift (@sprintf (" time = %d [s]"  , t_plt[$ ti])), fontsize =  30 )
294+     linkyaxes! (axs... )
290295
291-         Plots. plot (
292-             p1,
293-             p2,
294-             p3,
295-             p4,
296-             p5,
297-             p6,
298-             p7,
299-             size =  (1800.0 , 1500.0 ),
300-             bottom_margin =  30.0  *  Plots. PlotMeasures. px,
301-             left_margin =  30.0  *  Plots. PlotMeasures. px,
302-             top_margin =  30.0  *  Plots. PlotMeasures. px,
303-             right_margin =  30.0  *  Plots. PlotMeasures. px,
304-             layout =  (3 , 3 ),
305-         )
296+     record (fig, joinpath (path, " animation.mp4"  ), 1 : nt) do  i
297+         ti[] =  i
306298    end 
307- 
308-     Plots. mp4 (anim, joinpath (path, " animation.mp4"  ), fps =  10 )
309299end 
310300
311301function  plot_timeheight_p3 (nc_data_file, precip; output =  " output"  )
0 commit comments