diff --git a/src/Persefone.jl b/src/Persefone.jl index 461dd0004e86cfc7bacb3f1a77958546e15776a2..4e423a03340b768fae15d07b10893f211193ccb2 100644 --- a/src/Persefone.jl +++ b/src/Persefone.jl @@ -138,8 +138,8 @@ include("analysis/makieplots.jl") include("world/landscape.jl") include("world/weather.jl") -include("crop/almass.jl") include("crop/farmplot.jl") +include("crop/almass.jl") include("farm/farm.jl") include("nature/insects.jl") diff --git a/src/core/input.jl b/src/core/input.jl index a8bc2a42d392c2ab220590867d791a53644fd9fe..46460cb92af1701ff1109771a439809722bb44a5 100644 --- a/src/core/input.jl +++ b/src/core/input.jl @@ -17,6 +17,11 @@ const PARAMFILE = joinpath(pkgdir(Persefone), "src/parameters.toml") #XXX do I need to use absolute paths for all input files in case working dir is changed? # (can be done with `joinpath(dirname(@__FILE__), <filename>)` ) +""" +The crop models that can be used in the simulation. +""" +const AVAILABLE_CROPMODELS = ["almass", "simple"] + """ @param(domainparam) @@ -89,6 +94,9 @@ function preprocessparameters(settings::Dict{String,Any}, defaultoutdir::String) Base.error("Enddate is earlier than startdate.") #TODO replace with exception end settings["world.mapresolution"] = settings["world.mapresolution"] * 1m + if ! (settings["crop.cropmodel"] in AVAILABLE_CROPMODELS) + error("crop.cropmodel = \"$(settings["crop.cropmodel"])\", but has to be one of: $AVAILABLE_CROPMODELS") + end #FIXME enable parallelisation # if !isempty(settings["internal.scanparams"]) && (nprocs() < 2) # @warn "To parallelise multiple simulation runs, use `julia -p <n>`." diff --git a/src/core/simulation.jl b/src/core/simulation.jl index f745b24ec4636caf23edc1d7de49a2924e387c19..70ab96279bc43577b49e02258eb925382ef5b11b 100644 --- a/src/core/simulation.jl +++ b/src/core/simulation.jl @@ -23,7 +23,8 @@ mutable struct AgricultureModel <: SimulationModel weather::Dict{Date,Weather} crops::Dict{String,ALMaSS.CropType} farmers::Vector{Farmer} - farmplots::Vector{ALMaSS.FarmPlot} + #farmplots::Vector{ALMaSS.FarmPlot} + farmplots::Vector{AbstractFarmPlot} animals::Vector{Union{Animal,Nothing}} migrants::Vector{Pair{Animal,Date}} events::Vector{FarmEvent} @@ -117,8 +118,13 @@ function initmodel(settings::Dict{String, Any}) settings["world.weatherfile"]), settings["core.startdate"], settings["core.enddate"]) - crops = ALMaSS.readcropparameters(settings["crop.cropfile"], - settings["crop.growthfile"]) + if settings["crop.cropmodel"] == "almass" + crops = ALMaSS.readcropparameters(settings["crop.cropfile"], + settings["crop.growthfile"]) + farmplots = Vector{ALMaSS.FarmPlot}() + else + error("Init for crop model \"$(settings["crop.cropmodel"])\" not implemented") + end model = AgricultureModel(settings, StableRNG(settings["core.seed"]), logger, @@ -129,7 +135,7 @@ function initmodel(settings::Dict{String, Any}) weather, crops, Vector{Farmer}(), - Vector{ALMaSS.FarmPlot}(), + farmplots, Vector{Union{Animal,Nothing}}(), Vector{Pair{Animal, Date}}(), Vector{FarmEvent}()) diff --git a/src/crop/almass.jl b/src/crop/almass.jl index e66ce77b3597b3741c94bbe3b181b73b6e3b01c3..8d26660c91f595fe1ba6a2deb6bb932ec17e7841 100644 --- a/src/crop/almass.jl +++ b/src/crop/almass.jl @@ -7,7 +7,7 @@ module ALMaSS -using Persefone: ModelAgent, EventType, SimulationModel, maxtemp, mintemp, fertiliser +using Persefone: AbstractFarmPlot, EventType, SimulationModel, maxtemp, mintemp, fertiliser import Persefone: stepagent! using Dates: Date, month, monthday using CSV: CSV @@ -136,7 +136,7 @@ end This represents one field, i.e. a collection of pixels with the same management. This is the spatial unit with which the crop growth model and the farm model work. """ -mutable struct FarmPlot <: ModelAgent +mutable struct FarmPlot <: AbstractFarmPlot #TODO add Unitful const id::Int64 pixels::Vector{Tuple{Int64, Int64}} diff --git a/src/crop/farmplot.jl b/src/crop/farmplot.jl index 46a563dc2d3fdd9617be37e1c9e164923e057691..4bd2721a997e5b152e35d994b472a3dca2102730 100644 --- a/src/crop/farmplot.jl +++ b/src/crop/farmplot.jl @@ -212,3 +212,5 @@ function cropcover(pos::Tuple{Int64,Int64}, model::SimulationModel) model.farmplots[model.landscape[pos...].fieldid].LAItotal end + + diff --git a/src/crop/simplecrop.jl b/src/crop/simplecrop.jl new file mode 100644 index 0000000000000000000000000000000000000000..b903db5ee3ae495bd58db0be3314856510aa15ea --- /dev/null +++ b/src/crop/simplecrop.jl @@ -0,0 +1,13 @@ + +module SimpleCrop + +""" + stepagent!(farmplot, model) + +Update a farm plot by one day. +""" +function stepagent!(farmplot::FarmPlot, model::SimulationModel) +end + +end # module SimpleCrop + diff --git a/test/paramscan.toml b/test/paramscan.toml index d2db42fb9add8f360c2247adb5cc3e65f8223054..565e6855f876dbc6474137cd22b0353c384485f8 100644 --- a/test/paramscan.toml +++ b/test/paramscan.toml @@ -28,5 +28,5 @@ popoutfreq = "daily" # output frequency population-level data, daily/monthly/yea indoutfreq = "end" # output frequency individual-level data, daily/monthly/yearly/end/never [crop] -cropmodel = "linear" # crop growth model to use, "linear" or "aquacrop" (not yet implemented) +cropmodel = "simple" # crop growth model to use, "simple" or "almass"