From 31c8338b118d87a82edfca8b8af5302682e1b76b Mon Sep 17 00:00:00 2001 From: Daniel Vedder <daniel.vedder@idiv.de> Date: Thu, 24 Nov 2022 17:52:31 +0100 Subject: [PATCH] Wrote `setting()` function --- data/config.toml | 24 ++++++++++++++++++++++++ src/Persephone.jl | 5 +++-- src/core/input.jl | 29 +++++++++++++++++++++++++++++ src/core/simulation.jl | 20 ++++++++++++++------ 4 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 data/config.toml diff --git a/data/config.toml b/data/config.toml new file mode 100644 index 0000000..cb73b7c --- /dev/null +++ b/data/config.toml @@ -0,0 +1,24 @@ +### Persephone - a socio-economic-ecological model of European agricultural landscapes. +### +### This is an example configuration file for development. +### Note: the reference version is at src/parameters.toml +### + +[core] +configfile = "data/config.toml" # location of the configuration file +mapfile = "data/region_hohenlohe.tif" # location of the map file +outdir = "results" # location and name of the output folder +logfile = "simulation.log" # name of the log file +loglevel = "debug" # verbosity level: "debug", "normal", "errors" +quietmode = false # if true, only print log statements to file, not the screen +runtime = 5 # duration in days that the simulation will run for +seed = 0 # seed value for the RNG (0 -> random value) + +[farm] + + +[ecology] + +[crop] +cropmodel = "linear" # crop growth model to use, "linear" or "aquacrop" (not yet implemented) + diff --git a/src/Persephone.jl b/src/Persephone.jl index 3be2462..da0a2eb 100644 --- a/src/Persephone.jl +++ b/src/Persephone.jl @@ -4,7 +4,7 @@ ### Lea Kolb <lea-deborah.kolb@idiv.de> ### (c) 2022, licensed under the terms of the MIT license ### -### This file defines the module (= "library") for the Persephone model. +### This file defines the module/package for the Persephone model. ### To run the model, either execute `run.jl` from the commandline, ### or import the module using your own wrapper script or software. ### @@ -24,7 +24,8 @@ using export simulate, initsim, - runsim + stepsim, + finalisesim ## The file that stores all default parameters const paramfile = "src/parameters.toml" diff --git a/src/core/input.jl b/src/core/input.jl index 9d147fc..7463dd9 100644 --- a/src/core/input.jl +++ b/src/core/input.jl @@ -6,6 +6,27 @@ ## Note: some of this code was adapted from the GeMM model ## (https://github.com/CCTB-Ecomods/gemm/blob/master/src/input.jl) +let settings::Dict{String, Dict{String, Any}} + """ + initsettings(configfile) + + Initialise the global model settings for this run. + """ + global function initsettings(configfile::String) + settings = getsettings(configfile) + end + + """ + setting(domain, param) + + Return a configuration parameter from the global settings. + Domain may be any of "core", "ecology", "farm", or "crop". + """ + global function setting(domain::String, param::String) + settings[domain][param] + end +end + """ getsettings(configfile) @@ -91,3 +112,11 @@ function parsecommandline() args end +""" + readtiffmapfile(filename) + +Read in a TIFF map file and return it as an array. +""" +function readtiffmapfile(filename) + #TODO +end diff --git a/src/core/simulation.jl b/src/core/simulation.jl index 7ddda5e..3314005 100644 --- a/src/core/simulation.jl +++ b/src/core/simulation.jl @@ -4,19 +4,27 @@ ### function initsim(config::String) - settings = getsettings(config) - TOML.print(settings) - Random.seed!(settings["core"]["seed"]) + initsettings(config) + Random.seed!(setting("core", "seed")) + #TODO create output folder + #TODO create world +end + +function stepsim() + println("Simulating another day.") #TODO end -function runsim() +function finalisesim() + println("Simulation ran. Nothing happened. But it will!") #TODO end function simulate(config::String=paramfile) initsim(config) - runsim() - println("Simulation ran. Nothing happened. But it will!") + for day in 1:setting("core", "runtime") + stepsim() + end + finalisesim() #TODO end -- GitLab