Skip to content

Commit e8c65ee

Browse files
authored
Merge pull request #63 from jbisits/jib-animateanomaly
Functions to animate anomaly
2 parents b2a31f6 + dda99c5 commit e8c65ee

3 files changed

Lines changed: 136 additions & 1 deletion

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StaircaseShenanigans"
22
uuid = "c2bb06a8-94f3-4279-b990-30bf3ab8ba6f"
33
authors = ["Josef Bisits <jbisits@gmail.com>"]
4-
version = "0.4.1"
4+
version = "0.4.2"
55

66
[deps]
77
GibbsSeaWater = "9a22fb26-0b63-4589-b28e-8f9d0b5c3d05"

ext/StaircaseShenanigansMakieExt/plot_recipes.jl

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,82 @@ function StaircaseShenanigans.animate_tracers(tracers::AbstractString; xslice =
7272

7373
return nothing
7474
end
75+
"""
76+
function StaircaseShenanigans.animate_tracers_anomaly(tracers::AbstractString)
77+
Animate the salinity and temperature `tracers` anomalies from saved `.nc` output.
78+
"""
79+
function StaircaseShenanigans.animate_tracers_anomaly(tracers::AbstractString; xslice = 52, yslice = 52)
80+
81+
NCDataset(tracers) do ds
82+
83+
x = ds["xC"][:]
84+
z = ds["zC"][:]
85+
t = ds["time"][:]
86+
87+
n = Observable(1)
88+
S = @lift ds[:S′][:, yslice, :, $n]
89+
S_profile = @lift ds[:S′][xslice, yslice, :, $n]
90+
Θ = @lift ds[:T′][:, yslice, :, $n]
91+
Θ_profile = @lift ds[:T′][xslice, yslice, :, $n]
92+
time_title = @lift @sprintf("t=%1.2f minutes", t[$n] / 60)
93+
94+
fig = Figure(size = (1000, 1000))
95+
ax = [Axis(fig[j, i], title = (i == 1 && j == 1) ? time_title : "") for i 1:2, j 1:2]
96+
97+
# Salinity
98+
Srange = extrema(ds[:S′][:, :, :, end])
99+
lines!(ax[1], S_profile, z)
100+
ax[1].xlabel = "S′ gkg⁻¹"
101+
ax[1].ylabel = "z (m)"
102+
ax[1].xaxisposition = :top
103+
xlims!(ax[1], Srange)
104+
105+
Scmap = cgrad(:haline)[2:end-1]
106+
Slow = cgrad(:haline)[1]
107+
Shigh = cgrad(:haline)[end]
108+
hmS = heatmap!(ax[2], x, z, S, colorrange = Srange, colormap = Scmap,
109+
lowclip = Slow, highclip = Shigh)
110+
111+
ax[2].xlabel = "x (m)"
112+
ax[2].ylabel = "z (m)"
113+
Colorbar(fig[1, 3], hmS, label = "S′ gkg⁻¹")
114+
115+
linkyaxes!(ax[1], ax[2])
116+
hideydecorations!(ax[2], ticks = false)
117+
118+
# Temperature
119+
Θrange = extrema(ds[:T′][:, :, :, end])
120+
lines!(ax[3], Θ_profile, z)
121+
ax[3].xlabel = "Θ°C"
122+
ax[3].ylabel = "z (m)"
123+
ax[3].xaxisposition = :top
124+
xlims!(ax[3], Θrange)
125+
126+
Θcmap = cgrad(:thermal)[2:end-1]
127+
Θlow = cgrad(:thermal)[1]
128+
Θhigh = cgrad(:thermal)[end]
129+
hmΘ = heatmap!(ax[4], x, z, Θ, colorrange = Θrange, colormap = Θcmap,
130+
lowclip = Θlow, highclip = Θhigh)
131+
132+
ax[4].xlabel = "x (m)"
133+
ax[4].ylabel = "z (m)"
134+
Colorbar(fig[2, 3], hmΘ, label = "Θ°C")
135+
136+
linkyaxes!(ax[3], ax[4])
137+
hideydecorations!(ax[4], ticks = false)
138+
139+
frames = eachindex(t)
140+
record(fig, joinpath(pwd(), "tracers.mp4"),
141+
frames, framerate=8) do i
142+
msg = string("Plotting frame ", i, " of ", frames[end])
143+
print(msg * " \r")
144+
n[] = i
145+
end
146+
147+
end
148+
149+
return nothing
150+
end
75151
"""
76152
function animate_density(computed_output::AbstractString, variable::AbstractString=σ;
77153
xslice = 52, yslice = 52)
@@ -126,6 +202,63 @@ function StaircaseShenanigans.animate_density(computed_output::AbstractString, v
126202

127203
return nothing
128204
end
205+
"""
206+
function animate_density_anomaly(computed_output::AbstractString, variable::AbstractString=σ;
207+
xslice = 52, yslice = 52)
208+
Animate the density anomaly from `variable` and the background `variable` in `computed_output`.
209+
"""
210+
function StaircaseShenanigans.animate_density_anomaly(computed_output::AbstractString, variable::AbstractString;
211+
xslice = 52, yslice = 52)
212+
213+
NCDataset(computed_output) do ds
214+
215+
x = ds["xC"][:]
216+
z = ds["zC"][:]
217+
t = ds["time"][:]
218+
219+
n = Observable(1)
220+
σ_backgroud = ds[variable*"_background"][:, yslice, :]
221+
σ = @lift ds[variable][:, yslice, :, $n] .- σ_backgroud
222+
σ_backgroud_profile = ds[variable*"_background"][xslice, yslice, :]
223+
σ_profile = @lift ds[variable][xslice, yslice, :, $n] .- σ_backgroud_profile
224+
time_title = @lift @sprintf("t=%1.2f minutes", t[$n] / 60)
225+
226+
fig = Figure(size = (1000, 500))
227+
ax = [Axis(fig[1, i], title = i == 1 ? time_title : "") for i 1:2]
228+
229+
colorrange = extrema(ds[variable][:, :, :, end] .- ds[variable*"_background"][:, :, :])
230+
231+
lines!(ax[1], σ_profile, z)
232+
ax[1].xlabel = "σ₀′ kgm⁻³"
233+
ax[1].ylabel = "z"
234+
ax[1].xaxisposition = :top
235+
ax[1].xticklabelrotation = π / 4
236+
xlims!(ax[1], colorrange)
237+
238+
colormap = cgrad(:dense)[2:end-1]
239+
lowclip = cgrad(:dense)[1]
240+
highclip = cgrad(:dense)[end]
241+
hm = heatmap!(ax[2], x, z, σ; colorrange, colormap, lowclip, highclip)
242+
243+
ax[2].xlabel = "x (m)"
244+
ax[2].ylabel = "z (m)"
245+
Colorbar(fig[1, 3], hm, label = "σ₀′ kgm⁻³")
246+
247+
linkyaxes!(ax[1], ax[2])
248+
hideydecorations!(ax[2], ticks = false)
249+
250+
frames = eachindex(t)
251+
record(fig, joinpath(pwd(), "density.mp4"),
252+
frames, framerate=8) do i
253+
msg = string("Plotting frame ", i, " of ", frames[end])
254+
print(msg * " \r")
255+
n[] = i
256+
end
257+
258+
end
259+
260+
return nothing
261+
end
129262
"""
130263
function visualise_initial_conditions(sdns::StaircaseDNS, xslice::Integer, yslice::Integer)
131264
Plot the initial state of the `tracers` in a `model`. This function assumes there are two

src/makie_plotting_functions.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
function animate_tracers end
2+
function animate_tracers_anomaly end
23
function animate_density end
4+
function animate_density_anomaly end
35
function visualise_initial_conditions end
46
function visualise_initial_density end

0 commit comments

Comments
 (0)