Skip to content

Commit

Permalink
add surface radiative fluxes to leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
szy21 committed Sep 9, 2024
1 parent e078085 commit f7d1a6d
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 52 deletions.
105 changes: 59 additions & 46 deletions experiments/ClimaEarth/run_amip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -906,70 +906,83 @@ if ClimaComms.iamroot(comms_ctx)
include("user_io/leaderboard.jl")
ClimaAnalysis = Leaderboard.ClimaAnalysis

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

compare_vars_biases_plot_extrema = Dict(
"pr" => (-5.0, 5.0),
"rsdt" => (-2.0, 2.0),
"rsut" => (-50.0, 50.0),
"rlut" => (-50.0, 50.0),
"rsdt" => (-2.0, 2.0),
"rsutcs" => (-20.0, 20.0),
"rlutcs" => (-20.0, 20.0),
"rsds" => (-50.0, 50.0),
"rsus" => (-10.0, 10.0),
"rlds" => (-50.0, 50.0),
"rlus" => (-50.0, 50.0),
"rsdscs" => (-10.0, 10.0),
"rsuscs" => (-10.0, 10.0),
"rldscs" => (-20.0, 20.0),
)

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

first_var = get(ClimaAnalysis.SimDir(diagnostics_folder_path), short_name = first(compare_vars_biases))

diagnostics_times = ClimaAnalysis.times(first_var)
# Remove the first `spinup_months` months from the leaderboard
spinup_months = 6
# The monthly average output is at the end of the month, so this is safe
spinup_cutoff = spinup_months * 31 * 86400.0
if diagnostics_times[end] > spinup_cutoff
filter!(x -> x > spinup_cutoff, diagnostics_times)
end
compare_vars_biases_groups = [
["pr", "rsdt", "rsut", "rlut"],
["rsds", "rsus", "rlds", "rlus"],
["rsutcs", "rlutcs", "rsdscs", "rsuscs", "rldscs"],
]
for compare_vars_biases in compare_vars_biases_groups

first_var = get(ClimaAnalysis.SimDir(diagnostics_folder_path), short_name = first(compare_vars_biases))

diagnostics_times = ClimaAnalysis.times(first_var)
# Remove the first `spinup_months` months from the leaderboard
spinup_months = 6
# The monthly average output is at the end of the month, so this is safe
spinup_cutoff = spinup_months * 31 * 86400.0
if diagnostics_times[end] > spinup_cutoff
filter!(x -> x > spinup_cutoff, diagnostics_times)
end

output_dates = Dates.DateTime(first_var.attributes["start_date"]) .+ Dates.Second.(diagnostics_times)

@info "Working with dates:"
@info output_dates

function compute_biases(dates)
if isempty(dates)
return map(x -> 0.0, compare_vars_biases)
else
return Leaderboard.compute_biases(
diagnostics_folder_path,
compare_vars_biases,
dates,
cmap_extrema = compare_vars_biases_plot_extrema,
)
output_dates = Dates.DateTime(first_var.attributes["start_date"]) .+ Dates.Second.(diagnostics_times)

@info "Working with dates:"
@info output_dates

function compute_biases(dates)
if isempty(dates)
return map(x -> 0.0, compare_vars_biases)
else
return Leaderboard.compute_biases(
diagnostics_folder_path,
compare_vars_biases,
dates,
cmap_extrema = compare_vars_biases_plot_extrema,
)
end
end
end

function plot_biases(dates, biases, output_name)
isempty(dates) && return nothing
function plot_biases(dates, biases, output_name)
isempty(dates) && return nothing

output_path = joinpath(leaderboard_base_path, "bias_$(output_name).png")
Leaderboard.plot_biases(biases; output_path)
end
output_path = joinpath(leaderboard_base_path, "bias_$(output_name).png")
Leaderboard.plot_biases(biases; output_path)
end

ann_biases = compute_biases(output_dates)
plot_biases(output_dates, ann_biases, "total")
ann_biases = compute_biases(output_dates)
plot_biases(output_dates, ann_biases, first(compare_vars_biases) * "_total")

## collect all days between cs.dates.date0 and cs.dates.date
MAM, JJA, SON, DJF = Leaderboard.split_by_season(output_dates)
## collect all days between cs.dates.date0 and cs.dates.date
MAM, JJA, SON, DJF = Leaderboard.split_by_season(output_dates)

