Skip to content

Commit

Permalink
Update ClimaAnalysis, working contour plot grids
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici committed Feb 1, 2024
1 parent a6a8ca3 commit 153a7da
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions post_processing/ci_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function make_plots_generic(
# Default plotting function needs access to kwargs
if isnothing(plot_fn)
plot_fn =
(fig, p_loc, var) -> viz.plot!(fig, var, args...; p_loc, kwargs...)
(grid_loc, var) -> viz.plot!(grid_loc, var, args...; kwargs...)
end

MAX_PLOTS_PER_PAGE = MAX_NUM_ROWS * MAX_NUM_COLS
Expand All @@ -89,8 +89,7 @@ function make_plots_generic(
map(1:MAX_PLOTS_PER_PAGE) do i
row = mod(div(i - 1, MAX_NUM_COLS), MAX_NUM_ROWS) + 1
col = mod(i - 1, MAX_NUM_COLS) + 1
fig[row, col] = CairoMakie.GridLayout()
return [row, col]
return fig[row, col] = CairoMakie.GridLayout()
end

fig = makefig()
Expand All @@ -99,14 +98,13 @@ function make_plots_generic(
grid_pos = 1

for var in vars
# Create a new page if this is the first plot
if grid_pos > MAX_PLOTS_PER_PAGE
fig = makefig()
grid = gridlayout()
grid_pos = 1
end

plot_fn(fig, grid[grid_pos], var)
plot_fn(grid[grid_pos], var)
grid_pos += 1

# Flush current page
Expand Down Expand Up @@ -625,19 +623,19 @@ EDMFBoxPlots = Union{
}

"""
plot_edmf_vert_profile(fig, p_loc, var_group)
plot_edmf_vert_profile!(fig, p_loc, var_group)
Helper function for `make_plots_generic`. Takes a list of variables and plots
them on the same axis.
"""
function plot_edmf_vert_profile(fig, p_loc, var_group)
function plot_edmf_vert_profile!(grid_loc, var_group)
z = var_group[1].dims["z"]
units = var_group[1].attributes["units"]

ax = CairoMakie.Axis(
fig[p_loc...],
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])
)

for var in var_group
Expand All @@ -654,11 +652,9 @@ This is fairly brittle - it just checks that the long name starts with "Updraft"
and matches on the rest of the long name.
"""
function group_edmf_vars(vars)
get_longname_suffix(v) =
startswith(long_name(v), "Updraft") ? long_name(v)[9:end] : long_name(v)
grouped_vars = OrderedDict{String, Vector{ClimaAnalysis.OutputVar}}()
for var in sort(vars, by = get_longname_suffix)
suffix = get_longname_suffix(var)
for var in sort(vars, by = short_var_info)
suffix = short_var_info(var)
if haskey(grouped_vars, suffix)
push!(grouped_vars[suffix], var)
else
Expand All @@ -668,6 +664,18 @@ function group_edmf_vars(vars)
return grouped_vars
end

function short_var_info(var)
attr = var.attributes
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], ", ")
end

function make_plots(::EDMFBoxPlots, simulation_path)
simdir = SimDir(simulation_path)

Expand Down Expand Up @@ -707,12 +715,18 @@ function make_plots(::EDMFBoxPlots, simulation_path)
simulation_path,
output_name = "tmp",
values(grouped_vars);
plot_fn = plot_edmf_vert_profile,
plot_fn = plot_edmf_vert_profile!,
MAX_NUM_COLS = 2,
MAX_NUM_ROWS = 4,
)

make_plots_generic(simulation_path, vars_zt, summary_files = [tmp_file])
make_plots_generic(
simulation_path,
vars_zt,
summary_files = [tmp_file],
MAX_NUM_COLS = 2,
MAX_NUM_ROWS = 4,
)

end

Expand All @@ -737,10 +751,17 @@ function make_plots(::EDMFSpherePlots, simulation_path)
simulation_path,
output_name = "tmp",
values(grouped_vars);
plot_fn = plot_edmf_vert_profile,
plot_fn = plot_edmf_vert_profile!,
MAX_NUM_COLS = 2,
MAX_NUM_ROWS = 4,
)

make_plots_generic(simulation_path, vars_zt, summary_files = [tmp_file])
make_plots_generic(
simulation_path,
vars_zt,
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 153a7da

Please sign in to comment.