diff --git a/src/Persephone.jl b/src/Persephone.jl index 96bfece2c8be93670e0d0ce90dfbfc9a03a4ffb5..3a978d7408f9d6376fa603d4f0e47404c5cdb072 100644 --- a/src/Persephone.jl +++ b/src/Persephone.jl @@ -46,7 +46,7 @@ include("nature/nature.jl") include("nature/lifehistory.jl") include("nature/ecologicaldata.jl") #include("nature/species/skylark.jl") -#include("nature/species/wolpertinger.jl") +include("nature/species/wolpertinger.jl") #include("nature/species/wyvern.jl") include("core/simulation.jl") diff --git a/src/core/landscape.jl b/src/core/landscape.jl index 573c9511e0e6ffa0ae54d69128397ae567f1c3e7..7672839848aa54d9182d01534c71f4dbda18bee4 100644 --- a/src/core/landscape.jl +++ b/src/core/landscape.jl @@ -1,3 +1,4 @@ + ### Persephone - a socio-economic-ecological model of European agricultural landscapes. ### ### This file manages the landscape maps that underlie the model. @@ -40,7 +41,7 @@ function initlandscape() lc = landcover[x,y][1] (ismissing(lc)) && (lc = 0) lcv = LandCover(Int(lc/10)) - landscape[x,y] = Pixel(lcv, farmfields[x,y][1]) + landscape[x,y] = Pixel(lcv, farmfields[x,y][1], Vector{Symbol}()) end end return landscape diff --git a/src/nature/ecologicaldata.jl b/src/nature/ecologicaldata.jl index c387eb2baf79ea800d164a1b69659222cec4a569..e57b15e5524b8de62458873ba30745588e621054 100644 --- a/src/nature/ecologicaldata.jl +++ b/src/nature/ecologicaldata.jl @@ -14,7 +14,7 @@ Create output files for each data group collected by the nature model. function initecologicaldata() newdataoutput(POPFILE, "Date;Species;Abundance", savepopulationdata, param("nature.popoutfreq")) - newdataoutput(INDFILE, "Date;ID;X;Y;Species;Sex;Age;Energy", + newdataoutput(INDFILE, "Date;ID;X;Y;Species;Sex;Age", saveindividualdata, param("nature.indoutfreq")) end @@ -29,7 +29,7 @@ function savepopulationdata(model::AgentBasedModel) pops = Dict{String,Int}(s=>0 for s = param("nature.targetspecies")) for a in allagents(model) (typeof(a) != Animal) && continue - pops[a.species.name] += 1 + pops[a.traits["name"]] += 1 end data = "" for p in keys(pops) @@ -50,7 +50,7 @@ function saveindividualdata(model::AgentBasedModel) data = "" for a in allagents(model) (typeof(a) != Animal) && continue - entry = join([model.date,a.id,a.pos[1],a.pos[2],a.species.name,a.sex,a.age,a.energy], ";") + entry = join([model.date,a.id,a.pos[1],a.pos[2],a.traits["name"],a.sex,a.age], ";") data *= entry*"\n" end data diff --git a/src/nature/species/wolpertinger.jl b/src/nature/species/wolpertinger.jl index 33a73e37f8609434e3c46fe6373152ac03501d0b..a8956f2d6c34e0b51fea4eb6ef9a5ba5fb2e0b4c 100644 --- a/src/nature/species/wolpertinger.jl +++ b/src/nature/species/wolpertinger.jl @@ -5,49 +5,34 @@ ### Although I dare say the Wolpertinger is probably rather endangered... ### -##TODO convert to @species syntax - """ - initwolpertinger!(model) - -Initialise a population of Wolpertingers in random locations around the landscape. +The wolpertinger is a mysterious beast, found in the hills and alps of Bavaria. +It is purported to have the body of a hare, the wings of a bird, and the antlers +of a deer. """ -function initwolpertinger!(model::AgentBasedModel) - species = getspecies("Wolpertinger") - x, y = size(model.landscape) - popsize = Int(round((x*y)*species.traits["popdensity"])) - for i in 1:popsize - add_agent!(Animal, model, species, hermaphrodite, 0, species.traits["birthenergy"]) - end - @debug "Hid $(popsize) wolpertingers for gullible tourists to find." -end +@species Wolpertinger begin + popdensity = 1/100000 + fecundity = 0.02 + mortality = 0.01 + maxspeed = 5 -""" - updatewolpertinger(animal, model) + initialise! = initrandompopulation(popdensity) + phase = "lifephase" -Wolpertingers are rather stupid creatures, all they do is move around randomly -and occasionally reproduce by spontaneous parthogenesis... -""" -function updatewolpertinger!(w::Animal, model::AgentBasedModel) - # walk in a random direction - direction = Tuple(rand([-1,1], 2)) - speed = rand([1, trait(w, "maxspeed")]) - for i in 1:speed - walk!(w, direction, model; ifempty=false) - end - w.energy -= speed - # reproduce every once in a blue moon - if rand() < trait(w, "fecundity") - @debug "Wolpertinger $(w.id) has reproduced." - add_agent!(w.pos, Animal, model, getspecies("Wolpertinger"), - hermaphrodite, 0, trait(w, "birthenergy")) + """ + Wolpertingers are rather stupid creatures, all they do is move around randomly + and occasionally reproduce by spontaneous parthogenesis... + """ + @phase lifephase begin + direction = Tuple(rand([-1,1], 2)) + for i in 1:rand(1:@trait(maxspeed)) + walk!(animal, direction, model; ifempty=false) + end + + if rand() < @trait(fecundity) + @reproduce + end + + @kill @trait(mortality) end end - -newspecies("Wolpertinger", - initwolpertinger!, - updatewolpertinger!, - Dict("popdensity"=>1/10000, - "birthenergy"=>400, - "fecundity"=>0.01, - "maxspeed"=>5)) diff --git a/src/parameters.toml b/src/parameters.toml index 1f8a75b132f65cccd3e91d8c5f351f805caa606f..b24fe1e54ee70c33cb29372b06e384e5e0e1a29e 100644 --- a/src/parameters.toml +++ b/src/parameters.toml @@ -18,10 +18,10 @@ startdate = 2020-01-01 enddate = 2020-12-31 [farm] - +farmmodel = "FieldManager" # which version of the farm model to use [nature] -targetspecies = ["Wolpertinger", "Wyvern"] # list of target species to simulate +targetspecies = ["Wolpertinger"] # list of target species to simulate popoutfreq = "daily" # output frequency population-level data, daily/monthly/yearly/end/never indoutfreq = "end" # output frequency individual-level data, daily/monthly/yearly/end/never