Skip to content

Commit

Permalink
Add support for plotting limits in leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Sbozzolo committed Aug 7, 2024
1 parent 4c999b1 commit 526b750
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 9 additions & 1 deletion experiments/ClimaEarth/run_amip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,9 @@ if ClimaComms.iamroot(comms_ctx)
ClimaAnalysis = Leaderboard.ClimaAnalysis

compare_vars_biases = ["pr", "rsut", "rlut", "rsutcs", "rlutcs"]

compare_vars_biases_plot_extrema = Dict("pr" => (-5.0, 10.0))

diagnostics_folder_path = atmos_sim.integrator.p.output_dir
leaderboard_base_path = dir_paths.artifacts

Expand All @@ -982,7 +985,12 @@ if ClimaComms.iamroot(comms_ctx)
if isempty(dates)
return map(x -> 0.0, compare_vars_biases)
else
return Leaderboard.compute_biases(diagnostics_folder_path, compare_vars_biases, dates)
return Leaderboard.compute_biases(
diagnostics_folder_path,
compare_vars_biases,
dates,
cmap_extrema = compare_vars_biases_plot_extrema,
)
end
end

Expand Down
15 changes: 11 additions & 4 deletions experiments/ClimaEarth/user_io/leaderboard/compare_with_obs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ function bias(output_dir::AbstractString, short_name::AbstractString, target_dat
return bias(obs, sim, target_dates)
end

function compute_biases(output_dir, short_names, target_dates::AbstractArray{<:Dates.DateTime})
return map(name -> bias(output_dir, name, target_dates), short_names)
function compute_biases(output_dir, short_names, target_dates::AbstractArray{<:Dates.DateTime}; cmap_extrema = Dict())
return map(short_names) do name
bias_outvar = bias(output_dir, name, target_dates)
# The attribute is used in plot_bias to fix the colormap
haskey(cmap_extrema, name) && (bias_outvar.attributes["cmap_extrema"] = cmap_extrema[name])
return bias_outvar
end
end


Expand Down Expand Up @@ -128,11 +133,13 @@ function plot_biases(biases; output_path)
loc = 1

for bias_var in biases
min_level, max_level = get(bias_var.attributes, "cmap_extrema", extrema(bias_var.data))

# Make sure that 0 is at the center
cmap = constrained_cmap(CairoMakie.cgrad(:vik).colors, extrema(bias_var.data)...; categorical = true)
cmap = constrained_cmap(CairoMakie.cgrad(:vik).colors, min_level, max_level; categorical = true)
nlevels = 10
# Offset so that it covers 0
levels = collect(range(minimum(bias_var.data), maximum(bias_var.data), length = nlevels))
levels = collect(range(min_level, max_level, length = nlevels))
offset = levels[argmin(abs.(levels))]
levels = levels .- offset
ticklabels = map(x -> string(round(x; digits = 0)), levels)
Expand Down

0 comments on commit 526b750

Please sign in to comment.