From 14416e974d639bffeadae8426121c15434ccb6c4 Mon Sep 17 00:00:00 2001 From: Daniel Vedder <daniel.vedder@idiv.de> Date: Thu, 19 Jan 2023 16:18:58 +0100 Subject: [PATCH] Minor changes --- src/Persephone.jl | 1 + src/core/input.jl | 2 +- src/core/output.jl | 2 ++ src/core/simulation.jl | 10 ++++++++-- src/crop/crops.jl | 14 -------------- test/landscape_tests.jl | 3 +-- 6 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/Persephone.jl b/src/Persephone.jl index 3b0b0ff..1369288 100644 --- a/src/Persephone.jl +++ b/src/Persephone.jl @@ -19,6 +19,7 @@ using GeoArrays, #XXX this is a big dependency - can we get rid of it? Logging, LoggingExtras, + #MacroTools, #http://fluxml.ai/MacroTools.jl/stable/utilities/ Random, TOML diff --git a/src/core/input.jl b/src/core/input.jl index 318a71d..872486c 100644 --- a/src/core/input.jl +++ b/src/core/input.jl @@ -75,7 +75,7 @@ Certain software parameters can be set via the commandline. function parsecommandline() versionstring = """ Persephone $(@project_version), commit $(read(`git rev-parse HEAD`, String)[1:8]) - © 2022 Daniel Vedder, Lea Kolb (MIT license) + © 2022-2023 Daniel Vedder, Lea Kolb (MIT license) https://git.idiv.de/xo30xoqa/persephone """ s = ArgParseSettings(add_version=true, version=versionstring) diff --git a/src/core/output.jl b/src/core/output.jl index b7ca007..dca2801 100644 --- a/src/core/output.jl +++ b/src/core/output.jl @@ -46,6 +46,8 @@ function setupdatadir(model::AgentBasedModel) # Export a copy of the current parameter settings to the output folder. # This can be used to replicate this exact run in future, and also # records the current time and git commit. + #TODO check if there have been changes to the repository since the last + # commit, as this may impact replicability open(joinpath(@param(core.outdir), basename(@param(core.configfile))), "w") do f println(f, "#\n# --- Persephone configuration parameters ---") println(f, "# This file was generated automatically.") diff --git a/src/core/simulation.jl b/src/core/simulation.jl index 0c98df3..b805fb1 100644 --- a/src/core/simulation.jl +++ b/src/core/simulation.jl @@ -48,8 +48,14 @@ Execute one update of the model. function stepsimulation!(model::AgentBasedModel) @info "Simulating day $(model.date)." for a in Schedulers.ByType((Farmer,FarmPlot,Animal), true)(model) - #The animal may have been killed, so we need a try/catch - try stepagent!(model[a], model) catch keyerror end + #The animal may have been killed, so we need a try/catch + # try + # stepagent!(model[a], model) + # catch exc + # #FIXME check if the KeyError comes from the model[a] or the function call + # isa(exc, KeyError) ? continue : throw(exc) + # end + stepagent!(model[a], model) end updateevents!(model) outputdata(model) diff --git a/src/crop/crops.jl b/src/crop/crops.jl index c84c75d..84a78f5 100644 --- a/src/crop/crops.jl +++ b/src/crop/crops.jl @@ -62,20 +62,6 @@ function initfields!(model::AgentBasedModel) @info "Initialised $n farm plots." end -#XXX only needed during development, can be deleted again? -function countfields(model::AgentBasedModel) - ids::Vector{Int64} = [] - width, height = size(model.landscape) - for x in 1:width - for y in 1:height - i = model.landscape[x,y].fieldid - (ismissing(i)) && continue - push!(ids, i) - end - end - ids |> sort! |> unique! |> length -end - """ averagefieldsize(model) diff --git a/test/landscape_tests.jl b/test/landscape_tests.jl index e1a19bf..24f0481 100644 --- a/test/landscape_tests.jl +++ b/test/landscape_tests.jl @@ -40,8 +40,8 @@ end space = GridSpace(size(landscape), periodic=false) properties = Dict{Symbol,Any}(:landscape=>landscape, :settings=>TESTSETTINGS) model = AgentBasedModel(FarmPlot, space, properties=properties, warn=false) - @test_logs (:info, "Initialised 2092 farm plots.") match_mode=:any Ps.initfields!(model) # these tests are specific to the Jena maps + @test_logs (:info, "Initialised 2092 farm plots.") match_mode=:any Ps.initfields!(model) @test size(model.landscape) == (1754, 1602) @test Ps.landcover((100,100), model) == Ps.forest @test Ps.landcover((300,1), model) == Ps.soil @@ -49,7 +49,6 @@ end @test Ps.landcover((400,400), model) == Ps.grass @test Ps.landcover((800,800), model) == Ps.agriculture @test Ps.landcover((1100,1100), model) == Ps.builtup - @test Ps.countfields(model) == 2092 @test Ps.averagefieldsize(model) == 5.37 @test count(f -> ismissing(f.fieldid), model.landscape) == 1685573 @test length(Ps.farmplot((800,800), model).pixels) == 4049 -- GitLab