MAM_biases = compute_biases(MAM)
plot_biases(MAM, MAM_biases, "MAM")
JJA_biases = compute_biases(JJA)
plot_biases(JJA, JJA_biases, "JJA")
SON_biases = compute_biases(SON)
plot_biases(SON, SON_biases, "SON")
DJF_biases = compute_biases(DJF)
plot_biases(DJF, DJF_biases, "DJF")
MAM_biases = compute_biases(MAM)
plot_biases(MAM, MAM_biases, first(compare_vars_biases) * "_MAM")
JJA_biases = compute_biases(JJA)
plot_biases(JJA, JJA_biases, first(compare_vars_biases) * "_JJA")
SON_biases = compute_biases(SON)
plot_biases(SON, SON_biases, first(compare_vars_biases) * "_SON")
DJF_biases = compute_biases(DJF)
plot_biases(DJF, DJF_biases, first(compare_vars_biases) * "_DJF")
end

compare_vars_rmses = ["pr", "rsut", "rlut"]

Expand Down
54 changes: 48 additions & 6 deletions experiments/ClimaEarth/user_io/leaderboard/compare_with_obs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,66 @@ OBS_DS["rlut"] = ObsDataSource(;
SIM_DS_KWARGS["rlut"] = (;)
OTHER_MODELS_RMSEs["rlut"] = []

OBS_DS["rsutcs"] = ObsDataSource(;
path = joinpath(@clima_artifact("radiation_obs"), "CERES_EBAF_Ed4.2_Subset_200003-201910.nc"),
var_name = "toa_sw_clr_t_mon",
)
SIM_DS_KWARGS["rsutcs"] = (;)

OBS_DS["rsdt"] = ObsDataSource(;
path = joinpath(@clima_artifact("radiation_obs"), "CERES_EBAF_Ed4.2_Subset_200003-201910.nc"),
var_name = "solar_mon",
)
SIM_DS_KWARGS["rsdt"] = (;)

OBS_DS["rsutcs"] = ObsDataSource(;
path = joinpath(@clima_artifact("radiation_obs"), "CERES_EBAF_Ed4.2_Subset_200003-201910.nc"),
var_name = "toa_sw_clr_t_mon",
)
SIM_DS_KWARGS["rsutcs"] = (;)

OBS_DS["rlutcs"] = ObsDataSource(;
path = joinpath(@clima_artifact("radiation_obs"), "CERES_EBAF_Ed4.2_Subset_200003-201910.nc"),
var_name = "toa_lw_clr_t_mon",
)
SIM_DS_KWARGS["rlutcs"] = (;)

OBS_DS["rsus"] = ObsDataSource(;
path = joinpath(@clima_artifact("radiation_obs"), "CERES_EBAF_Ed4.2_Subset_200003-201910.nc"),
var_name = "sfc_sw_up_all_mon",
)
SIM_DS_KWARGS["rsus"] = (;)

OBS_DS["rsds"] = ObsDataSource(;
path = joinpath(@clima_artifact("radiation_obs"), "CERES_EBAF_Ed4.2_Subset_200003-201910.nc"),
var_name = "sfc_sw_down_all_mon",
)
SIM_DS_KWARGS["rsds"] = (;)

OBS_DS["rlus"] = ObsDataSource(;
path = joinpath(@clima_artifact("radiation_obs"), "CERES_EBAF_Ed4.2_Subset_200003-201910.nc"),
var_name = "sfc_lw_up_all_mon",
)
SIM_DS_KWARGS["rlus"] = (;)

OBS_DS["rlds"] = ObsDataSource(;
path = joinpath(@clima_artifact("radiation_obs"), "CERES_EBAF_Ed4.2_Subset_200003-201910.nc"),
var_name = "sfc_lw_down_all_mon",
)
SIM_DS_KWARGS["rlds"] = (;)

OBS_DS["rsdscs"] = ObsDataSource(;
path = joinpath(@clima_artifact("radiation_obs"), "CERES_EBAF_Ed4.2_Subset_200003-201910.nc"),
var_name = "sfc_sw_down_clr_t_mon",
)
SIM_DS_KWARGS["rsdscs"] = (;)

OBS_DS["rsuscs"] = ObsDataSource(;
path = joinpath(@clima_artifact("radiation_obs"), "CERES_EBAF_Ed4.2_Subset_200003-201910.nc"),
var_name = "sfc_sw_up_clr_t_mon",
)
SIM_DS_KWARGS["rsuscs"] = (;)

OBS_DS["rldscs"] = ObsDataSource(;
path = joinpath(@clima_artifact("radiation_obs"), "CERES_EBAF_Ed4.2_Subset_200003-201910.nc"),
var_name = "sfc_lw_down_clr_t_mon",
)
SIM_DS_KWARGS["rldscs"] = (;)

include("cmip_rmse.jl")

function bias(output_dir::AbstractString, short_name::AbstractString, target_dates::AbstractArray{<:Dates.DateTime})
Expand Down

0 comments on commit f7d1a6d

Please sign in to comment.