Skip to content

Commit

Permalink
Add descriptive_name for ScheduledDiagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
Sbozzolo committed Sep 6, 2023
1 parent cd042ee commit 89ef341
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/diagnostics/Writers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,89 @@
# writers come with opinionated defaults.


"""
descriptive_name(sd_t::ScheduledDiagnosticTime)
Return a compact, unique-ish, identifier for the given `ScheduledDiagnosticTime` `sd_t`.
We split the period in seconds into days, hours, minutes, seconds. In most cases
(with standard periods), this output will look something like
`air_density_1d_max`. This function can be used for filenames.
The name is not unique to the `ScheduledDiagnosticTime` because it ignores other
parameters such as whether there is a reduction in space or the compute
frequency.
"""
function descriptive_name(sd_t::ScheduledDiagnosticTime)
var = "$(sd_t.variable.short_name)"

isa_reduction = !isnothing(sd_t.reduction_time_func)

if isa_reduction
red = "$(sd_t.reduction_time_func)"

# Convert period from seconds to days, hours, minutes, seconds
period = ""

days, rem_seconds = divrem(sd_t.output_every, 24 * 60 * 60)
hours, rem_seconds = divrem(rem_seconds, 60 * 60)
minutes, seconds = divrem(rem_seconds, 60)

if days > 0
period *= "$(days)d_"
end
if hours > 0
period *= "$(hours)h_"
end
if minutes > 0
period *= "$(minutes)m_"
end
if seconds > 0
period *= "$(seconds)s_"
end

suffix = period * red
else
# Not a reduction
suffix = "inst"
end
return "$(var)_$(suffix)"
end

"""
descriptive_name(sd_i::ScheduledDiagnosticIterations, [Δt])
Return a compact, unique-ish, identifier for the given
`ScheduledDiagnosticIterations` `sd_i`.
If the timestep `Δt` is provided, convert the steps into seconds. In this case,
the output will look like `air_density_1d_max`. Otherwise, the output will look
like `air_density_100it_max`. This function can be used for filenames.
The name is not unique to the `ScheduledDiagnosticIterations` because it ignores
other parameters such as whether there is a reduction in space or the compute
frequency.
"""
function descriptive_name(sd_i::ScheduledDiagnosticIterations,
Δt = nothing)

if !isnothing(Δt)
# Convert iterations into time
return descriptive_name(ScheduledDiagnosticTime(sd_i, Δt))
else
var = "$(sd_i.variable.short_name)"
suffix =
isnothing(sd_i.reduction_time_func) ? "inst" :
"$(sd_i.output_every)it_(sd_i.reduction_time_func)"
return "$(var)_$(suffix)"
end
end


"""
HDF5Writer()
Expand Down

0 comments on commit 89ef341

Please sign in to comment.