Skip to content

Commit 5ded149

Browse files
authored
Merge pull request #137 from jbisits/moreanimations
More animations
2 parents 2ba09bc + 7a72144 commit 5ded149

File tree

5 files changed

+144
-9
lines changed

5 files changed

+144
-9
lines changed

examples/twolayer_example.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ profile_function = StepChange(transition_depth)#HyperbolicTangent(INTERFACE_LOCA
1919
tracer_perturbation_depth = find_depth(model, INTERFACE_LOCATION / 2)
2020
tracer_perturbation = SalinityGaussianProfile(tracer_perturbation_depth, 0.0, 1.5)
2121
noise_depth = find_depth(model, INTERFACE_LOCATION)
22-
initial_noise = SalinityNoise(noise_depth, 1.0)
22+
initial_noise = SalinityNoise(noise_depth, 1e-2)
2323

2424
dns = TwoLayerDNS(model, profile_function, initial_conditions; initial_noise)
2525

ext/TLDNSMakieExt/plotrecipes.jl

Lines changed: 138 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ function TLDNS.animate_2D_field(rs::Raster, xslice::Int64, yslice::Int64; colorm
9696
ax[2].xaxisposition = :top
9797
ax[2].xticklabelrotation = π / 4
9898
if !isnothing(vline)
99-
vlines!(ax[2], vline, linestyle = :dash, color = :red,
100-
label = "Predicted maximum density")
99+
label = isequal(field_name, "σ") ? "Predicted maximum " * field_name :
100+
"Predicted equilibrium " * field_name
101+
vlines!(ax[2], vline, linestyle = :dash, color = :red;
102+
label)
101103
axislegend(ax[2])
102104
end
103105

@@ -113,6 +115,39 @@ function TLDNS.animate_2D_field(rs::Raster, xslice::Int64, yslice::Int64; colorm
113115

114116
return nothing
115117

118+
end
119+
"""
120+
function plot_scalar_diagnostics(saved_output::AbstractString)
121+
Animate the density and diagnostics (at this stage ∫ϵ and ∫κᵥ) from `saved_output`. **Note:**
122+
this function assumes that `saved_output` is a `.nc` file.
123+
"""
124+
function TLDNS.plot_scalar_diagnostics(saved_output::AbstractString)
125+
126+
NCDataset(saved_output) do ds
127+
t = ds["time"][:] / (60)
128+
∫ϵ = ds["∫ϵ"][:]
129+
∫κᵥ = ds["∫κᵥ"][:]
130+
131+
fig = Figure(size = (600, 1000))
132+
ax = [Axis(fig[i, 1]) for i 1:2]
133+
lines!(ax[1], t, ∫ϵ)
134+
ax[1].title = "Integraged TKE"
135+
ax[1].ylabel = "∫ϵ"
136+
137+
lines!(ax[2], t, ∫κᵥ)
138+
ax[2].title = "Integrated inferred vertical diffusivity"
139+
ax[2].xlabel = "t (minutes)"
140+
ax[2].ylabel = "∫κᵥ"
141+
142+
linkxaxes!(ax[1], ax[2])
143+
144+
plotsave = "TKE_and_inferredK.png"
145+
save(plotsave, fig)
146+
@info "Save plot to $(plotsave)"
147+
end
148+
149+
return nothing
150+
116151
end
117152
"""
118153
function animate_volume_distributions(rs::Raster)
@@ -122,9 +157,10 @@ a `Raster`. Optional arguments:
122157
the subsequent histograms;
123158
- `unit` for the variable that is being plotted - must be a `String`.
124159
"""
125-
function TLDNS.animate_volume_distributions(rs::Raster; edges = nothing, unit = nothing)
160+
function TLDNS.animate_volume_distributions(rs::Raster; edges = nothing, unit = nothing, vline = nothing)
126161

127162
t = lookup(rs, Ti)
163+
field_name = rs.name
128164
rs_series_hist = Vector{RasterLayerHistogram}(undef, length(t))
129165
for i eachindex(t)
130166
if i == 1
@@ -140,10 +176,16 @@ function TLDNS.animate_volume_distributions(rs::Raster; edges = nothing, unit =
140176
time_title = @lift @sprintf("t=%1.2f minutes", t[$n] / 60)
141177

142178
fig = Figure(size = (500, 500))
143-
xlabel = isnothing(unit) ? string(rs.name) : string(rs.name) * unit
179+
xlabel = isnothing(unit) ? string(field_name) : string(field_name) * unit
144180
xlimits = isnothing(edges) ? rs_series_hist[1].histogram.edges[1] : edges
145181
ylabel = "Volume (m³)"
146182
ax = Axis(fig[1, 1], title = time_title; xlabel, ylabel)
183+
if !isnothing(vline)
184+
label = isequal(field_name, "σ") ? "Predicted maximum " * field_name :
185+
"Predicted equilibrium " * field_name
186+
vlines!(ax, vline, linestyle = :dash, color = :red; label)
187+
188+
end
147189
xlims!(ax, xlimits[1], xlimits[end])
148190
plot!(ax, dₜ, color = :steelblue)
149191

@@ -154,7 +196,98 @@ function TLDNS.animate_volume_distributions(rs::Raster; edges = nothing, unit =
154196
n[] = i
155197
end
156198

157-
return fig
199+
return nothing
200+
201+
end
202+
"""
203+
function animate_volume_distributions(rs::RasterStack)
204+
**Note:** This method assumes that the `RasterStack` has two variables for a 2D distribution.
205+
"""
206+
function TLDNS.animate_volume_distributions(rs::RasterStack, edges; unit = (" (gkg⁻¹)", " (°C)"))
207+
208+
t = lookup(rs, Ti)
209+
rs_series_hist = Vector{RasterStackHistogram}(undef, length(t))
210+
for i eachindex(t)
211+
rs_series_hist[i] = RasterStackHistogram(rs[:, :, :, i], edges)
212+
end
213+
n = Observable(1)
214+
dₜ = @lift rs_series_hist[$n]
215+
time_title = @lift @sprintf("t=%1.2f minutes", t[$n] / 60)
216+
217+
fig = Figure(size = (500, 500))
218+
xlabel = isnothing(unit[1]) ? string(names(rs)[1]) : string(names(rs)[1]) * unit[1]
219+
ylabel = isnothing(unit[2]) ? string(names(rs)[2]) : string(names(rs)[2]) * unit[2]
220+
xlimits, ylimits = edges
221+
ax = Axis(fig[1, 1], title = time_title; xlabel, ylabel)
222+
xlims!(ax, xlimits[1], xlimits[end])
223+
ylims!(ax, ylimits[1], ylimits[end])
224+
hm = heatmap!(ax, dₜ, color = :viridis, colorscale = log10)
225+
Colorbar(fig[1, 2], hm)
226+
227+
frames = eachindex(t)
228+
savename = string(names(rs)[1]) * string(names(rs)[2]) * "_vd.mp4"
229+
record(fig, joinpath(pwd(), savename), frames, framerate=8) do i
230+
msg = string("Plotting frame ", i, " of ", frames[end])
231+
print(msg * " \r")
232+
n[] = i
233+
end
234+
235+
return nothing
236+
end
237+
function TLDNS.animate_volume_distributions(rs::RasterStack, edges; unit = (" (gkg⁻¹)", " (°C)"))
238+
239+
t = lookup(rs, Ti)
240+
n = Observable(1)
241+
dₜ = Observable(RasterStackHistogram(rs[:, :, :, 1], edges))
242+
time_title = @lift @sprintf("t=%1.2f minutes", t[$n] / 60)
243+
244+
fig = Figure(size = (500, 500))
245+
xlabel = isnothing(unit[1]) ? string(names(rs)[1]) : string(names(rs)[1]) * unit[1]
246+
ylabel = isnothing(unit[2]) ? string(names(rs)[2]) : string(names(rs)[2]) * unit[2]
247+
xlimits, ylimits = edges
248+
ax = Axis(fig[1, 1], title = time_title; xlabel, ylabel)
249+
xlims!(ax, xlimits[1], xlimits[end])
250+
ylims!(ax, ylimits[1], ylimits[end])
251+
252+
hm = heatmap!(ax, dₜ, color = :viridis, colorscale = log10)
253+
Colorbar(fig[1, 2], hm)
254+
255+
frames = eachindex(t)
256+
savename = string(names(rs)[1]) * string(names(rs)[2]) * "_vd.mp4"
257+
record(fig, joinpath(pwd(), savename), frames, framerate=8) do i
258+
msg = string("Plotting frame ", i, " of ", frames[end])
259+
print(msg * " \r")
260+
n[] = i
261+
dₜ[] = RasterStackHistogram(rs[:, :, :, i], edges)
262+
end
263+
264+
return nothing
265+
end
266+
function TLDNS.volume_distribution_snaphsots(rs::RasterStack, edges, snapshots;
267+
unit = (" (gkg⁻¹)", " (°C)"))
268+
269+
t = lookup(rs, Ti)
270+
271+
fig = Figure(size = (1500, 1500))
272+
xlabel = isnothing(unit[1]) ? string(names(rs)[1]) : string(names(rs)[1]) * unit[1]
273+
ylabel = isnothing(unit[2]) ? string(names(rs)[2]) : string(names(rs)[2]) * unit[2]
274+
ax = [Axis(fig[j, i]; xlabel, ylabel) for i 1:2, j 1:3]
275+
276+
for (i, s) enumerate(snapshots)
277+
xlims!(ax[i], 34.57, 34.75)
278+
ylims!(ax[i], -1.6, 0.6)
279+
ax[i].title = "t=$(round(t[s] / 60, digits = 2)) minutes"
280+
281+
stack_hist = RasterStackHistogram(rs[:, :, :, s], edges)
282+
hm = heatmap!(ax[i], stack_hist, color = :viridis, colorscale = log10; colorrange)
283+
if i == 1
284+
Colorbar(fig[:, 3], hm)
285+
end
286+
end
287+
288+
save("ST_vd.png", fig)
289+
290+
return nothing
158291

159292
end
160293
"""

src/TwoLayerDirectNumericalShenanigans.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export DOMAIN_EXTENT, HIGH_RESOLUTION, SO_DIFFUSIVITIES, REFERENCE_DENSITY,
5959
export compute_density, compute_density!
6060

6161
export animate_2D_field, visualise_initial_conditions, visualise_initial_density,
62-
visualise_snapshot
62+
visualise_snapshot, plot_scalar_diagnostics
6363

6464
include("initialconditions.jl")
6565
include("continuousprofilefunctions.jl")

src/makiefunctions.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
"Plotting functions to extend with `DNCSMakieRasterExt`"
1+
"Plotting functions to extend with `TLDNSMakieRasterExt`"
22
function animate_2D_field end
33
function visualise_initial_conditions end
44
function visualise_initial_stepchange end
55
function initial_tracer_heaviside end
66
function visualise_initial_density end
77
function visualise_snapshot end
88
function animate_volume_distributions end
9+
function volume_distribution_snaphsots end
10+
function plot_scalar_diagnostics end

src/twolayerdns.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ function DNS_simulation_setup(dns::TwoLayerDNS, Δt::Number,
197197
"σ" => Dict("longname" => "Seawater potential density calculated using TEOS-10 at $(density_reference_gp_height)dbar",
198198
"units" => "kgm⁻³"),
199199
"η_space" => Dict("longname" => "Minimum (in space) Kolmogorov length"),
200-
"∫κᵥ" => Dict("longname" => "Volumen integrated inferred vertical diffusivity",
200+
"∫κᵥ" => Dict("longname" => "Volume integrated inferred vertical diffusivity",
201201
"units" => "m²s⁻¹"),
202202
"∫ϵ" => Dict("longname" => "Volume integrated turbulent kintetic energy dissipation")
203203
)

0 commit comments

Comments
 (0)