Skip to content

Commit

Permalink
One .pdf instead of 36 .png long_runs artifacts
Browse files Browse the repository at this point in the history
Long runs where producing 36 artifacts (.png files), this commit
tidy this up by gathering them into one .pdf instead.
  • Loading branch information
AlexisRenchon committed Oct 22, 2024
1 parent e205018 commit 19411c2
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 62 deletions.
171 changes: 127 additions & 44 deletions .buildkite/Manifest-v1.11.toml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .buildkite/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Poppler_jll = "9c32591e-4766-534b-9725-b71a8799265b"
ProfileCanvas = "efd6af41-a80b-495e-886c-e51b0c7d77a3"
RootSolvers = "7181ea78-2dcb-4de3-ab41-2b8ab5a31e74"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Expand Down
11 changes: 9 additions & 2 deletions experiments/long_runs/bucket.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# # Global bucket run

# The code sets up and runs the bucket model on a spherical domain,
# using ERA5 data.
# using ERA5 data.

# Simulation Setup
# Number of spatial elements: 101 in horizontal, 5 in vertical
Expand Down Expand Up @@ -38,6 +38,8 @@ using CairoMakie
using Dates
import NCDatasets

using Poppler_jll: pdfunite

const FT = Float64;
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
regridder_type = :InterpolationsRegridder
Expand Down Expand Up @@ -167,6 +169,7 @@ setup_and_solve_problem(; greet = true);
simdir = ClimaAnalysis.SimDir(outdir)
short_names =
["swa", "rn", "tsfc", "qsfc", "lhf", "shf", "wsoil", "wsfc", "ssfc"]
tmpdir = mktempdir(root_path)
for short_name in short_names
var = get(simdir; short_name)
times = ClimaAnalysis.times(var)
Expand All @@ -182,6 +185,10 @@ for short_name in short_names
:mask => ClimaAnalysis.Utils.kwargs(color = :white),
),
)
CairoMakie.save(joinpath(root_path, "$(short_name)_$t.png"), fig)
CairoMakie.save(joinpath(tmpdir, "$(short_name)_$t.pdf"), fig)
end
end
figures = readdir(tmpdir)
pdfunite() do unite
run(Cmd([unite, figures..., "figures.pdf"]))
end
9 changes: 8 additions & 1 deletion experiments/long_runs/land.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import GeoMakie
using Dates
import NCDatasets

using Poppler_jll: pdfunite

const FT = Float64;
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
regridder_type = :InterpolationsRegridder
Expand Down Expand Up @@ -593,6 +595,7 @@ setup_and_solve_problem(; greet = true);
#### ClimaAnalysis ####
simdir = ClimaAnalysis.SimDir(outdir)
short_names = ["gpp", "ct", "lai", "swc", "si", "swa", "lwu", "et", "er", "sr"]
tmpdir = mktempdir(root_path)
for short_name in short_names
var = get(simdir; short_name)
times = ClimaAnalysis.times(var)
Expand All @@ -607,6 +610,10 @@ for short_name in short_names
:mask => ClimaAnalysis.Utils.kwargs(color = :white),
),
)
CairoMakie.save(joinpath(root_path, "$(short_name)_$t.png"), fig)
CairoMakie.save(joinpath(tmpdir, "$(short_name)_$t.pdf"), fig)
end
end
figures = readdir(tmpdir)
pdfunite() do unite
run(Cmd([unite, figures..., "figures.pdf"]))
end
9 changes: 8 additions & 1 deletion experiments/long_runs/land_region.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ using CairoMakie
using Dates
import NCDatasets

using Poppler_jll: pdfunite

const FT = Float64;
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
regridder_type = :InterpolationsRegridder
Expand Down Expand Up @@ -597,6 +599,7 @@ setup_and_solve_problem(; greet = true);
#### ClimaAnalysis ####
simdir = ClimaAnalysis.SimDir(outdir)
short_names = ["gpp", "ct", "swc", "si"]
tmpdir = mktempdir(root_path)
for short_name in short_names
var = get(simdir; short_name)
times = ClimaAnalysis.times(var)
Expand All @@ -606,7 +609,11 @@ for short_name in short_names
tmp = ClimaAnalysis.slice(var, time = t; kwargs...)
if !all(isnan.(tmp.data))
viz.heatmap2D!(fig, tmp)
CairoMakie.save(joinpath(root_path, "$(short_name)_$t.png"), fig)
CairoMakie.save(joinpath(tmpdir, "$(short_name)_$t.pdf"), fig)
end
end
end
figures = readdir(tmpdir)
pdfunite() do unite
run(Cmd([unite, figures..., "figures.pdf"]))
end
9 changes: 8 additions & 1 deletion experiments/long_runs/soil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ using CairoMakie
using Dates
import NCDatasets

using Poppler_jll: pdfunite

