From 3a702e24ce7c967c82e622e6a28c606f02b90d46 Mon Sep 17 00:00:00 2001 From: Daniel Vedder <daniel.vedder@idiv.de> Date: Mon, 2 Jan 2023 17:24:26 +0100 Subject: [PATCH] Added "core.overwrite" parameter --- src/Persephone.jl | 3 --- src/core/input.jl | 7 +++++-- src/core/output.jl | 21 ++++++++++++++------- src/parameters.toml | 1 + 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Persephone.jl b/src/Persephone.jl index 8849be7..b45406d 100644 --- a/src/Persephone.jl +++ b/src/Persephone.jl @@ -25,12 +25,9 @@ using ## define exported functions and variables export #types - LandCover, - EventType, Pixel, FarmEvent, FarmPlot, - Sex, Animal, Farmer, #functions diff --git a/src/core/input.jl b/src/core/input.jl index 9d31152..cb1c9f9 100644 --- a/src/core/input.jl +++ b/src/core/input.jl @@ -9,8 +9,11 @@ ##XXX Does it make sense to move the settings dict into the model object itself? ## (It could be integrated into the properties dict.) Advantage: we have less ## global state lying around, and serialising becomes easier (if we want to do -## that). Disadvantage: only functions that have access to the model object can -## access the settings - this may give problems during initialisation. +## that). Also, during testing we often need to change individual parameters, +## which is currently impossible. Disadvantage: immutability of parameters at +## runtime is intended, and some start-up functions may have problems if they need +## access to parameters before the model object has been created. +##TODO -> yes, changing this is probably sensible let settings::Dict{String, Dict{String, Any}} """ initsettings(configfile) diff --git a/src/core/output.jl b/src/core/output.jl index 87afd97..830303f 100644 --- a/src/core/output.jl +++ b/src/core/output.jl @@ -16,14 +16,21 @@ Creates the output directory and copies relevant files into it. function setupdatadir() # Check whether the output directory already exists and handle conflicts if isdir(param("core.outdir")) - @warn "The chosen output directory $(param("core.outdir")) already exists." - println("Type 'yes' to overwrite this directory. Otherwise, the simulation will abort.") - print("Overwrite? ") - answer = readline() - (answer != "yes") && Base.error("Output directory exists, will not overwrite. Aborting.") - else - mkpath(param("core.outdir")) + overwrite = param("core.overwrite") + if param("core.overwrite") == "ask" + println("The chosen output directory $(param("core.outdir")) already exists.") + println("Type 'yes' to overwrite this directory. Otherwise, the simulation will abort.") + print("Overwrite? ") + answer = readline() + (answer == "yes") && (overwrite = true) + end + if !overwrite + Base.error("Output directory exists, will not overwrite. Aborting.") + else + @warn "Overwriting existing output directory $(param("core.outdir"))." + end end + mkpath(param("core.outdir")) # Setup the logging system and logfile loglevel = Logging.Info if param("core.loglevel") == "debug" diff --git a/src/parameters.toml b/src/parameters.toml index 69677aa..33efc7d 100644 --- a/src/parameters.toml +++ b/src/parameters.toml @@ -11,6 +11,7 @@ configfile = "src/parameters.toml" # location of the configuration file landcovermap = "data/landcover_jena.tif" # location of the landcover map farmfieldsmap = "data/fields_jena.tif" # location of the field geometry map outdir = "results" # location and name of the output folder +overwrite = "ask" # overwrite the output directory? (true/false/"ask") loglevel = "debug" # verbosity level: "debug", "info", "quiet" seed = 0 # seed value for the RNG (0 -> random value) # dates to start and end the simulation -- GitLab