From e4711f30cc7405e43d0d45c1175abd71b7c95820 Mon Sep 17 00:00:00 2001 From: Iago Bonnici Date: Thu, 24 Oct 2024 11:02:45 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Start=20testing=20GrowthRate.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/allometry.jl | 1 + src/components/body_mass.jl | 6 +++--- src/components/foodweb.jl | 4 ++-- src/components/growth_rate.jl | 10 ++++------ src/components/hill_exponent.jl | 6 +++--- src/components/metabolic_class.jl | 8 ++++---- src/components/species.jl | 5 +++-- src/components/temperature.jl | 4 ++-- test/user/data_components/growth_rate.jl | 24 ++++++++++++++---------- 9 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/components/allometry.jl b/src/components/allometry.jl index 49bece2b1..9626e214a 100644 --- a/src/components/allometry.jl +++ b/src/components/allometry.jl @@ -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. diff --git a/src/components/body_mass.jl b/src/components/body_mass.jl index 6b9ba66e0..7e25265eb 100644 --- a/src/components/body_mass.jl +++ b/src/components/body_mass.jl @@ -6,7 +6,7 @@ # ========================================================================================== # Blueprints. -module BM +module BodyMass_ include("blueprint_modules.jl") include("blueprint_modules_identifiers.jl") import .EcologicalNetworksDynamics: _Species, Species, _Foodweb, Foodweb @@ -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) @@ -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 diff --git a/src/components/foodweb.jl b/src/components/foodweb.jl index bd4182925..1d38b19c5 100644 --- a/src/components/foodweb.jl +++ b/src/components/foodweb.jl @@ -11,7 +11,7 @@ # ========================================================================================== # Blueprints. -module FoodwebBlueprints +module Foodweb_ include("blueprint_modules.jl") include("blueprint_modules_identifiers.jl") import .EN: _Species, Species @@ -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 diff --git a/src/components/growth_rate.jl b/src/components/growth_rate.jl index 7a8885f0e..a273fe15e 100644 --- a/src/components/growth_rate.jl +++ b/src/components/growth_rate.jl @@ -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: @@ -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 @@ -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, @@ -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 diff --git a/src/components/hill_exponent.jl b/src/components/hill_exponent.jl index dd6cf7f0a..87d5746f5 100644 --- a/src/components/hill_exponent.jl +++ b/src/components/hill_exponent.jl @@ -6,7 +6,7 @@ # ========================================================================================== # Blueprints. -module HE +module HillExponent_ include("blueprint_modules.jl") #------------------------------------------------------------------------------------------- @@ -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) @@ -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. diff --git a/src/components/metabolic_class.jl b/src/components/metabolic_class.jl index 5e3f2d1d6..e9f60016e 100644 --- a/src/components/metabolic_class.jl +++ b/src/components/metabolic_class.jl @@ -13,7 +13,7 @@ # ========================================================================================== # Blueprints. -module MC +module MetabolicClass_ include("blueprint_modules.jl") include("./blueprint_modules_identifiers.jl") import .EcologicalNetworksDynamics: Species, _Species, Foodweb, _Foodweb @@ -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) @@ -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) diff --git a/src/components/species.jl b/src/components/species.jl index 6990b54f2..aadee34bc 100644 --- a/src/components/species.jl +++ b/src/components/species.jl @@ -9,7 +9,8 @@ # ========================================================================================== # Blueprints. -module SpeciesBlueprints +# Name + '_'-suffix is the module defining blueprints for this component. +module Species_ include("blueprint_modules.jl") #------------------------------------------------------------------------------------------- @@ -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. diff --git a/src/components/temperature.jl b/src/components/temperature.jl index d46221ec5..644e63f7a 100644 --- a/src/components/temperature.jl +++ b/src/components/temperature.jl @@ -7,7 +7,7 @@ # ========================================================================================== # Blueprints. -module T +module Temperature_ include("blueprint_modules.jl") #------------------------------------------------------------------------------------------- @@ -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) diff --git a/test/user/data_components/growth_rate.jl b/test/user/data_components/growth_rate.jl index b75d6ac33..ac806d7db 100644 --- a/test/user/data_components/growth_rate.jl +++ b/test/user/data_components/growth_rate.jl @@ -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]", + ) ) #--------------------------------------------------------------------------------------- @@ -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]