From f1b459cabe05b4849f7d0f5a05439eac5c9c72da Mon Sep 17 00:00:00 2001
From: Daniel Vedder <daniel.vedder@idiv.de>
Date: Tue, 14 Nov 2023 14:21:16 +0100
Subject: [PATCH] Made graphics output format configurable

---
 Project.toml                  |  2 +-
 src/analysis/makieplots.jl    | 10 ++++------
 src/core/output.jl            |  7 ++++---
 src/nature/species/skylark.jl |  2 +-
 src/parameters.toml           |  1 +
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/Project.toml b/Project.toml
index f417599..fee76e4 100644
--- a/Project.toml
+++ b/Project.toml
@@ -1,7 +1,7 @@
 name = "Persefone"
 uuid = "039acd1d-2a07-4b33-b082-83a1ff0fd136"
 authors = ["Daniel Vedder <daniel.vedder@idiv.de>"]
-version = "0.4.0"
+version = "0.4.1"
 
 [deps]
 Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671"
diff --git a/src/analysis/makieplots.jl b/src/analysis/makieplots.jl
index 807015f..97b599c 100644
--- a/src/analysis/makieplots.jl
+++ b/src/analysis/makieplots.jl
@@ -30,9 +30,8 @@ function visualisemap(model::AgentBasedModel,date=nothing,landcover=nothing)
     isnothing(date) && (date = inds.Date[end])
     #XXX other colour schemes: :tab10, :Accent_8, :Dark2_8, :Paired_12, :Set1_9
     # https://juliagraphics.github.io/ColorSchemes.jl/stable/catalogue/
-    update_theme!(palette=(color=cgrad(:seaborn_bright,
-                                       max(2, length(@param(nature.targetspecies)))),),
-                  cycle=[:color])
+    ncolors = max(2, length(@param(nature.targetspecies)))
+    update_theme!(palette=(color=cgrad(:seaborn_bright, ncolors),), cycle=[:color])
     for s in @param(nature.targetspecies)
         points = @select!(@subset(inds, :Species .== s, :Date .== date),
                           :X, :Y)
@@ -53,9 +52,8 @@ Returns a Makie figure object.
 """
 function populationtrends(model::AgentBasedModel)
     pops = model.datatables["populations"]
-    update_theme!(palette=(color=cgrad(:seaborn_bright,
-                                       max(2, length(@param(nature.targetspecies)))),),
-                  cycle=[:color])
+    ncolors = max(2, length(@param(nature.targetspecies)))
+    update_theme!(palette=(color=cgrad(:seaborn_bright, ncolors),), cycle=[:color])
     f = Figure()
     dates = @param(core.startdate):@param(core.enddate)
     ax = Axis(f[1,1], xlabel="Date", ylabel="Population size",
diff --git a/src/core/output.jl b/src/core/output.jl
index 98b5b42..513b140 100644
--- a/src/core/output.jl
+++ b/src/core/output.jl
@@ -213,15 +213,16 @@ end
     visualiseoutput(model)
 
 Cycle through all data outputs and call their respective plot functions,
-saving each figure as a PDF.
+saving each figure to file.
 """
-function visualiseoutput(model::AgentBasedModel, format::String="pdf")
+function visualiseoutput(model::AgentBasedModel)
     @debug "Visualising output."
     CairoMakie.activate!() # make sure we're using Cairo
     for output in model.dataoutputs
         isnothing(output.plotfunction) && continue
         figure = output.plotfunction(model)
-        save(joinpath(@param(core.outdir), output.name*"."*format), figure)
+        save(joinpath(@param(core.outdir), output.name*"."*@param(core.figureformat)),
+             figure)
     end
 end
 
diff --git a/src/nature/species/skylark.jl b/src/nature/species/skylark.jl
index f79c9fe..a7c7191 100644
--- a/src/nature/species/skylark.jl
+++ b/src/nature/species/skylark.jl
@@ -114,7 +114,7 @@ At the moment, this implementation is still in development.
         m, d = monthday(model.date)
         migrate = (((m < arrive[1]) || (m == arrive[1] && d < arrive[2])) ||
                    ((m > leave[1]) || (m == leave[1] && d >= leave[2])))
-        if migrate
+        if migrate #FIXME not all migrate?
             @kill(@trait(migrationmortality), "migration")
             returndate = Date(year(model.date), arrive[1], arrive[2])
             model.date != @param(core.startdate) && (returndate += Year(1))
diff --git a/src/parameters.toml b/src/parameters.toml
index b9539d3..e80a55c 100644
--- a/src/parameters.toml
+++ b/src/parameters.toml
@@ -13,6 +13,7 @@ overwrite = "ask" # overwrite the output directory? (true/false/"ask")
 csvoutput = true # save collected data in CSV files
 visualise = true # generate result graphs
 storedata = true # keep collected data in memory
+figureformat = "pdf" # file format to use for graphical output
 loglevel = "debug" # verbosity level: "debug", "info", "warn"
 processors = 2 # number of processors to use on parallel runs
 seed = 2 # seed value for the RNG (0 -> random value)
-- 
GitLab