Skip to content
Snippets Groups Projects
Commit 84b933f8 authored by Marco Matthies's avatar Marco Matthies
Browse files

AquaCrop: wrap interface code in WrapAquaCrop submodule

parent e5e3a07a
No related branches found
No related tags found
No related merge requests found
module WrapAquaCrop
# Persefone.jl wrapper for AquaCrop.jl
# Use different name from `AquaCrop` to avoid name clash
import AquaCrop import AquaCrop
using Persefone:
AnnualDate,
cm,
SimulationModel
import Persefone:
stepagent!,
croptype,
cropname,
cropheight,
cropcover,
cropyield,
sow!,
harvest!,
isharvestable
using Unitful: @u_str
# We can't use Length{Float64} as that is a Union type # We can't use Length{Float64} as that is a Union type
const Tlength = typeof(1.0cm) const Tlength = typeof(1.0cm)
...@@ -68,3 +91,5 @@ function harvest!(cs::AquaCropState, model::SimulationModel) ...@@ -68,3 +91,5 @@ function harvest!(cs::AquaCropState, model::SimulationModel)
# TODO: implement this # TODO: implement this
return 0.0u"g/m^2" return 0.0u"g/m^2"
end end
end # module WrapAquaCrop
...@@ -21,11 +21,11 @@ function initcropmodel(cropmodel::AbstractString, cropdirectory::AbstractString) ...@@ -21,11 +21,11 @@ function initcropmodel(cropmodel::AbstractString, cropdirectory::AbstractString)
crops = Dict(name => SimpleCrop.CropType(ct.name, ct.group, ct.minsowdate, ct.maxsowdate) crops = Dict(name => SimpleCrop.CropType(ct.name, ct.group, ct.minsowdate, ct.maxsowdate)
for (name, ct) in crops_almass) for (name, ct) in crops_almass)
elseif cropmodel == "aquacrop" elseif cropmodel == "aquacrop"
Tcroptype = AquaCropType Tcroptype = WrapAquaCrop.AquaCropType
Tcropstate = AquaCropState Tcropstate = WrapAquaCrop.AquaCropState
# TODO: temporarily using ALMaSS crop types # TODO: temporarily using ALMaSS crop types
crops_almass = ALMaSS.readcropparameters(cropdirectory) crops_almass = ALMaSS.readcropparameters(cropdirectory)
crops = Dict(name => AquaCropType(ct.name, ct.group, ct.minsowdate, ct.maxsowdate) crops = Dict(name => WrapAquaCrop.AquaCropType(ct.name, ct.group, ct.minsowdate, ct.maxsowdate)
for (name, ct) in crops_almass) for (name, ct) in crops_almass)
else else
error("initcropmodel: no implementation for crop model '$cropmodel'") error("initcropmodel: no implementation for crop model '$cropmodel'")
...@@ -81,7 +81,7 @@ function makecropstate(model::SimulationModel) ...@@ -81,7 +81,7 @@ function makecropstate(model::SimulationModel)
0.0m 0.0m
) )
elseif @param(crop.cropmodel) == "aquacrop" elseif @param(crop.cropmodel) == "aquacrop"
cs = AquaCropState(model.crops["natural grass"], 0.0cm) cs = WrapAquaCrop.AquaCropState(model.crops["natural grass"], 0.0cm)
else else
Base.error("Unhandled crop model '$(@param(crop.cropmodel))' in makecropstate().") Base.error("Unhandled crop model '$(@param(crop.cropmodel))' in makecropstate().")
end end
......
...@@ -57,14 +57,15 @@ end ...@@ -57,14 +57,15 @@ end
end end
@testset "Submodule AquaCrop" begin @testset "Submodule AquaCrop" begin
ct = Ps.AquaCropType("olive tree", "no_crop_group", AnnualDate(4, 1), AnnualDate(5, 1)) PsAC = Ps.WrapAquaCrop
ct = PsAC.AquaCropType("olive tree", "no_crop_group", AnnualDate(4, 1), AnnualDate(5, 1))
id = 0 id = 0
pixels = [(0, 0)] pixels = [(0, 0)]
farmer = 0 farmer = 0
fp = FarmPlot(id, pixels, farmer, Ps.AquaCropState(ct)) fp = FarmPlot(id, pixels, farmer, PsAC.AquaCropState(ct))
@test fp isa FarmPlot @test fp isa FarmPlot
@test fp isa FarmPlot{Ps.AquaCropState} @test fp isa FarmPlot{PsAC.AquaCropState}
@test croptype(fp) isa Ps.AquaCropType @test croptype(fp) isa PsAC.AquaCropType
@test cropname(fp) isa String @test cropname(fp) isa String
@test cropheight(fp) isa Length{Float64} @test cropheight(fp) isa Length{Float64}
@test cropcover(fp) isa Float64 @test cropcover(fp) isa Float64
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment