Skip to content

Commit

Permalink
🚧 Start testing GrowthRate.
Browse files Browse the repository at this point in the history
  • Loading branch information
iago-lito committed Oct 24, 2024
1 parent 5e7c75e commit e4711f3
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/components/allometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
include("./allometry_api.jl")
include("./allometry_identifiers.jl")
using .AllometryApi
export Allometry

# Check the given parameters against a template (typically a default value)
# so as to reject missing or unexpected values.
Expand Down
6 changes: 3 additions & 3 deletions src/components/body_mass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# ==========================================================================================
# Blueprints.

module BM
module BodyMass_
include("blueprint_modules.jl")
include("blueprint_modules_identifiers.jl")
import .EcologicalNetworksDynamics: _Species, Species, _Foodweb, Foodweb
Expand Down Expand Up @@ -105,7 +105,7 @@ end
# ==========================================================================================
# Component and generic constructors.

@component BodyMass{Internal} requires(Species) blueprints(BM)
@component BodyMass{Internal} requires(Species) blueprints(BodyMass_)
export BodyMass

(::_BodyMass)(M::Real) = BodyMass.Flat(M)
Expand All @@ -132,7 +132,7 @@ end
ref(raw -> raw._foodweb.M)
get(BodyMasses{Float64}, "species")
write!((raw, rhs::Real, i) -> begin
BM.check(rhs, i)
BodyMass_.check(rhs, i)
rhs
end)
end
Expand Down
4 changes: 2 additions & 2 deletions src/components/foodweb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ==========================================================================================
# Blueprints.

module FoodwebBlueprints
module Foodweb_
include("blueprint_modules.jl")
include("blueprint_modules_identifiers.jl")
import .EN: _Species, Species
Expand Down Expand Up @@ -126,7 +126,7 @@ end
# ==========================================================================================
# Component and generic constructors.

@component Foodweb{Internal} requires(Species) blueprints(FoodwebBlueprints)
@component Foodweb{Internal} requires(Species) blueprints(Foodweb_)
# Consistency alias.
const (TrophicLayer, _TrophicLayer) = (Foodweb, _Foodweb)
export Foodweb, TrophicLayer
Expand Down
10 changes: 4 additions & 6 deletions src/components/growth_rate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
# (reassure JuliaLS)
(false) && (local GrowthRate, _GrowthRate)

# HERE: test after fixing JuliaLS.

# ==========================================================================================
# Blueprints.

module GR
module GrowthRate_
include("blueprint_modules.jl")
include("blueprint_modules_identifiers.jl")
import .EcologicalNetworksDynamics:
Expand Down Expand Up @@ -84,7 +82,7 @@ function F.late_check(raw, bp::Map)
(; r) = bp
index = @ref raw.species.index
prods = @ref raw.producers.mask
@check_list_refs r :species index template(prods)
@check_list_refs r :producer index template(prods)
for (sp, m) in r
check(m, sp)
end
Expand Down Expand Up @@ -174,7 +172,7 @@ end
# ==========================================================================================
# Component and generic constructors.

@component GrowthRate{Internal} requires(Foodweb) blueprints(GR)
@component GrowthRate{Internal} requires(Foodweb) blueprints(GrowthRate_)
export GrowthRate

