diff --git a/Makefile b/Makefile index 341ef53168de3159440a6bba5dff77a720af1772..7d1cfcc182c88405249766ce1ce8ab01a3f1fc4d 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 eb4fc11b692544e3455656c9fd496b7212b05b7a..f873077423bf5caa3f59f6f9b985df741863b380 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 0b5a2c171c6ce9bd06232c4ad01b7191a464da58..23b85cd4be84ca83a0f7ac1f39804417cff81f26 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 64d1b0d8aac9201d36f550831c57238aff8d63ca..f6599f2feba7760da86dec1dfad652c8a6187cda 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 99bb68d83c6a6e2b0de37dc27f41fbea71b60c88..36cb12597e1570c9d1b1da04f314349a5890f34f 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 7605365e3243dfe4f1a53b6d96bfbedd27743be3..aa45dd2dc483b78b9fee327eab0ac51652394d19 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 65f0d8123f91a50ead4345583034055dda97f0ee..f34a20d46d2b1c7fd223cd24ad19cc35da793596 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]