Skip to content
Snippets Groups Projects
Commit 14416e97 authored by xo30xoqa's avatar xo30xoqa
Browse files

Minor changes

parent 24ac928a
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
......
......@@ -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.")
......
......@@ -49,7 +49,13 @@ 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
# 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)
......
......@@ -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)
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment