From f4c8040256b2e54525efa3441f8b10a1e87a0357 Mon Sep 17 00:00:00 2001 From: Marco Matthies <71844+marcom@users.noreply.github.com> Date: Mon, 2 Sep 2024 08:58:51 +0200 Subject: [PATCH] Add crop state init for AquaCrop Currently errors with an error from inside AquaCrop.jl --- Project.toml | 1 + src/crop/aquacrop.jl | 14 +++++++++++++- src/crop/cropmodels.jl | 2 +- test/crop_tests.jl | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index b34a8e3..b7d065c 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ authors = ["Daniel Vedder <daniel.vedder@idiv.de>"] version = "0.5.5" [deps] +AquaCrop = "8f16cebd-c0b4-44a3-857f-c101f083256c" ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" diff --git a/src/crop/aquacrop.jl b/src/crop/aquacrop.jl index 2ae7942..6986873 100644 --- a/src/crop/aquacrop.jl +++ b/src/crop/aquacrop.jl @@ -1,3 +1,5 @@ +import AquaCrop + struct AquaCropType name::String group::String @@ -9,7 +11,17 @@ cropname(ct::AquaCropType) = ct.name mutable struct AquaCropState croptype::AquaCropType - height::Length{Float64} + height::Length{Float64} # TODO: remove height field, supply from cropstate + cropstate::AquaCrop.AquaCropField + + function AquaCropState(croptype::AquaCropType, height::Length{Float64}=0.0cm) + ac_parentdir = "./tmp-aquacrop-param" # TODO + # TODO: runtype can be :Fortran, :Julia or :Persefone in the + # future, so then use :Persefone + ac_runtype = :Julia + cropstate = AquaCrop.AquaCropField(ac_parentdir, ac_runtype) + return new(croptype, height, cropstate) + end end croptype(cs::AquaCropState) = cs.croptype diff --git a/src/crop/cropmodels.jl b/src/crop/cropmodels.jl index 4846716..c9cc1fd 100644 --- a/src/crop/cropmodels.jl +++ b/src/crop/cropmodels.jl @@ -82,7 +82,7 @@ function makecropstate(model::SimulationModel) 0.0m ) elseif @param(crop.cropmodel) == "aquacrop" - cs = AquaCropState(model.crops["natural grass"], 0.0m) + cs = AquaCropState(model.crops["natural grass"], 0.0cm) else Base.error("Unhandled crop model '$(@param(crop.cropmodel))' in makecropstate().") end diff --git a/test/crop_tests.jl b/test/crop_tests.jl index ec80f27..59ffdb6 100644 --- a/test/crop_tests.jl +++ b/test/crop_tests.jl @@ -58,7 +58,7 @@ end id = 0 pixels = [(0, 0)] farmer = 0 - fp = FarmPlot(id, pixels, farmer, Ps.AquaCropState(ct, 0.0cm)) + fp = FarmPlot(id, pixels, farmer, Ps.AquaCropState(ct)) @test fp isa FarmPlot @test fp isa FarmPlot{Ps.AquaCropState} @test croptype(fp) isa Ps.AquaCropType -- GitLab