PlantBiophysics.jlPlantBiophysics.jl

First Simulation​#

This tutorial calculates the temperature, photosynthesis, and heat exchanges of one leaf under a single set of weather conditions. We will choose three models, provide the weather and leaf inputs, then inspect the results.

Describe the weather​#

Atmosphere holds the conditions around the leaf for one timestep. Air temperature T is in °C, wind speed Wind in m s⁻¹, and pressure P in kPa. Relative humidity Rh is a fraction: 0.45 means 45%.

julia
using PlantBiophysics, PlantSimEngine, PlantMeteo, Dates, DataFrames

meteo = Atmosphere(
    T=22.0,
    Wind=0.8333,
    P=101.325,
    Rh=0.45,
    duration=Hour(1),
)
Atmosphere(date = Dates.DateTime("2026-10-01T09:32:03.338"), duration = Dates.Hour(1), T = 22.0, Wind = 0.8333, P = 101.325, Rh = 0.45, Precipitations = 0.0, Cₐ = 400.0, e = 1.1942726652307052, eₛ = 2.6539392560682336, VPD = 1.4596665908375284, ρ = 1.1959231214133237, λ = 2.44897e6, γ = 0.06738328944039168, ε = 0.564158119529222, Δ = 0.16228881621709323)

PlantBiophysics supplies the models, PlantMeteo supplies Atmosphere, and PlantSimEngine combines and runs them. The one-hour duration describes the interval represented by this weather. The leaf models calculate fluxes for these conditions, rather than totals accumulated over the hour.

Choose models and leaf inputs​#

We combine Monteith() for energy balance, Fvcb() for photosynthesis, and Medlyn(0.03, 12.0) for stomatal conductance. Monteith() and Fvcb() use their default parameters; the two Medlyn arguments set g0 and g1. These values illustrate the workflow and should be adapted to your plant.

The models also need four leaf inputs:

InputMeaningUnit
Ra_SW_fAbsorbed shortwave radiation per unit leaf areaW m⁻²
aPPFDAbsorbed photosynthetic photon flux per unit leaf areaµmol photons m⁻² s⁻¹
sky_fractionFraction of the sky visible from the leaf0–1
dCharacteristic leaf dimension used for boundary-layer exchangem

CompositeModel combines the models on one object, representing our leaf. Its Status stores these inputs and the values the models will calculate.

julia
scene = CompositeModel(
    Monteith(),
    Fvcb(),
    Medlyn(0.03, 12.0);
    status=Status(
        Ra_SW_f=13.747,
        sky_fraction=1.0,
        aPPFD=1500.0,
        d=0.03,
    ),
    environment=meteo,
)

The models work together: leaf temperature affects photosynthesis, while stomatal conductance affects water loss and leaf cooling. You do not need to choose their order or write an iteration loop. See the model pages for equations and parameter details.

Run the simulation​#

run! computes one timestep by default. outputs=:all asks it to save the calculated values for later analysis. The latest results are also available directly on the leaf:

julia
simulation = run!(scene; outputs=:all)
leaf = only(model_objects(scene))
(Rn=leaf.status.Rn, H=leaf.status.H, λE=leaf.status.λE,
 Tₗ=leaf.status.Tₗ, A=leaf.status.A, Gₛ=leaf.status.Gₛ)
(Rn = 26.29698177559164, H = -198.15841326174672, λE = 224.45539503733835, Tₗ = 18.003618476920586, A = 32.010730315098684, Gₛ = 1.3459773860136361)

Rn, H, and λE are net radiation, sensible heat flux, and latent heat flux (W m⁻²). Tₗ is leaf temperature (°C), A is net CO₂ assimilation (µmol CO₂ m⁻² s⁻¹), and Gₛ is stomatal conductance to CO₂ (mol CO₂ m⁻² s⁻¹). These fluxes are expressed per unit leaf area.

Collect the results in a table​#

collect_outputs retrieves the saved values. Each row contains one variable at one timestep; here we select the six results above:

julia
rows = collect_outputs(simulation; sink=DataFrame)
results = subset(
    rows,
    :application_id => ByRow(==(:energy_balance)),
    :variable => ByRow(in((:Rn, :H, :λE, :Tₗ, :A, :Gₛ))),
)
select(results, :timestep, :variable, :value)
6×3 DataFrame
Rowtimestepvariablevalue
Int64SymbolFloat64
11A32.0107
21Gₛ1.34598
31H-198.158
41Rn26.297
51Tₗ18.0036
61λE224.455

All six values are saved under :energy_balance because Monteith calls the photosynthesis and stomatal models during its calculations.

Continue with Simulation over several time steps to supply changing weather, save a time series, and plot the results.