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

Introduce an AbstracFarmPlot type and a SimpleCrop submodule

parent e83abab5
No related branches found
No related tags found
No related merge requests found
......@@ -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")
......
......@@ -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>`."
......
......@@ -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}())
......
......@@ -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}}
......
......@@ -212,3 +212,5 @@ function cropcover(pos::Tuple{Int64,Int64}, model::SimulationModel)
model.farmplots[model.landscape[pos...].fieldid].LAItotal
end
module SimpleCrop
"""
stepagent!(farmplot, model)
Update a farm plot by one day.
"""
function stepagent!(farmplot::FarmPlot, model::SimulationModel)
end
end # module SimpleCrop
......@@ -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"
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