Select Git revision
aquacrop.jl
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
aquacrop.jl 1.84 KiB
import AquaCrop
struct AquaCropType
name::String
group::String
minsowdate::Union{Missing,AnnualDate}
maxsowdate::Union{Missing,AnnualDate}
end
cropname(ct::AquaCropType) = ct.name
mutable struct AquaCropState
croptype::AquaCropType
height::Length{Float64} # TODO: remove height field, supply from cropstate
cropstate::AquaCrop.AquaCropField
function AquaCropState(croptype::AquaCropType, height::Length{Float64}=0.0cm)
ac_parentdir = AquaCrop.test_toml_dir # TODO: hardcoded croptype
ac_runtype = :Julia
# cropstate = AquaCrop.AquaCropField(ac_parentdir, ac_runtype)
cropstate, allok = AquaCrop.initialize_cropfield(ac_parentdir, ac_runtype)
if ! allok.logi
error("AquaCrop.initialize_cropfield() failed, status = $allok")
end
return new(croptype, height, cropstate)
end
end
croptype(cs::AquaCropState) = cs.croptype
cropname(cs::AquaCropState) = cropname(croptype(cs))
cropheight(cs::AquaCropState) = cs.height
cropcover(cs::AquaCropState) = 0.0 # TODO: implement
cropyield(cs::AquaCropState) = 0.0 # TODO: implement, units?
isharvestable(cs::AquaCropState) = true # TODO: implement this correctly
"""
stepagent!(cropstate, model)
Update a crop state by one day.
"""
function stepagent!(cs::AquaCropState, model::SimulationModel)
# TODO: call into AquaCrop.jl to simulate one day
end
"""
sow!(cropstate, model, cropname)
Change the cropstate to sow the specified crop.
"""
function sow!(cs::AquaCropState, model::SimulationModel, cropname::String)
cs.croptype = model.crops[cropname]
cs.height = 0.0cm
# TODO: other things needed for AquaCrop?
end
"""
harvest!(cropstate, model)
Harvest the crop of this cropstate.
"""
function harvest!(cs::AquaCropState, model::SimulationModel)
# TODO: implement this
return 0.0u"g/m^2"
end