diff --git a/data/config.toml b/data/config.toml new file mode 100644 index 0000000000000000000000000000000000000000..cb73b7ce305854bc9522f8008b6fb66f3fac63aa --- /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 3be24621685ea376923bd0b78d1e8434217320f2..da0a2eb9974ee14e384416657a50d49552a827b1 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 9d147fcc610874b53f824b68f1e0926de8ed2c36..7463dd9932d89d6afd9df15bc3916688d31b57c4 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 7ddda5e8667a0d957075a3ba6ae8b50939b39a2a..331400590c50bff184a6c86d8e88af27166b029a 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