From 5144fa4c443474c39325f37fbbd0751edfe3cdaa Mon Sep 17 00:00:00 2001 From: Marco Matthies <71844+marcom@users.noreply.github.com> Date: Fri, 31 Jan 2025 00:58:43 +0100 Subject: [PATCH] Add `soiltype` field to `FarmPlot` - no majority counting of Pixels implemented yet, soil type is currently still determined by the first pixel of a FarmPlot --- src/crop/cropmodels.jl | 3 ++- src/crop/farmplot.jl | 1 + test/crop_tests.jl | 4 ++-- test/nature_tests.jl | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/crop/cropmodels.jl b/src/crop/cropmodels.jl index 0d2a68b..4030860 100644 --- a/src/crop/cropmodels.jl +++ b/src/crop/cropmodels.jl @@ -53,7 +53,8 @@ function initfields!(model::SimulationModel) push!(model.farmplots[objectid].pixels, (x,y)) else cropstate = makecropstate(model) - fp = FarmPlot(length(model.farmplots) + 1, [(x, y)], -1, cropstate) + soiltype = model.landscape[x,y].soiltype + fp = FarmPlot(length(model.farmplots) + 1, [(x, y)], -1, soiltype, cropstate) push!(model.farmplots, fp) model.landscape[x,y].fieldid = fp.id convertid[rawid] = fp.id diff --git a/src/crop/farmplot.jl b/src/crop/farmplot.jl index c44d6ad..f676276 100644 --- a/src/crop/farmplot.jl +++ b/src/crop/farmplot.jl @@ -12,6 +12,7 @@ mutable struct FarmPlot{T} <: ModelAgent const id::Int64 pixels::Vector{Tuple{Int64, Int64}} farmer::Int64 + soiltype::SoilType cropstate::T end diff --git a/test/crop_tests.jl b/test/crop_tests.jl index 23200a7..f404a3e 100644 --- a/test/crop_tests.jl +++ b/test/crop_tests.jl @@ -31,7 +31,7 @@ end mature = false events = Ps.Management[] force_growth = false - fp = FarmPlot(id, pixels, farmer, Ps.ALMaSS.CropState(croptype=ct, phase=Ps.ALMaSS.janfirst)) + fp = FarmPlot(id, pixels, farmer, Ps.soiltype_nodata, Ps.ALMaSS.CropState(croptype=ct, phase=Ps.ALMaSS.janfirst)) @test fp isa FarmPlot @test fp isa FarmPlot{Ps.ALMaSS.CropState} @test croptype(fp) isa Ps.ALMaSS.CropType @@ -46,7 +46,7 @@ end id = 0 pixels = [(0, 0)] farmer = 0 - fp = FarmPlot(id, pixels, farmer, Ps.SimpleCrop.CropState(ct, 0.0cm)) + fp = FarmPlot(id, pixels, farmer, Ps.soiltype_nodata, Ps.SimpleCrop.CropState(ct, 0.0cm)) @test fp isa FarmPlot @test fp isa FarmPlot{Ps.SimpleCrop.CropState} @test croptype(fp) isa Ps.SimpleCrop.CropType diff --git a/test/nature_tests.jl b/test/nature_tests.jl index 1e829fc..fcbf97f 100644 --- a/test/nature_tests.jl +++ b/test/nature_tests.jl @@ -49,7 +49,7 @@ end) # end eval model = inittestmodel() model.landscape[6,6] = Pixel(Ps.agriculture, Ps.soiltype_sand, 1, [], [], []) fp = Ps.FarmPlot( - 1, [(6,6)], 1, + 1, [(6,6)], 1, Ps.soiltype_nodata, Ps.ALMaSS.CropState( croptype = model.crops["winter wheat"], phase = Ps.ALMaSS.janfirst, -- GitLab