Skip to content

Commit

Permalink
Plot custom title
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici committed Jan 30, 2024
1 parent b176ddc commit 819ec7f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
1 change: 1 addition & 0 deletions examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
[compat]
BlockArrays = "0.16"
CairoMakie = "0.10, 0.11"
ClimaAnalysis = "0.3"
ClimaCoreMakie = "0.3, 0.4"
ClimaCorePlots = "0.2"
ClimaCoreSpectra = "0.1"
Expand Down
43 changes: 30 additions & 13 deletions post_processing/ci_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ EDMFBoxPlots = Union{
}

"""
plot_edmf_vert_profile!(fig, p_loc, var_group)
plot_edmf_vert_profile!(grid_loc, var_group)
Helper function for `make_plots_generic`. Takes a list of variables and plots
them on the same axis.
Expand All @@ -616,10 +616,10 @@ function plot_edmf_vert_profile!(grid_loc, var_group)
z = var_group[1].dims["z"]
units = var_group[1].attributes["units"]
ax = CairoMakie.Axis(
grid_loc[1,1],
grid_loc[1, 1],
ylabel = "z [$(var_group[1].dim_attributes["z"]["units"])]",
xlabel = "$(short_name(var_group[1])) [$units]",
title = short_var_info(var_group[1])
title = var_info(var_group[1]),
)

for var in var_group
Expand All @@ -628,17 +628,28 @@ function plot_edmf_vert_profile!(grid_loc, var_group)
length(var_group) > 1 && Makie.axislegend(ax)
end


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

"""
group_edmf_vars(vars)
Groups pairs of updraft and gridmean EDMF OutputVars into a Dict.
This is fairly brittle - it just checks that the long name starts with "Updraft"
and matches on the rest of the long name.
Groups updraft and gridmean EDMF OutputVars into a Dict.
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 = short_var_info)
suffix = short_var_info(var)
for var in sort(vars, by = var_info)
suffix = var_info(var)
if haskey(grouped_vars, suffix)
push!(grouped_vars[suffix], var)
else
Expand All @@ -648,16 +659,21 @@ function group_edmf_vars(vars)
return grouped_vars
end

function short_var_info(var)
function var_info(var)
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
name = replace(short_name(var), "up" => "")
time = "t = " * attr["slice_time"]
return join([name, coords, time], ", ")
var_info = [name, coords]

time = get(attr, "slice_time", nothing)
isnothing(time) || push!(var_info, "t = $(time)s")

return join(var_info, ", ")
end

function make_plots(::EDMFBoxPlots, simulation_path)
Expand Down Expand Up @@ -707,6 +723,7 @@ function make_plots(::EDMFBoxPlots, simulation_path)
make_plots_generic(
simulation_path,
vars_zt,
plot_fn = plot_custom_title!,
summary_files = [tmp_file],
MAX_NUM_COLS = 2,
MAX_NUM_ROWS = 4,
Expand Down Expand Up @@ -746,9 +763,9 @@ function make_plots(::EDMFSpherePlots, simulation_path)
make_plots_generic(
simulation_path,
vars_zt,
plot_fn = plot_custom_title!,
summary_files = [tmp_file],
MAX_NUM_COLS = 2,
MAX_NUM_ROWS = 4,
more_kwargs = Dict(:axis => ca_kwargs(title = var -> var.attributes["short_name"]))
)
end

0 comments on commit 819ec7f

Please sign in to comment.