Skip to content
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
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ClimaCorePlots = "cf7c7e5a-b407-4c48-9047-11a94a308626"
ClimaParams = "5c42b081-d73a-476f-9059-fd94b934656c"
CloudMicrophysics = "6a9e3e04-43cd-43ba-94b9-e8782df3c71b"
Cloudy = "9e3b23bb-e7cc-4b94-886c-65de2234ba87"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
KinematicDriver = "83200819-b45f-4027-aa6a-8223b29c73a7"
Expand Down
5 changes: 3 additions & 2 deletions test/experiments/KiD_driver/run_KiD_simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function run_KiD_simulation(::Type{FT}, opts) where {FT}
)

# Some basic plots
opts["plotting_flag"] == true && with_theme(theme_minimal()) do
opts["plotting_flag"] == true && with_theme(theme_minimal(), fontsize = 30) do
@info "Plotting"
output = joinpath(path, "figures")

Expand All @@ -157,7 +157,8 @@ function run_KiD_simulation(::Type{FT}, opts) where {FT}
plot_animation_p3(z_centers, solver, aux, moisture, precip, K1D, output)
plot_timeheight_p3(output_nc, precip; output)
else
plot_animation(output_nc; output)
get(opts, "make_animation", false) && plot_animation(output_nc; output)
plot_profiles_in_time(output_nc; output, n = 10)
plot_timeheight(output_nc; output, mixed_phase = false)
end
end
Expand Down
94 changes: 94 additions & 0 deletions test/plotting_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ENV["GKSwstype"] = "nul"
import ClimaCorePlots, Plots
Plots.GRBackend()
using CairoMakie
using Dates

function plot_initial_profiles_comparison(KM; sdm_case = "dry")
sdm_data = load_sdm_data(sdm_case)
Expand Down Expand Up @@ -313,6 +314,99 @@ function plot_animation(nc_data_file; output = "output")
Plots.mp4(anim, joinpath(path, "animation.mp4"), fps = 10)
end

function plot_profiles_in_time(nc_data_file; output = "output", n = 10)

path = joinpath(@__DIR__, output)
mkpath(path)

ds = NC.NCDataset(joinpath(@__DIR__, nc_data_file))
profs = ds.group["profiles"]

z_plt = Array(profs["zc"])
t_plt = Array(profs["t"])
nt = length(t_plt)

# Select n evenly distributed time indices
Δi = round(Int, (nt - 2) / n)
time_indices = [1; Δi:Δi:(nt - Δi); nt] # explicitly include first and last indices
ni = length(time_indices)
selected_times = t_plt[time_indices]

kg_to_g = 1e3
m⁻³_to_cm⁻³ = 1e-6
q_tot = profs["q_tot"][:, time_indices] .* kg_to_g
q_liq = profs["q_liq"][:, time_indices] .* kg_to_g
q_ice = profs["q_ice"][:, time_indices] .* kg_to_g
q_rai = profs["q_rai"][:, time_indices] .* kg_to_g
q_sno = profs["q_sno"][:, time_indices] .* kg_to_g
N_liq = profs["N_liq"][:, time_indices] .* m⁻³_to_cm⁻³
N_rai = profs["N_rai"][:, time_indices] .* m⁻³_to_cm⁻³
SN_liq_act = profs["SN_liq_act"][:, time_indices] .* m⁻³_to_cm⁻³

close(ds)

# Create colormap for time progression
# colormap = :viridis
colormap = cgrad(:darkrainbow, (0:ni) / ni, categorical = true)
# colors = get(colorschemes[colormap], range(0, 1, length = n))
ymax = z_plt[end] + (z_plt[end] - z_plt[end - 1]) # extend y-axis a bit beyond the last point
lims(x) = iszero(x) ? (nothing, (0, ymax)) : ((0, 1.1 * maximum(x)), (0, ymax))

fig = Figure(size = (2000, 1500))

# Create axes
ax_q_tot = Axis(fig[1, 1]; xlabel = "q_tot [g/kg]", limits = lims(q_tot), ylabel = "z [m]")
ax_q_liq = Axis(fig[1, 2]; xlabel = "q_liq [g/kg]", limits = lims(q_liq))
ax_N_liq = Axis(fig[1, 3]; xlabel = "N_liq [1/cm³]", limits = lims(N_liq))
ax_q_rai = Axis(fig[2, 1]; xlabel = "q_rai [g/kg]", limits = lims(q_rai), ylabel = "z [m]")
ax_N_rai = Axis(fig[2, 2]; xlabel = "N_rai [1/cm³]", limits = lims(N_rai))
ax_q_ice = Axis(fig[2, 3]; xlabel = "q_ice [g/kg]", limits = lims(q_ice))
ax_q_sno = Axis(fig[3, 1]; xlabel = "q_sno [g/kg]", limits = lims(q_sno), ylabel = "z [m]")
ax_SN_liq_act = Axis(fig[3, 2]; xlabel = "SN_liq_act [1/cm³]", limits = lims(SN_liq_act))

# Link y-axes
axs = [ax_q_tot, ax_q_liq, ax_N_liq, ax_q_rai, ax_N_rai, ax_q_ice, ax_q_sno]
linkyaxes!(axs...)

# Plot lines for each selected time
args = (; colormap, colorrange = (0, 1))
for (i, t) in enumerate(selected_times)
color = (i - 0.5) / ni # Normalize color for colormap
lines!(ax_q_tot, q_tot[:, i], z_plt; args..., color)
lines!(ax_q_liq, q_liq[:, i], z_plt; args..., color)
lines!(ax_N_liq, N_liq[:, i], z_plt; args..., color)
lines!(ax_q_rai, q_rai[:, i], z_plt; args..., color)
lines!(ax_N_rai, N_rai[:, i], z_plt; args..., color)
lines!(ax_q_ice, q_ice[:, i], z_plt; args..., color)
lines!(ax_q_sno, q_sno[:, i], z_plt; args..., color)
lines!(ax_SN_liq_act, SN_liq_act[:, i], z_plt; args..., color)
end

# Add colorbar
tloc = ((1:ni) .- 0.5) / ni # locations offset by 0.5 to center label on the color
tlab = begin
# Canonicalize time labels
can_times = @. canonicalize(Second(selected_times))
# shorten time labels
map(can_times) do t
s = string(t)
s == "empty period" && return "0 s"
s = replace(s, "seconds" => "s", "minutes" => "m", "hours" => "h", "days" => "d")
s = replace(s, "second" => "s", "minute" => "m", "hour" => "h", "day" => "d")
s = replace(s, "milli" => "m", "micro" => "μ", "nano" => "n")
end
end
Colorbar(fig[:, 4]; colormap, colorrange = (0, 1), width = 20, ticks = (tloc, tlab))

# Add title
Label(fig[0, :], "Vertical Profiles at Multiple Time Steps", fontsize = 24)

# Save figure
save(joinpath(path, "profiles_multitime.png"), fig)

return fig
end

function plot_timeheight_p3(nc_data_file, precip; output = "output")
path = joinpath(@__DIR__, output)
mkpath(path)
Expand Down
Loading