-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a new file, experiments/ClimaEarth/user_io/postprocessing.jl, which contains the `postprocess_sim` function. This function copies the if statements previously at the end of run_amip.jl, but it uses dispatch for the simulation mode.
- Loading branch information
1 parent
22fe7b7
commit fed5e27
Showing
3 changed files
with
138 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
## helpers for user-specified IO | ||
include("debug_plots.jl") | ||
include("diagnostics_plots.jl") | ||
|
||
""" | ||
postprocess_sim(mode_type::AbstractSlabPlanetModeType, cs, postprocessing_vars) | ||
If they exist, perform conservation checks, for any slabplanet simulation, and then call | ||
`common_postprocessing` to perform common postprocessing tasks that are common to all simulation types. | ||
""" | ||
function postprocess_sim(mode_type::AbstractSlabPlanetModeType, cs, postprocessing_vars) | ||
(; | ||
dir_paths, | ||
plot_diagnostics, | ||
use_coupler_diagnostics, | ||
output_default_diagnostics, | ||
t_end, | ||
conservation_softfail, | ||
atmos_output_dir, | ||
amip_diags_handler, | ||
comms_ctx, | ||
) = postprocessing_vars | ||
|
||
if !isnothing(cs.conservation_checks) | ||
@info "Conservation Check Plots" | ||
plot_global_conservation( | ||
cs.conservation_checks.energy, | ||
cs, | ||
conservation_softfail, | ||
figname1 = joinpath(dir_paths.artifacts, "total_energy_bucket.png"), | ||
figname2 = joinpath(dir_paths.artifacts, "total_energy_log_bucket.png"), | ||
) | ||
plot_global_conservation( | ||
cs.conservation_checks.water, | ||
cs, | ||
conservation_softfail, | ||
figname1 = joinpath(dir_paths.artifacts, "total_water_bucket.png"), | ||
figname2 = joinpath(dir_paths.artifacts, "total_water_log_bucket.png"), | ||
) | ||
end | ||
common_postprocessing(cs, postprocessing_vars) | ||
end | ||
|
||
""" | ||
postprocess_sim(mode_type::AMIP_mode, cs, postprocessing_vars) | ||
Conditionally plot AMIP diagnostics and call `common_postprocessing` to perform | ||
postprocessing tasks that are common to all simulation types. | ||
""" | ||
function postprocess_sim(mode_type::AMIP_mode, cs, postprocessing_vars) | ||
(; | ||
dir_paths, | ||
plot_diagnostics, | ||
use_coupler_diagnostics, | ||
output_default_diagnostics, | ||
t_end, | ||
conservation_softfail, | ||
atmos_output_dir, | ||
amip_diags_handler, | ||
comms_ctx, | ||
) = postprocessing_vars | ||
|
||
if use_coupler_diagnostics | ||
## plot data that correspond to the model's last save_hdf5 call (i.e., last month) | ||
@info "AMIP plots" | ||
|
||
## ClimaESM | ||
include("user_io/diagnostics_plots.jl") | ||
|
||
# define variable names and output directories for each diagnostic | ||
amip_short_names_atmos = ["ta", "ua", "hus", "clw", "pr", "ts", "toa_fluxes_net"] | ||
amip_short_names_coupler = ["F_turb_energy"] | ||
output_dir_coupler = dir_paths.output | ||
|
||
# Check if all output variables are available in the specified directories | ||
make_diagnostics_plots( | ||
atmos_output_dir, | ||
dir_paths.artifacts, | ||
short_names = amip_short_names_atmos, | ||
output_prefix = "atmos_", | ||
) | ||
make_diagnostics_plots( | ||
output_dir_coupler, | ||
dir_paths.artifacts, | ||
short_names = amip_short_names_coupler, | ||
output_prefix = "coupler_", | ||
) | ||
end | ||
|
||
# Check this because we only want monthly data for making plots | ||
if t_end > 84600 * 31 * 3 && output_default_diagnostics | ||
include("leaderboard/leaderboard.jl") | ||
leaderboard_base_path = dir_paths.artifacts | ||
compute_leaderboard(leaderboard_base_path, atmos_output_dir) | ||
compute_pfull_leaderboard(leaderboard_base_path, atmos_output_dir) | ||
end | ||
common_postprocessing(cs, postprocessing_vars) | ||
end | ||
|
||
""" | ||
common_postprocessing(cs, postprocessing_vars) | ||
Perfrom postprocessing common to all simulation types. | ||
""" | ||
function common_postprocessing(cs, postprocessing_vars) | ||
(; plot_diagnostics, comms_ctx, dir_paths, amip_diags_handler, atmos_output_dir) = postprocessing_vars | ||
if plot_diagnostics | ||
@info "Plotting diagnostics" | ||
include("user_io/diagnostics_plots.jl") | ||
make_diagnostics_plots(atmos_output_dir, dir_paths.artifacts) | ||
end | ||
|
||
## plot all model states and coupler fields (useful for debugging) | ||
!CA.is_distributed(comms_ctx) && debug(cs, dir_paths.artifacts) | ||
|
||
# if isinteractive() #hide | ||
# ## clean up for interactive runs, retain all output otherwise #hide | ||
# rm(dir_paths.output; recursive = true, force = true) #hide | ||
# end #hide | ||
|
||
## close all AMIP diagnostics file writers | ||
!isnothing(amip_diags_handler) && map(diag -> close(diag.output_writer), amip_diags_handler.scheduled_diagnostics) | ||
end |