Skip to content

Commit 7975335

Browse files
authored
Merge pull request #1313 from CliMA/js/canopy-diags
add default_diagnostics for CanopyModel
2 parents 0a873e3 + b9e3a76 commit 7975335

File tree

3 files changed

+325
-306
lines changed

3 files changed

+325
-306
lines changed

docs/src/tutorials/standalone/Canopy/canopy_tutorial.jl

Lines changed: 21 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ using ClimaLand.Canopy.PlantHydraulics
5353
import ClimaLand.Simulations: LandSimulation, solve!
5454
import ClimaLand
5555
import ClimaLand.Parameters as LP
56+
import ClimaDiagnostics
5657
using DelimitedFiles
5758
import ClimaLand.FluxnetSimulations as FluxnetSimulations
59+
using CairoMakie, ClimaAnalysis, GeoMakie, Poppler_jll, Printf, StatsBase
60+
import ClimaLand.LandSimVis as LandSimVis
5861

5962
# Define the floating point precision desired (64 or 32 bit), and get the
6063
# parameter set holding constants used across CliMA Models:
@@ -228,16 +231,16 @@ function set_ic!(Y, p, t0, model)
228231
evaluate!(Y.canopy.energy.T, atmos.T, t0)
229232
end
230233

231-
# Allocate the struct which stores the saved auxiliary state
232-
# and create the callback which saves it at each element in saveat.
233-
234-
n = 16
235-
saveat = Array(start_date:Second(n * dt):end_date);
236-
sv = (;
237-
t = Array{DateTime}(undef, length(saveat)),
238-
saveval = Array{NamedTuple}(undef, length(saveat)),
239-
)
240-
saving_cb = ClimaLand.NonInterpSavingCallback(sv, saveat);
234+
# Set up the diagnostics writer, which will save model variables
235+
# throughout the course of the simulation.
236+
diag_writer = ClimaDiagnostics.Writers.DictWriter();
237+
diagnostics = ClimaLand.Diagnostics.default_diagnostics(
238+
canopy,
239+
start_date;
240+
output_vars = ["gpp", "trans"],
241+
output_writer = diag_writer,
242+
average_period = :hourly,
243+
);
241244

242245
# Create the callback function which updates the forcing variables,
243246
# or drivers.
@@ -261,59 +264,18 @@ simulation = LandSimulation(
261264
end_date,
262265
dt,
263266
canopy;
264-
set_ic! = set_ic!,
265-
updateat = updateat,
266-
solver_kwargs = (; saveat = deepcopy(saveat)),
267+
set_ic!,
268+
updateat,
267269
timestepper = ode_algo,
268-
user_callbacks = (saving_cb,),
270+
user_callbacks = (),
271+
diagnostics,
269272
);
270273

274+
# Now we can solve the simulation, which will run the model forward in time.
271275
sol = solve!(simulation);
272276

273277
# # Create some plots
274278

275-
# We can now plot the data produced in the simulation. For example, GPP:
276-
277-
daily = FT.(sol.t) ./ 3600 ./ 24
278-
model_GPP = [
279-
parent(sv.saveval[k].canopy.photosynthesis.GPP)[1] for
280-
k in 1:length(sv.saveval)
281-
]
282-
283-
plt1 = Plots.plot(size = (600, 700));
284-
Plots.plot!(
285-
plt1,
286-
daily,
287-
model_GPP .* 1e6,
288-
label = "Model",
289-
xlim = [minimum(daily), maximum(daily)],
290-
xlabel = "days",
291-
ylabel = "GPP [μmol/mol]",
292-
);
293-
294-
# Transpiration plot:
295-
296-
T = [
297-
parent(sv.saveval[k].canopy.turbulent_fluxes.transpiration)[1] for
298-
k in 1:length(sv.saveval)
299-
]
300-
T = T .* (1e3 * 24 * 3600)
301-
302-
plt2 = Plots.plot(size = (500, 700));
303-
Plots.plot!(
304-
plt2,
305-
daily,
306-
T,
307-
label = "Model",
308-
xlim = [minimum(daily), maximum(daily)],
309-
xlabel = "days",
310-
ylabel = "Vapor Flux [mm/day]",
311-
);
312-
313-
# Show the two plots together:
314-
315-
Plots.plot(plt1, plt2, layout = (2, 1));
316-
317-
# Save the output:
318-
savefig("ozark_standalone_canopy_test.png");
319-
# ![](ozark_standalone_canopy_test.png)
279+
# We can now plot the data produced in the simulation. For example, GPP and transpiration:
280+
LandSimVis.make_diurnal_timeseries(simulation; short_names = ["gpp", "trans"])
281+
# ![](diurnal_timeseries.pdf)

0 commit comments

Comments
 (0)