diff --git a/data/region_jena.tif b/data/fields_jena.tif similarity index 100% rename from data/region_jena.tif rename to data/fields_jena.tif diff --git a/data/region_hohenlohe.tif b/data/landcover_hohenlohe.tif similarity index 100% rename from data/region_hohenlohe.tif rename to data/landcover_hohenlohe.tif diff --git a/data/landcover_jena.tif b/data/landcover_jena.tif new file mode 100644 index 0000000000000000000000000000000000000000..839afe968b6e110aab2f8ea9dd44274c01ace912 Binary files /dev/null and b/data/landcover_jena.tif differ diff --git a/data/region_thueringer_becken.tif b/data/landcover_thueringer_becken.tif similarity index 100% rename from data/region_thueringer_becken.tif rename to data/landcover_thueringer_becken.tif diff --git a/src/core/output.jl b/src/core/output.jl index 55f5d0fb6851e45df76a2c96a2052f6f25a43d63..75a37a3c0a269f9ccff3e2007a24da1a43bd7a5f 100644 --- a/src/core/output.jl +++ b/src/core/output.jl @@ -44,9 +44,12 @@ function setupdatadir() println(f, "# with git commit $(read(`git rev-parse HEAD`, String))#\n") astoml(f) end - # Copy the map file to the output folder - mapf = param("core.mapfile") - !(isfile(mapf)) && Base.error("The map file $(mapf) doesn't exist.") - cp(mapf, joinpath(param("core.outdir"), basename(mapf)), force = true) + # Copy the map files to the output folder + lcmap = param("core.landcovermap") + ffmap = param("core.farmfieldsmap") + !(isfile(lcmap)) && Base.error("The map file $(lcmap) doesn't exist.") + !(isfile(ffmap)) && Base.error("The map file $(ffmap) doesn't exist.") + cp(lcmap, joinpath(param("core.outdir"), basename(lcmap)), force = true) + cp(ffmap, joinpath(param("core.outdir"), basename(ffmap)), force = true) end diff --git a/src/core/simulation.jl b/src/core/simulation.jl index 8337356dd35f979c656813dbecd15a7958b24e57..48744d994c4e7e07a7f8eeaa61059ae23cf0aba8 100644 --- a/src/core/simulation.jl +++ b/src/core/simulation.jl @@ -10,20 +10,25 @@ Initialise the model: read in parameters, create the output data directory, and instantiate the AgentBasedModel object. """ function initialise(config::String=PARAMFILE) + # do some housekeeping initsettings(config) Random.seed!(param("core.seed")) setupdatadir() - landcover = GeoArrays.read(param("core.mapfile")) - #TODO load field map + # initialise world-level properties + landcover = GeoArrays.read(param("core.landcovermap")) + farmfields = GeoArrays.read(param("core.farmfieldsmap")) space = GridSpace(size(landcover)[1:2], periodic=false) - properties = Dict{Symbol,Any}(:day=>0, - :landcover=>landcover) + properties = Dict{Symbol,Any}(:age=>0, + :date=>param("core.startdate"), + :landcover=>landcover, + :farmfields=>farmfields) model = AgentBasedModel(Union{Farmer,Animal,CropPlot}, space, properties=properties, rng=Random.Xoshiro(param("core.seed"))) + # initialise submodels initfarms!(model) initfields!(model) initnature!(model) - @info "Simulation initialised." + @info "Simulation initialised at $(Dates.now())." model end @@ -33,12 +38,12 @@ end Execute one update of the model. """ function stepsimulation!(model::AgentBasedModel) - model.day += 1 - @info "Simulating day $(model.day)." + model.age += 1 + model.date += Day(1) + @info "Simulating day $(model.date)." for a in Schedulers.ByType((Farmer,Animal,CropPlot), true)(model) stepagent!(getindex(model, a), model) end - #TODO end """ @@ -47,7 +52,7 @@ end Wrap up the simulation. Output all remaining data and exit. """ function finalise(model::AgentBasedModel) - @info "Simulation ran. Things are beginning to happen!" + @info "Simulation completed at $(Dates.now()),\nwrote output to $(param("core.outdir"))." #TODO genocide!(model) end @@ -59,6 +64,7 @@ Carry out a complete simulation run. """ function simulate(config::String=PARAMFILE) model = initialise(config) - step!(model, dummystep, stepsimulation!, param("core.runtime")) + runtime = Dates.value(param("core.enddate")-param("core.startdate")) + step!(model, dummystep, stepsimulation!, runtime) finalise(model) end diff --git a/src/parameters.toml b/src/parameters.toml index 52e2521740afbcdfb8fc53d77839b9c07e1d087b..4248b4529cee29ee3013c0781924b1b2404024e5 100644 --- a/src/parameters.toml +++ b/src/parameters.toml @@ -8,11 +8,14 @@ [core] configfile = "src/parameters.toml" # location of the configuration file -mapfile = "data/region_jena.tif" # location of the map file +landcovermap = "data/landcover_jena.tif" # location of the landcover map +farmfieldsmap = "data/fields_jena.tif" # location of the field geometry map TODO not the real file yet outdir = "results" # location and name of the output folder loglevel = "debug" # verbosity level: "debug", "info", "quiet" -runtime = 10 # duration in days that the simulation will run for seed = 0 # seed value for the RNG (0 -> random value) +# dates to start and end the simulation +startdate = 2020-01-01 +enddate = 2020-01-05 [farm]