From 441b94033095a611094e19de5d53cd9749019c0d Mon Sep 17 00:00:00 2001 From: Marco Matthies <71844+marcom@users.noreply.github.com> Date: Fri, 31 Jan 2025 01:22:53 +0100 Subject: [PATCH] Set the soil type of a FarmPlot to the most frequent soil type of its pixels --- src/crop/cropmodels.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/crop/cropmodels.jl b/src/crop/cropmodels.jl index 4030860..4a67eba 100644 --- a/src/crop/cropmodels.jl +++ b/src/crop/cropmodels.jl @@ -3,6 +3,8 @@ ### Functions for switchable crop models. ### +using StatsBase: mode + """ initfields!(cropmodel, cropfile, growthfile) @@ -61,6 +63,12 @@ function initfields!(model::SimulationModel) end end end + + # Adjust soil type to most common soil type of the pixels + # belonging to a farmplot + for fp in model.farmplots + fp.soiltype = mode(map(p -> model.landscape[p[1], p[2]].soiltype, fp.pixels)) + end @info "Initialised $(length(model.farmplots)) farm plots." end -- GitLab