Skip to content

Commit

Permalink
Switch to actual monthly means
Browse files Browse the repository at this point in the history
ClimaDiagnostics 0.2.4 introduces a new schedule to use actual months
when computing reductions. This commit switches to using that when
monthly reducitons are requested.
  • Loading branch information
Sbozzolo committed Aug 19, 2024
1 parent b360b0b commit a4f4989
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 293 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CSV = "0.10"
CUDA = "5.3"
ClimaComms = "0.5.6, 0.6"
ClimaCore = "0.13.2, 0.14"
ClimaDiagnostics = "0.2"
ClimaDiagnostics = "0.2.4"
ClimaParams = "0.10.2"
ClimaUtilities = "0.1.2"
DataFrames = "1"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/diagnostics/users_diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ providing the space and output_dir defined in steps 1. and 2.
Now that you defined your model and your writter, you can create a callback function to be called when solving your model. For example:

```
diags = ClimaLand.default_diagnostics(model, 1.0; output_writer = nc_writer)
diags = ClimaLand.default_diagnostics(model, 1.0, reference_date; output_writer = nc_writer)
diagnostic_handler =
ClimaDiagnostics.DiagnosticsHandler(diags, Y, p, t0; dt = Δt)
Expand Down
3 changes: 2 additions & 1 deletion experiments/integrated/global/global_soil_canopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ nc_writer = ClimaDiagnostics.Writers.NetCDFWriter(subsurface_space, output_dir)

diags = ClimaLand.default_diagnostics(
land,
t0;
t0,
ref_time;
output_writer = nc_writer,
average_period = :hourly,
)
Expand Down
3 changes: 2 additions & 1 deletion experiments/long_runs/land.jl
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,8 @@ function setup_prob(t0, tf, Δt; outdir = outdir, nelements = (101, 15))

diags = ClimaLand.default_diagnostics(
land,
t0;
t0,
ref_time;
output_writer = nc_writer,
output_vars = :long,
)
Expand Down
7 changes: 6 additions & 1 deletion experiments/long_runs/soil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,12 @@ function setup_prob(t0, tf, Δt; outdir = outdir, nelements = (101, 15))

nc_writer = ClimaDiagnostics.Writers.NetCDFWriter(subsurface_space, outdir)

diags = ClimaLand.default_diagnostics(soil, t0; output_writer = nc_writer)
diags = ClimaLand.default_diagnostics(
soil,
t0,
ref_time;
output_writer = nc_writer,
)

diagnostic_handler =
ClimaDiagnostics.DiagnosticsHandler(diags, Y, p, t0; dt = Δt)
Expand Down
7 changes: 6 additions & 1 deletion experiments/standalone/Bucket/global_bucket_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ space = bucket_domain.space.subsurface

nc_writer = ClimaDiagnostics.Writers.NetCDFWriter(space, output_dir)

diags = ClimaLand.default_diagnostics(model, t0; output_writer = nc_writer)
diags = ClimaLand.default_diagnostics(
model,
t0,
ref_time;
output_writer = nc_writer,
)

diagnostic_handler =
ClimaDiagnostics.DiagnosticsHandler(diags, Y, p, t0; dt = Δt)
Expand Down
5 changes: 4 additions & 1 deletion src/diagnostics/Diagnostics.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Diagnostics

import Dates: Month, Period

import ClimaComms

using ..Bucket: BucketModel
Expand All @@ -13,7 +15,8 @@ import ..Domains: top_center_to_surface
import ClimaDiagnostics:
DiagnosticVariable, ScheduledDiagnostic, average_pre_output_hook!

import ClimaDiagnostics.Schedules: EveryStepSchedule, EveryDtSchedule
import ClimaDiagnostics.Schedules:
EveryStepSchedule, EveryDtSchedule, EveryCalendarDtSchedule

import ClimaDiagnostics.Writers: HDF5Writer, NetCDFWriter

Expand Down
84 changes: 60 additions & 24 deletions src/diagnostics/default_diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default_diagnostics
reduction,
output_writer,
t_start,
reference_date,
short_names...;
pre_output_hook! = nothing,
)
Expand All @@ -26,25 +27,37 @@ function common_diagnostics(
reduction,
output_writer,
t_start,
reference_date,
short_names...;
pre_output_hook! = nothing,
)
return [
ScheduledDiagnostic(
variable = get_diagnostic_variable(short_name),
compute_schedule_func = EveryStepSchedule(),
output_schedule_func = EveryDtSchedule(period; t_start),
reduction_time_func = reduction,
output_writer = output_writer,
pre_output_hook! = pre_output_hook!,
) for short_name in short_names
]
return vcat(
map(short_names) do short_name
output_schedule_func =
period isa Period ?
EveryCalendarDtSchedule(period; t_start, reference_date) :
EveryDtSchedule(period; t_start)
return ScheduledDiagnostic(
variable = get_diagnostic_variable(short_name),
compute_schedule_func = EveryStepSchedule(),
output_schedule_func = output_schedule_func,
reduction_time_func = reduction,
output_writer = output_writer,
pre_output_hook! = pre_output_hook!,
)
end...,
)
end

include("standard_diagnostic_frequencies.jl")

# Bucket
function default_diagnostics(land_model::BucketModel, t_start; output_writer)
function default_diagnostics(
land_model::BucketModel,
t_start,
reference_date;
output_writer,
)

define_diagnostics!(land_model)

Expand All @@ -64,15 +77,21 @@ function default_diagnostics(land_model::BucketModel, t_start; output_writer)
"ssfc",
]

default_outputs =
hourly_averages(bucket_diagnostics...; output_writer, t_start)
default_outputs = hourly_averages(
bucket_diagnostics...;
output_writer,
t_start,
reference_date,
)

return [default_outputs...]
end

# SoilCanopyModel
function default_diagnostics(
land_model::SoilCanopyModel,
t_start;
t_start,
reference_date;
output_writer,
output_vars = :long,
average_period = :daily,
Expand Down Expand Up @@ -143,14 +162,26 @@ function default_diagnostics(
end

if average_period == :hourly
default_outputs =
hourly_averages(soilcanopy_diagnostics...; output_writer, t_start)
default_outputs = hourly_averages(
soilcanopy_diagnostics...;
output_writer,
t_start,
reference_date,
)
elseif average_period == :daily
default_outputs =
daily_averages(soilcanopy_diagnostics...; output_writer, t_start)
elseif average_period == :monthly # !! this is currently 30 days, not exact month
default_outputs =
monthly_averages(soilcanopy_diagnostics...; output_writer, t_start)
default_outputs = daily_averages(
soilcanopy_diagnostics...;
output_writer,
t_start,
reference_date,
)
elseif average_period == :monthly
default_outputs = monthly_averages(
soilcanopy_diagnostics...;
output_writer,
t_start,
reference_date,
)
end

return [default_outputs...]
Expand All @@ -160,15 +191,20 @@ end
# SoilModel
function default_diagnostics(
land_model::EnergyHydrology,
t_start;
t_start,
reference_date;
output_writer,
)

define_diagnostics!(land_model)

soil_diagnostics = ["swc", "si", "sie"]

default_outputs =
daily_averages(soil_diagnostics...; output_writer, t_start)
default_outputs = daily_averages(
soil_diagnostics...;
output_writer,
t_start,
reference_date,
)
return [default_outputs...]
end
Loading

0 comments on commit a4f4989

Please sign in to comment.