Skip to content

Commit

Permalink
address some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici committed Feb 1, 2024
1 parent 062451e commit 5a156ed
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions post_processing/ci_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,40 @@ YLOGSCALE = Dict(
long_name(var) = var.attributes["long_name"]
short_name(var) = var.attributes["short_name"]

function var_info(var)
"""
parse_var_attributes(var)
Takes in an OutputVar and parses some of its attributes into a short, informative string.
Used to generate unique titles when the same var is being plotted for several times/locations.
This could be extended to parse more attributes.
For example, the sample attributes:
attributes = Dict(
"units" => "%",
"short_name" => "cl",
"slice_y" => "0.0",
"long_name" => "Cloud fraction, Instantaneous x = 0.0 m y = 0.0 m",
"slice_y_units" => "m",
"slice_x_units" => "m",
"comments" => "",
"slice_x" => "0.0",
)
will be parsed into "cl, x = 0.0, y = 0.0"
"""
function parse_var_attributes(var)
MISSING_STR = "MISSING_ATTRIBUTE"
attr = var.attributes

name = replace(short_name(var), "up" => "")
coords = if haskey(attr, "slice_lat")
"lat = $(attr["slice_lat"]), lon = $(attr["slice_lon"])"
else
"x = $(attr["slice_x"]), y = $(attr["slice_y"])"
end
var_info = [name, coords]

time = get(attr, "slice_time", nothing)
isnothing(time) || push!(var_info, "t = $(time)s")
attributes = ["slice_lat", "slice_lon", "slice_x", "slice_y", "slice_time"]
info = [
replace(key, "slice_" => "") * " = " * get(attr, key, MISSING_STR)
for key in attributes
]
# Filter out missing entries
info = filter(x -> !occursin(MISSING_STR, x), [name, info...])

return join(var_info, ", ")
return join(info, ", ")
end

function make_plots_generic(
Expand Down Expand Up @@ -636,7 +655,7 @@ function plot_edmf_vert_profile!(grid_loc, var_group)
grid_loc[1, 1],
ylabel = "z [$(var_group[1].dim_attributes["z"]["units"])]",
xlabel = "$(short_name(var_group[1])) [$units]",
title = var_info(var_group[1]),
title = parse_var_attributes(var_group[1]),
)

for var in var_group
Expand All @@ -647,14 +666,15 @@ end


"""
plot_custom_title!(grid_loc, var)
plot_parsed_attribute_title!(grid_loc, var)
Helper function for `make_plots_generic`. Plots a variable with a custom title.
Helper function for `make_plots_generic`. Plots an OutputVar `var`,
setting the axis title to `parse_var_attributes(var)`
"""
plot_custom_title!(grid_loc, var) = viz.plot!(
plot_parsed_attribute_title!(grid_loc, var) = viz.plot!(
grid_loc,
var;
more_kwargs = Dict(:axis => ca_kwargs(title = var_info(var))),
more_kwargs = Dict(:axis => ca_kwargs(title = parse_var_attributes(var))),
)

"""
Expand All @@ -665,12 +685,12 @@ Groupings are matched via variable short name, location, and time (if applicable
"""
function group_edmf_vars(vars)
grouped_vars = OrderedDict{String, Vector{ClimaAnalysis.OutputVar}}()
for var in sort(vars, by = var_info)
suffix = var_info(var)
if haskey(grouped_vars, suffix)
push!(grouped_vars[suffix], var)
for var in sort(vars, by = parse_var_attributes)
info = parse_var_attributes(var)
if haskey(grouped_vars, info)
push!(grouped_vars[info], var)
else
grouped_vars[suffix] = [var]
grouped_vars[info] = [var]
end
end
return grouped_vars
Expand Down Expand Up @@ -723,12 +743,11 @@ function make_plots(::EDMFBoxPlots, simulation_path)
make_plots_generic(
simulation_path,
vars_zt,
plot_fn = plot_custom_title!,
plot_fn = plot_parsed_attribute_title!,
summary_files = [tmp_file],
MAX_NUM_COLS = 2,
MAX_NUM_ROWS = 4,
)

end

EDMFSpherePlots =
Expand Down Expand Up @@ -763,7 +782,7 @@ function make_plots(::EDMFSpherePlots, simulation_path)
make_plots_generic(
simulation_path,
vars_zt,
plot_fn = plot_custom_title!,
plot_fn = plot_parsed_attribute_title!,
summary_files = [tmp_file],
MAX_NUM_COLS = 2,
MAX_NUM_ROWS = 4,
Expand Down

0 comments on commit 5a156ed

Please sign in to comment.