Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vor as unicodeplot, days/day speed shown #80

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/feedback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mutable struct Feedback
# PROGRESS
progress_meter::ProgressMeter.Progress # struct containing everything progress related
progress_txt::Union{IOStream,Nothing} # txt is a Nothing in case of no output

# OUTPUT
verbose::Bool # print stuff to REPL?
output::Bool # output to netCDF?
Expand All @@ -16,6 +16,7 @@ mutable struct Feedback
nans_detected::Bool # did NaNs occur in the simulation?
end


"""Initialises the progress txt file."""
function initialize_feedback(M::ModelSetup)
@unpack verbose, output = M.parameters
Expand Down Expand Up @@ -53,6 +54,8 @@ function initialize_feedback(M::ModelSetup)
nans_detected = false # currently not used

# PROGRESSMETER
dt_in_sec[1] = M.constants.Δt_sec # hack: redefine element in global constant dt_in_sec
# used to pass on the time step to ProgressMeter.speedstring
desc = "Weather is speedy$(output ? " run $run_id: " : ": ")"
progress_meter = ProgressMeter.Progress(n_timesteps,enabled=verbose,showspeed=true;desc)

Expand All @@ -64,8 +67,8 @@ end

"""Calls the progress meter and writes every 5% progress increase to txt."""
function progress!(F::Feedback)
ProgressMeter.next!(F.progress_meter) # update progress meter
@unpack counter,n = F.progress_meter
ProgressMeter.next!(F.progress_meter) # update progress meter
@unpack counter,n = F.progress_meter # unpack counter after update

# write progress to txt file too
if (counter/n*100 % 1) > ((counter+1)/n*100 % 1)
Expand Down
47 changes: 35 additions & 12 deletions src/pretty_printing.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
function Base.show(io::IO, P::PrognosticVariables)

lf = 1 # first leapfrog index
lev = size(P.temp)[end] # surface level
temp = view(P.temp,:,:,lf,lev)
lev = size(P.vor)[end] # surface level
ζ = view(P.vor,:,:,lf,lev) # create a view on vorticity

temp_surf_grid_degC = gridded(temp) # to grid space
temp_surf_grid_degC .-= 273.15 # and ˚C
temp_surf_grid_degC = temp_surf_grid_degC[:,end:-1:1] # flip latitudes
ζ_grid = gridded(ζ) # to grid space
ζ_grid = ζ_grid[:,end:-1:1] # flip latitudes

nlon,nlat = size(temp_surf_grid_degC)
nlon,nlat = size(ζ_grid)

plot_kwargs = pairs(( xlabel="˚E",
xfact=360/(nlon-1),
ylabel="˚N",
yfact=180/(nlat-1),
yoffset=-90,
zlabel="˚C",
title="Surface temperature",
colormap=:plasma))
title="Surface relative vorticity",
colormap=:viridis,
compact=true,
colorbar=false,
width=60,
height=30))

print(io,UnicodePlots.heatmap(temp_surf_grid_degC';plot_kwargs...))
print(io,UnicodePlots.heatmap(ζ_grid';plot_kwargs...))
end



# hack: define global constant whose element will be changed in initialize_feedback
# used to pass on the time step to ProgressMeter.speedstring via calling this
# constant from the ProgressMeter module
const dt_in_sec = [1800]

function ProgressMeter.speedstring(sec_per_iter,dt_in_sec=SpeedyWeather.dt_in_sec)
if sec_per_iter == Inf
return " N/A days/day"
end

sim_time_per_time = dt_in_sec[1]/sec_per_iter

for (divideby, unit) in ( (365*1_000, "millenia"),
(365, "years"),
(1, "days"),
(1/24, "hours"))
if (sim_time_per_time / divideby) > 2
return @sprintf "%5.2f %2s/day" (sim_time_per_time / divideby) unit
end
end
return " <2 hours/days"
end