# Construct either variant based on user input,
Expand Down Expand Up @@ -210,7 +208,7 @@ end
get(GrowthRates{Float64}, sparse, "producer")
template(raw -> @ref raw.producers.mask)
write!((raw, rhs::Real, i) -> begin
GR.check(rhs)
GrowthRate_.check(rhs)
rhs = Float64(rhs)
raw.biorates.r[i] = rhs
rhs
Expand Down
6 changes: 3 additions & 3 deletions src/components/hill_exponent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# ==========================================================================================
# Blueprints.

module HE
module HillExponent_
include("blueprint_modules.jl")

#-------------------------------------------------------------------------------------------
Expand All @@ -28,7 +28,7 @@ end
# ==========================================================================================
# Component and generic constructors.

@component HillExponent{Internal} blueprints(HE)
@component HillExponent{Internal} blueprints(HillExponent_)
export HillExponent

(::_HillExponent)(h) = HillExponent.Raw(h)
Expand All @@ -38,7 +38,7 @@ export HillExponent
depends(HillExponent)
get(raw -> raw._scratch[:hill_exponent])
set!((raw, rhs::Real) -> begin
HE.check_value(rhs)
HillExponent_.check_value(rhs)
h = Float64(rhs)
raw._scratch[:hill_exponent] = h
# Legacy updates, required because scalars don't alias.
Expand Down
8 changes: 4 additions & 4 deletions src/components/metabolic_class.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# ==========================================================================================
# Blueprints.

module MC
module MetabolicClass_
include("blueprint_modules.jl")
include("./blueprint_modules_identifiers.jl")
import .EcologicalNetworksDynamics: Species, _Species, Foodweb, _Foodweb
Expand Down Expand Up @@ -136,7 +136,7 @@ end
# ==========================================================================================
# Component and generic constructors.

@component MetabolicClass{Internal} requires(Foodweb) blueprints(MC)
@component MetabolicClass{Internal} requires(Foodweb) blueprints(MetabolicClass_)
export MetabolicClass

(::_MetabolicClass)(favourite::Symbol) = MetabolicClass.Favor(favourite)
Expand All @@ -158,9 +158,9 @@ end
ref_cached(raw -> Symbol.(raw._foodweb.metabolic_class)) # Legacy reverse conversion.
get(MetabolicClasses{Symbol}, "species")
write!((raw, rhs, i) -> begin
rhs = MC.check_value(rhs, i)
rhs = MetabolicClass_.check_value(rhs, i)
is_prod = is_producer(raw, i)
MC.check_against_status(rhs, is_prod, i)
MetabolicClass_.check_against_status(rhs, is_prod, i)
raw._foodweb.metabolic_class[i...] = String(rhs)
rhs
end)
Expand Down
5 changes: 3 additions & 2 deletions src/components/species.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
# ==========================================================================================
# Blueprints.

module SpeciesBlueprints
# Name + '_'-suffix is the module defining blueprints for this component.
module Species_
include("blueprint_modules.jl")

#-------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -67,7 +68,7 @@ end
# ==========================================================================================
# Component and generic constructors.

@component Species{Internal} blueprints(SpeciesBlueprints)
@component Species{Internal} blueprints(Species_)
export Species

# Build from a number or default to names.
Expand Down
4 changes: 2 additions & 2 deletions src/components/temperature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# ==========================================================================================
# Blueprints.

module T
module Temperature_
include("blueprint_modules.jl")

#-------------------------------------------------------------------------------------------
Expand All @@ -29,7 +29,7 @@ end
# ==========================================================================================
# Component and generic constructors.

@component Temperature{Internal} blueprints(T)
@component Temperature{Internal} blueprints(Temperature_)
export Temperature

(::_Temperature)(T = 293.15) = Temperature.Raw(T)
Expand Down
24 changes: 14 additions & 10 deletions test/user/data_components/growth_rate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,32 @@
gr = GrowthRate([:c => 3])
m = base + gr
@test m.growth_rate == [0, 0, 3] == m.r
@test typeof(gr) === FR

# Only producers indices allowed.
@sysfails(
base + GrowthRate([:a => 1]),
Check(FR),
"Invalid 'producers' node label in 'r'. Expected :c, got instead: :a."
Check(
late,
[GrowthRate.Map],
"Invalid 'producer' node label in 'r': :a. \
Valid nodes labels for this template are:\n [:c]",
)
)

gr = GrowthRate([0, 0, 4])
m = base + gr
@test m.growth_rate == [0, 0, 4] == m.r
@test typeof(gr) === FR

# Only producers values allowed.
@sysfails(
base + GrowthRate([4, 5, 7]),
Check(FR),
"Non-missing value found for 'r' at node index [1] (4.0), \
but the template for 'producers' only allows values \
at the following indices:\n [3]"
Check(
late,
[GrowthRate.Raw],
"Non-missing value found for 'r' at node index [1] (4.0), \
but the template for 'producers' only allows values \
at the following indices:\n [3]",
)
)

#---------------------------------------------------------------------------------------
Expand All @@ -37,12 +42,11 @@
base += BodyMass(; Z = 1) + MetabolicClass(:all_invertebrates)

gr = GrowthRate(:Miele2019)
@test typeof(gr) == FA
@test gr.allometry[:p][:a] == 1
@test gr.allometry[:p][:b] == -1 / 4

# Alternative explicit input.
@test gr == GrowthRateFromAllometry(; a_p = 1, b_p = -0.25)
@test gr == GrowthRate.Allometric(; a_p = 1, b_p = -0.25)

m = base + gr
@test m.growth_rate == [0, 0, 1]
Expand Down

0 comments on commit e4711f3

Please sign in to comment.