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 Jan 30, 2024
1 parent 0b13664 commit b176ddc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
6 changes: 3 additions & 3 deletions examples/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.0"
manifest_format = "2.0"
project_hash = "9f81176e38b8045a54f2ad5c8891f255e16c2488"
project_hash = "1efea2db8dbdf443c1c46cf2bc43d6ed80120b5a"

[[deps.ADTypes]]
git-tree-sha1 = "41c37aa88889c171f1300ceac1313c06e891d245"
Expand Down Expand Up @@ -284,9 +284,9 @@ weakdeps = ["SparseArrays"]

[[deps.ClimaAnalysis]]
deps = ["NCDatasets", "OrderedCollections", "Statistics"]
git-tree-sha1 = "b49f7ecb3b41723e880617ad9404c8bfb4bb1fd0"
git-tree-sha1 = "a5bb4e6dad37480b65ad1575de9496d02dc9aad6"
uuid = "29b5916a-a76c-4e73-9657-3c8fd22e65e6"
version = "0.2.1"
version = "0.3.0"
weakdeps = ["CairoMakie"]

[deps.ClimaAnalysis.extensions]
Expand Down
1 change: 0 additions & 1 deletion examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
[compat]
BlockArrays = "0.16"
CairoMakie = "0.10, 0.11"
ClimaAnalysis = "0.2.1"
ClimaCoreMakie = "0.3, 0.4"
ClimaCorePlots = "0.2"
ClimaCoreSpectra = "0.1"
Expand Down
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 @@ -609,19 +607,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 @@ -638,11 +636,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 @@ -652,6 +648,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 @@ -691,12 +699,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 Down Expand Up @@ -724,10 +738,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 b176ddc

Please sign in to comment.