diff --git a/Manifest.toml b/Manifest.toml index 993858b658f40907038b3a578e3d1ae01d0c12e1..0fc0e12a5419da51e724936b814746e78cf6bbda 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.8.2" manifest_format = "2.0" -project_hash = "3094d3134b943670349bd9f535622ba576264330" +project_hash = "410e4f52e8705498e2b8e0db499b81897c7f31a9" [[deps.AbstractFFTs]] deps = ["ChainRulesCore", "LinearAlgebra"] diff --git a/Project.toml b/Project.toml index 81ef1b8be3605852b44706587a4cd613def0aca6..8b5ec15a49f5c15b0b2adff87705bb666f3c792e 100644 --- a/Project.toml +++ b/Project.toml @@ -9,5 +9,6 @@ ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" GeoArrays = "2fb1d81b-e6a0-5fc5-82e6-8e06903437ab" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" +LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" diff --git a/data/config.toml b/data/config.toml deleted file mode 100644 index 40becd7524b41c4c3b353146547d44893370cfb4..0000000000000000000000000000000000000000 --- a/data/config.toml +++ /dev/null @@ -1,23 +0,0 @@ -### 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" -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 04b89d28171d838771c16dc38690a87a003d57d4..65d7c02aea356658732537167047e85482015b81 100644 --- a/src/Persephone.jl +++ b/src/Persephone.jl @@ -18,6 +18,7 @@ using Dates, GeoArrays, Logging, + LoggingExtras, Random, TOML diff --git a/src/core/input.jl b/src/core/input.jl index 8626428a2a76ddc8ba341ad0613440f4b4e69f63..9ed685c6a3b13aa5644227353738b177f66028a2 100644 --- a/src/core/input.jl +++ b/src/core/input.jl @@ -83,10 +83,15 @@ end Certain software parameters can be set via the commandline. """ function parsecommandline() - s = ArgParseSettings() + versionstring = """ + Persephone $(@project_version), commit $(read(`git rev-parse HEAD`, String)[1:8]) + © 2022 Daniel Vedder, Lea Kolb (MIT license) + https://git.idiv.de/xo30xoqa/persephone + """ + s = ArgParseSettings(add_version=true, version=versionstring) @add_arg_table! s begin "--configfile", "-c" - help = "name of the config file" + help = "name of the configuration file" arg_type = String required = false "--seed", "-s" @@ -101,13 +106,13 @@ function parsecommandline() arg_type = String required = false "--loglevel", "-l" - help = "verbosity: \"debug\", \"normal\", or \"errors\"" + help = "verbosity: \"debug\", \"info\", or \"errors\"" arg_type = String required = false "--runtime", "-r" - help = "duration in days that the simulation will run" - arg_type = Int - required = false + help = "duration in days that the simulation will run" + arg_type = Int + required = false end args = parse_args(s) for a in keys(args) diff --git a/src/core/output.jl b/src/core/output.jl index a811e66b0ea324fce9a146f37672a807b0f1ce5a..55f5d0fb6851e45df76a2c96a2052f6f25a43d63 100644 --- a/src/core/output.jl +++ b/src/core/output.jl @@ -3,7 +3,7 @@ ### This file includes functions for saving the model output. ### -## Note: some of this code was adapted from the GeMM model by Leidinger et al. +## Note: `setupdatadir()` was adapted from the GeMM model by Leidinger et al. ## (https://github.com/CCTB-Ecomods/gemm/blob/master/src/output.jl) """ @@ -22,6 +22,17 @@ function setupdatadir() else mkpath(param("core.outdir")) end + # Setup the logging system and logfile + loglevel = Logging.Info + if param("core.loglevel") == "debug" + loglevel = Logging.Debug + elseif param("core.loglevel") == "quiet" + loglevel = Logging.Warn + end + logfile = open(joinpath(param("core.outdir"), "simulation.log"), "w+") + simulationlogger = TeeLogger(ConsoleLogger(logfile, loglevel), + ConsoleLogger(stdout, loglevel)) + global_logger(simulationlogger) @info "Setting up output directory $(param("core.outdir"))" # 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 @@ -35,6 +46,7 @@ function setupdatadir() end # Copy the map file to the output folder mapf = param("core.mapfile") - !(isfile(mapf)) && @error "The map file $(mapf) doesn't exist." + !(isfile(mapf)) && Base.error("The map file $(mapf) doesn't exist.") cp(mapf, joinpath(param("core.outdir"), basename(mapf)), force = true) end + diff --git a/src/core/simulation.jl b/src/core/simulation.jl index c0c021690a2945d519b37380a37a1a1015ff8b98..0e647b34beb89ec4a5f2e2dde9726a01db4bc182 100644 --- a/src/core/simulation.jl +++ b/src/core/simulation.jl @@ -8,15 +8,16 @@ function initsim(config::String) Random.seed!(param("core.seed")) setupdatadir() #TODO create world + @info "Simulation initialised." end function stepsim() - println("Simulating another day.") + @info "Simulating another day." #TODO end function finalisesim() - println("Simulation ran. Nothing happened. But it will!") + @info "Simulation ran. Nothing happened. But it will!" #TODO end diff --git a/src/parameters.toml b/src/parameters.toml index b0c98a464744e9d68a68e5e12634069f6d8ae112..b6b11524ef69f1d51b5265999879726da0d4765d 100644 --- a/src/parameters.toml +++ b/src/parameters.toml @@ -10,8 +10,7 @@ configfile = "src/parameters.toml" # location of the configuration file mapfile = "data/region_jena.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" +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)