From 629aaee2b49a1e4bbcc8635dc8379d3b8968f150 Mon Sep 17 00:00:00 2001 From: Daniel Vedder <daniel.vedder@idiv.de> Date: Wed, 25 Oct 2023 17:29:28 +0200 Subject: [PATCH] Added tests for visualisation, changed colour scheme --- Makefile | 2 +- Project.toml | 2 +- src/analysis/makieplots.jl | 5 ++++- src/core/output.jl | 6 +++--- src/nature/ecologicaldata.jl | 4 ---- test/io_tests.jl | 13 ++++++++++++- test/test_parameters.toml | 3 ++- 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 341ef53..7d1cfcc 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ run: # run an example simulation if [ -d "example_results" ]; then rm -r example_results; fi ./run.jl -o example_results - src/analysis/analyse_nature.R example_results + #src/analysis/analyse_nature.R example_results test: # running test suite diff --git a/Project.toml b/Project.toml index eb4fc11..f873077 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.3.4" +version = "0.3.5" [deps] Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671" diff --git a/src/analysis/makieplots.jl b/src/analysis/makieplots.jl index 0b5a2c1..23b85cd 100644 --- a/src/analysis/makieplots.jl +++ b/src/analysis/makieplots.jl @@ -28,6 +28,8 @@ function visualisemap(model::AgentBasedModel,date=nothing,landcover=nothing) return f end isnothing(date) && (date = inds.Date[end]) + update_theme!(palette=(color=cgrad(:seaborn_bright, length(unique(inds.Species))),), + cycle=[:color]) for s in unique(inds.Species) points = @select!(@subset(inds, :Species .== s, :Date .== date), :X, :Y) @@ -60,7 +62,8 @@ function populationtrends(model::AgentBasedModel) deleteat!(ticks[1], 2:2:length(ticks[1])) deleteat!(ticks[2], 2:2:length(ticks[2])) end - + update_theme!(palette=(color=cgrad(:seaborn_bright, length(unique(pops.Species))),), + cycle=[:color]) f = Figure() ax = Axis(f[1,1], xlabel="Date", ylabel="Population size", limits=((1, length(dates)), nothing), xticks = ticks) diff --git a/src/core/output.jl b/src/core/output.jl index 64d1b0d..f6599f2 100644 --- a/src/core/output.jl +++ b/src/core/output.jl @@ -215,13 +215,13 @@ end Cycle through all data outputs and call their respective plot functions, saving each figure as a PDF. """ -function visualiseoutput(model::AgentBasedModel) - #TODO write tests +function visualiseoutput(model::AgentBasedModel, format::String="pdf") @debug "Visualising output." + CairoMakie.activate!() for output in model.dataoutputs isnothing(output.plotfunction) && continue figure = output.plotfunction(model) - save(joinpath(@param(core.outdir), output.name*".pdf"), figure) + save(joinpath(@param(core.outdir), output.name*"."*format), figure) end end diff --git a/src/nature/ecologicaldata.jl b/src/nature/ecologicaldata.jl index 99bb68d..36cb125 100644 --- a/src/nature/ecologicaldata.jl +++ b/src/nature/ecologicaldata.jl @@ -3,10 +3,6 @@ ### This file includes the functions for collecting and saving ecological output data. ### -#XXX NOP functions while I try and get Makie to work -visualisemap(model) = nothing -populationtrends(model) = nothing - """ initecologicaldata() diff --git a/test/io_tests.jl b/test/io_tests.jl index 7605365..aa45dd2 100644 --- a/test/io_tests.jl +++ b/test/io_tests.jl @@ -66,7 +66,7 @@ end @testset "Model object serialization" begin model = inittestmodel() - Ps.createdatadir(@param(core.outdir), @param(core.overwrite)) + Ps.createdatadir(@param(core.outdir), true) @test_logs((:debug, "Saved model object to results_testsuite/test.dat."), min_level=Logging.Debug, match_mode=:any, savemodelobject(model, "test")) @@ -81,3 +81,14 @@ end @test length(model.agents) == length(model2.agents) rm(@param(core.outdir), force=true, recursive=true) end + +@testset "Output visualisation" begin + model = initialise(TESTPARAMETERS) + stepsimulation!(model) + @test_logs((:debug, "Visualising output."), + min_level=Logging.Debug, match_mode=:any, + visualiseoutput(model)) + @test isfile(joinpath(@param(core.outdir), "individuals.pdf")) + @test isfile(joinpath(@param(core.outdir), "populations.pdf")) + rm(@param(core.outdir), force=true, recursive=true) +end diff --git a/test/test_parameters.toml b/test/test_parameters.toml index 65f0d81..f34a20d 100644 --- a/test/test_parameters.toml +++ b/test/test_parameters.toml @@ -10,6 +10,7 @@ configfile = "test_parameters.toml" # location of the configuration file outdir = "results_testsuite" # location and name of the output folder overwrite = true # 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 loglevel = "warn" # verbosity level: "debug", "info", "warn" processors = 6 # number of processors to use on parallel runs @@ -29,7 +30,7 @@ farmmodel = "FieldManager" # which version of the farm model to use (not yet imp [nature] targetspecies = ["Wolpertinger", "Wyvern"] # list of target species to simulate popoutfreq = "daily" # output frequency population-level data, daily/monthly/yearly/end/never -indoutfreq = "end" # output frequency individual-level data, daily/monthly/yearly/end/never +indoutfreq = "daily" # output frequency individual-level data, daily/monthly/yearly/end/never insectmodel = ["season", "habitat", "pesticides"] # which factors affect insect growth ("weather" is not yet implemented) [crop] -- GitLab