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

ALMaSS: allow choosing highnutrientcurve when calling sow!

`sow!(::ALMaSS.CropState, ...)` calls `setphase!`, which needs to know
which growth curve to use.  Some crop types (e.g. "permanent
set-aside") do not have a lownutrientgrowthcurve, which then causes an
error when `setphase!` tries to access the `missing` growth curve.

The highnutrientgrowthcurve would only be chosen when the cropstate
had `fertilising` in its events.  As the events for a cropstate are
now `empty!`ied in `sow!`, it's not possible to set the `fertilising`
event before calling `sow!`.

This previously didn't cause a bug, as the logic for which growth
curve to choose was the wrong way around, choosing the
highnutrientgrowth curve when no `fertilising` event was set for the
cropstate.
parent dbc4e94b
No related branches found
No related tags found
No related merge requests found
......@@ -796,13 +796,17 @@ supply_global_radiation(model::SimulationModel) =
Change the cropstate to sow the specified crop.
"""
function sow!(cs::CropState, model::SimulationModel, cropname::String)
function sow!(cs::CropState, model::SimulationModel, cropname::String;
highnutrients::Bool=false)
!ismissing(cs.croptype.minsowdate) && model.date < cs.croptype.minsowdate &&
@warn "$(model.date) is earlier than the minimum sowing date for $(cropname)."
empty!(cs.events)
if highnutrients
push!(cs.events, fertiliser)
end
cs.croptype = model.crops[cropname]
setphase!(cs, sow, model)
cs.mature = false
empty!(cs.events)
# cs.vegddegs = 0.0
# cs.ddegs = 0.0
......
......@@ -36,9 +36,9 @@ end
Sow the specified crop on the farmplot.
"""
function sow!(farmplot::FarmPlot, model::SimulationModel, cropname::String)
function sow!(farmplot::FarmPlot, model::SimulationModel, cropname::String; kwargs...)
createevent!(model, farmplot.pixels, sowing)
sow!(farmplot.cropstate, model, cropname)
sow!(farmplot.cropstate, model, cropname; kwargs...)
@debug "Farmer $(farmplot.farmer) sowed $(cropname) on farmplot $(farmplot.id)."
end
......
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