diff --git a/src/core/input.jl b/src/core/input.jl index b0a2b99342c1f6030345889a94126bf9b1555b5d..db2bdef3750c7748cfde8b4b8615bae32e65041f 100644 --- a/src/core/input.jl +++ b/src/core/input.jl @@ -46,7 +46,7 @@ end Combines all configuration options to produce a single settings dict. Precedence: function arguments - commandline parameters - user config file - default values """ -function getsettings(configfile::String, userparams::Dict{String,Any}=Dict()) +function getsettings(configfile::String, userparams::Dict{String,Any}=Dict{String,Any}()) # read in and merge configurations from the commandline, the default config file # and a config file supplied by the user (via the --configfile option) defaults::Dict{String, Any} = TOML.parsefile(PARAMFILE) |> flattenTOML diff --git a/src/crop/cropmodels.jl b/src/crop/cropmodels.jl index 83497fd176c08ea39f33e4c618fc37d624a57bcc..3d84e98f7d6e87967d76163cae07d3028549dfc5 100644 --- a/src/crop/cropmodels.jl +++ b/src/crop/cropmodels.jl @@ -17,7 +17,7 @@ function initcropmodel(cropmodel::AbstractString, cropdirectory::AbstractString) elseif cropmodel == "simple" Tcroptype = SimpleCrop.CropType Tcropstate = SimpleCrop.CropState - crops_almass = ALMaSS.readcropparameters(cropfile, growthfile) + crops_almass = ALMaSS.readcropparameters(cropdirectory) crops = Dict(name => SimpleCrop.CropType(ct.name, ct.group, ct.minsowdate, ct.maxsowdate) for (name, ct) in crops_almass) else diff --git a/src/parameters.toml b/src/parameters.toml index 0cb6ea75c6cce17d5fe3cf81f286801ca19f5732..1c60864671e93e8733ebf65598bcdaaf6790c1d0 100644 --- a/src/parameters.toml +++ b/src/parameters.toml @@ -47,4 +47,3 @@ insectmodel = ["season", "habitat", "pesticides", "weather"] # factors affecting [crop] cropmodel = "almass" # crop growth model to use, "almass", "aquacrop", or "simple" cropdirectory = "data/crops/almass" # the directory storing all data files for the selected crop model - diff --git a/test/crop_tests.jl b/test/crop_tests.jl index 9632b1d59549eea5decd4909982b54e16fce2eb4..106f3854133a6d55e805551e822f1d4b092d2bfc 100644 --- a/test/crop_tests.jl +++ b/test/crop_tests.jl @@ -6,13 +6,13 @@ const TESTPARAM_ALMASS = joinpath(pkgdir(Persefone), "test", "test_parameters_almass.toml") const TESTPARAM_SIMPLECROP = joinpath(pkgdir(Persefone), "test", "test_parameters_simplecrop.toml") -@testset for paramfile in (TESTPARAM_ALMASS, TESTPARAM_SIMPLECROP) +@testset for configfile in (TESTPARAM_ALMASS, TESTPARAM_SIMPLECROP) @testset "Model initialisation" begin - model = initialise(paramfile) + model = initialise(; configfile) @test model isa AgricultureModel end @testset "Time step" begin - model = initialise(paramfile) + model = initialise(; configfile) stepsimulation!(model) @test model isa AgricultureModel end diff --git a/test/crop_data_general.csv b/test/cropparams-almass/crop_data_general.csv similarity index 100% rename from test/crop_data_general.csv rename to test/cropparams-almass/crop_data_general.csv diff --git a/test/almass_crop_growth_curves.csv b/test/cropparams-almass/crop_growth_curves.csv similarity index 100% rename from test/almass_crop_growth_curves.csv rename to test/cropparams-almass/crop_growth_curves.csv diff --git a/test/io_tests.jl b/test/io_tests.jl index deebec3c249b7df52368432deb209001ec02b525..79d9fa103bb28e9dfb896220ef27680e325a8303 100644 --- a/test/io_tests.jl +++ b/test/io_tests.jl @@ -95,7 +95,7 @@ end end @testset "Output visualisation" begin - model = initialise(TESTPARAMETERS) + model = initialise(; configfile=TESTPARAMETERS) stepsimulation!(model) @test_logs((:debug, "Visualising output."), min_level=Logging.Debug, match_mode=:any, diff --git a/test/runtests.jl b/test/runtests.jl index 7fb635a5c663fc831d963786a07cf353b8961e15..f4401eb979260e76796ca17e722146e7c8ceea80 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -44,8 +44,7 @@ function inittestmodel(smallmap=true) TESTSETTINGS["core.startdate"], TESTSETTINGS["core.enddate"]) # TODO: support other crop models besides ALMaSS - crops = Ps.ALMaSS.readcropparameters(TESTSETTINGS["crop.cropfile"], - TESTSETTINGS["crop.growthfile"]) + crops = Ps.ALMaSS.readcropparameters(TESTSETTINGS["crop.cropdirectory"]) farmers = Vector{Farmer}() farmplots = Vector{Ps.FarmPlot{Ps.ALMaSS.CropState}}() model = AgricultureModel{Ps.ALMaSS.CropType,Ps.ALMaSS.CropState}( diff --git a/test/simulation_tests.jl b/test/simulation_tests.jl index b8bb76ecb48efe6e9b76e645deac852a5142c1c0..c18856951c1dd07dc23bf0bceb1ac4a06dbb9eb4 100644 --- a/test/simulation_tests.jl +++ b/test/simulation_tests.jl @@ -4,7 +4,7 @@ ### @testset "Model initialisation" begin - model = initialise(TESTPARAMETERS, params=Dict("core.visualise"=>false)) + model = initialise(; configfile=TESTPARAMETERS, params=Dict{String,Any}("core.visualise"=>false)) @test typeof(model.settings) == Dict{String, Any} @test @param(core.visualise) == false @test model.date == Date(2022,2,1) @@ -48,7 +48,8 @@ end Random.seed!(1) rand1 = rand() Random.seed!(1) - model = initialise(TESTPARAMETERS, 218) + model = initialise(; configfile=TESTPARAMETERS, + params=Dict{String,Any}("core.seed" => 218)) @test rand() == rand1 Random.seed!(1) @test @param(core.seed) == 218 diff --git a/test/test_parameters.toml b/test/test_parameters.toml index 089712ee2f4ab8c4ecd7da50ed97fc7dc4ca74be..47c5a08e094537da28b0d519f4776e1228f8c04b 100644 --- a/test/test_parameters.toml +++ b/test/test_parameters.toml @@ -41,5 +41,4 @@ insectmodel = ["season", "habitat", "pesticides"] # which factors affect insect [crop] cropmodel = "almass" # crop growth model to use, "almass", "aquacrop", or "simple" -cropfile = "crop_data_general.csv" # file with general crop parameters -growthfile = "almass_crop_growth_curves.csv" # file with crop growth parameters \ No newline at end of file +cropdirectory = "test/cropparams-almass/" # the directory storing all data files for the selected crop model diff --git a/test/test_parameters_almass.toml b/test/test_parameters_almass.toml index 159e59d2cb484a8f51da325c3bbbad1ae0af9e48..fa520c207a6980016d2595ed5d16c78f76137af4 100644 --- a/test/test_parameters_almass.toml +++ b/test/test_parameters_almass.toml @@ -41,6 +41,4 @@ insectmodel = ["season", "habitat", "pesticides"] # which factors affect insect [crop] cropmodel = "almass" # crop growth model to use, "almass", "aquacrop", or "simple" -cropfile = "crop_data_general.csv" # file with general crop parameters -growthfile = "almass_crop_growth_curves.csv" # file with crop growth parameters - +cropdirectory = "test/cropparams-almass/" # the directory storing all data files for the selected crop model diff --git a/test/test_parameters_simplecrop.toml b/test/test_parameters_simplecrop.toml index b7c08f1008786b06a0fc391437efd294bad8fdd2..43bd55087732774a792cb39d098b7e3abcfce43c 100644 --- a/test/test_parameters_simplecrop.toml +++ b/test/test_parameters_simplecrop.toml @@ -41,7 +41,4 @@ insectmodel = ["season", "habitat", "pesticides"] # which factors affect insect [crop] cropmodel = "simple" # crop growth model to use, "almass", "aquacrop", or "simple" -cropfile = "crop_data_general.csv" # file with general crop parameters -# TODO: this parameter should be unnecessary, but removing it -# currently gives an error -growthfile = "almass_crop_growth_curves.csv" # file with crop growth parameters +cropdirectory = "test/cropparams-almass/" # the directory storing all data files for the selected crop model