const FT = Float64;
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
regridder_type = :InterpolationsRegridder
Expand Down Expand Up @@ -365,6 +367,7 @@ setup_and_solve_problem(; greet = true);
#### ClimaAnalysis ####
simdir = ClimaAnalysis.SimDir(outdir)
short_names = ["swc", "si", "sie"]
tmpdir = mktempdir(root_path)
for short_name in short_names
var = get(simdir; short_name)
times = ClimaAnalysis.times(var)
Expand All @@ -380,6 +383,10 @@ for short_name in short_names
:mask => ClimaAnalysis.Utils.kwargs(color = :white),
),
)
CairoMakie.save(joinpath(root_path, "$(short_name)_$t.png"), fig)
CairoMakie.save(joinpath(tmpdir, "$(short_name)_$t.pdf"), fig)
end
end
figures = readdir(tmpdir)
pdfunite() do unite
run(Cmd([unite, figures..., "figures.pdf"]))
end
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Expand Down
90 changes: 77 additions & 13 deletions test/diagnostics/diagnostics_tests.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using Test
using ClimaLand
using ClimaLand.Diagnostics: @with_error
import ClimaComms
ClimaComms.@import_required_backends
import ClimaParams
import SciMLBase
import ClimaTimeSteppers
import ClimaDiagnostics
using Dates

@test isdefined(ClimaLand.Diagnostics, :compute_sw_albedo!)

@test !hasmethod(
ClimaLand.Diagnostics.compute_sw_albedo!,
(Any, Any, Any, Any, Any),
)

# Define some diagnostics for a DummyModel

@test ClimaLand.Diagnostics.ALL_DIAGNOSTICS isa Dict
Expand All @@ -30,17 +32,79 @@ ClimaLand.Diagnostics.add_diagnostic_variable!(

@test length(ClimaLand.Diagnostics.ALL_DIAGNOSTICS) == 1

ClimaLand.Diagnostics.define_diagnostics!(DummyModel())
# First, run a simulation for 1 hour
FT = Float32
t0 = 0.0
Δt = 100.0
tf = 3Δt
bucket_domain = ClimaLand.SphericalShell(;
radius = FT(100),
depth = FT(3.5),
nelements = (1, 10),
npolynomial = 1,
)

bucket_atmos, bucket_rad = ClimaLand.prescribed_analytic_forcing(FT)
τc = FT(1.0)
α_bareground_func = (coordinate_point) -> 0.2
α_snow = FT(0.8)
z_0m = FT(1e-2)
z_0b = FT(1e-3)
albedo = ClimaLand.Bucket.PrescribedBaregroundAlbedo{FT}(
α_snow,
α_bareground_func,
bucket_domain.space.surface,
)
bucket_parameters =
ClimaLand.Bucket.BucketModelParameters(FT; albedo, z_0m, z_0b, τc)

model = ClimaLand.Bucket.BucketModel(
parameters = bucket_parameters,
domain = bucket_domain,
atmosphere = bucket_atmos,
radiation = bucket_rad,
)

Y, p, coords = ClimaLand.initialize(model)
Y.bucket.T .= 280.0
Y.bucket.W .= 0.0 # no moisture
Y.bucket.Ws .= 0.0 # no runoff
Y.bucket.σS .= 0.0

# Just to trigger the error
out = Y = p = t = land_model = nothing
exp_tendency! = ClimaLand.make_exp_tendency(model)
set_initial_cache! = ClimaLand.make_set_initial_cache(model)
set_initial_cache!(p, Y, t0)

@test_throws ErrorException("Cannot compute albedo with model = Nothing") ClimaLand.Diagnostics.compute_albedo!(
out,
prob = SciMLBase.ODEProblem(
ClimaTimeSteppers.ClimaODEFunction((T_exp!) = exp_tendency!),
Y,
(t0, tf),
p,
t,
land_model,
)

@test_throws ErrorException ClimaLand.Diagnostics.get_diagnostic_variable("Foo")
# ClimaDiagnostics

ClimaLand.Diagnostics.define_diagnostics!(model)
diags = ["rn", "lhf"]

d_writer = ClimaDiagnostics.Writers.DictWriter()

out = ClimaLand.Diagnostics.daily_averages(
FT,
diags...;
output_writer = d_writer,
reference_date = DateTime(2005),
)

diagnostic_handler = ClimaDiagnostics.DiagnosticsHandler(out, Y, p, t0; dt = Δt)

diag_cb = ClimaDiagnostics.DiagnosticsCallback(diagnostic_handler)

updateat = collect(t0:Δt:tf);
drivers = ClimaLand.get_drivers(model)
updatefunc = ClimaLand.make_update_drivers(drivers)
driver_cb = ClimaLand.DriverUpdateCallback(updateat, updatefunc)
cb = SciMLBase.CallbackSet(driver_cb)
timestepper = ClimaTimeSteppers.RK4()
ode_algo = ClimaTimeSteppers.ExplicitAlgorithm(timestepper)
SciMLBase.solve(prob, ode_algo; dt = Δt, callback = cb)
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ end
@safetestset "Integrated soil and snow" begin
include("integrated/soil_snow.jl")
end

# Diagnostics
@safetestset "Diagnostics" begin
include("diagnostics/diagnostics_tests.jl")
end

0 comments on commit 19411c2

Please sign in to comment.