Skip to content

Commit

Permalink
Rename reference_date to start_date
Browse files Browse the repository at this point in the history
  • Loading branch information
Sbozzolo committed Sep 10, 2024
1 parent ff49192 commit 27f9323
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 153 deletions.
74 changes: 29 additions & 45 deletions src/diagnostics/default_diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
# level interfaces, add them here. Feel free to include extra files.

"""
default_diagnostics(model, t_end, reference_date; output_writer)
default_diagnostics(model, t_end, start_date; output_writer)
Return a list of `ScheduledDiagnostic`s associated with the given `model` that use
`output_write` to write to disk. `t_end` is the expected simulation end time and it is used
to choose the most reasonable output frequency.
`reference_date` is the date that we assign at the start of the simulation.
`start_date` is the date that we assign at the start of the simulation.
We convert time to date as
```julia
current_date = reference_date + integrator.t
current_date = start_date + integrator.t
```
The logic is as follows:
Expand All @@ -28,7 +28,7 @@ If `t_end >= 90 year` take monthly means.
function default_diagnostics(
model::AtmosModel,
t_end,
reference_date::DateTime;
start_date::DateTime;
output_writer,
)
# Unfortunately, [] is not treated nicely in a map (we would like it to be "excluded"),
Expand All @@ -39,7 +39,7 @@ function default_diagnostics(
default_diagnostics(
getfield(model, x),
t_end,
reference_date;
start_date;
output_writer,
) != [],
fieldnames(AtmosModel),
Expand All @@ -48,12 +48,12 @@ function default_diagnostics(
# We use a map because we want to ensure that diagnostics is a well defined type, not
# Any. This reduces latency.
return vcat(
core_default_diagnostics(output_writer, t_end, reference_date),
core_default_diagnostics(output_writer, t_end, start_date),
map(non_empty_fields) do field
default_diagnostics(
getfield(model, field),
t_end,
reference_date;
start_date;
output_writer,
)
end...,
Expand All @@ -65,7 +65,7 @@ end
# that all the default_diagnostics return the same type). This is used by
# default_diagnostics(model::AtmosModel; output_writer), so that we can ignore defaults for
# submodels that have no given defaults.
default_diagnostics(submodel, t_end, reference_date; output_writer) = []
default_diagnostics(submodel, t_end, start_date; output_writer) = []

"""
produce_common_diagnostic_function(period, reduction)
Expand All @@ -76,15 +76,15 @@ function common_diagnostics(
period,
reduction,
output_writer,
reference_date,
start_date,
short_names...;
pre_output_hook! = nothing,
)
return vcat(
map(short_names) do short_name
output_schedule_func =
period isa Period ?
EveryCalendarDtSchedule(period; reference_date) :
EveryCalendarDtSchedule(period; start_date) :
EveryDtSchedule(period)

return ScheduledDiagnostic(
Expand Down Expand Up @@ -129,7 +129,7 @@ end
########
# Core #
########
function core_default_diagnostics(output_writer, t_end, reference_date)
function core_default_diagnostics(output_writer, t_end, start_date)
core_diagnostics = [
"ts",
"ta",
Expand Down Expand Up @@ -174,9 +174,9 @@ function core_default_diagnostics(output_writer, t_end, reference_date)
output_writer,
output_short_name = "orog_inst",
),
average_func(core_diagnostics...; output_writer, reference_date)...,
min_func("ts"; output_writer, reference_date),
max_func("ts"; output_writer, reference_date),
average_func(core_diagnostics...; output_writer, start_date)...,
min_func("ts"; output_writer, start_date),
max_func("ts"; output_writer, start_date),
]
end

Expand All @@ -186,7 +186,7 @@ end
function default_diagnostics(
::T,
t_end,
reference_date;
start_date;
output_writer,
) where {T <: Union{EquilMoistModel, NonEquilMoistModel}}
moist_diagnostics = [
Expand All @@ -204,9 +204,7 @@ function default_diagnostics(
"clivi",
]
average_func = frequency_averages(t_end)
return [
average_func(moist_diagnostics...; output_writer, reference_date)...,
]
return [average_func(moist_diagnostics...; output_writer, start_date)...]
end

#######################
Expand All @@ -215,16 +213,14 @@ end
function default_diagnostics(
::Microphysics1Moment,
t_end,
reference_date;
start_date;
output_writer,
)
precip_diagnostics = ["husra", "hussn"]

average_func = frequency_averages(t_end)

return [
average_func(precip_diagnostics...; output_writer, reference_date)...,
]
return [average_func(precip_diagnostics...; output_writer, start_date)...]
end

##################
Expand All @@ -233,7 +229,7 @@ end
function default_diagnostics(
::RRTMGPI.AbstractRRTMGPMode,
t_end,
reference_date;
start_date;
output_writer,
)
rad_diagnostics = [
Expand All @@ -252,14 +248,14 @@ function default_diagnostics(

average_func = frequency_averages(t_end)

return [average_func(rad_diagnostics...; output_writer, reference_date)...]
return [average_func(rad_diagnostics...; output_writer, start_date)...]
end


function default_diagnostics(
::RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics,
t_end,
reference_date;
start_date;
output_writer,
)
rad_diagnostics = [
Expand Down Expand Up @@ -290,12 +286,8 @@ function default_diagnostics(
average_func = frequency_averages(t_end)

return [
average_func(rad_diagnostics...; output_writer, reference_date)...,
average_func(
rad_clearsky_diagnostics...;
output_writer,
reference_date,
)...,
average_func(rad_diagnostics...; output_writer, start_date)...,
average_func(rad_clearsky_diagnostics...; output_writer, start_date)...,
]
end

Expand All @@ -305,7 +297,7 @@ end
function default_diagnostics(
::PrognosticEDMFX,
t_end,
reference_date;
start_date;
output_writer,
)
edmfx_draft_diagnostics = [
Expand Down Expand Up @@ -338,24 +330,16 @@ function default_diagnostics(
average_func = frequency_averages(t_end)

return [
average_func(
edmfx_draft_diagnostics...;
output_writer,
reference_date,
)...,
average_func(
edmfx_env_diagnostics...;
output_writer,
reference_date,
)...,
average_func(edmfx_draft_diagnostics...; output_writer, start_date)...,
average_func(edmfx_env_diagnostics...; output_writer, start_date)...,
]
end


function default_diagnostics(
::DiagnosticEDMFX,
t_end,
reference_date;
start_date;
output_writer,
)
diagnostic_edmfx_draft_diagnostics = [
Expand All @@ -378,12 +362,12 @@ function default_diagnostics(
average_func(
diagnostic_edmfx_draft_diagnostics...;
output_writer,
reference_date,
start_date,
)...,
average_func(
diagnostic_edmfx_env_diagnostics...;
output_writer,
reference_date,
start_date,
)...,
]
end
Loading

0 comments on commit 27f9323

Please sign in to comment.