diff --git a/src/Persefone.jl b/src/Persefone.jl index f7a5c304dda3f80708a61fa9d7ee3141adf5bb2c..eeb8ec0694a6abdf7b4896505679611e03bcbbc8 100644 --- a/src/Persefone.jl +++ b/src/Persefone.jl @@ -46,7 +46,7 @@ export Weather, FarmEvent, ModelAgent, - # FarmPlot, + FarmPlot, Animal, Farmer, DataOutput, @@ -103,7 +103,9 @@ export loadmodelobject, croptype, cropname, - cropheight + cropheight, + cropcover, + cropyield ## Import and define units and dimensions import Unitful: cm, m, km, ha, mg, g, kg, Length, Area, Mass diff --git a/src/crop/almass.jl b/src/crop/almass.jl index 116cd50ca2b17f1084e57b8b442170e7d840d8f2..68d60eb4759a4b54aa8aab6593a7e54e89453323 100644 --- a/src/crop/almass.jl +++ b/src/crop/almass.jl @@ -21,7 +21,9 @@ import Persefone: stepagent!, croptype, cropname, - cropheight + cropheight, + cropcover, + cropyield using Dates: Date, month, monthday using CSV: CSV @@ -89,6 +91,8 @@ end croptype(cs::CropState) = cs.croptype cropname(cs::CropState) = cropname(croptype(cs)) cropheight(cs::CropState) = cs.height +cropcover(cs::CropState) = 0.0 +cropyield(cs::CropState) = 0.0 """ Base.tryparse(type, str) diff --git a/src/crop/farmplot.jl b/src/crop/farmplot.jl index a3c283ee9b15b5acc048d8ecb34d990b0010956d..0758219930808ccf43be5b89a669f8040c16d445 100644 --- a/src/crop/farmplot.jl +++ b/src/crop/farmplot.jl @@ -3,9 +3,6 @@ ### This file contains code for the fields that farmers manage. ### -# abstract type AbstractFarmPlot <: ModelAgent end - -# mutable struct FarmPlot{T <: AbstractCropState} <: AbstractFarmPlot mutable struct FarmPlot{T} <: ModelAgent const id::Int64 pixels::Vector{Tuple{Int64, Int64}} @@ -15,6 +12,8 @@ end croptype(f::FarmPlot{T}) where {T} = croptype(f.crop_state) cropname(f::FarmPlot{T}) where {T} = cropname(croptype(f)) cropheight(f::FarmPlot{T}) where {T} = cropheight(f.crop_state) +cropcover(f::FarmPlot{T}) where {T} = cropcover(f.crop_state) +cropyield(f::FarmPlot{T}) where {T} = cropyield(f.crop_state) """ initfields_fill_with!(make_farmplot_fn, model) diff --git a/src/crop/simplecrop.jl b/src/crop/simplecrop.jl index 7c622e7ea7c8571adac8f5fa05b0da21303973f8..d7b61b21f4f764b24a371074784f0531f93741d2 100644 --- a/src/crop/simplecrop.jl +++ b/src/crop/simplecrop.jl @@ -10,7 +10,9 @@ import Persefone: stepagent!, croptype, cropname, - cropheight + cropheight, + cropcover, + cropyield struct CropType name::String @@ -20,12 +22,15 @@ cropname(ct::CropType) = ct.name mutable struct CropState croptype::CropType - cropheight::Length{Float64} + height::Length{Float64} end croptype(cs::CropState) = cs.croptype cropname(cs::CropState) = cropname(croptype(cs)) cropheight(cs::CropState) = cs.height +cropcover(cs::CropState) = 0.0 +cropyield(cs::CropState) = 0.0 + """ stepagent!(farmplot, model) diff --git a/test/crop_tests.jl b/test/crop_tests.jl index b2d12fbc98d2fefec76ff2767a82beb9a7bd159d..7a097ce492e756a6ac7fb49d614e81ce89d0b02e 100644 --- a/test/crop_tests.jl +++ b/test/crop_tests.jl @@ -6,7 +6,6 @@ const TESTPARAM_ALMASS = joinpath(pkgdir(Persefone), "test", "test_parameters_almass.toml") const TESTPARAM_SIMPLECROP = joinpath(pkgdir(Persefone), "test", "test_parameters_simplecrop.toml") -#"Model initialisation" begin @testset for paramfile in (TESTPARAM_ALMASS, TESTPARAM_SIMPLECROP) @testset "Model initialisation" begin model = initialise(paramfile) @@ -19,3 +18,28 @@ const TESTPARAM_SIMPLECROP = joinpath(pkgdir(Persefone), "test", "test_parameter end end +@testset "Submodule ALMaSS" begin + ct = Ps.ALMaSS.CropType("olive tree", missing, missing, missing, missing, missing, + missing, missing) + fp = FarmPlot(0, [(0,0)], + Ps.ALMaSS.CropState(ct, Ps.ALMaSS.janfirst, 0.0, 0.0m, 0.0, 0.0, Ps.EventType[])) + @test fp isa FarmPlot + @test fp isa FarmPlot{Ps.ALMaSS.CropState} + @test croptype(fp) isa Ps.ALMaSS.CropType + @test cropname(fp) isa String + @test cropheight(fp) isa Length{Float64} + @test cropcover(fp) isa Float64 + @test cropyield(fp) isa Float64 +end + +@testset "Submodule SimpleCrop" begin + ct = Ps.SimpleCrop.CropType("olive tree") + fp = FarmPlot(0, [(0,0)], Ps.SimpleCrop.CropState(ct, 0.0m)) + @test fp isa FarmPlot + @test fp isa FarmPlot{Ps.SimpleCrop.CropState} + @test croptype(fp) isa Ps.SimpleCrop.CropType + @test cropname(fp) isa String + @test cropheight(fp) isa Length{Float64} + @test cropcover(fp) isa Float64 + @test cropyield(fp) isa Float64 +end