From 7ccf4c6f5b7ae2eab98ecc23e7fc7f9808270e99 Mon Sep 17 00:00:00 2001
From: Marco Matthies <71844+marcom@users.noreply.github.com>
Date: Sun, 14 Jul 2024 19:55:19 +0200
Subject: [PATCH] Move ALMaSS crop model to its own submodule

---
 src/core/simulation.jl |  6 +++---
 src/crop/crops.jl      |  6 ++++++
 src/crop/farmplot.jl   | 10 +++++-----
 src/farm/farm.jl       |  2 +-
 test/nature_tests.jl   |  2 +-
 test/runtests.jl       |  4 ++--
 6 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/core/simulation.jl b/src/core/simulation.jl
index 05158aa..b94b521 100644
--- a/src/core/simulation.jl
+++ b/src/core/simulation.jl
@@ -21,7 +21,7 @@ mutable struct AgricultureModel <: SimulationModel
     date::Date
     landscape::Matrix{Pixel}
     weather::Dict{Date,Weather}
-    crops::Dict{String,CropType}
+    crops::Dict{String,ALMaSS.CropType}
     farmers::Vector{Farmer}
     farmplots::Vector{FarmPlot}
     animals::Vector{Union{Animal,Nothing}}
@@ -117,8 +117,8 @@ function initmodel(settings::Dict{String, Any})
                                        settings["world.weatherfile"]),
                               settings["core.startdate"],
                               settings["core.enddate"])
-        crops = readcropparameters(settings["crop.cropfile"],
-                                   settings["crop.growthfile"])
+        crops = ALMaSS.readcropparameters(settings["crop.cropfile"],
+                                          settings["crop.growthfile"])
         model = AgricultureModel(settings,
                                  StableRNG(settings["core.seed"]),
                                  logger,
diff --git a/src/crop/crops.jl b/src/crop/crops.jl
index 996c6da..3b4ce0c 100644
--- a/src/crop/crops.jl
+++ b/src/crop/crops.jl
@@ -5,6 +5,10 @@
 
 #TODO write tests for input functions
 
+module ALMaSS
+using Dates: Date
+using CSV: CSV
+
 """
     GrowthPhase
 
@@ -119,3 +123,5 @@ function readcropparameters(generalcropfile::String, growthfile::String)
     end
     croptypes
 end
+
+end # module ALMaSS
diff --git a/src/crop/farmplot.jl b/src/crop/farmplot.jl
index 359c0c0..5d95d2f 100644
--- a/src/crop/farmplot.jl
+++ b/src/crop/farmplot.jl
@@ -15,8 +15,8 @@ mutable struct FarmPlot <: ModelAgent
     #TODO add Unitful
     const id::Int64
     pixels::Vector{Tuple{Int64, Int64}}
-    croptype::CropType
-    phase::GrowthPhase
+    croptype::ALMaSS.CropType
+    phase::ALMaSS.GrowthPhase
     growingdegreedays::Float64
     height::Float64
     LAItotal::Float64
@@ -47,7 +47,7 @@ function initfields!(model::SimulationModel)
                 push!(model.farmplots[objectid].pixels, (x,y))
             else
                 #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)],
                                 model.crops["natural grass"], phase,
                               0.0, 0.0, 0.0, 0.0, Vector{Management}())
@@ -75,8 +75,8 @@ function stepagent!(farmplot::FarmPlot, model::SimulationModel)
     gdd = (maxtemp(model)+mintemp(model))/2 - basetemp
     gdd > 0 && (farmplot.growingdegreedays += gdd)
     # update the phase on key dates
-    monthday(model.date) == (1,1) && (farmplot.phase = janfirst)
-    monthday(model.date) == (3,1) && (farmplot.phase = marchfirst)
+    monthday(model.date) == (1,1) && (farmplot.phase = ALMaSS.janfirst)
+    monthday(model.date) == (3,1) && (farmplot.phase = ALMaSS.marchfirst)
     # update crop growth
     growcrop!(farmplot, model)
 end
diff --git a/src/farm/farm.jl b/src/farm/farm.jl
index 391b825..ef3d34c 100644
--- a/src/farm/farm.jl
+++ b/src/farm/farm.jl
@@ -13,7 +13,7 @@ mutable struct Farmer <: ModelAgent
     # farm submodels? (#69)
     const id::Int64
     fields::Vector{FarmPlot}
-    croprotation::Vector{CropType}
+    croprotation::Vector{ALMaSS.CropType}
     #TODO add AES
 end
 
diff --git a/test/nature_tests.jl b/test/nature_tests.jl
index afeab5e..9f7d11e 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, 1)
     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}()))
     push!(model.animals,
           Ps.Mermaid(1, Ps.male, (-1,-1), (3,3), Ps.life),
diff --git a/test/runtests.jl b/test/runtests.jl
index b36a792..39aef77 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -43,8 +43,8 @@ function inittestmodel(smallmap=true)
                                       TESTSETTINGS["world.weatherfile"]),
                              TESTSETTINGS["core.startdate"],
                              TESTSETTINGS["core.enddate"])
-    crops = Ps.readcropparameters(TESTSETTINGS["crop.cropfile"],
-                                  TESTSETTINGS["crop.growthfile"])
+    crops = Ps.ALMaSS.readcropparameters(TESTSETTINGS["crop.cropfile"],
+                                         TESTSETTINGS["crop.growthfile"])
     model = AgricultureModel(TESTSETTINGS,
                              StableRNG(TESTSETTINGS["core.seed"]),
                              global_logger(),
-- 
GitLab