Skip to content

Commit

Permalink
Adjust tests to a ModelList simulation that returns outputs with run!…
Browse files Browse the repository at this point in the history
… instead of through status. All tests pass with PSE, DOCUMENTATION NOT REWORKED
  • Loading branch information
Samuel-amap committed Feb 6, 2025
1 parent c1a75f2 commit 1f06374
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/fitting/fit_FvCB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ function PlantSimEngine.fit(
),
status=(Tₗ=x[:, 1], aPPFD=x[:, 2], Cᵢ=x[:, 3])
)
PlantSimEngine.run!(leaf)
PlantSimEngine.status(leaf).A
outputs = PlantSimEngine.run!(leaf)
outputs.A
end

# Fitting the A-Cᵢ curve using LsqFit.jl
Expand Down
4 changes: 2 additions & 2 deletions test/test-beer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ meteo = Atmosphere(T=20.0, Wind=1.0, P=101.3, Rh=0.65, Ri_PAR_f=300.0)
# Computing the light interception using the Beer-Lambert law:
@testset "Beer-Lambert" begin
@test Beer <: AbstractLight_InterceptionModel
run!(m, meteo, constants)
@test status(m).aPPFD[1] 300.0 * (1.0 - exp(-0.5 * 2.0)) * constants.J_to_umol # in μmol[PAR] m[leaf]⁻² s⁻¹
outputs = run!(m, meteo, constants)
@test outputs.aPPFD[1] 300.0 * (1.0 - exp(-0.5 * 2.0)) * constants.J_to_umol # in μmol[PAR] m[leaf]⁻² s⁻¹
end;


4 changes: 2 additions & 2 deletions test/test-energy_balance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ end;
status=(Ra_SW_f=13.747, sky_fraction=1.0, aPPFD=1500.0, d=0.03)
)

run!(leaf, meteo)
outputs = run!(leaf, meteo)

for i in keys(ref)
@test leaf.status[i][1] ref[i]
@test outputs[i][1] ref[i]
end
end;

Expand Down
4 changes: 2 additions & 2 deletions test/test-gs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ leaf = ModelList(
# Computing the stomatal conductance using the Medlyn et al. (2011) model:

@testset "Medlyn et al. (2011)" begin
run!(leaf, meteo)
@test status(leaf).Gₛ[1] 0.6607197172920005 # in mol[CO₂] m-2 s-1
outputs = run!(leaf, meteo)
@test outputs.Gₛ[1] 0.6607197172920005 # in mol[CO₂] m-2 s-1
end;


Expand Down
39 changes: 11 additions & 28 deletions test/test-structs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ end;

@testset "init_status!" begin
leaf = ModelList(photosynthesis=A, stomatal_conductance=Gs)
@test leaf.status.Tₗ == [-Inf]
@test leaf.status.Tₗ == -Inf

PlantSimEngine.init_status!(leaf, Tₗ=25.0)
@test leaf.status.Tₗ == [25.0]
@test leaf.status.Tₗ == 25.0
end;


Expand All @@ -31,7 +31,7 @@ end;
@test to_initialize(leaf) == to_initialize(photosynthesis=A, stomatal_conductance=Gs)
@test to_initialize(photosynthesis=A) == (photosynthesis=(:aPPFD, :Tₗ, :Cₛ),)

@test leaf.status.Tₗ == [-Inf]
@test leaf.status.Tₗ == -Inf
@test is_initialized(leaf) == false

leaf =
Expand All @@ -45,41 +45,24 @@ end;
end;


@testset "Status as DataFrame" begin
df = DataFrame(:Ra_SW_f => [13.747, 13.8], :sky_fraction => [1.0, 1.0], :d => [0.03, 0.03], :aPPFD => [1300.0, 1500.0])
@testset "Outputs as DataFrame" begin
st = (:Ra_SW_f => [13.747, 13.8], :sky_fraction => [1.0, 1.0], :d => [0.03, 0.03], :aPPFD => [1300.0, 1500.0])

# Reference ModelList
m = ModelList(
energy_balance=Monteith(),
photosynthesis=Fvcb=0.24), # because I set-up the tests with this value for α
stomatal_conductance=Medlyn(0.03, 12.0),
status=TimeStepTable{Status}(df)
)

# Automatically transform the DataFrame into a TimeStepTable{Status}:
m_2 = ModelList(
energy_balance=Monteith(),
photosynthesis=Fvcb=0.24), # because I set-up the tests with this value for α
stomatal_conductance=Medlyn(0.03, 12.0),
status=df
)

# Keep the DataFrame structure:
m_df = ModelList(
energy_balance=Monteith(),
photosynthesis=Fvcb=0.24), # because I set-up the tests with this value for α
stomatal_conductance=Medlyn(0.03, 12.0),
status=df,
init_fun=x -> DataFrame(x)
status=st
)

meteo = Atmosphere(T=20.0, Wind=1.0, P=101.3, Rh=0.65)
constants = Constants()

run!(m, meteo, constants, nothing) # 1.525 μs
run!(m_2, meteo, constants) # idem
run!(m_df, meteo, constants) # 26.125 μs
out = run!(m, meteo, constants, nothing) # 1.525 μs

out_df = outputs(out, DataFrame)

@test DataFrame(status(m_2)) == DataFrame(status(m))
@test status(m_df) == DataFrame(status(m))
@test DataFrame(out) == out_df
@test out_df == DataFrame(out)
end;

0 comments on commit 1f06374

Please sign in to comment.