@@ -348,8 +348,7 @@ function compute_spectrum(var::ClimaAnalysis.OutputVar; mass_weight = nothing)
348348
349349 FT = eltype (var. data)
350350
351- mass_weight =
352- isnothing (mass_weight) ? ones (FT, length (var. dims[dim3])) : mass_weight
351+ mass_weight = isnothing (mass_weight) ? ones (FT, length (var. dims[dim3])) : mass_weight
353352
354353 # Number of spherical wave numbers, excluding the first and the last
355354 # This number was reverse-engineered from ClimaCoreSpectra
@@ -358,18 +357,14 @@ function compute_spectrum(var::ClimaAnalysis.OutputVar; mass_weight = nothing)
358357 mesh_info = nothing
359358
360359 if ! isempty (times)
361- output_spectrum =
362- zeros ((length (times), num_output, length (var. dims[dim3])))
360+ output_spectrum = zeros ((length (times), num_output, length (var. dims[dim3])))
363361 dims = Dict (time => times)
364362 dim_attributes = Dict (time => var. dim_attributes[time])
365363 for index in 1 : length (times)
366364 spectrum_data, _wave_numbers, _spherical, mesh_info =
367365 power_spectrum_2d (FT, var. data[index, :, :, :], mass_weight)
368366 output_spectrum[index, :, :] .=
369- dropdims (sum (spectrum_data, dims = 1 ), dims = 1 )[
370- (begin + 1 ): (end - 1 ),
371- :,
372- ]
367+ dropdims (sum (spectrum_data, dims = 1 ), dims = 1 )[(begin + 1 ): (end - 1 ), :]
373368 end
374369 else
375370 dims = Dict {String, Vector{FT}} ()
@@ -378,10 +373,7 @@ function compute_spectrum(var::ClimaAnalysis.OutputVar; mass_weight = nothing)
378373 spectrum_data, _wave_numbers, _spherical, mesh_info =
379374 power_spectrum_2d (FT, var. data[:, :, :], mass_weight)
380375 output_spectrum[:, :] .=
381- dropdims (sum (spectrum_data, dims = 1 ), dims = 1 )[
382- (begin + 1 ): (end - 1 ),
383- :,
384- ]
376+ dropdims (sum (spectrum_data, dims = 1 ), dims = 1 )[(begin + 1 ): (end - 1 ), :]
385377 end
386378
387379 w_numbers = collect (1 : 1 : (mesh_info. num_spherical - 1 ))
@@ -392,19 +384,17 @@ function compute_spectrum(var::ClimaAnalysis.OutputVar; mass_weight = nothing)
392384 dim_attributes[dim3] = var. dim_attributes[dim3]
393385
394386 attributes = Dict (
395- " short_name" => " log_spectrum_" * var . attributes[ " short_name" ] ,
396- " long_name" => " Spectrum of " * var . attributes[ " long_name" ] ,
387+ " short_name" => " log_spectrum_" * short_name (var) ,
388+ " long_name" => " Spectrum of " * long_name (var) ,
397389 " units" => " " ,
398390 )
399391
400392 return ClimaAnalysis. OutputVar (
401- attributes,
402- dims,
403- dim_attributes,
404- log10 .(output_spectrum),
393+ attributes, dims, dim_attributes, log10 .(output_spectrum),
405394 )
406395end
407396
397+
408398"""
409399 map_comparison(func, simdirs, args)
410400
@@ -1282,13 +1272,15 @@ Helper function for `make_plots_generic`. Takes a list of variables and plots
12821272them on the same axis.
12831273"""
12841274function plot_les_vert_profile! (grid_loc, var_group)
1285- z = var_group[1 ]. dims[" z" ]
1286- units = var_group[1 ]. attributes[" units" ]
1275+ var1 = var_group[1 ]
1276+ units = var1. attributes[" units" ]
1277+ z = var1. dims[" z" ]
1278+ z_units = var1. dim_attributes[" z" ][" units" ]
12871279 ax = CairoMakie. Axis (
12881280 grid_loc[1 , 1 ],
1289- ylabel = " z [$(var_group[ 1 ] . dim_attributes[ " z " ][ " units " ]) ]" ,
1290- xlabel = " $(short_name (var_group[ 1 ] )) [$units ]" ,
1291- title = parse_var_attributes (var_group[ 1 ] ),
1281+ ylabel = " z [$z_units ]" ,
1282+ xlabel = " $(short_name (var1 )) [$units ]" ,
1283+ title = parse_var_attributes (var1 ),
12921284 )
12931285
12941286 for var in var_group
@@ -1304,63 +1296,45 @@ function make_plots(
13041296 simdirs = SimDir .(output_paths)
13051297
13061298 reduction = " inst"
1307- short_names = [
1308- " wa" ,
1309- " ua" ,
1310- " va" ,
1311- " ta" ,
1312- " thetaa" ,
1313- " ha" ,
1314- " hus" ,
1315- " hur" ,
1316- " cl" ,
1317- " clw" ,
1318- " cli" ,
1299+ # 3D+time variables to plot
1300+ short_names_xyzt = [
1301+ " wa" , " ua" , " va" , " ta" , " thetaa" , " ha" ,
1302+ " hus" , " hur" , " cl" , " clw" , " cli" ,
1303+ " husra" , " hussn" , # 1M microphysics
1304+ " cdnc" , " ncra" , # 2M microphysics
13191305 ]
1320- short_names = short_names ∩ collect (keys (simdirs[1 ]. vars))
1306+ short_names_xyzt = short_names_xyzt ∩ collect (keys (simdirs[1 ]. vars))
13211307
13221308 # Window average from instantaneous snapshots?
1323- function horizontal_average (var)
1324- return average_xy (var)
1325- end
1326- function windowed_reduction (var)
1327- hours = 3600.0
1309+ function average_t_last2hrs (var)
13281310 window_end = last (var. dims[" time" ])
1329- window_start = window_end - 2 hours
1330- var_window = ClimaAnalysis. window (
1331- var,
1332- " time" ;
1333- left = window_start,
1334- right = window_end,
1311+ window_start = window_end - CA. time_to_seconds (" 2hours" )
1312+ var_window = ClimaAnalysis. window (var, " time" ;
1313+ left = window_start, right = window_end,
13351314 )
1336- var_reduced = horizontal_average (average_time (var_window))
1337- return var_reduced
1315+ return average_xy (average_time (var_window))
13381316 end
13391317
1340- var_groups_xyt_reduced =
1341- map_comparison (simdirs, short_names) do simdir, short_name
1342- return [get (simdir; short_name, reduction) |> windowed_reduction]
1343- end
1318+ var_groups_z_avg_xyt = map_comparison (simdirs, short_names_xyzt) do simdir, short_name
1319+ return [get (simdir; short_name, reduction) |> average_t_last2hrs]
1320+ end
13441321
1345- var_groups_xy_reduced =
1346- map_comparison (simdirs, short_names) do simdir, short_name
1347- return [get (simdir; short_name, reduction) |> horizontal_average]
1348- end
1322+ var_groups_tz_avg_xy = map_comparison (simdirs, short_names_xyzt) do simdir, short_name
1323+ return [get (simdir; short_name, reduction) |> average_xy]
1324+ end
13491325
1350- tmp_file = make_plots_generic (
1351- output_paths,
1352- var_groups_xyt_reduced,
1353- output_name = " tmp" ;
1326+ tmp_file = make_plots_generic (output_paths, var_groups_z_avg_xyt;
1327+ output_name = " tmp" ,
13541328 plot_fn = plot_les_vert_profile!,
1355- MAX_NUM_COLS = 2 ,
1356- MAX_NUM_ROWS = 4 ,
1329+ MAX_NUM_COLS = 2 , MAX_NUM_ROWS = 4 ,
13571330 )
13581331
1359- make_plots_generic (
1360- output_paths,
1361- vcat (var_groups_xy_reduced... ),
1332+ summary_file = make_plots_generic (output_paths, vcat (var_groups_tz_avg_xy... );
13621333 plot_fn = plot_parsed_attribute_title!,
13631334 summary_files = [tmp_file],
1335+ MAX_NUM_COLS = 2 , MAX_NUM_ROWS = 4 ,
1336+ )
1337+
13641338 MAX_NUM_COLS = 2 ,
13651339 MAX_NUM_ROWS = 4 ,
13661340 )
0 commit comments