diff --git a/src/Persephone.jl b/src/Persephone.jl index 7795c487a1ce4d5608933db1f9615491cd516c08..3b0b0ff85734d863673c68a03862cbbd02174b24 100644 --- a/src/Persephone.jl +++ b/src/Persephone.jl @@ -34,8 +34,22 @@ export #macros @param, @species, + @initialise, @phase, + @trait, + @setphase, + @respond, + @here, + @kill, + @reproduce, + @neighbours, @habitat, + @landcover, + @cropheight, + @croptype, + @distanceto, + @distancetoedge, + @countanimals, #functions simulate, initialise, @@ -53,6 +67,11 @@ include("crop/crops.jl") include("nature/nature.jl") include("nature/populations.jl") include("nature/ecologicaldata.jl") +#TODO loop over files in nature/species directory +# (the below doesn't work yet) +# for f in readdir("nature/species", join=true) +# endswith(f, ".jl") && include(f) +# end #include("nature/species/skylark.jl") include("nature/species/wolpertinger.jl") include("nature/species/wyvern.jl") diff --git a/src/nature/species/wolpertinger.jl b/src/nature/species/wolpertinger.jl index de906cfe4ed8356d4bfb54ccf57bacd4ccb47bb0..a4bc779578e7be0abf97682b67a238ef866aa05b 100644 --- a/src/nature/species/wolpertinger.jl +++ b/src/nature/species/wolpertinger.jl @@ -15,10 +15,9 @@ of a deer. fecundity = 0.02 mortality = 0.015 maxspeed = 5 - crowdingfactor = maxspeed*2 + crowding = maxspeed*2 initialise! = initrandompopulation(popsize) - phase = "lifephase" """ Wolpertingers are rather stupid creatures, all they do is move around randomly @@ -30,9 +29,7 @@ of a deer. walk!(animal, direction, model; ifempty=false) end - #TODO density-dependent reproduction - #neighbours = length((n.id for n in nearby_agents(animal, model, @trait(maxspeed)))) - if rand() < @trait(fecundity) # && neighbours < @trait(crowdingfactor) + if rand() < @trait(fecundity) && @countanimals(species="Wolpertinger") < @trait(crowding) @reproduce end diff --git a/src/parameters.toml b/src/parameters.toml index 33efc7d54db84631f3ed7789e3ec92521c61f279..8495d50167c1eb90922ae5dcf18edb2eac8a424c 100644 --- a/src/parameters.toml +++ b/src/parameters.toml @@ -15,9 +15,9 @@ 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 -startdate = 2020-01-01 -#enddate = 2020-01-01 -enddate = 2021-12-31 +startdate = 2022-01-01 +enddate = 2022-01-02 +#enddate = 2022-12-31 [farm] farmmodel = "FieldManager" # which version of the farm model to use (not yet implemented) diff --git a/test/io_tests.jl b/test/io_tests.jl index 3554457fd714ff15819be495515da63de92085c0..475c1daaa031e476a889651bab292e82db73b10a 100644 --- a/test/io_tests.jl +++ b/test/io_tests.jl @@ -8,8 +8,10 @@ space = GridSpace((10,10), periodic=false) model = AgentBasedModel(Animal, space, properties=properties, warn=false) @test @param(core.configfile) == TESTPARAMETERS - @test @param(core.startdate) == Date(2020, 1, 1) + @test @param(core.startdate) == Date(2022, 1, 1) @test @param(nature.targetspecies) == ["Wolpertinger", "Wyvern"] + @param(core.enddate) = Date(2022,1,3) + @test @param(core.enddate) == Date(2022,1,3) #TODO test commandline parameters end diff --git a/test/landscape_tests.jl b/test/landscape_tests.jl index 958e0460a32aa51f88303dc79413580cf3dbf59b..e1a19bfc9d70a37b6a9836e986e820b68aac5efd 100644 --- a/test/landscape_tests.jl +++ b/test/landscape_tests.jl @@ -25,7 +25,11 @@ function smalltestlandscape(agenttype::Type=Animal) end landscape[6,4] = Pixel(Ps.water, 0, []) space = GridSpace(size(landscape), periodic=false) - properties = Dict{Symbol,Any}(:landscape=>landscape, :settings=>TESTSETTINGS) + properties = Dict{Symbol,Any}(:date=>TESTSETTINGS["core"]["startdate"], + :landscape=>landscape, + :events=>Vector{FarmEvent}(), + :dataoutputs=>Vector{DataOutput}(), + :settings=>TESTSETTINGS) return AgentBasedModel(agenttype, space, properties=properties, warn=false) end @@ -36,7 +40,7 @@ end space = GridSpace(size(landscape), periodic=false) properties = Dict{Symbol,Any}(:landscape=>landscape, :settings=>TESTSETTINGS) model = AgentBasedModel(FarmPlot, space, properties=properties, warn=false) - Ps.initfields!(model) + @test_logs (:info, "Initialised 2092 farm plots.") match_mode=:any Ps.initfields!(model) # these tests are specific to the Jena maps @test size(model.landscape) == (1754, 1602) @test Ps.landcover((100,100), model) == Ps.forest @@ -52,28 +56,17 @@ end end @testset "Event system" begin - # initialise a basic model landscape - landscape = Ps.initlandscape(TESTSETTINGS["core"]["landcovermap"], - TESTSETTINGS["core"]["farmfieldsmap"]) - space = GridSpace(size(landscape), periodic=false) - properties = Dict{Symbol,Any}(:date=>Date(2022, 1, 1), - :landscape=>landscape, - :events=>Vector{FarmEvent}(), - :dataoutputs=>Vector{DataOutput}(), - :settings=>TESTSETTINGS) - model = AgentBasedModel(Union{Farmer,Animal,FarmPlot}, space, - properties=properties, warn=false) - # create some events and see whether they show up on the map and disappear as they should + model = smalltestlandscape() createevent!(model, [(1,1), (1,2), (1,3), (2,1), (2,3)], Ps.tillage) createevent!(model, [(1,1), (1,2), (1,3), (2,2)], Ps.sowing, 2) @test model.landscape[1,1].events == [Ps.tillage, Ps.sowing] @test model.landscape[2,1].events == [Ps.tillage] @test model.landscape[2,2].events == [Ps.sowing] - stepsimulation!(model) + @test_logs (:info, "Simulating day 2022-01-01.") match_mode=:any stepsimulation!(model) @test model.landscape[1,1].events == [Ps.sowing] @test model.landscape[2,1].events == [] @test model.landscape[2,2].events == [Ps.sowing] - stepsimulation!(model) + @test_logs (:info, "Simulating day 2022-01-02.") match_mode=:any stepsimulation!(model) @test model.landscape[1,1].events == [] @test model.landscape[2,1].events == [] @test model.landscape[2,2].events == [] diff --git a/test/test_parameters.toml b/test/test_parameters.toml index 464a6a9bcc194e610b9afa093c1a691ee4f7d802..0e3e021262d79cac888fc2961751792f301c8c69 100644 --- a/test/test_parameters.toml +++ b/test/test_parameters.toml @@ -9,11 +9,11 @@ landcovermap = "landcover_jena.tif" # location of the landcover map farmfieldsmap = "fields_jena.tif" # location of the field geometry map outdir = "results_testsuite" # location and name of the output folder overwrite = true # overwrite the output directory? (true/false/"ask") -loglevel = "info" # verbosity level: "debug", "info", "quiet" +loglevel = "debug" # verbosity level: "debug", "info", "quiet" seed = 1 # seed value for the RNG (0 -> random value) # dates to start and end the simulation -startdate = 2020-01-01 -enddate = 2020-01-02 +startdate = 2022-01-01 +enddate = 2022-01-02 [farm] farmmodel = "FieldManager" # which version of the farm model to use (not yet implemented)