Skip to content

Commit

Permalink
Clean up daily/hourly functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sbozzolo committed Sep 11, 2023
1 parent 748ec47 commit 0d4ced6
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 38 deletions.
102 changes: 82 additions & 20 deletions src/diagnostics/default_diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,71 +62,133 @@ function average_pre_output_hook!(accum, counter)
end

"""
get_daily_max(long_names...; output_writer = HDF5Writer())
daily_maxs(short_names...; output_writer = HDF5Writer())
Return a list of `ScheduledDiagnostics` that compute the daily max for the given variables.
"""
daily_max(long_names...; output_writer = HDF5Writer()) =
common_diagnostics(24 * 60 * 60, max, output_writer, long_names...)
daily_maxs(short_names...; output_writer = HDF5Writer()) =
common_diagnostics(24 * 60 * 60, max, output_writer, short_names...)
"""
daily_max(short_names; output_writer = HDF5Writer())
Return a `ScheduledDiagnostics` that computes the daily max for the given variable.
"""
get_daily_min(long_names...; output_writer = HDF5Writer())
daily_max(short_names; output_writer = HDF5Writer()) =
common_diagnostics(24 * 60 * 60, max, output_writer, short_names)[1]

"""
daily_mins(short_names...; output_writer = HDF5Writer())
Return a list of `ScheduledDiagnostics` that compute the daily min for the given variables.
"""
daily_min(long_names...; output_writer = HDF5Writer()) =
common_diagnostics(24 * 60 * 60, min, output_writer, long_names...)
daily_mins(short_names...; output_writer = HDF5Writer()) =
common_diagnostics(24 * 60 * 60, min, output_writer, short_names...)
"""
daily_min(short_names; output_writer = HDF5Writer())
Return a `ScheduledDiagnostics` that computes the daily min for the given variable.
"""
daily_min(short_names; output_writer = HDF5Writer()) =
common_diagnostics(24 * 60 * 60, min, output_writer, short_names)[1]
"""
get_daily_average(long_names...; output_writer = HDF5Writer())
daily_averages(short_names...; output_writer = HDF5Writer())
Return a list of `ScheduledDiagnostics` that compute the daily average for the given variables.
"""
# An average is just a sum with a normalization before output
daily_average(long_names...; output_writer = HDF5Writer()) = common_diagnostics(
daily_averages(short_names...; output_writer = HDF5Writer()) =
common_diagnostics(
24 * 60 * 60,
(+),
output_writer,
short_names...;
pre_output_hook! = average_pre_output_hook!,
)
"""
daily_average(short_names; output_writer = HDF5Writer())
Return a `ScheduledDiagnostics` that compute the daily average for the given variable.
"""
# An average is just a sum with a normalization before output
daily_average(short_names; output_writer = HDF5Writer()) = common_diagnostics(
24 * 60 * 60,
(+),
output_writer,
long_names...;
short_names;
pre_output_hook! = average_pre_output_hook!,
)

)[1]
"""
get_hourly_max(long_names...; output_writer = HDF5Writer())
hourly_maxs(short_names...; output_writer = HDF5Writer())
Return a list of `ScheduledDiagnostics` that compute the hourly max for the given variables.
"""
hourly_max(long_names...; output_writer = HDF5Writer()) =
common_diagnostics(60 * 60, max, output_writer, long_names...)
hourly_maxs(short_names...; output_writer = HDF5Writer()) =
common_diagnostics(60 * 60, max, output_writer, short_names...)

"""
hourly_max(short_names; output_writer = HDF5Writer())
Return a `ScheduledDiagnostics` that computse the hourly max for the given variable.
"""
hourly_max(short_names...; output_writer = HDF5Writer()) =
common_diagnostics(60 * 60, max, output_writer, short_names)

"""
get_hourly_min(long_names...; output_writer = HDF5Writer())
hourly_mins(short_names...; output_writer = HDF5Writer())
Return a list of `ScheduledDiagnostics` that compute the hourly min for the given variables.
"""
hourly_min(long_names...; output_writer = HDF5Writer()) =
common_diagnostics(60 * 60, min, output_writer, long_names...)
hourly_min(short_names...; output_writer = HDF5Writer()) =
common_diagnostics(60 * 60, min, output_writer, short_names...)
"""
hourly_mins(short_names...; output_writer = HDF5Writer())
Return a `ScheduledDiagnostics` that computes the hourly min for the given variable.
"""
hourly_min(short_names; output_writer = HDF5Writer()) =
common_diagnostics(60 * 60, min, output_writer, short_names)[1]

"""
get_daily_average(long_names...; output_writer = HDF5Writer())
hourly_averages(short_names...; output_writer = HDF5Writer())
Return a list of `ScheduledDiagnostics` that compute the hourly average for the given variables.
"""

# An average is just a sum with a normalization before output
hourly_average(long_names...; output_writer = HDF5Writer()) =
hourly_averages(short_names...; output_writer = HDF5Writer()) =
common_diagnostics(
60 * 60,
(+),
output_writer,
long_names...;
short_names...;
pre_output_hook! = average_pre_output_hook!,
)
"""
hourly_average(short_names...; output_writer = HDF5Writer())
Return a `ScheduledDiagnostics` that computes the hourly average for the given variable.
"""

# An average is just a sum with a normalization before output
hourly_averages(short_names; output_writer = HDF5Writer()) = common_diagnostics(
60 * 60,
(+),
output_writer,
short_names;
pre_output_hook! = average_pre_output_hook!,
)[1]

# Include all the subdefaults
include("defaults/moisture_model.jl")
34 changes: 16 additions & 18 deletions src/diagnostics/defaults/moisture_model.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
# FIXME: Gabriele added this as an example. Put something meaningful here!
function get_default_diagnostics(::T) where {T <: DryModel}
return vcat(
daily_average("air_density"),
[
ScheduledDiagnosticTime(
variable = ALL_DIAGNOSTICS["air_density"],
compute_every = :timestep,
output_every = 86400, # seconds
reduction_time_func = min,
output_writer = HDF5Writer(),
),
ScheduledDiagnosticIterations(
variable = ALL_DIAGNOSTICS["air_density"],
compute_every = 1,
output_every = 1, # iteration
output_writer = HDF5Writer(),
),
],
)
return [
daily_averages("air_density")...,
ScheduledDiagnosticTime(
variable = ALL_DIAGNOSTICS["air_density"],
compute_every = :timestep,
output_every = 86400, # seconds
reduction_time_func = min,
output_writer = HDF5Writer(),
),
ScheduledDiagnosticIterations(
variable = ALL_DIAGNOSTICS["air_density"],
compute_every = 1,
output_every = 1, # iteration
output_writer = HDF5Writer(),
),
]
end

0 comments on commit 0d4ced6

Please sign in to comment.