diff --git a/src/Persephone.jl b/src/Persephone.jl index 3b0b0ff85734d863673c68a03862cbbd02174b24..1369288a797e8b53aca4d9b8f8d64cd029af729a 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 318a71d459f1dd829c44bd6d01312b83d7613aea..872486ce5692589eb7dc248d4ccbb9a42c6f243d 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 b7ca0071348e74db2189cf468533fc92b2655f2f..dca2801548619f954afde8dec1e0f644206bea76 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 0c98df361e43d6866b391597098238b37e642a5f..b805fb1e67bb1d75450b9a5f243ff05bbea301ac 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 c84c75d5d2621946eb5d64caf7033b46ae7c7c4f..84a78f50baf1d95b3f0d20cdc73dfbed0435f2b7 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 e1a19bfc9d70a37b6a9836e986e820b68aac5efd..24f0481228372a83ed798f841468b73cf12c34c0 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