diff --git a/Project.toml b/Project.toml index 23bc614b01a86436e4df58fffcb5921236a4e8a8..eb4fc11b692544e3455656c9fd496b7212b05b7a 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.3" +version = "0.3.4" [deps] Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671" diff --git a/docs/persefonejl_logo.png b/docs/persefonejl_logo.png deleted file mode 100644 index 0eb200c911a4e4703024e06e3a33b231be6b75fe..0000000000000000000000000000000000000000 Binary files a/docs/persefonejl_logo.png and /dev/null differ diff --git a/src/Persefone.jl b/src/Persefone.jl index 9dc807dd78e4acd24b75b9c99cc384a06303a623..206ab2ac860ad2ce03eeaa6b4eaa2b0777b57973 100644 --- a/src/Persefone.jl +++ b/src/Persefone.jl @@ -79,6 +79,7 @@ export stepsimulation!, createevent!, finalise!, + outputdata, visualisemap, populationtrends, visualiseoutput, diff --git a/src/analysis/makieplots.jl b/src/analysis/makieplots.jl index 13bd6a533f8eb50c186f834f9b0790f0977b6a4d..0b5a2c171c6ce9bd06232c4ad01b7191a464da58 100644 --- a/src/analysis/makieplots.jl +++ b/src/analysis/makieplots.jl @@ -14,11 +14,12 @@ Returns a Makie figure object. """ function visualisemap(model::AgentBasedModel,date=nothing,landcover=nothing) # load and plot the map - isnothing(landcover) && (landcover = load(@param(world.landcovermap))) + # Note: if the landcover map is supplied, it needs to be rotr90'ed + isnothing(landcover) && (landcover = rotr90(load(@param(world.landcovermap)))) f = Figure() ax = Axis(f[1,1]) hidedecorations!(ax) - image!(f[1,1], rotr90(landcover)) + image!(f[1,1], landcover) ax.aspect = DataAspect() # check if there are individuals and plot them inds = model.datatables["individuals"] diff --git a/src/core/input.jl b/src/core/input.jl index 16b377cde0f0e84b61de9bc6b6b1dac01e442b1d..e57b98168148502a7dfd1072dd6914dc3d3097bc 100644 --- a/src/core/input.jl +++ b/src/core/input.jl @@ -180,6 +180,10 @@ end Deserialise a model object that was previously saved with `[savemodelobject](@ref)`. """ function loadmodelobject(fullfilename::String) + if !isfile(fullfilename) + @warn "File $(fullfilename) does not exist. Loading failed." + return + end object = deserialize(fullfilename) # Do basic integrity checks if !(typeof(object) <: Dict && typeof(object["model"]) <: AgentBasedModel) diff --git a/src/core/output.jl b/src/core/output.jl index f9366bba640e72ee7f57b82f08e807983ca19df1..64d1b0d8aac9201d36f550831c57238aff8d63ca 100644 --- a/src/core/output.jl +++ b/src/core/output.jl @@ -172,12 +172,13 @@ function newdataoutput!(model::AgentBasedModel, name::String, header::Vector{Str end """ - outputdata(model) + outputdata(model, force=false) Cycle through all registered data outputs and activate them according to their -configured frequency. +configured frequency. If `force` is `true`, activate all outputs regardless +of their configuration. """ -function outputdata(model::AgentBasedModel) +function outputdata(model::AgentBasedModel, force=false) #XXX enable output every X days, or weekly? #XXX all output functions except for "end" are run on the first update # -> should they all be run on the last update, too? @@ -185,9 +186,9 @@ function outputdata(model::AgentBasedModel) isnextmonth = d -> (day(d) == day(startdate)) isnextyear = d -> (month(d) == month(startdate) && day(d) == day(startdate)) for output in model.dataoutputs - (output.frequency == "never") && continue + (!force && output.frequency == "never") && continue # check if this output should be activated today - if (output.frequency == "daily") || + if force || (output.frequency == "daily") || (output.frequency == "monthly" && isnextmonth(model.date)) || (output.frequency == "yearly" && isnextyear(model.date)) || (output.frequency == "end" && model.date == @param(core.enddate)) @@ -236,7 +237,8 @@ function savemodelobject(model::AgentBasedModel, filename::String) object = Dict("model"=>model, "modelversion"=>pkgversion(Persefone), "juliaversion"=>VERSION) - filename = joinpath(@param(core.outdir), filename*".dat") + !endswith(filename, ".dat") && (filename *= ".dat") + filename = joinpath(@param(core.outdir), filename) serialize(filename, object) @debug "Saved model object to $(filename)." end diff --git a/src/core/simulation.jl b/src/core/simulation.jl index 8e2ef2d9c38f7cac308bcbe95c3acd1a8184fad2..dd33eff0224235ce5febf1cd50f48306c7ca1b24 100644 --- a/src/core/simulation.jl +++ b/src/core/simulation.jl @@ -62,9 +62,6 @@ function initmodel(settings::Dict{String, Any}) createdatadir(settings["core.outdir"], settings["core.overwrite"]) logger = modellogger(settings["core.loglevel"], settings["core.outdir"]) with_logger(logger) do - events = Vector{FarmEvent}() - dataoutputs = Vector{DataOutput}() - datatables = Dict{String, DataFrame}() landscape = initlandscape(settings["world.landcovermap"], settings["world.farmfieldsmap"]) weather = initweather(settings["world.weatherfile"], @@ -79,16 +76,16 @@ function initmodel(settings::Dict{String, Any}) :landscape=>landscape, :weather=>weather, :crops=>crops, - :dataoutputs=>dataoutputs, - :datatables=>datatables, - :events=>events) - model = AgentBasedModel(Union{Farmer,Animal,FarmPlot}, space, properties=properties, + :dataoutputs=>Vector{DataOutput}(), + :datatables=>Dict{String, DataFrame}(), + :events=>Vector{FarmEvent}()) + model = AgentBasedModel(Union{Farmer,Animal,FarmPlot}, + space, properties=properties, rng=StableRNG(settings["core.seed"]), warn=false) saveinputfiles(model) initfields!(model) initfarms!(model) initnature!(model) - #outputdata(model) #XXX record data before run starts? model end end