Skip to content

Commit beb82e2

Browse files
committed
rft: formatting
1 parent 576ac23 commit beb82e2

File tree

1 file changed

+40
-66
lines changed

1 file changed

+40
-66
lines changed

post_processing/ci_plots.jl

Lines changed: 40 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -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
)
406395
end
407396

397+
408398
"""
409399
map_comparison(func, simdirs, args)
410400
@@ -1287,13 +1277,15 @@ Helper function for `make_plots_generic`. Takes a list of variables and plots
12871277
them on the same axis.
12881278
"""
12891279
function plot_les_vert_profile!(grid_loc, var_group)
1290-
z = var_group[1].dims["z"]
1291-
units = var_group[1].attributes["units"]
1280+
var1 = var_group[1]
1281+
units = var1.attributes["units"]
1282+
z = var1.dims["z"]
1283+
z_units = var1.dim_attributes["z"]["units"]
12921284
ax = CairoMakie.Axis(
12931285
grid_loc[1, 1],
1294-
ylabel = "z [$(var_group[1].dim_attributes["z"]["units"])]",
1295-
xlabel = "$(short_name(var_group[1])) [$units]",
1296-
title = parse_var_attributes(var_group[1]),
1286+
ylabel = "z [$z_units]",
1287+
xlabel = "$(short_name(var1)) [$units]",
1288+
title = parse_var_attributes(var1),
12971289
)
12981290

12991291
for var in var_group
@@ -1309,63 +1301,45 @@ function make_plots(
13091301
simdirs = SimDir.(output_paths)
13101302

13111303
reduction = "inst"
1312-
short_names = [
1313-
"wa",
1314-
"ua",
1315-
"va",
1316-
"ta",
1317-
"thetaa",
1318-
"ha",
1319-
"hus",
1320-
"hur",
1321-
"cl",
1322-
"clw",
1323-
"cli",
1304+
# 3D+time variables to plot
1305+
short_names_xyzt = [
1306+
"wa", "ua", "va", "ta", "thetaa", "ha",
1307+
"hus", "hur", "cl", "clw", "cli",
1308+
"husra", "hussn", # 1M microphysics
1309+
"cdnc", "ncra", # 2M microphysics
13241310
]
1325-
short_names = short_names collect(keys(simdirs[1].vars))
1311+
short_names_xyzt = short_names_xyzt collect(keys(simdirs[1].vars))
13261312

13271313
# Window average from instantaneous snapshots?
1328-
function horizontal_average(var)
1329-
return average_xy(var)
1330-
end
1331-
function windowed_reduction(var)
1332-
hours = 3600.0
1314+
function average_t_last2hrs(var)
13331315
window_end = last(var.dims["time"])
1334-
window_start = window_end - 2hours
1335-
var_window = ClimaAnalysis.window(
1336-
var,
1337-
"time";
1338-
left = window_start,
1339-
right = window_end,
1316+
window_start = window_end - CA.time_to_seconds("2hours")
1317+
var_window = ClimaAnalysis.window(var, "time";
1318+
left = window_start, right = window_end,
13401319
)
1341-
var_reduced = horizontal_average(average_time(var_window))
1342-
return var_reduced
1320+
return average_xy(average_time(var_window))
13431321
end
13441322

1345-
var_groups_xyt_reduced =
1346-
map_comparison(simdirs, short_names) do simdir, short_name
1347-
return [get(simdir; short_name, reduction) |> windowed_reduction]
1348-
end
1323+
var_groups_z_avg_xyt = map_comparison(simdirs, short_names_xyzt) do simdir, short_name
1324+
return [get(simdir; short_name, reduction) |> average_t_last2hrs]
1325+
end
13491326

1350-
var_groups_xy_reduced =
1351-
map_comparison(simdirs, short_names) do simdir, short_name
1352-
return [get(simdir; short_name, reduction) |> horizontal_average]
1353-
end
1327+
var_groups_tz_avg_xy = map_comparison(simdirs, short_names_xyzt) do simdir, short_name
1328+
return [get(simdir; short_name, reduction) |> average_xy]
1329+
end
13541330

1355-
tmp_file = make_plots_generic(
1356-
output_paths,
1357-
var_groups_xyt_reduced,
1358-
output_name = "tmp";
1331+
tmp_file = make_plots_generic(output_paths, var_groups_z_avg_xyt;
1332+
output_name = "tmp",
13591333
plot_fn = plot_les_vert_profile!,
1360-
MAX_NUM_COLS = 2,
1361-
MAX_NUM_ROWS = 4,
1334+
MAX_NUM_COLS = 2, MAX_NUM_ROWS = 4,
13621335
)
13631336

1364-
make_plots_generic(
1365-
output_paths,
1366-
vcat(var_groups_xy_reduced...),
1337+
summary_file = make_plots_generic(output_paths, vcat(var_groups_tz_avg_xy...);
13671338
plot_fn = plot_parsed_attribute_title!,
13681339
summary_files = [tmp_file],
1340+
MAX_NUM_COLS = 2, MAX_NUM_ROWS = 4,
1341+
)
1342+
13691343
MAX_NUM_COLS = 2,
13701344
MAX_NUM_ROWS = 4,
13711345
)

0 commit comments

Comments
 (0)