From a3ce5121368549c7b7ba85b6c482ae2cfeec0461 Mon Sep 17 00:00:00 2001
From: Daniel Vedder <daniel.vedder@idiv.de>
Date: Thu, 20 Jun 2024 11:27:53 +0200
Subject: [PATCH] Renamed EventType to Management

---
 src/crop/farmplot.jl          |  4 ++--
 src/nature/insects.jl         |  2 +-
 src/nature/species/skylark.jl | 17 ++++++++++-------
 src/world/landscape.jl        | 12 ++++++------
 4 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/crop/farmplot.jl b/src/crop/farmplot.jl
index 3f037e0..cb349be 100644
--- a/src/crop/farmplot.jl
+++ b/src/crop/farmplot.jl
@@ -22,7 +22,7 @@ mutable struct FarmPlot <: ModelAgent
     LAItotal::Float64
     LAIgreen::Float64
     #biomass::Float64 #XXX I need to figure out how to calculate this
-    events::Vector{EventType}
+    events::Vector{Management}
 end
 
 """
@@ -50,7 +50,7 @@ function initfields!(model::SimulationModel)
                 month(model.date) < 3 ? phase = janfirst : phase = marchfirst
                 fp = FarmPlot(length(model.farmplots)+1, [(x,y)],
                                 model.crops["natural grass"], phase,
-                              0.0, 0.0, 0.0, 0.0, Vector{EventType}())
+                              0.0, 0.0, 0.0, 0.0, Vector{Management}())
                 push!(model.farmplots, fp)
                 model.landscape[x,y].fieldid = fp.id
                 convertid[rawid] = fp.id
diff --git a/src/nature/insects.jl b/src/nature/insects.jl
index b8c8306..33824ab 100644
--- a/src/nature/insects.jl
+++ b/src/nature/insects.jl
@@ -38,7 +38,7 @@ function insectbiomass(pixel::Pixel, model::SimulationModel)::Float64
     ## based on fig. 3a in Paquette et al. (2013)
     if "season" in @param(nature.insectmodel)
         calendarday = dayofyear(model.date)
-        seasonfactor = -0.085(calendarday-187)^2
+        seasonfactor = (-0.085(calendarday-187)^2)mg/m²
     end
 
     ## habitat dependence of insect biomass,
diff --git a/src/nature/species/skylark.jl b/src/nature/species/skylark.jl
index 9f4e2e7..776d909 100644
--- a/src/nature/species/skylark.jl
+++ b/src/nature/species/skylark.jl
@@ -31,9 +31,9 @@ At the moment, this implementation is still in development.
 """
 @species Skylark begin
     # species parameters
-    const eggtime::Int64 = 11 # 11 days from laying to hatching
-    const nestlingtime::UnitRange{Int64} = 7:11 # 7-11 days from hatching to leaving nest
-    const fledglingtime::UnitRange{Int64} = 25:30 # 25-30 days from hatching to independence
+    const eggtime::Int64 = 11 # days from laying to hatching
+    const nestlingtime::UnitRange{Int64} = 7:11 # days from hatching to leaving nest
+    const fledglingtime::UnitRange{Int64} = 25:30 # days from hatching to independence
 
     const eggpredationmortality::Float64 = 0.03 # per-day egg mortality from predation
     const nestharvestmortality::Float64 = 0.9 # egg/nestling mortality after a harvest event (XXX guess)
@@ -45,8 +45,8 @@ At the moment, this implementation is still in development.
 
     const nestingbegin::Tuple{Int64,Int64} = (April, 10) # begin nesting in the middle of April
     const nestbuildingtime::UnitRange{Int64} = 4:5 # 4-5 days needed to build a nest (doubled for first nest)
-    const eggsperclutch::UnitRange{Int64} = 2:5 # 2-5 eggs laid per clutch
-    const breedingdelay::Int64 = 18 # wait 18 days after hatching to start a new brood
+    const eggsperclutch::UnitRange{Int64} = 2:5 # eggs laid per clutch
+    const breedingdelay::Int64 = 18 # days after hatching before starting a new brood
     const nestingend::Int64 = July # last month of nesting
     
     const habitats::Function = skylarkhabitat
@@ -221,9 +221,12 @@ Do lots of foraging (not yet implemented).
     # if all young have fledged, move to nonbreeding (if it's July) or breed again
     if isempty(self.clutch)
         self.nest = ()
-        month(model.date) >= self.nestingend ?
-            @setphase(nonbreeding) :
+        if month(model.date) >= self.nestingend
+            self.territory = []
+            @setphase(nonbreeding)
+        else
             @setphase(nestbuilding)
+        end
     end
 end
 
diff --git a/src/world/landscape.jl b/src/world/landscape.jl
index d78bd70..4f6a930 100644
--- a/src/world/landscape.jl
+++ b/src/world/landscape.jl
@@ -7,8 +7,8 @@
 "The land cover classes encoded in the Mundialis Sentinel data."
 @enum LandCover nodata forest grass water builtup soil agriculture
 
-"The types of landscape event that can be simulated"
-@enum EventType tillage sowing fertiliser pesticide harvesting
+"The types of management event that can be simulated"
+@enum Management tillage sowing fertiliser pesticide harvesting
 #XXX rename to Management or similar?
 
 """
@@ -21,7 +21,7 @@ in a single object. The model landscape consists of a matrix of pixels.
 mutable struct Pixel
     landcover::LandCover
     fieldid::Union{Missing,Int64}
-    events::Vector{EventType}
+    events::Vector{Management}
     animals::Vector{Int64}
 end
 
@@ -32,7 +32,7 @@ A data structure to define a landscape event, giving its type,
 spatial extent, and duration.
 """
 mutable struct FarmEvent
-    etype::EventType
+    management::Management
     pixels::Vector{Tuple{Int64,Int64}}
     duration::Int64
 end
@@ -82,7 +82,7 @@ function updateevents!(model::SimulationModel)
         if event.duration <= 0
             push!(expiredevents, e)
             for p in event.pixels
-                i = findnext(x -> x == event.etype, model.landscape[p...].events, 1)
+                i = findnext(x -> x == event.management, model.landscape[p...].events, 1)
                 deleteat!(model.landscape[p...].events, i)
             end
         end
@@ -96,7 +96,7 @@ end
 Add a farm event to the specified pixels (a vector of position tuples) for a given duration.
 """
 function createevent!(model::SimulationModel, pixels::Vector{Tuple{Int64,Int64}},
-                     name::EventType, duration::Int64=1)
+                     name::Management, duration::Int64=1)
     push!(model.events, FarmEvent(name, pixels, duration))
     for p in pixels
         push!(model.landscape[p...].events, name)
-- 
GitLab