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

Move ALMaSS crop model to its own submodule

parent 402fa8e4
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ mutable struct AgricultureModel <: SimulationModel ...@@ -21,7 +21,7 @@ mutable struct AgricultureModel <: SimulationModel
date::Date date::Date
landscape::Matrix{Pixel} landscape::Matrix{Pixel}
weather::Dict{Date,Weather} weather::Dict{Date,Weather}
crops::Dict{String,CropType} crops::Dict{String,ALMaSS.CropType}
farmers::Vector{Farmer} farmers::Vector{Farmer}
farmplots::Vector{FarmPlot} farmplots::Vector{FarmPlot}
animals::Vector{Union{Animal,Nothing}} animals::Vector{Union{Animal,Nothing}}
...@@ -117,8 +117,8 @@ function initmodel(settings::Dict{String, Any}) ...@@ -117,8 +117,8 @@ function initmodel(settings::Dict{String, Any})
settings["world.weatherfile"]), settings["world.weatherfile"]),
settings["core.startdate"], settings["core.startdate"],
settings["core.enddate"]) settings["core.enddate"])
crops = readcropparameters(settings["crop.cropfile"], crops = ALMaSS.readcropparameters(settings["crop.cropfile"],
settings["crop.growthfile"]) settings["crop.growthfile"])
model = AgricultureModel(settings, model = AgricultureModel(settings,
StableRNG(settings["core.seed"]), StableRNG(settings["core.seed"]),
logger, logger,
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
#TODO write tests for input functions #TODO write tests for input functions
module ALMaSS
using Dates: Date
using CSV: CSV
""" """
GrowthPhase GrowthPhase
...@@ -119,3 +123,5 @@ function readcropparameters(generalcropfile::String, growthfile::String) ...@@ -119,3 +123,5 @@ function readcropparameters(generalcropfile::String, growthfile::String)
end end
croptypes croptypes
end end
end # module ALMaSS
...@@ -15,8 +15,8 @@ mutable struct FarmPlot <: ModelAgent ...@@ -15,8 +15,8 @@ mutable struct FarmPlot <: ModelAgent
#TODO add Unitful #TODO add Unitful
const id::Int64 const id::Int64
pixels::Vector{Tuple{Int64, Int64}} pixels::Vector{Tuple{Int64, Int64}}
croptype::CropType croptype::ALMaSS.CropType
phase::GrowthPhase phase::ALMaSS.GrowthPhase
growingdegreedays::Float64 growingdegreedays::Float64
height::Float64 height::Float64
LAItotal::Float64 LAItotal::Float64
...@@ -47,7 +47,7 @@ function initfields!(model::SimulationModel) ...@@ -47,7 +47,7 @@ function initfields!(model::SimulationModel)
push!(model.farmplots[objectid].pixels, (x,y)) push!(model.farmplots[objectid].pixels, (x,y))
else else
#XXX does this phase calculation work out? #XXX does this phase calculation work out?
month(model.date) < 3 ? phase = janfirst : phase = marchfirst month(model.date) < 3 ? phase = ALMaSS.janfirst : phase = ALMaSS.marchfirst
fp = FarmPlot(length(model.farmplots)+1, [(x,y)], fp = FarmPlot(length(model.farmplots)+1, [(x,y)],
model.crops["natural grass"], phase, model.crops["natural grass"], phase,
0.0, 0.0, 0.0, 0.0, Vector{Management}()) 0.0, 0.0, 0.0, 0.0, Vector{Management}())
...@@ -75,8 +75,8 @@ function stepagent!(farmplot::FarmPlot, model::SimulationModel) ...@@ -75,8 +75,8 @@ function stepagent!(farmplot::FarmPlot, model::SimulationModel)
gdd = (maxtemp(model)+mintemp(model))/2 - basetemp gdd = (maxtemp(model)+mintemp(model))/2 - basetemp
gdd > 0 && (farmplot.growingdegreedays += gdd) gdd > 0 && (farmplot.growingdegreedays += gdd)
# update the phase on key dates # update the phase on key dates
monthday(model.date) == (1,1) && (farmplot.phase = janfirst) monthday(model.date) == (1,1) && (farmplot.phase = ALMaSS.janfirst)
monthday(model.date) == (3,1) && (farmplot.phase = marchfirst) monthday(model.date) == (3,1) && (farmplot.phase = ALMaSS.marchfirst)
# update crop growth # update crop growth
growcrop!(farmplot, model) growcrop!(farmplot, model)
end end
......
...@@ -13,7 +13,7 @@ mutable struct Farmer <: ModelAgent ...@@ -13,7 +13,7 @@ mutable struct Farmer <: ModelAgent
# farm submodels? (#69) # farm submodels? (#69)
const id::Int64 const id::Int64
fields::Vector{FarmPlot} fields::Vector{FarmPlot}
croprotation::Vector{CropType} croprotation::Vector{ALMaSS.CropType}
#TODO add AES #TODO add AES
end end
......
...@@ -49,7 +49,7 @@ end) # end eval ...@@ -49,7 +49,7 @@ end) # end eval
model = inittestmodel() model = inittestmodel()
model.landscape[6,6] = Pixel(Ps.agriculture, 1) model.landscape[6,6] = Pixel(Ps.agriculture, 1)
push!(model.farmplots, push!(model.farmplots,
FarmPlot(1, [(6,6)], model.crops["winter wheat"], Ps.janfirst, FarmPlot(1, [(6,6)], model.crops["winter wheat"], Ps.ALMaSS.janfirst,
0.0, 0.0, 0.0, 0.0, Vector{Ps.Management}())) 0.0, 0.0, 0.0, 0.0, Vector{Ps.Management}()))
push!(model.animals, push!(model.animals,
Ps.Mermaid(1, Ps.male, (-1,-1), (3,3), Ps.life), Ps.Mermaid(1, Ps.male, (-1,-1), (3,3), Ps.life),
......
...@@ -43,8 +43,8 @@ function inittestmodel(smallmap=true) ...@@ -43,8 +43,8 @@ function inittestmodel(smallmap=true)
TESTSETTINGS["world.weatherfile"]), TESTSETTINGS["world.weatherfile"]),
TESTSETTINGS["core.startdate"], TESTSETTINGS["core.startdate"],
TESTSETTINGS["core.enddate"]) TESTSETTINGS["core.enddate"])
crops = Ps.readcropparameters(TESTSETTINGS["crop.cropfile"], crops = Ps.ALMaSS.readcropparameters(TESTSETTINGS["crop.cropfile"],
TESTSETTINGS["crop.growthfile"]) TESTSETTINGS["crop.growthfile"])
model = AgricultureModel(TESTSETTINGS, model = AgricultureModel(TESTSETTINGS,
StableRNG(TESTSETTINGS["core.seed"]), StableRNG(TESTSETTINGS["core.seed"]),
global_logger(), global_logger(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment