diff --git a/experiments/AMIP/coupler_driver.jl b/experiments/AMIP/coupler_driver.jl index fc0b75bf4..f6ee47e17 100644 --- a/experiments/AMIP/coupler_driver.jl +++ b/experiments/AMIP/coupler_driver.jl @@ -860,8 +860,18 @@ if ClimaComms.iamroot(comms_ctx) @info "Error against observations" include("user_io/leaderboard.jl") compare_vars = ["pr"] - output_path = joinpath(COUPLER_ARTIFACTS_DIR, "biases.png") - Leaderboard.plot_biases(atmos_sim.integrator.p.output_dir, compare_vars, cs.dates.date; output_path) + function plot_biases(dates, output_name) + output_path = joinpath(COUPLER_ARTIFACTS_DIR, "bias_$(output_name).png") + Leaderboard.plot_biases(atmos_sim.integrator.p.output_dir, compare_vars, dates; output_path) + end + plot_biases(cs.dates.date, "total") + + MAM, JJA, SON, DJF = Leaderboard.split_by_season(cs.dates.date) + + !isempty(MAM) && plot_biases(cs.dates.date, "MAM") + !isempty(JJA) && plot_biases(cs.dates.date, "JJA") + !isempty(SON) && plot_biases(cs.dates.date, "SON") + !isempty(DJF) && plot_biases(cs.dates.date, "DJF") end end diff --git a/experiments/AMIP/user_io/leaderboard/utils.jl b/experiments/AMIP/user_io/leaderboard/utils.jl index 686cd70e4..fbefa52b4 100644 --- a/experiments/AMIP/user_io/leaderboard/utils.jl +++ b/experiments/AMIP/user_io/leaderboard/utils.jl @@ -203,3 +203,27 @@ function find_and_resample( return resample(data_arr, (lon_arr, lat_arr), dest_lonlat) end + +""" + split_by_season(dates::AbstractArray{<: Dates.DateTime}) + +Take an array of dates and return 4 split into seasons. +""" +function split_by_season(dates::AbstractArray{<:Dates.DateTime}) + MAM, JJA, SON, DJF = + Vector{Dates.DateTime}(), Vector{Dates.DateTime}(), Vector{Dates.DateTime}(), Vector{Dates.DateTime}() + + for date in dates + if Dates.Month(3) <= Dates.Month(date) <= Dates.Month(5) + push!(MAM, date) + elseif Dates.Month(6) <= Dates.Month(date) <= Dates.Month(8) + push!(JJA, date) + elseif Dates.Month(9) <= Dates.Month(date) <= Dates.Month(11) + push!(SON, date) + else + push!(DJF, date) + end + end + + return (MAM, JJA, SON, DJF) +end diff --git a/test/experiment_tests/leaderboard.jl b/test/experiment_tests/leaderboard.jl index 808981e1d..6ab669f4e 100644 --- a/test/experiment_tests/leaderboard.jl +++ b/test/experiment_tests/leaderboard.jl @@ -30,6 +30,24 @@ include(joinpath(pkgdir(ClimaCoupler), "artifacts", "artifact_funcs.jl")) @test_throws ErrorException Leaderboard.bias([1], [2, 3], ([1], [2])) @test_throws ErrorException Leaderboard.bias([1, 2], [2, 3, 4], ([1], [2])) + + dates = [ + Dates.DateTime(2015, 1, 13), + Dates.DateTime(2018, 2, 13), + Dates.DateTime(1981, 7, 6), + Dates.DateTime(1993, 11, 19), + Dates.DateTime(2040, 4, 1), + Dates.DateTime(2000, 8, 18), + ] + + expected_dates = ( + [Dates.DateTime(2040, 4, 1)], + [Dates.DateTime(1981, 7, 6), Dates.DateTime(2000, 8, 18)], + [Dates.DateTime(1993, 11, 19)], + [Dates.DateTime(2015, 1, 13), Dates.DateTime(2018, 2, 13)], + ) + + @test Leaderboard.split_by_season(dates) == expected_dates end @testset "Leaderboard" begin