Skip to content
Snippets Groups Projects
Commit d08fb074 authored by xo30xoqa's avatar xo30xoqa
Browse files

Various bugfixes in the MarbledWhite model

parent fce2c738
No related branches found
No related tags found
No related merge requests found
......@@ -167,7 +167,7 @@ function marbledwhitelifestats(model::SimulationModel)
!("MarbledWhite" in @param(nature.targetspecies)) && return nothing
f = Figure(size=(1600,800))
data = @data("marbledwhite_lifestats")
iszero(length(data)) && return nothing
iszero(size(data)[1]) && return nothing
n = length(data[!, "ID"])
# fecundity / population density / displacement
violin(f[1,1], repeat([1], n), data[!, "Fecundity"], axis=(ylabel="Eggs/Female", xticks=([1], [""]), title="Fecundity"))
......
......@@ -144,7 +144,7 @@ function initmarbledwhitedata(model::SimulationModel)
@param(nature.popoutfreq), nothing, marbledwhitelifestats)
newdataoutput!(model, "marbledwhite_trends",
["Year", "Abundance", "Occupancy", "Temperature"],
"15 July", marbledwhitetrends, marbledwhitetrendsplot)
"20 September", marbledwhitetrends, marbledwhitetrendsplot)
end
"""
......@@ -181,8 +181,8 @@ Save marbledwhite abundance data, including total abundance and demographic data
"""
function marbledwhitetrends(model::SimulationModel)
trends = Dict{String,Int}("Abundance" => 0, "Occupancy" => 0, "Temperature" => 0)
# retrieve adult abundance
abundance = @data("marbledwhite_abundance").Adults[end]
# retrieve adult abundance (i.e. the number of adults that flew this summer)
abundance = size(@subset(@data("marbledwhite_lifestats"), :Year .== year(model.date)))[1]
# calculate occupancy rate
width, height = size(model.landscape)
occupied, totalsites = (0,0)
......
......@@ -64,14 +64,14 @@
# lifecycle parameters
# (eggsperday and time parameters from Reinhardt et al. 2007)
const maxeggsperday = 6 # number of eggs laid under optimal conditions #TODO recalculate
const maxeggsperday = 5 # number of eggs laid under optimal conditions #TODO recalculate
const eggtime = 18:22 # days as egg
const larvatime = 290:320 # days as larva
const pupatime = 16:29 # days as pupa
const maxadulttime = 34 # maximum lifespan in days as adult #XXX Reinhardt et al. say 17-34
const maturationtime = 5:8 # days from hatching to first oviposition
const juvenilemortality = 0.98 #0:25 # in percent (Wilson 1985, Dennis 1992) #TODO check up
const mowingmortality = 0.3 # juvenile mortality from mowing events
const mowingmortality = 0.1 # juvenile mortality from mowing events
const earliesteclosure::AnnualDate = (June, 15) # (Ebert & Rennwald 1991)
const latesteclosure::AnnualDate = (August, 15) # (Ebert & Rennwald 1991)
......@@ -228,7 +228,7 @@ the land cover must be either grass or fallow, and if grass, must either not
be managed, or not have been fertilised and be a certain height.
"""
function suitablehabitat(butterfly::MarbledWhite, model::SimulationModel, pos::Tuple{Int64,Int64})
(@landcover() == agriculture && @cropname() == "permanent set-aside") ||
(@landcover() == agriculture && @cropname() == "permanent set-aside") || #TODO check height
(@landcover() == grass && (@cropname() == "NA" ||
(@cropname() == "permanent grassland (low yield)" &&
@cropheight() >= butterfly.minheight &&
......@@ -273,7 +273,7 @@ function recordlifestats(butterfly::MarbledWhite, model::SimulationModel)
# use Pythagoras to calculate the lifetime displacement
displacement = round(sqrt(sum(abs.(butterfly.birthplace .- butterfly.pos).^2)))
record!(model, "marbledwhite_lifestats",
[butterfly.id, Year(model.date),
[butterfly.id, year(model.date),
stats["Fecundity"],
# save current population density and lifetime displacement distances (but strip out units)
countanimals(butterfly.pos, model, radius=500m, species="MarbledWhite"),
......@@ -315,12 +315,13 @@ random, but I don't have data for that.)
eclose = self.birthdate+Day(self.daysinphase[1]+self.daysinphase[2]+self.daysinphase[3])
if eclose < self.earliesteclosure
diff = @nextyear(self.earliesteclosure) - eclose
self.daysinphase[2] += diff.value
@debug("Increased larval time by $(diff) to stay in flying period.")
#XXX add a random increase to avoid hard cut-offs
self.daysinphase[2] += (diff.value + @randn(0:60))
@debug("Increased larval time by >$(diff) to stay in flying period.")
elseif eclose > self.latesteclosure
diff = eclose - @nextyear(self.latesteclosure)
self.daysinphase[2] -= diff.value
@debug("Reduced larval time by $(diff) to stay in flying period.")
self.daysinphase[2] -= (diff.value + @randn(0:60))
@debug("Reduced larval time by >$(diff) to stay in flying period.")
end
end
self.birthplace = self.pos
......@@ -330,14 +331,12 @@ end
Initialise the marbled white population with one individual on every grassland pixel.
"""
@populate MarbledWhite begin
#TODO this is very rough at the moment
habitat = @habitat(@cropname() == "permanent grassland (low yield)" ||
@cropname() == "permanent set-aside" ||
(@cropname() == "NA" && @landcover() == grass))
initphase = egg # this should advance within a few days to the correct phase
birthphase = egg
#popsize = 200 #FIXME use something else
indarea = 1ha # initialise 1 individual per 100 suitable pixels #XXX
sex = female #TODO change to hermaphrodite to force all individuals to have the same sex
sex = hermaphrodite
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment