DEB-IBM for Abatus cordatus

DEB-IBM for Abatus cordatus preview image

1 collaborator

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.0.4 • Viewed 527 times • Downloaded 59 times • Run 0 times
Download the 'DEB-IBM for Abatus cordatus' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Dec 2019

Anse du Halage version (with Delille1989 as resources)

ODD

1. Purpose

The model was developed from the individual mechanistic Dynamic Energy Budget (DEB) model to extrapolate the response of the populations of the sea urchin Abatus cordatus, endemic to the Kerguelen Plateau (sub-Antarctic region), to changes in environmental conditions (temperature and resources), through comparisons between sites and between predicted future scenarios.

2. Entities, State variables & Scales


DEB notation ..... equivalent in the code ..... (dimension) signification


UH ...... UH ..................... (t·L2) scaled maturity ∂UH ..... dUH ................... change of scaled maturity in time UE ...... UE ..................... (t·L2) scaled reserves ∂UE ..... dUE ................... change of scaled reserves in time e ........ escaled ................ (-) scaled reserve density per unit of structure UR ...... UR ..................... (t·L2) scaled energy in reproduction buffer ∂UR ..... dUR ................... change of energy in reproduction buffer L ......... L ......................... (L) structural length ∂L ....... dL ........................ change of structural length in time Lw ....... Lphy .................... (L), physical length (L/∂M) Lb ....... Lb ...................... (L) structural length at birth

̈q ......... qacceleration ...... (t-2) ageing acceleration ∂̈q ....... dqacceleration ..... change of ageing acceleration in time ḣ ......... hrate ................. (t-1) specific death probability rate ∂ḣ ....... dhrate ................ change of hazard rate in time ḧa ....... h_a ...................... (t-2) Weibull ageing acceleration sG ....... sG ....................... (-) Gompertz stress coefficient

SA ...... SA ...................... (L2) assimilation flux (scaled) SC ...... SC ...................... (L2) mobilisation flux (scaled)

g ......... g ......................... (-) energy investment ratio ̇v ......... vrate .................. (L·t-1) energy conductance κ ......... kap ...................... (-) fraction of mobilised reserve allocated to soma κR ....... kapR .................. (-) reproduction efficiency ̇kM ....... kMrate .............. (t-1) somatic maintenance rate coefficient ̇kJ ........ kJrate ............... (t-1) maturity maintenance rate coefficient UHb ..... UH^b .................. (t·L2) scaled maturity at birth UHp ..... UH^p .................. (t·L2) scaled maturity at puberty

yVE ..... yVE ..................... (mol/mol) yield of structure on reserve sM ....... sM ..................... (-) acceleration factor Lm ....... zoom ................... (L) maximum volumetric length

Add-My-Pet parameters ('amp parameters' in interface) [̇pM] .... pM ...................... (e·L-3·t-1) specific volume-linked somatic maintenance rate EHb .... EH^b ................... (e) maturity at birth
EHp .... EH^p ................... (e) maturity at puberty [EG] .... EG ...................... (e·L-3) volume-specific costs of structure


The model includes two types of entities: individuals and the environment.
Individuals are divided into 4 types of sub-agents, depending on life-stage and sex: embryos, juveniles, adult males and adult females. Life-stages are considered using DEB definitions. Individuals are characterized by four primary state variables, based on DEB theory (Kooijman 2010): scaled reserve (UE), structural length (L), scaled maturity (UH) and scaled reproduction buffer (UR). Additional state variables for individuals are age (in months and in years), ageing acceleration (̈q) and death probability rate (ḣ). State variables in DEB are originally dependent on energy (unit of Joules), but in order to simplify the calculcations of differential equations so that they do not require measurements of energy, each state variable was discarded of their energy unit by dividing with the maximum surface-area specific assimilation rate {ṗAm} following Martin 2010 and Kooijman 2010. Females have supplementary attributes linked to reproduction processes for which the state variable is the gonado-somatic index (GSI). Finally, each individual has a variable called scatter-multiplier, used to implement a slight variation in three standard DEB parameters (UHb, UHp, g) and initial energy reserve at birth (UE0yo). This scatter-multiplier is the exponential of a number taken randomly on a normal distribution of mean 0 and standard deviation cv (set by the user in interface).

The environment in the model is characterized by two state variables, monthly average temperature (T, unit: °C) and monthly resources availability represented by the proportion of food an individual can intake on a scale of 0 to 1 (f, no dimension). Values for these variables are input into the model from external files, as time-series of monthly values. Temperature data was collected from existing thermo-recorders on the corresponding sites (implemented by the PROTEKER programme), while resources data comes from the publication by Delille & Bouvy 1989 for the site Anse du Halage. The variable f can be affected by the population density on site, due to intra-population competition for food.

The model as given here runs on a monthly temporal resolution over a temporal extent of 210 years which can be modified by the user in the interface. In other words, changes are applied to individuals and the environment on a monthly basis and thus each update corresponds to the state of the system at the end of the diplayed month: one timestep in the model represents one month and simulations are run for a total of 210 years. The first ten years are assumed to be the model initialisation phase and should be removed for the analysis of results. The model is non spatial, but can be adapted for spatialization. In this implementation, the model runs on one single patch of environment representing 1 square meter, and thus density of population is equal to number of individuals present in the model. Movements of individuals are not taken into account, and each individual born on the patch grows and dies on that same patch.

3. Process overview & Scheduling

At each timestep, the model runs the following commands in that order:

Reset the death counts
Update calendar

(For each patch:

    Update environmental variables
    If competition ON [
        Calculate competition 
    ]
    Calculate f 
)

(For each individual:

    Remove if marked as deceased 
    Convert relevant parameters with temperature correction factor
    Calculate change in reserve
    If not mature [
        Calculate change in maturity
    ]
    If mature [
        Calculate change in reproduction buffer 
    ]
    Calculate change in structural length
    If scaled reserve < scaled length [ 
        Starve
    ]
    Calculate ageing
)

Update individuals

(For each individual:

    Update reproduction timers
)

(For each females:
    Update birth timer
    If first month of reproduction period [
        If reproduction ON [    
            Mark GSI down 
            Prepare eggs
            ]
    ]
    Calculate GSI
    If GSI >= 0.07 [
        Turn ON reproduction
        If month before reproduction period [
            Mark U_R down 
            Launch reproduction (with birth_time)
            ]
    ]
    If GSI < 0.07 [ 
        Turn OFF reproduction
    ]
    If reproduction ON [
        If within reproduction period [ 
            reproduce
            ]
        If within birth-giving period [
            release offsprings
            ]
    ]
)

Background mortality
Check temperature
Monitoring of population
Update time 

Individuals execute the same command one by one in a fixed order before going to the next command, but all have access to the same state of the environment since it updates once at the beginning of the timestep only.

In this model, time is represented continuously using ordinary differential equations (ODE) for the individual state variables, and all other variables are calculated in a discreet manner (every month, with one month rounded to 30.5 days).

Below is an illustration of the different calendars and timers used in the model, beginning at the point where the simulation starts (Gregorian calendar for reference):

repro_time:      7     8     9    10     11     0     1     2     3     4     5     6,     7     8 .......
GSI_time:        5     6     7     8     9     10    11    12     1     2     3     4,     5     6 .......
birth_time:      1     0     0     0     0      8     7     6     5     4     3     2,     1     0 .......
month_time:      10    11    12    01    02    03    04    05    06    07    08    09,    10    11 .......
Gregorian calendar: Oct   Nov   Dec   Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep,   Oct   Nov.......

'reprotime' follows the reproduction year, runs on a twelve steps loop, 'GSItime' follows the GSI cycle year, runs on a twelve steps loop, 'birthtime' is a countdown tracker for the time between the start of reproduction and the following release of offpsrings in a year. It is triggered by the launching of reproduction and counts backward, staying at 0 if not triggered. 'monthtime' follows the Gregorian calendar

4. Design concepts

Basic Principles

The IBM was built using the DEB-IBM model developed by B. Martin for Daphnia magna, along with its DEB-IBM user manual and model description (Martin et al. 2010). The underlying theory for the individual development in the model follows the Dynamic Energy Budget theory (Kooijman 2010). The population is studied following the IBM principles (Railsback & Grimm 2019), as a dynamic system composed of autonomous individuals affected by the environmental conditions throughout their life-cycle. Each individual undergoes a continuous development from birth till death, following the DEB principles with a slight variation between individuals at their initialisation, and represents a component of the IBM population, which is itself affected as a whole by variables such as population death rates and density-dependent processes. The emerging state of the population is then observed, and compared between different scenarios of environmental variations.

Emergence

The model illustrates the evolution of the population structure following the response of the individuals to the environmental conditions input. Metabolic responses, life-stages, ability to reproduce, starvation and ageing processes of the individuals, emerging from the mechanistic representation of their development, affect the population structure and average characteristics. A background mortality rate and a mortality caused by above normal temperatures are forced into the model, and the same reproductive output is imposed to all females that are able to reproduce.

Adaptation

Agents do not have an adaptive behavior. Individual traits vary among individuals in a population, but each individual carry the same traits along their entire lifespan and do not change nor learn from the events they experience or from each other. Consequently, the design concepts "objectives", "learning", "prediction", and "sensing" do not apply.

Objectives

Learning

Prediction

Sensing

Interaction

Individuals do not have any direct interaction. They only affect each other indirectly, as the size of the population influences the resources availability and thus the capacity of each individual to ingest a maximum proportion of food.

Stochasticity

In the model, stochasticity is used in the ageing submodel: there is a 50% chance that the individual will look into their probability of dying. This stochastic element can be modified in the code by changing the numbers x and y in the 'update individual' procedure. Stochasticity is also implemented in four of the initial variables for each individual (scaled maturity at birth, scaled maturity at puberty, energy investment ratio, energy reserve at birth), using the scatter-multiplier, a number randomly chosen on a log-normal distribution (taken from Martin 2010, Kooijman 2010).

Collectives

The individuals are grouped under a particular type of entity depending on their life-stage and sex, and will move between groups in one direction only. Thus, individuals are born into the "juveniles" group and move onto either the "males" or "females" group after reaching puberty. The age at which a juvenile reaches puberty is an emergent property of its development, but the sex is arbitrarily and randomly imposed on the individual that becomes an adult so that the sex-ratio of the population is around 0.99. Depending on which group they belong to, some variables are different: juveniles do not modify their reproduction buffers, while males and female do not modify their maturity compartment, and females possess some proper variables such as GSI (Gonado-somatic index), eggs (number of eggs produced) and Ri (reproductive output). These collectives do not emerge from individual behaviour, but instead are implemented by the modeller in order to distinguish the life stages and sex of the individuals.

Observations

The main output of the model are plots of the population structure with densities of population in the different life-stages, of the cumulative counts of individuals dead of different causes, as well as of mean values in state variables UR, UE and L and change in those state variables (∂UR, ∂UE and ∂L) for the different type of agents. These plots allow to observe the response of the population to the different environmental conditions and the metabolic responses of the individuals in the population in relation to those environmental conditions. Additionally, plots of the mean age at death of individuals dying due to the ageing submodel were used to calibrate the submodel itself.

NB: The plots are built on the lists compiled during the calc-pop-varb procedure (called by the update-pop procedure at the end of each month), which are built so that in case none of the individuals possessing the variable is present, an outlier mock value is applied instead. This is used to facilitate processing of the outputs afterwards.

Details

5. Initialisation

For the standard model, the following elements must be selected in the interface:

  • Sites: 'Anse du Halage'
  • projection: 'present'
  • future: 'mixed temp & food' (not used under 'present' projection)
  • sensitivity: 'resistant'
  • competition: 'ON'
  • run_time: '210'
  • cv: '0.1'

The initial DEB parameters can be calculated by the model if the 'add-my-pet?' switch is set to ON in the interface and the basic DEB parameters [̇pM], EHb, EHp, [EG] and Lm for the species as taken from the Add-my-Pet database are input into the relevant boxes (respectively: pM, EH^b, EH^p, EG, zoom).

The standard model is run for 210 years in total for the site Anse du Halage under present-day conditions, with a population sensitivity set to 'resistant' and competition affecting resources availability. At setup, lists are made out of the input files of temperature and f data for the site. The model is initialized for the month of October (monthtime 10) and the environment is setup with the corresponding environmental variables: if the model is used for a simulation under present-day conditions, the values are taken as is. If the model is set for future projections, the values are modified according to the chosen scenario (i.e. either one of RCP 2.6 and RCP 8.5 with food only, temperature only or food and temperature combined). Values for calculations of temperature correction factor are given as Tref = 293.15 and T_A = 9000. The carrying capacity is set at 200 ind./m2 and the proportion of females at 0.5.

Initial parameters are based on DEB parameters, taken from the individual mechanistic DEB model for A. cordatus developped by C. Guillaumot in 2019 and published on the add-my-pet database. Two simulations procedures are run for the initialisation of individuals: a simulation of embryonic development to determine the initial reserve at birth, and a simulation of the development of one individual from 0 till 5 years old at constant f and temperature. The first simulation uses a bisection method to go through possible embryonic developments depending on the initial energy invested into the egg at conception. The simulation runs with the aim to obtain an embryo with a scaled reserve e close (within ±5%) to the reference scaled reserve when it reaches birth. The initial cost is taken as the mean of an upper and lower bound, which are arbitrarily set in the first loop and then determined by the result of the simulated development at the end of the loop: if the scaled reserve e is within the range of the reference e before the embryo reaches birth, the value that was taken for the initial cost is used as the lower bound in the next loop; if the scaled reserve e reaches the needed value after the embryo has reached birth, the value that was taken for initial cost is used as the upper bound in the next loop. When the embryo reaches birth with a reserve density within the aimed range, the simulation stops and the reserve density is set aside. The second simulation starts off where the first one finished, using the resulting reserve density at birth. It runs a loop for the development of the individual from birth till five years old, with standard parameters and a constant functional response f = 1. The simulation keeps track of the age of the individual, and for each year the values for the state variables are set aside and the simulation continues until the next year. Once these two simulations are run, the model creates the initial population of 120 individuals and first gives all of them initial parameters for individuals at birth (0 years old) with initial values from the DEB model slightly altered by a scatter-multiplier. Then the total number of individuals is divided in equal proportions into six classes corresponding to six age classes from 0 to 5 years old. Initial parameters are modified for individuals from classes 1 to 5 years old, by putting the initial parameters corresponding to their age that were set aside from the second simulation. All individuals are given an age in months and years, and a breed corresponding to their life-stage or sex (juveniles from 0 to 2 years old, female or male for 3 to 6 years old). Each individual sets their calendars with GSItime at 5 and reprotime at 7, and females are given initial values of 0.03 for their GSI and set their birth_time timer at 0.

Initialisation differs from run to run in one aspect only, the individuals' own parameter values: each individual created at initialisation gets its parameters slightly altered by a stochastic element, the scatter-multiplier. This scatter-multiplier is the exponential of a number taken randomly on a normal distribution of mean 0 and standard deviation cv (set by the user in the interface of the model, at 0.1 for the standard model).

Temperature data for two other sites is available: Port Couvreux and Ile Haute. In order to use the model with those sites, they must be selected in 'Sites' on the interface. NB: Keep in mind that even if these sites are selected, the food resources data will be that of Anse du Halage, as detailed data on food availability for other sites are not available. This is merely to test the model with a different kind of temperature data.

6. Input data

The model reads environmental variables from input files containing time-series data on monthly resources availability (from Delille & Bouvy 1989) and monthly average temperatures (PROTEKER programme IPEV n°1044). The two files are text files containing an ordered list of values (see below for Anse du Halage data). The temperature files contains 72 values of monthly average temperatures corresponding to temperature records from october 2012 to september 2018. The resources file contains 12 values, taken from the measures of organic carbon content in sediments published in Delille & Bouvy 1989. From each files, two ordered lists are compiled by the model during the setup procedure: one list with values from 0 to the total number of values, used as a timestamp, and one list with the corresponding value. Then the lists are used in parallel to take out the value found at the same level as the timestamp corresponding to the model's timing.

Data for resources and temperatures at Anse du Halage (to use, copy onto two separate txt files with the same name as in the code, only copy the values (no header, no text, make two columns):

   Resources:
month  f value
01  0.748
02  0.775
03  0.756
04  0.712
05  0.559
06  0.477
07  0.432
08  0.432
09  0.477
10  0.648
11  0.909
12  1.000

   Temperatures:
time   mean temperature
0   3.576178523
1   4.272769444
2   5.693903226
3   6.680989247
4   7.540075893
5   7.95569852
6   7.359872222
7   5.870103495
8   4.220568056
9   3.152399194
10  2.534522849
11  2.528454167
12  2.880237584
13  3.636294643
14  5.96272449
15  6.222271505
16  7.38149256
17  7.409368775
18  6.966427778
19  5.492860215
20  4.282763889
21  3.241544355
22  2.01715457
23  1.521733333
24  2.291408054
25  3.276548936
26  5.257983871
27  6.709844086
28  7.32331994
29  7.503302826
30  6.7152625
31  5.828805108
32  4.465727778
33  3.162452957
34  2.993697581
35  2.861191667
36  2.898080537
37  3.910002778
38  5.598921622
39  6.695869792
40  7.683181034
41  7.759943472
42  7.293447222
43  6.056247312
44  4.463266667
45  3.685244624
46  2.871793011
47  2.45
48  3.922534228
49  4.934752793
50  6.197569892
51  7.121584677
52  8.077349702
53  8.012516824
54  7.298430556
55  5.771642473
56  4.241619444
57  3.590569892
58  3.162024194
59  3.287647222
60  4.061998658
61  4.965858136
62  6.445442204
63  7.738768817
64  8.714534226
65  8.409689098
66  7.613561111
67  5.821275538
68  4.157559722
69  3.148745968
70  2.482346774
71  2.836618056

7. Submodels

Update calendar The model advances by one month on the gregorian calendar.

Update environmental variables The model takes the relevant temperature and f values for the current month in the input list.

Competition and f The model calculates the current population density and quantifies the competition effect on the food availability depending on how far from the carrying capacity the population density is, and updates the f value in accordance.

If popdensity < 1.9 * carcap, then foodcompet = ((1 - f-scaled) * (1 - (popdensity / (2 * carcap - popdensity)))) If popdensity ≥ 1.9 * carcap, then foodcompet = ((1 - f-scaled) * (1 - (popdensity / (car_cap / 10))))

The use of two types of formula is because if popdensity = 2 * carcap, the first formulat gives an error due to a division by 0, and if popdensity > 2 * carcap, then the formula gives the untrue result of less competition with a bigger population.

Explanation of the procedure: Competition is only effective if the food availability is less than the maximum (hence the use of '1 - f-scaled'). In which case, proportionnally to how much the f is lessened compared to maximum, the size of the current population has an influence on how important the competition is: If the population is below the carrying capacity (carcap), then food is more available for the individuals present, but if the population is over the carrying capacity, the availability of food is lessened. Therefore, if pop > carcap, foodcompet < 0 <=> f decreases if pop = carcap, foodcompet = 0 <=> f constant if pop < carcap, food_compet > 0 <=> f increases

Meaning, the competition is actually calculated depending on how far from the carrying capacity is the population density, and how far from maximum f is the food availability. The less food there is and the bigger the population, the higher the competition.

The regulatory effect of this competition lies in the starvation of individuals at lower food availability, which leads to a reduction of the population size with higher competition (combination of low food availability and big population size).

f is always contained between 0 and 1. If the competition is turned off, f is the direct value taken from the input list.

Convert parameters with TC A temperature correction factor (TC) is calculated using the Arrhenius temperature (TA) and applied to conductance ̇v, somatic maintenance rate ̇kM, maturity maintenance rate ̇kJ and Weibull ageing acceleration ḧa, which are all affected in the same way by the correction factor. TC = exp((TA/Tref - TA/T) A given metabolic rate X at temperature T is thus modified with: X(T) = X * exp(TA/Tref - TA/T) with Tref being the reference temperature (20°C) and T the actual temperature (in Kelvin) of the organism’s life environment.

Change in reserve The reserve is supplied from ingested food, represented in the model by the functional response f (from 0 to 1) proportional to food availability. Scaled assimilation rate SA is found with ̇pA /{ṗAm}, where ̇pA is the flux of assimilation (in energy per time) and ṗAm the maximal assimilation flux per surface area of structure (with the same dimension). Since ̇pA = {ṗAm} * f * L2, with L the structural length, then SA = f * L2. A flux of mobilized energy goes outside of the reserve compartment: the scaled mobilisation flux SC is the scaled equivalent of ̇pC / {ṗAm} therefore equal to: L2 * (ge/(g+e)) * (1+L * ̇kM/̇v) = SC, where g is the energy investment ratio (the cost of the added volume for this timestep relative to the maximum potentially available energy for growth and maintenance), e is the scaled reserve density (reserve density relative to maximum reserve density) and L the structural length, and with ̇kM the rate of mobilisation of the κ fraction of SC for somatic maintenance, proportional to structural length, and ̇v the energy conductance. The reserve dynamics calculated at each time step correspond to ∂UE = SA - SC.

Change in maturity or reproduction buffer Before puberty (ability to reproduce), changes in maturity level are calculated as the flux of energy going into the maturity compartment, that is the fraction 1-κ of the mobilisation flux after paying for the maintenance costs of the maturity compartment UH: ṗR = (1-κ) * ṗC - ṗJ.

The maturity level of the compartment UH changes each month through the scaled formula for ∂UH: SR = (1-κ) * SC - ̇kJ * UH = ∂UH,

while the reproduction buffer UR receives no energy, thus ∂UR is set to 0.

Juveniles keep growing until they reach puberty, when the maturity level UH is equivalent to UHp. At this point, they are able to reproduce, thus the energy flux SR is redirected entirely to the reproduction buffer UR and the maturity compartment does not increase anymore: UH stays set as UHp. Therefore, after puberty, and except for females undergoing reproduction: SR = (1-kap) * SC - ̇kJ * UHp = ∂UR .

Change in structural length The structural length L changes with the flow of energy that remains from the fraction κ of mobilisation flux SC after somatic maintenance has been paid for: the structural length at the end of the month is different from the month before by ∂L, calculated with the scaled formula ∂L = (1/3) * ((̇v/gL2) * SC - ̇kM * L).

If scaled reserve falls below the scaled structural length, starvation is launched.

Starvation When scaled reserve falls below the scaled structural length l (length relative to maximum length), that is when e < l, it is assumed that the individual is confronted to starving conditions: the kappa rule is then altered as energy is entirely redirected to somatic maintenance and all other fluxes (growth, reproduction or maturation) are set to 0, the following calculations are made:

Mobilisation flux SC = ([ṗM] / L3)/({ṗAm} ) . Since [ṗM] = [EG] * ̇kM and [EG] = g * kappa{ṗAm} / ̇v ,

we can rewrite SC = (L3 * ̇kM * g * kappa{ṗAm} / ̇v ) / ({ṗAm}) = (L3 * ̇kM * g * kappa)/ ̇v

then recalculate ∂UE = SA – SC .

When e < 0, the organism doesn’t have enough energy to pay somatic maintenance and dies.

The starvation strategy used in the population model was chosen among the ones presented in Kooijman 2010 based on Magniez 1983 research on A. cordatus reproduction and development.

Ageing Two ordinary differential equations are calculated: changes in ageing acceleration ̈q (also called the scaled density of damage inducing compounds) and changes in hazard mortality rate ḣ. ∂̈q = (̈q (L/Lm)3 * sG + ḧa) * e * (̇v/L- ̇r)- ̇r * ̈q

∂ḣ = ̈q - ̇r * ḣ , with ̇r = (3/L)*∂L

These calculations are used for the simulation of the accumulation of damage inducing compounds and their effect, following the DEB theory for ageing (Kooijman 2010). Damage inducing compounds density is proportional to reserve mobilisation SC and influences the hazard mortality rate ḣ which is a function of the damage accumulated in the body. Damage inducing compounds are diluted via growth ̇r, and additionally ageing is calculated with two other parameters, the Weibull ageing acceleration ḧa and the Gompertz stress coefficient sG . In other words, the hazard mortality rate is the simulation of the vulnerability of the individual towards damage, such as the risk of dying from an illness increasing as the individual ages. Additionally, in our model, the ageing submodel relies on a stochastic element, where the individual has a 50% chance of looking into its death probability rate ḣ.

Update individuals The calculated changes are applied to each state variables of the individual: For a state variable X, X = X + ∂X * 30.5 . The temporal resolution is a monthly interval: each ODE is calculated then the resulting ∂ is applied *30.5. If the individual has reached a maturity level corresponding to a threshold, it updates its life stage (i.e. its breed) accordingly. The individual also updates its age.

Update reproduction and birth timers The reproduction calendar (reprotime) and the GSI calendar (GSItime) advance by one month each timestep, and fall back to the start in a twelve months cycle. The starting date of the two calendars is not the same (March for reprotime and June for GSItime). The birth timer (birth_time) is updated if it has been set off, by counting down (e.g. if it was at 7, the timer will be set to 6). If the timer has not been set off (i.e. is still set to 0), it will stay at 0. This timer is borne by females only and will set off if the female has launched reproduction.

Reproduction Only females are considered in the reproduction processes. The value of the Gonado-somatic index (GSI = 100 * ((ash-free gonads dry weight) / (ash-free body dry weight)) when the reproduction period comes is what allows a female to reproduce. Whenever the level of GSI is high enough (at least 0.07%), the female signals being ready for reproduction. If the GSI falls back below the threshold, the signal is turned off.

Following is the explanation of the process in the order of execution (see pseudo-code): If the signal is on when the reproduction period comes (i.e. it has been turned on the month before the reproduction period), females note down their value of GSI and prepare their eggs. Females calculate their GSI every month (see submodel 'Calculate GSI'). If it is the month before the reproduction period and the GSI is above the threshold, females note down the value of energy density in their reproduction buffer and in addition to turning their reproduction signal on, they start their birth timer (by setting the 'birthtime' countdown to 9) which serves as a tracker in the reproduction process from conception of offsprings till their birth. Once the reproduction period starts, the birth timer is what allows to verify if the individual is undergoing reproduction and to adapt its state variables accordingly: at birthtime 8, 7 and 6, females are reproducing (i.e. conceiving offsprings by decreasing the energy in their reproduction buffer, see below); at birth_time 3, 2 and 1, females release offsprings (i.e. a number of new juveniles proportional to the number of females having reproduced is initiated into the model, see below).

When females are reproducing, conception of offsprings causes a decrease in energy in their reproduction buffer: their usual ∂UR (see submodel 'Change in maturity or reproduction buffer') is set to 0 for the three months, while UR is forced to decrease: for each month of the reproduction period the female decreases its buffer by a third of 52% of the energy stored: ∂2UR = (URstart - 0.52 * URstart) / 3, with UR_start the reproduction buffer at the start of the period. The GSI follows a similar pattern (see submodel 'Calculate GSI').

When females release offsprings (i.e. give birth), five months after conception, 65% of the eggs are assumed to have survived until birth. The reproductive output (Ri) is: Ri = 0.65 * eggs For each of the three months of offspring release, the number of juveniles (Ri / 3) are intiated into the model with parameters from the calculations of the initial simulation.

Calculate GSI The GSI is estimated for each month according to the time of accumulation of energy into the reproduction buffer from the end of the reproduction, with this equation: GSI = ((timeofaccumulation * ̇kM * g) / (f3 * (f + κ * g * yVE ))) * ((1-κ) * f3 - ((̇kJ * UHp) / (Lm2 * sM3)) ) , where the time of accumulation is the number of days since the end of the reproduction period, ̇kM the somatic maintenance rate coefficient and ̇kJ the maturity maintenance rate coefficient, g the energy investment ratio, f the scaled functional response, yVE is the parameter for the yield of structure on reserve, that is the number of moles of structure that can be produced with one mole of reserve, sM the acceleration factor, UHp the scaled energy in the complexity compartment at puberty, κ the fraction of energy directed towards structure and 1-κ the fraction of energy directed towards complexity and Lm the maximum volumetric length (see "Entities, State variables and scales" for the dimensions and in-code notations).

The GSI of a reproducing female will decrease by 52% of its initial value over the 3 months period of reproduction (i.e. a decrease of one third of 52% per month): ∂GSI = (GSIstart - 0.52 * GSIstart) / 3, where GSIstart is the level of gonadal index at the onset of reproduction.

Background mortality The barckground mortality rate is applied to the overall population: 3.42% of juveniles and 2% of adults (males and females) die each month. Depending on the cause of death, the individuals set on a certain flag (deceasedbg or deceasedold) and a 'deceased' flag. They are then removed only at the start of the next tick (for monitoring purpose).

Check temperature Depending on the temperature for the current and prior month and on the type of sensitivity to temperatures chosen for the model, a mortality rate is applied to the population for temperatures from 8 to 12°C. For a "vulnerable" setting, temperatures exceeding thresholds of 8, 9.5, 11 and 12°C for two consecutive months cause a mortality rate of 25%, 35%, 45% and 100% respectively. For an "intermediate" setting, temperatures exceeding thresholds of 8, 9.5, 11 and 12°C for only one month cause a mortality rate of 10%, 20%, 30% and 100% respectively. For a "resistant" setting, temperatures exceeding thresholds of 8, 9.5, 11 and 12°C for two consecutive months cause a mortality rate of 10%, 20%, 30% and 100% respectively. When the cause of death is temperature, individuals die on the spot (contrary to background mortality).

Monitoring of population At the end of each timestep, the population density is calculated and the data collected for monitoring and plotting mean values of state variables. Plots are built on the lists compiled out of all individuals state variables values. To facilitate processing of the outputs afterwards, mock values are implemented in case none of the individuals possessing the variable is present at the timestep. These mock values are values purposely exceedingly higher than the normal range for the variable, so that they can then be easily spotted and taken out during processing of results.

Update time The counters for the number of years and months since the beginning of the simulation advance by respectively one twelfth and one, each timestep.

References (short list)

Delille, D., Bouvy, M., 1989. Bacterial responses to natural organic inputs in a marine subantarctic area. Hydrobiologia, 182(3), 225-238. doi:10.1007/BF00007517. Guillaumot, C., 2019. AmP Abatus cordatus, version 2019/01/17. https://www.bio.vu.nl/thb/deb/deblab/add_my_pet/entries_web/Abatus_cordatus/Abatus_cordatus_res.html Kooijman, S.A.L.M., 2010. Dynamic energy budget theory for metabolic organisation, third ed. Cambridge university press. Martin, B.T., Zimmer, E.I., Grimm, V., Jager, T., 2010. DEB-IBM User Manual: Dynamic Energy Budget theory meets individual‐based modelling: a generic and accessible implementation. Available at https://www.bio.vu.nl/thb/deb/deblab/debibm/DEB_IBM_manual.pdf.
Railsback, S. F., Grimm, V., 2019. Agent-based and Individual-based Modeling: A Practical Introduction. Princeton university press.

Supplementary information:

For further details and information such as sensitivity analysis, detailed explanations of processes in submodels, the ecophysiological data used and full references, see our research article on the construction of this model: Arnould-Pétré Margot, Guillaumot Charlène, Danis Bruno, Féral Jean-Pierre and Saucède Thomas "Modelling individual-based population dynamics for an endemic species of the Southern Ocean, the sea urchin Abatus cordatus, under contrasting environmental conditions”, submitted to the Ecological Modelling Special Issue of the 2019 Dynamic Energy Budget Symposium.

Main things to keep in mind in this implementation:

For the model to work, the files for the environmental data (temperatures: "temptimemonthavgHalage.txt"_ and resources: "inputRScesMfDelille.txt"_) need to exist in the same folder as where the model is stored.

  • For now, the model only fully works if the site Anse du Halage is selected. Sites Port Couvreux and Ile Haute can also be selected, however the site-specific data is only available for temperature and not for resources. Thus, if one of those two sites is selected, the file for the resources data will be that of Anse du Halage. This is merely to test the model for different temperature data using real time-series records rather than future projections. NB: Here again make sure that the relevant temperature files ("temptimemonthavgCouvreux.txt"_ or "temptimemonthavgHaute.txt"_) are present in the same folder as the model.

  • The temporal resolution is a monthly interval : each ODE is calculated then the resulting ∂ is applied *30.5

  • Temperature and functional response f are in the form of time-series. (To test with constant and DEB standard values, uncomment the corresponding lines at the beginning of the go procedure in the code.)

  • This species lives in water at ~5°C average, however we are missing the upper limit of the arrhenius relationship. Because of this, the mortality due to temperature is mainly randomly applied among individuals in the population without distinction.

  • Depending on the cause of death, the individuals set on a certain flag (deceasedbg or deceasedold) + a 'deceased' flag and are removed only at the start of the next tick (for monitoring purpose). If the cause is temperature, they die on the spot.

  • State variables plots are built on the lists compiled during the calc-pop-varb procedure (called by the update-pop procedure at the end of each run/month), which are built so that in case none of the individuals possessing the variable is present, an outlier mock value is applied instead. This is used to facilitate processing of the outputs afterwards. Death plot is non cumulative: death counts reset at the beginning of each tick.

Comments and Questions

How to run the model:

A few simple steps are necessary to run this model under its basic implementation (you can find the same information in the file ODD.pdf - "How to run the model + Model description"): 1/ The files for the environmental data need to exist in the same folder as where the model is stored. To do this, after downloading the model, download the data files from the ‘’Files’’ tab in the NetLogo modeling commons (http://modelingcommons.org/browse/one_model/6201#model_tabs_browse_files). For the basic implementation, the two files needed are “temp_time_monthavg_Halage.txt” for temperatures and “inputRSces_M_f_Delille.txt” for resources. Make sure the model (.nlogo) and the data (.txt) files are stored in the same folder in the computer. 2/ Once you open the model (.nlogo), the interface is generally the first thing that is visible. Navigation between the interface, the information page (this page), and the code of the model is done through the three tabs at the top of the software (‘Interface’, ‘Info’, ‘Code’). Make sure that the following elements are selected in the interface: • Sites: ‘Anse du Halage’ • projection: ‘present’ • future: ‘mixed temp & food’ • sensitivity: ‘resistant’ • competition: ’On’ • run_time: ‘210’ • cv: ‘0.1’ • add-my-pet?: ‘Off’ Also ensure that none of the green boxes (‘input paramaters’) is empty. If any of them is empty, switch the add-my-pet? button ‘On’ and fill the relevant boxes with the basic DEB parameters for A. cordatus as taken from the Add-my-Pet database (https://www.bio.vu.nl/thb/deb/deblab/add_my_pet/entries_web/Abatus_cordatus/Abatus_cordatus_res.html): [ṗM], EHb, EHp, [EG] and Lm, which correspond to these boxes respectively: p_M, E_H^b, E_H^p, E_G, zoom. Except in the aforementioned case, do not modify any of the parameters in the green boxes placed under the line « Input parameters » on the interface. 3/ Click on the purple setup button. This initializes the model, and should barely take a second on an average computer. A sure way of knowing the model has finished setup, is color shapes appearing in the small black square that is on the bottom-right of the purple buttons. 4/ Once setup is finished, click on the purple go button. This will run the model for the simulated duration input in the run_time box (number of years). Clicking on the go button again before the end of the simulation will pause the model, clicking on it after the end of the simulation will continue the simulation without a temporal limit. The go once button will only run the model for a single loop, that is a simulation of one month. 5/ The model can be run for future projections with different combinations of food and/or temperature scenarios. For this, select in the interface the desired RCP scenario under projection and the wanted combination under future. Three types of sensitivity to high temperature are also available under sensitivity (see « Check temperature » submodel in the ODD below for a short explanation of the difference between the three types).

Posted over 5 years ago

How to run the model

The first section of the ODD (see 'files' tab) presents step-by-step instructions on how to run the model.

Posted about 5 years ago

Click to Run Model

; the indivduals are given their own agentsets depending on lifestage, and sex for adults:
breed [embryos embryo]  ;; there shouldn't be any: if an embryo appears, there is an issue in the individual energetic dynamics.
breed [juveniles juvenile]
breed [females female]
breed [males male]

;_-_-_-_-_-_-_-_-_
; ------------------------------------------------------------------------------------------------------------------------------------------
globals[  ; global parameters: are accessible for patches and turtles, and the same for all (one change affects all)

;.....................................CALENDARS - TIMERS (from the start of the simulation)........................................................
;repro_time        ;  7     8     9    10     11     0     1     2     3     4     5     6,     7     8 .......based on reproduction timings
;GSI_time          ;  5     6     7     8     9     10    11    12     1     2     3     4,     5     6 .......for accumulation or decrease of GSI
;birth_time        ;  1     0     0     0     0      8     7     6     5     4     3     2,     1     0 .......only runs if triggered by reproduction, for the DEBbirth of individuals
time               ;  1     2     3     4     5      6     7     8     9    10    11    12,    13    14 .......no reseting: time since the start of the run
;;;                ; Oct   Nov   Dec   Jan   Feb   Mar   Apr   May   Jun    Jul   Aug   Sep,   Oct   Nov.......corresponding Gregorian calendar for AH
month_time         ; 10     11    12    01    02    03    04    05    06    07    08    09,    10    11 .......month numeration for the Gregorian calendar

year ; year count from the beginning of the run

;;; Global parameters and their dimensions:

; ...............parameters linked to  temperature and resources:
  f        ; - , scaled functional response
  TC       ; temperature correction factor used to adapt the standard DEB parameters to species-specific site temperature

; ...............population:
  pop_init          ; #, initial population (in a one-patch simulation configuration)
  prop_fem          ; proportion of females on site
  pop_density       ; indiv/m^2, current population density on site
  car_cap           ; carrying capacity for the site
  density_adults    ; #/m^2, density of adults on the patch
  density_juveniles ; #/m^2, density of juveniles on the patch
  surface           ; number of 1m^2 patches, useful in case the model is used with a spatial component ;;;RMV?
  food_compet       ; quantification of the scale of competition

; ...............mortality accounts:
  olddeath          ; count of the number of death due to ageing  (individual-specific)
  bgdeath           ; count of the number of death due to background death (fixed monthly percentage of random death on the population)
  bgdeath_adu       ; same as bgdeath but only counting the adults
  bgdeath_juv       ; same as bgdeath but only counting the juveniles
  starvedeath       ; count of the number of death due to starvation  (individual-specific)
  tempdeath         ; count of the number of death due to temperature (percentage of random death on the population depending on the SST)

; ............... for environmental input parameters:
  ;;for making the in-program LISTS (order according to the position of the column in the file):
  ;Temperature:
  timeMark    ; month number on the first column of the file (0 to 71)
  avgTemp     ; temperature value ;; average over a month for 2012-2018 from PROTEKER data
  avgTemp_fut ; future temperature list (new list created from present list)

  Tbefore    ; for checking mortality: temperature of the month preceding the current tick

  ;Resources:
  infoMonth  ; month number on the first column of the file (1 to 12)
  inputf     ; f value  ;; from Delille1989
  inputf_fut ; future resources list (new list created from present list)


;;; Variables used only in the setup:

; ............... for calculation of the cost of an egg (specific variables used for the simulation of embryo development in calc-embryo):
  e_scaled_embryo
  ref_e_scaled
  U_E_embryo
  S_C_embryo
  U_H_embryo
  L_embryo
  dU_E_embryo
  dU_H_embryo
  dL_embryo
  lower_bound
  upper_bound
  simulation_embryo   ; to count the number of loops

  U_E^start     ; t L^2, initial embryo reserves calculated from the bisection method
  L_0           ; cm, initial structural volume of embryo
  estim_embryo  ; t L^2, initial embryo reserve in the simulation

; ............... for calculation of initial parameters for each age 1 to 5yo (simulation of individual development in calc-init):
  simul          ; to count the number of loops
  timestep_simul ; a different timestep is used in the setup development simulation
  f_simul        ; constant f value for the simulation

  L_simul        ; L, structural length used in the simulation

  U_E_simul
  U_H_simul
  U_H^p_simul
  U_R_simul
  h_rate_simul
  q_acceleration_simul
  dh_rate_simul
  dq_acceleration_simul
  e_scaled_simul
  S_C_simul
  S_A_simul
  dU_E_simul
  dU_H_simul
  dU_R_simul
  dL_simul
  age_months_simul


  U_E_1yo
  U_H_1yo
  U_R_1yo
  L_1yo
  h_rate_1yo
  q_acceleration_1yo

  U_E_2yo
  U_H_2yo
  U_R_2yo
  L_2yo
  h_rate_2yo
  q_acceleration_2yo

  U_E_3yo
  U_H_3yo
  U_R_3yo
  L_3yo
  h_rate_3yo
  q_acceleration_3yo

  U_E_3yo_juv
  U_H_3yo_juv
  U_R_3yo_juv
  L_3yo_juv
  h_rate_3yo_juv
  q_acceleration_3yo_juv

  U_E_4yo
  U_H_4yo
  U_R_4yo
  L_4yo
  h_rate_4yo
  q_acceleration_4yo

  U_E_5yo
  U_H_5yo
  U_R_5yo
  L_5yo
  h_rate_5yo
  q_acceleration_5yo

;;; other global variables (used in GO):
  U_E_0yo   ; Reserve at birth, calculated from the bisection method (embryo simulation)
  L_b       ; (L) structural length at birth

; ............... for plotting and data exploitation: mean values for the state variable for all turtles
  avg_UR_fem     ; lists the mean value of females U_R for each tick
  min_UR_fem     ; lists the min value of females U_R for each tick
  max_UR_fem     ; lists the max value of females U_R for each tick
  avg_dUR_fem    ; lists the mean value of females dU_R for each tick
  min_dUR_fem
  max_dUR_fem
  avg_dUE_fem
  min_dUE_fem
  max_dUE_fem
  avg_UE_fem
  min_UE_fem
  max_UE_fem
  avg_Lphy
  min_Lphy
  max_Lphy
  avg_UE_adu     ; lists the mean value of adults U_E for each tick
  min_UE_adu
  max_UE_adu
  avg_dUE_adu
  min_dUE_adu
  max_dUE_adu
  avg_Lphy_adu
  min_Lphy_adu
  max_Lphy_adu
  avg_UE_juv     ; lists the mean value of juveniles U_E for each tick
  min_UE_juv
  max_UE_juv
  avg_dUE_juv
  min_dUE_juv
  max_dUE_juv
  avg_UE         ; lists the mean value of inidividuals (juveniles & all adults included) U_E for each tick
  min_UE
  max_UE
  avg_dUE
  min_dUE
  max_dUE
  avg_dL
  min_dL
  max_dL
]

patches-own[   ; parameters for the environment (patch-specific):

; ............... DEB parameters for calculation of TC:
  T_ref    ; reference temperature in Kelvin
  T_A      ; Arrhenius temperature
  T        ; actual temperature (in Celsius)
  f-scaled ; functional response f from the input file
]

turtles-own[ ;variables that are turtle-only and turtle-specific: each individual has to change their own value for the variable, as changes only applies to the turtle that is asked to modify it

;;;;.....................................CALENDARS - TIMERS (from the start of the simulation)........................................................
repro_time        ;  7     8     9    10     11     0     1     2     3     4     5     6,     7     8 .......based on reproduction timings
GSI_time          ;  5     6     7     8     9     10    11    12     1     2     3     4,     5     6 .......for accumulation or decrease of GSI
;birth_time       ;  1     0     0     0     0      8     7     6     5     4     3     2,     1     0 .......only runs if triggered by reproduction, for the DEBbirth of individuals
;time             ;  1     2     3     4     5      6     7     8     9    10    11    12,    13    14 .......no reseting: time since the start of the run
;;;               ; Oct   Nov   Dec   Jan   Feb   Mar   Apr   May   Jun    Jul   Aug   Sep,   Oct   Nov.......corresponding Gregorian calendar for AH
;month_time       ; 10     11    12    01    02    03    04    05    06    07    08    09,    10    11 .......month numeration for the Gregorian calendar


; ............... State variables (dimensions):
  L           ; (L) structural length
  dL          ; change of structural length in time
  U_H         ; (t L^2) scaled maturity
  dU_H        ; change of scaled maturity in time
  U_E         ; (t L^2) scaled reserves
  dU_E        ; change of scaled reserves in time
  e_scaled    ; (-) scaled reserves per unit of structure
  U_R         ; (t L^2) scaled energy in reproduction buffer
  dU_R        ; change of energy in reproduction buffer
  Lphy        ; (L), physical length (L/del_M)

  age_months   ; time in month from the birth of the indiv
  age_years    ; time in years from the birht of the indiv


; ............... for ageing:
  q_acceleration  ; (t^-2) ageing acceleration
  dq_acceleration ; change of ageing acceleration in time
  h_rate          ; (t-1) specific death probability rate
  dh_rate         ; change of hazard rate in time
  h_a             ; (t^-2) Weibull ageing acceleration

; ............... Fluxes:
  S_A         ; (L^2) assimilation flux (scaled)
  S_C         ; (L^2) mobilisation flux (scaled)

; ............... Standard DEB parameters (dimensions):
  g           ; (-) energy investment ratio
  v_rate      ; (L/t) energy conductance
  kap         ; (-) fraction of mobilised reserve allocated to soma
  kap_R       ; (-) reproduction efficiency
  k_M_rate    ; (1/t) somatic mainitenance rate coefficient
  k_J_rate    ; (1/t) maturity mainitenance rate coefficient
  U_H^b       ; (t L^2) scaled maturity at birth
  U_H^p       ; (t L^2) scaled maturity at puberty

  scatter-multiplier  ; parameter used to put a random variation in individual parameters

; ............... specific flags for dead or starving state.
  deceased       ; flag to indicate the individual died during the tick (0/ON)
  deceased_old   ; flag to indicate the individual died of senescence (0/ON)
  deceased_bg    ; flag to indicate the individual died due to population bacckground mortality rate (0/ON)

  starvation     ; flag to indicate the individual is starving (ON) or not (0)
]

females-own [
; ............... for the reproduction and laying of offsprings:
  reproduction   ; flag switch to allow reproduction (OFF/ON)
  GSI            ; Gonado-somatic index, needed to switch reproduction on/off
  GSI_init       ; minimum GSI (outside of reproduction)
  dGSI           ; delta GSI
  GSI_max        ; GSI at the beginning of reproduction
  U_R_max        ; U_R at the beginning of reproduction
  eggs           ; number of eggs produced
  Ri             ; reproductive output (for the number of juveniles born)

;.....................................CALENDARS - TIMERS (from the start of the simulation)........................................................
;repro_time        ;  7     8     9    10     11     0     1     2     3     4     5     6,     7     8 .......based on reproduction timings, backbone timer
;GSI_time          ;  5     6     7     8     9     10    11    12     1     2     3     4,     5     6 .......for accumulation or decrease of GSI
birth_time         ;  1     0     0     0     0      8     7     6     5     4     3     2,     1     0 .......only runs if triggered by reproduction, for the DEBbirth of individuals
;time              ;  1     2     3     4     5      6     7     8     9    10    11    12,    13    14 .......no reseting: time since the start of the run
;;;                ; Oct   Nov   Dec   Jan   Feb   Mar   Apr   May   Jun    Jul   Aug   Sep,   Oct   Nov.......corresponding Gregorian calendar for AH
;month_time        ; 10     11    12    01    02    03    04    05    06    07    08    09,    10    11 .......month numeration for the Gregorian calendar

]


; -----------------------------------------------SETUP-----------------------------------------------------------------------------
;_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-INITIALIZATION OF THE MODEL_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

to setup
  clear-all

  ;setup the timers and calendars:
  set time 0
  set month_time 10
  set year 0


  ask patches [
    set T_ref 293.15   ; reference temperature for which TC = 1
    set T_A  9000      ; Arrhenius temperature in tolerance range
    input-temperature  ; get the temperature data from external file, depending on the site chosen
    input-resources    ; procedure to get f data from external files, depending on the site chosen

    if projection != "present" [  ; and modify it if future scenarios are chosen for the projection
      future-temp
      future-rsces
    ]

    setup-temperature  ; to get the environmental varb for the month of the setup
    setup-resources

    set pop_init 120            ; initial population for the site
    set car_cap 200           ; the carrying capacity of the site.
    set prop_fem 0.5   ; proportion of females in the pop, from Poulin1996
 ]

  if add-my-pet? [convert-parameters]  ; to use the model with another species with DEB parameters taken from the DEBtool database add-my-pet

  ; calcluation of initial individuals parameters:
  calc-embryo
  calc-init

  ; setup the pop:
    ask patches [
      sprout pop_init [          ; each patch creates a number of individuals equal to pop_init
        init-birth               ; and each of these individuals initialize their parameters.
      ]
    ]
    init-pop                     ; the population is divided into age classes with age-specific parameters


  ; setup of calendars for reproduction cycles:
  ask turtles [
      set GSI_time 5
      set repro_time 7
    ]

  ask females [
    set GSI 0.03
    set birth_time 0
  ]

reset-ticks
end 

; ----------------------------------------------------------GO--------------------------------------------------------------------------------
;_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-PROCEEDINGS OF THE MODEL_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
;_-_-_-Each round of the model realizes the following procedures in this order and then starts again from the top:

to go
  reset-countdeath      ; reset the death counts. Disabble to obtain a cumulative death plot.

  update-year_timer     ; timers for the month of the year are updated at the beginning for the input of environmental data

;;;Environmental settings:
  ask patches [
    update-resources    ; take the data for f and temperature for this month (calendar is the month_time calendar)
    update-temperature
    ;set f-scaled 1     ; uncomment this line and the next to run the model with DEB standard and constant values for f and T
    ;set T 20

    if competition? [calc-compet]   ; if the competition is switched on in the interface, calculate the effect of competition on f
    set f (f-scaled + food_compet)  ; set the functional response f based on resources availability (external file) and competition
    if f > 1 [set f 1]  ; f is 1 at maximum
    if f < 0 [set f 0] ; f is 0 at minimum
  ]

;;;Individual settings:
  ask turtles [
    if deceased = "on" [die]  ; the individuals that died during the previous timestep are removed
      ;(they are not removed in the previous timestep so that they appear in the plots to monitor their death, this varb was made to monitor ageing effect)

    convert-TC        ; calculate the temperature correction and convert the parameters affected by temperature
    calc-dU_E         ; calculate the changes in state variables that happened over the month
    calc-dU_H
    calc-dU_R
    calc-dL
    calc-ageing       ; calculate the changes in ageing parameters
  ]

  update-individual        ; update state variables of individuals by applying the calculated changes

  ask turtles [update-repro_timers]   ; the timers for reproduction are updated

;;;Females settings (for reproduction):
  ask females [    ; mature females
    update-birth-timer
    if repro_time = 0 and reproduction = "on" [         ; if it is the timing for reproduction, and if the reproduction has been allowed by the GSI the month before,
      set GSI_max GSI           ; set the current GSI as the GSI from which calculations will be made
      set eggs 27
    ]

    calc-GSI                    ; in any case they calculate their GSI each month

    ifelse GSI >= 0.07          ; if the GSI is enough,
     [set reproduction "on"       ; allow reproduction
        if repro_time = 11 [
          set U_R_max U_R         ; keep the last U_R before reproduction period in mind, to force the gradual decrease during reproduction
          set birth_time 9        ; make it known that reproduction is happening
        ]
    ]

     [set reproduction "off"]     ; if the GSI is not higher than the required threshold, the possibility to reproduce is cancelled

    if (birth_time >= 6) and (birth_time <= 8) [  ; if it's one of the three reproduction month,
      reproduce ]                                  ; females produce embryos (by adapting the reprobuffer)

      ; 5 months after conception, the juveniles are DEBborn
    if (birth_time <= 3) and (birth_time >= 1) [
      release-offsprings ]                        ; let the offspring out and give it initial parameters to start dvpmt
  ]

;;;Population data:
  update-pop                     ; update the population by calculating the density
  update-time                    ; update the calendars and timers that haven't been updated yet

  tick

  if count turtles = 0 [         ; stop the model if all individuals died
    user-message ("What have you done ?! The population went extinct! (O_O') ")
    stop]

  if time = run_time * 12 [      ; stop the model after the number years indicated in the interface
    stop]
end 


; ---------------------------------------DESCRIPTION OF THE PROCEDURES---------------------------------------------------------------------------------------------------
; ---------------------------------------Procedures for SETUP: ---------------------------------------------------------------------------------------------------

; ===============
; ====================================Input of environmental data from external file:
; ===============

;_-_-_-_-_-_-_-_-_for temperature:

to input-temperature     ; creating lists for each parameter
  if Sites = "Anse du Halage" [file-open "temp_time_monthavg_Halage.txt"]   ; open the text file in the folder

  ;; the following is for when other sites are chosen: in that case, careful that there needs to have the appropriate resources files for the site in the folder:
  ;/!\for now choosing sites other than Anse du Halage, Port Couvreux or Ile Haute is not possible, the files are not available/!\/!\/!\/!\/!\/!\/!\
  if Sites = "Ile Suhm" [file-open "temp_time_monthavg_Suhm.txt"]
  if Sites = "Port aux Français" [file-open "temp_time_monthavg_PaF.txt"]
  if Sites = "Ile Haute" [file-open "temp_time_monthavg_Haute.txt"]
  if Sites = "Fjord des Portes Noires" [file-open "temp_time_monthavg_PortesNoires.txt"]
  if Sites = "Port Couvreux" [file-open "temp_time_monthavg_Couvreux.txt"]

  set timeMark []    ; create empty list
  set avgTemp []

  while [file-at-end? = false] [                    ; concatenate the empty list and a list containing the next value in the file (the file is read from left to right, and the values taken one by one to add to the list)
    set timeMark sentence timeMark (list file-read)   ; first list with the values for the month
    set avgTemp sentence avgTemp (list file-read)     ; second list (parallel to the first) with the values for temp
  ]
  file-close       ; created a duo of parallel lists with the timestamp and the corresponding temperature
end 

;_-_for the future temperature data:

to future-temp
  ifelse future != "food only" [     ; for projections including the effect of temp changes:
    if projection = "RCP 2.6" [                      ; depending on the chosen scenario in the interface
      set avgTemp_fut map [i -> i + 1.1 ] avgTemp ]    ; create a new list from the current lists by adding the expected changes

    if projection = "RCP 8.5" [
      set avgTemp_fut map [i -> i + 1.7 ] avgTemp ]
  ]
  [                                  ; for projections isolating the effect of food changes:
    if projection = "RCP 2.6" [
      set avgTemp_fut avgTemp ]

    if projection = "RCP 8.5" [
      set avgTemp_fut avgTemp ]
  ]
end 

;_-_then get the values for the month used for setup:

to setup-temperature    ; see 'to-report select-rsces' procedure for explanation
  ifelse projection = "present"
   [set T select-temp timeMark avgTemp 0]     ; gives to T the value for temperature corresponding to the line 0 in the temp list.
   [set T select-temp timeMark avgTemp_fut 0]
end 

to-report select-temp [list1 list2 timing]   ; see 'to-report select-rsces' procedure for explanation:
  let m timing
  if ((timing / 72) >= 1) [              ; (if the number of ticks is higher than the number of values in the temperature list,
    set m (timing - (72 * floor (timing / 72))) ; get the corresponding value counting from the start of the list.)
  ]
  let Q (position m list1)
  report item Q list2
end 


;_-_-_-_-_-_-_-_-_for resources:

to input-resources
  if Sites = "Anse du Halage" [file-open "inputRSces_M_f_Delille.txt"]

  ;; the following is for when other sites are chosen: in that case, careful that there needs to have the appropriate resources files for the site in the folder:
  ;/!\for now the files are not available for other sites: choosing Port Couvreux of Ile Haute will use the file for Anse du Halage, while other site choices will not work at all/!\/!\/!\/!\/!\/!\/!\
  if Sites = "Ile Suhm" [file-open "inputRSces_M_f_Suhm.txt"]
  if Sites = "Port aux Français" [file-open "inputRSces_M_f_PaF.txt"]
  if Sites = "Ile Haute"  [file-open "inputRSces_M_f_Delille.txt"] ; [file-open "inputRSces_M_f_Haute.txt"] if the site-sepcific data is available, exchange the two commands
  if Sites = "Fjord des Portes Noires" [file-open "inputRSces_M_f_PortesNoires.txt"]
  if Sites = "Port Couvreux"  [file-open "inputRSces_M_f_Delille.txt"] ; [file-open "inputRSces_M_f_Couvreux.txt"] if the site-sepcific data is available, exchange the two commands

  set infoMonth []
  set inputf []
  while [file-at-end? = false] [
    set infoMonth sentence infoMonth (list file-read)
    set inputf sentence inputf (list file-read)
  ]
  file-close    ; created a duo of parallel lists with (month) and (f)
end 

;_-_for future resources data:

to future-rsces
  ifelse future != "temp only"          ; for projections including the effect of food changes:
  [
    if projection = "RCP 2.6" [                       ; depending on the chosen scenario in the interface
      set inputf_fut map [i -> i - i * 0.1 ] inputf ] ; create new lists from the current lists by adding the expected changes

    if projection = "RCP 8.5" [
      set inputf_fut map [i -> i - i * 0.2] inputf ]
  ]
  [                                ; for projections isolating the effect of temperature changes:
     if projection = "RCP 2.6" [
      set inputf_fut inputf ]

    if projection = "RCP 8.5" [
      set inputf_fut inputf ]
  ]
end 

;_-_then get the values for the month used for setup:

to setup-resources   ; see 'to report select-rsces' procedure for explanation
  ifelse projection = "present"
  [set f-scaled select-rsces infoMonth inputf month_time ]    ; get the f-scaled from the f list created in input-resources using the month list as an index.
  [set f-scaled select-rsces infoMonth inputf_fut month_time]
end 

;_-_What 'select-rsces' does:

to-report select-rsces [list1 list2 timeval]   ;list1 (infoMonth), list2 (inputf) and timeval (month_time) are indicators of where to take the informations
  let month timeval   ; (month is a temporary variable existing only within the procedure)

  let R (position month list1) ; R temporarily marks the position of the value corresponding to month in the 'list1' (eg. it finds the value of month_time in the list infoMonth and gives to R the line number of this value in the list)
  report item R list2          ; gives the item with index R in list2 = gives the corresponding f value indexed at this month
end 


; ===============
; ====================================Parameters conversion procedures:
; ===============

;_-_-_-_-_-_-_-_-_Conversion of parameters from add-my-pet parameters (for adaptation to other species):

to convert-parameters
  let p_am p_m * zoom / kap_init
  set U_H^b_init E_H^b / p_am
  set U_H^p_init E_H^p / p_am
  set k_M_rate_init p_m / E_G
  set g_init (E_G * v_rate_init / p_am) / kap_init
end 


; ===============
; =============================================Initialisation of the population:
; ===============

;_-_-_-_-_-_-_-_- Bisection method for the calculation of energy of an egg:

to calc-embryo
  set L_0 0.00001              ; (embryos start with almost no structure)
  set lower_bound 0
  set upper_bound 1000        ; the upper bound is given an arbitrary first value,

  set simulation_embryo 0
  loop [
    set simulation_embryo simulation_embryo + 1     ; (to keep track of the number of loops)
    set estim_embryo 0.5 * (lower_bound + upper_bound)
    set L_embryo L_0
    set U_E_embryo estim_embryo
    set U_H_embryo 0
    set e_scaled_embryo v_rate_init * (U_E_embryo / L_embryo ^ 3)
    set ref_e_scaled 1

    while [U_H_embryo < U_H^b_init and e_scaled_embryo > ref_e_scaled]  ; simulation of embryo development until DEBbirth:
    [ set e_scaled_embryo v_rate_init * (U_E_embryo / L_embryo ^ 3)
      set S_C_embryo L_embryo ^ 2 * (((g_init * e_scaled_embryo) / (g_init + e_scaled_embryo)) * (1 + ((L_embryo * k_M_rate_init) / v_rate_init)))
      set dU_E_embryo (-1 * S_C_embryo)                ; (embryo doesn't feed and only mobilizes reserves)
      set dU_H_embryo ((1 - kap_init) * S_C_embryo - k_J_rate_init * U_H_embryo)
      set dL_embryo ((1 / 3) * (((v_rate_init / (g_init * L_embryo ^ 2)) * S_C_embryo) - k_M_rate_init * L_embryo))

      set U_E_embryo U_E_embryo + dU_E_embryo
      set U_H_embryo U_H_embryo + dU_H_embryo
      set L_embryo L_embryo + dL_embryo
      set e_scaled_embryo v_rate_init * (U_E_embryo / L_embryo ^ 3)
    ]
   ; when the embryo reaches DEBbirth (first condition in the 'while' loop),
    if (e_scaled_embryo < ref_e_scaled + 0.05) and (e_scaled_embryo > ref_e_scaled - 0.05) and (U_H_embryo >= U_H^b_init) [
        ; if e is around the reference, the initial reserve is set and the loop stopped:
      set U_E^start estim_embryo  ; the cost of an egg is set.
      set U_E_0yo U_E_embryo      ; the U_E is set for the juveniles initialization.
      stop]

        ; if the reserve is not around 1,
    ifelse U_H_embryo > U_H^b_init
     [set upper_bound estim_embryo]   ; the upper or lower bound is modified accordingly for a new loop.
     [set lower_bound estim_embryo]

    if simulation_embryo > 200            ; the simulation is stopped if it an initial reserve is not found
    [user-message ("embryo calc did not converge")
      stop]
  ]
end 


;_-_-_-_-_-_-_-_-_ Calculation of individual parameters at each age:

to calc-init
  set L_b 0.276 * del_M    ; (phy length from Schatt1985)
  set f_simul 1
  set timestep_simul 2
  set simul 0

  set L_simul L_b
  set U_E_simul U_E_0yo    ; get the initial reserve from the bisection method
  set U_H_simul U_H^b_init
  set U_H^p_simul U_H^p_init
  set U_R_simul 0
  set h_rate_simul 0
  set q_acceleration_simul 0
  set age_months_simul 0

loop [        ; Simulation of an individual development from birth till 5yo:
    set simul simul + 1    ; (to keep track of the number of loops)

    set e_scaled_simul (v_rate_init * (U_E_simul / L_simul ^ 3))
    set S_C_simul L_simul ^ 2 * (g_init * e_scaled_simul / (g_init + e_scaled_simul)) * (1 + ((L_simul * k_M_rate_init) / v_rate_init))
    set S_A_simul f_simul * L_simul ^ 2
    set dU_E_simul (S_A_simul - S_C_simul)
    ifelse U_H_simul < U_H^p_init
     [set dU_H_simul ((1 - kap_init ) * S_C_simul - k_J_rate_init * U_H_simul)
      set dU_R_simul 0 ]
     [set dU_H_simul 0
      set dU_R_simul (( 1 - kap_init) * S_C_simul - k_J_rate_init * U_H^p_init) ]
    set dL_simul ((1 / 3) * (((v_rate_init /( g_init * L_simul ^ 2 )) * S_C_simul) - k_M_rate_init * L_simul))
    set dq_acceleration_simul ((q_acceleration_simul * (L_simul ^ 3 / (v_rate_init / ( g_init * k_M_rate_init)) ^ 3) * sG + h_a_init) * e_scaled_simul * ((v_rate_init / L_simul) - ((3 / L_simul) * dL_simul )) - ((3 / L_simul ) * dL_simul ) * q_acceleration_simul)
    set dh_rate_simul (q_acceleration_simul - ((3 / L_simul) * dL_simul ) * h_rate_simul)

    set U_E_simul U_E_simul + (dU_E_simul * 30.5 / timestep_simul )
    set U_H_simul U_H_simul + (dU_H_simul * 30.5 / timestep_simul )
    set U_R_simul U_R_simul + (dU_R_simul * 30.5 / timestep_simul )
    set L_simul L_simul + (dL_simul * 30.5 / timestep_simul)
    set q_acceleration_simul (q_acceleration_simul + (dq_acceleration_simul * 30.5 / timestep_simul ))
    set h_rate_simul (h_rate_simul + (dh_rate_simul * 30.5 / timestep_simul ))

    set age_months_simul age_months_simul + 1            ; update the age of individuals

; get the individual parameters for each age as the loop goes:
    if age_months_simul = 12 [
      ifelse turtles with [U_H_simul < U_H^p_init] = nobody
       [user-message ("no juveniles at 1 yo, calc-init failed")]
       [set U_E_1yo U_E_simul
        set U_H_1yo U_H_simul
        set U_R_1yo U_R_simul
        set L_1yo L_simul
        set h_rate_1yo h_rate_simul
        set q_acceleration_1yo q_acceleration_simul
      ]
    ]

    if age_months_simul = 24 [
      ifelse turtles with [U_H_simul < U_H^p_init] = nobody
       [user-message ("no juveniles at 2 yo, calc-init failed")]
       [set U_E_2yo U_E_simul
        set U_H_2yo U_H_simul
        set U_R_2yo U_R_simul
        set L_2yo L_simul
        set h_rate_2yo h_rate_simul
        set q_acceleration_2yo q_acceleration_simul
      ]
    ]

    if age_months_simul = 36 [
      ifelse turtles with [U_H_simul < U_H^p_init] = nobody
       [user-message ("no juveniles at 3 yo, calc-init failed")]
       [set U_E_3yo_juv U_E_simul
        set U_H_3yo_juv U_H_simul
        set U_R_3yo_juv U_R_simul
        set L_3yo_juv L_simul
        set h_rate_3yo_juv h_rate_simul
        set q_acceleration_3yo_juv q_acceleration_simul
      ]
    ]

    if age_months_simul = 36 [
      ifelse turtles with [U_H_simul >= U_H^p_init] = nobody
       [user-message ("no adults at 3 yo, calc-init failed")]
       [set U_E_3yo U_E_simul
        set U_H_3yo U_H_simul
        set U_R_3yo U_R_simul
        set L_3yo L_simul
        set h_rate_3yo h_rate_simul
        set q_acceleration_3yo q_acceleration_simul
      ]
    ]

    if age_months_simul = 48 [
      ifelse turtles with [U_H_simul >= U_H^p_init] = nobody
       [user-message ("no adults at 4 yo, calc-init failed")]
       [set U_E_4yo U_E_simul
        set U_H_4yo U_H_simul
        set U_R_4yo U_R_simul
        set L_4yo L_simul
        set h_rate_4yo h_rate_simul
        set q_acceleration_4yo q_acceleration_simul
      ]
    ]

    if age_months_simul = 60 [
      ifelse turtles with [U_H_simul >= U_H^p_init] = nobody
       [user-message ("no adults at 5 yo, calc-init failed")]
       [set U_E_5yo U_E_simul
        set U_H_5yo U_H_simul
        set U_R_5yo U_R_simul
        set L_5yo L_simul
        set h_rate_5yo h_rate_simul
        set q_acceleration_5yo q_acceleration_simul
      ]
    ]

    ifelse  age_months_simul >= 60
     [stop]
     [if simul > 70 [print age_months_simul user-message "calc-init did not end" stop]]
  ]
end 


;_-_-_-_-_-_-_-_- Give initial parameters for newborn individuals:

to init-birth  ; juveniles are initialized as they just reached DEBbirth (=start feeding)
  set v_rate v_rate_init
  set kap kap_init
  set kap_R kap_R_init
  set k_M_rate k_M_rate_init
  set k_J_rate k_J_rate_init

;input a slight variation in parameters between individuals:
  set scatter-multiplier e ^ (random-normal 0 cv)  ; scatter-multiplier is the exp of a number taken randomly on a normal distribution of mean 0 and sd cv(from interface)
  set g g_init / scatter-multiplier
  set U_H^b U_H^b_init / scatter-multiplier
  set U_H^p U_H^p_init / scatter-multiplier
  set U_E U_E_0yo / scatter-multiplier      ; get the initial reserve from the bisection method
  set U_H U_H^b
  set U_R 0
  set L L_b / scatter-multiplier
  set h_rate 0
  set q_acceleration 0

  set age_months 0
  set age_years 0
  set breed juveniles
end 


;_-_-_-_-_-_-_-_- Give initial parameters for all ages:

to init-pop

  let nbtot count turtles     ; at first, all the individuals that were created by 'sprout' are juveniles with 0yo parameters (given by init-birth procedure)

  ask n-of (pop_init / 6) turtles [                      ; divide the initial population into 6 age-groups in a cascade-like manner and give them their parameters.
   ; 5 year-olds initialisation:
    set U_E U_E_5yo / scatter-multiplier     ; parameters come from the individual development simulation calc-init,
    set U_H U_H_5yo / scatter-multiplier     ; including a slight variation in parameters from individual to individual.
    set U_R U_R_5yo / scatter-multiplier
    set L L_5yo / scatter-multiplier
    set h_rate h_rate_5yo / scatter-multiplier
    set q_acceleration q_acceleration_5yo / scatter-multiplier
    set age_months 60
    set age_years 5
  ]

  let Five_yo turtles with [age_months = 60]
  let nb_5yo (count Five_yo)                                       ; for age-groups above puberty,
  ask n-of floor (prop_fem * nb_5yo) Five_yo [set breed females]   ; set the sex-ratio of the population.
  ask Five_yo [if breed != females [set breed males] ]

   ; 4 year-olds initialisation:
  let nb4 count turtles with [age_months < 60]              ; remaining individuals which have not yet been given initial parameters
  ask n-of (pop_init / 6) turtles with [age_months < 60] [
    set U_E U_E_4yo / scatter-multiplier
    set U_H U_H_4yo / scatter-multiplier
    set U_R U_R_4yo / scatter-multiplier
    set L L_4yo / scatter-multiplier
    set h_rate h_rate_4yo / scatter-multiplier
    set q_acceleration q_acceleration_4yo / scatter-multiplier
    set age_months 48
    set age_years 4
 ]

  let Four_yo turtles with [age_months = 48]
  let nb_4yo (count Four_yo)
  ask n-of floor (prop_fem * nb_4yo) Four_yo [set breed females]
  ask Four_yo [if breed != females [set breed males] ]

   ; 3 year-olds initialisation:
  let nb3 count turtles with [age_months < 48]              ; remaining individuals which have not yet been given initial parameters
  ask n-of (pop_init / 6)turtles with [age_months < 48] [
    set U_E U_E_3yo / scatter-multiplier
    set U_H U_H^p
    set U_R U_R_3yo / scatter-multiplier
    set L L_3yo / scatter-multiplier
    set h_rate h_rate_3yo / scatter-multiplier
    set q_acceleration q_acceleration_3yo / scatter-multiplier

    set age_months 36
    set age_years 3
  ]

  let Three_yo turtles with [age_months = 36]
  let nb_3yo (count Three_yo)
  ask n-of floor (prop_fem * nb_3yo) Three_yo [set breed females]
  ask Three_yo [if breed != females [set breed males] ]

   ; 2 year-olds initialisation:
  let nb2 count turtles with [age_months < 36]              ; remaining individuals which have not yet been given initial parameters
  ask n-of (pop_init / 6) turtles with [age_months < 36] [
    set U_E U_E_2yo / scatter-multiplier
    set U_H U_H_2yo / scatter-multiplier
    set U_R U_R_2yo / scatter-multiplier
    set L L_2yo / scatter-multiplier
    set h_rate h_rate_2yo / scatter-multiplier
    set q_acceleration q_acceleration_2yo / scatter-multiplier

    set age_months 24
    set age_years 2
   ]

   ; 1 year-olds initialisation:
  let nb1 count turtles with [age_months < 24]              ; remaining individuals which have not yet been given initial parameters
  ask n-of (pop_init / 6) turtles with [age_months < 24] [
    set U_E U_E_1yo / scatter-multiplier
    set U_H U_H_1yo / scatter-multiplier
    set U_R U_R_1yo / scatter-multiplier
    set L L_1yo / scatter-multiplier
    set h_rate h_rate_1yo / scatter-multiplier
    set q_acceleration q_acceleration_1yo / scatter-multiplier

    set age_months 12
    set age_years 1
   ]

   ; 0 year-olds initialisation:
   ; the remaining individuals keep their 0yo parameters given to them by the init-birth procedure.
end 




; ---------------------------------------Procedures for GO: ---------------------------------------------------------------------------------------------------

;_-_-_-_-_-_-_-_-_Resetting the death counts:

to reset-countdeath
  set starvedeath 0
  set tempdeath 0
  set olddeath 0
  set bgdeath_adu 0
  set bgdeath_juv 0
end 


; ===============
; =============================================Setting the environmental parameters up-to-date:
; ===============

;_-_-_-_-_-_-_-_-_First updating of calendar:

to update-year_timer
  ifelse ticks = 0
   [set month_time month_time]
   [ifelse month_time != 12
    [set month_time month_time + 1]
    [set month_time 1]]            ; resetting the month_time calendar after 12 months
end 


;_-_-_-_-_-_-_-_-_To get the environmental data for the month:

to update-resources   ; see 'to-report select-resources' procedure for explanation
  ifelse projection = "present"      ; depending on the selected projection, take a different set of lists
   [set f-scaled select-rsces infoMonth inputf month_time]
   [set f-scaled select-rsces infoMonth inputf_fut month_time]
end 

to update-temperature
  ifelse projection = "present"       ; depending on the selected projection, take a different set of lists
   [set T select-temp timeMark avgTemp ticks]  ; get the T at the corresponding time of the year, from the temp list created in input-resources using the month list as an index.
   [set T select-temp timeMark avgTemp_fut ticks]
end 


;_-_-_-_-_-_-_-_-_For the effect of competition on the f:

to calc-compet

  calc-density    ; calculate the current month's population density

  ifelse pop_density < 1.9 * car_cap   ; this because if = 2, div by 0 error and if > 2, then the formula gives the untrue result (bigger pop less compet)
   [set food_compet ((1 - f-scaled) * (1 - (pop_density / (2 * car_cap - pop_density))))]
   [set food_compet ((1 - f-scaled) * (1 - (pop_density / (car_cap / 10))))]

;;explanation of the procedure:
 ;(1 - f_scaled) : compet is only effective if the food availability is less than the max.
  ; in which case, proportionnally to how much the f is lessened compared to max, the size of the current pop has an influence on how important the compet is:
   ;  if the pop is below car_cap, then the food is more available for the individuals present, but if the pop is over cc, the availability of food is lessened.
  ; Therefore, if pop > carrying capacity, food_compet < 0 <=> f decreases
   ;           if pop = cc, food_compet = 0 <=> f constant
   ;           if pop < cc, food_compet > 0 <=> f increases

 ;Meaning, the compet is actually calculated depending on how far from the carrying capacity the pop density is, and how far from max f it is.
 ; the pop that isn't there times the food not available  --> the less food there is and the bigger the pop, the higher the compet is.
end 


; ===============
; =============================================Changing individuals states and parameters:
; ===============

;_-_-_-_-_-_-_-_-_Calcualtion of the temperature correction factor:

to convert-TC
  set TC e ^ ((T_A / T_ref) - (T_A / (T + 273.15))) ; standard DEB parameters are for 20°C while A. Cordatus lives in an average SST of 5°C,
  set k_M_rate k_M_rate_init * TC                     ; so TC corrects parameters that are time dependent
  set v_rate v_rate_init * TC
  set k_J_rate k_J_rate_init * TC
  set h_a h_a_init * TC ^ 2
end 


;_-_-_-_-_-_-_-_-_Calculation of the changes in state variables:

;_-_change in energy contained in the reserve:

to calc-dU_E
  if U_H < U_H^b [set f 0]                   ; individuals don't feed before birth
  set e_scaled (v_rate * (U_E / L ^ 3))      ; calculation of scaled reserve
  set S_C L ^ 2 * (g * e_scaled / (g + e_scaled)) * (1 + ((L * k_M_rate) / v_rate))  ; caculation of mobilisation rate (rate at which energy is leaving the reserve)
  set S_A f * L ^ 2                          ; calculation of assimilation rate (rate at which energy is entering the reserve)
  set dU_E (S_A - S_C)
end 

;_-_change in energy contained in the maturity compartment:

to calc-dU_H
  ifelse U_H < U_H^p                        ; individuals supply their maturity compartment only until puberty
   [set dU_H ((1 - kap ) * S_C - k_J_rate * U_H)]
   [set dU_H 0]                              ; after puberty, quantity of energy stored in the maturity compartment stays the same.
end 

;_-_change in energy contained in the reproduction buffer:

to calc-dU_R
  if U_H >= U_H^p [                          ; for mature individuals only.
    ifelse (breed = males) or (birth_time < 6)   ; check if it is a male or a female outside of reproduction time,
     [set dU_R (( 1 - kap) * S_C - k_J_rate * U_H^p)]   ; in which case the change in energy stored in repro buffer is calculated as usual.
     [set dU_R 0]                            ; for females during reproduction, repro buffer calculated in the 'reproduce' procedure.
  ]
  if U_H < U_H^p [set dU_R 0]                ; for non mature individuals, no change in the repro buffer
end 

;_-_change in structural length:

to calc-dL
  set dL ((1 / 3) * (((v_rate /( g * L ^ 2 )) * S_C) - k_M_rate * L))
  if e_scaled < (L / (v_rate / (g * k_M_rate))) [   ; when scaled reserve density is insufficient to maintain the structural length,
    set starvation "on"   ;(starvation flag)
    starve                                      ; the individual is starving (see below for procedure).
  ]
end 

;_-_-_-_-Starvation strategy:

to starve
  set dL 0                  ; allocation of energy only for somatic maintenance
  ifelse U_H < U_H^p        ; all other flux are stopped
   [set dU_H 0]
   [set dU_R 0]
                                                    ; knowing dL = 0, the mobilisation flux is recalculated as S_C = [p_M]L^3 / {p_Am}
  set S_C (kap * (k_M_rate * g * L ^ 3) / v_rate)   ; with [p_M] = [E_G]k_M and [E_G] = gkap{p_Am}/v
  set dU_E S_A - S_C                                ; then dU_E is recalculated and will be applied in the next procedure
  set e_scaled v_rate * U_E / L ^ 3                 ; this new dU_E will affect e_scaled in the next tick

  if e_scaled <= 0 [                             ; when all energy is redirected to soma maintenance, if the scaled reserve still cannot recover
    set starvedeath starvedeath + 1 ; (for mortality accounts)
    set deceased "on"                            ; then the individual dies (flag which will get the individual removed in the next tick).
  ]
end 

;_-_calculation of the damage due to ageing:

to calc-ageing
    set dq_acceleration (q_acceleration * (L ^ 3 / (v_rate / ( g * k_M_rate)) ^ 3) * sG + h_a) * e_scaled * ((v_rate / L) - ((3 / L) * dL)) - ((3 / L ) * dL) * q_acceleration
    set dh_rate (q_acceleration - ((3 / L) * dL) * h_rate)
end 


;_-_-_-_-_-_-_-_-_Apply calculated changes to the individuals:

to update-individual
    ask turtles [
    set U_E U_E + (dU_E * 30.5)   ; changes are based on daily calculations upscaled for a month
    set U_H U_H + (dU_H * 30.5)
    set U_R U_R + (dU_R * 30.5)
    set L L + (dL * 30.5)
    if U_H > U_H^b [               ; damage due to ageing only starts from DEBbirth
      set q_acceleration (q_acceleration + dq_acceleration * 30.5)
      set h_rate (h_rate + dh_rate * 30.5)
    ]

    if deceased != "on"[
      let x random 2
      let y random 1
      if x = y [  ; with the current input of x = random 2 and y = random 1 (i.e. y = 0), this has 50% chance of being true
        if random-float 1 <  ( 1 - (1 - h_rate) ^ 30.5) [    ; damage induces death in a random manner, with a higher probability as it accumulates: here the individual checks that probability
          set olddeath olddeath + 1
          set deceased_old "on" set deceased "on"
        ]
      ]
    ]
  ]

   ;; setting the lifestage label of each individual:
  if any? juveniles with [U_H >= U_H^p] [                      ; juveniles who just reached puberty this round
    let newadults juveniles with [U_H >= U_H^p]                ; are called newadults temporarily
    let nb count newadults                                     ; count how many new adults there are
    ask n-of (prop_fem * nb) newadults [set breed females]     ; then they turn into female or male 50/50 (male priority: eg. in case of one individual, it becomes male)
    ask newadults [if breed != females [set breed males] ]]

  if any? embryos with [U_H >= U_H^b and U_H < U_H^p] [
    ask embryos with [U_H >= U_H^b and U_H < U_H^p] [set breed juveniles]  ; embryos turn into juveniles if they reach DEBbirth
  ]

  ask turtles with [U_H < U_H^b] [set breed embryos]            ; turtles that aren't DEBborn yet are called embryos (but shouldn't appear in the model: if they do, there is an issue in the ODE)

  ask turtles [                     ; update the age of individuals
    set age_months age_months + 1
    set age_years age_years + (1 / 12)
  ]
end 


; ===============
; =============================================Procedures involved in reproduction:
; ===============

;_-_-_-_-_-_-_-_-_Updating of calendars/timers that are used to time reproduction events:

;_-_reproduction and GSI calendars based on reproductive cycle:

to update-repro_timers
  ifelse ticks = 0
   [set repro_time repro_time]  ; at the start, keep the timing of the setup for the first round
   [ifelse repro_time != 11     ; for the rest of the run, the repro_time evolves
    [set repro_time repro_time + 1]
    [set repro_time 0 ]         ; reset when the end of the cycle is reached
  ]

  ifelse ticks = 0
   [set GSI_time GSI_time]      ; at the start, keep the timing of the setup for the first round
   [ifelse GSI_time != 12       ; for the rest of the run, the repro_time evolves
    [set GSI_time GSI_time + 1]
    [set GSI_time 1]            ; reset when the end of the cycle is reached
  ]
end 

;_-_birth and reproduction period timer:

to update-birth-timer               ; birth time, only for females.
  ifelse birth_time = 0             ; only update birth_time if it was triggered by reproduction (if not triggered, it should be 0)
    [set birth_time 0]
    [set birth_time birth_time - 1] ; this timer is a countdown
end 


;_-_-_-_-_-_-_-_-_Calculations of the gonado-somatic index for reproduction:

to calc-GSI
  ifelse GSI_time < 10                      ; if it is outside of the 3 month of egg-laying, calculate the GSI as usual:
   [set f f-scaled
    set GSI (TC * GSI_time * 30.5 * ((k_M_rate_init * g / f ^ 3) / (f + kap * g * y_VE)) * ((1 - kap) * f ^ 3 - k_J_rate_init * U_H^p / zoom ^ 2 / s_M ^ 3))]

  ; if it is in the 3 months of egg-laying, force the gradual decrease of GSI:
   [set GSI_init (GSI_max - GSI_max * 0.52)  ; Magniez1983 females invest 52% into reproduction
    set dGSI ((GSI_max - GSI_init) / 3)      ; change in GSI over a month
    set GSI (GSI - dGSI)]
end 


;_-_-_-_-_-_-_-_-_Reproduction event (conception of eggs):

to reproduce
  set U_R (U_R - ((U_R_max * 0.52) / 3))     ; adapt the reproduction buffer every month of reproduction according to data in Magniez1983
end 


;_-_-_-_-_-_-_-_-_How offsprings are born into the model:

to release-offsprings
  set Ri (0.65 * eggs)             ; 65% of embryos survive (Poulin 1996) until birth
  hatch-juveniles (Ri / 3) [       ; hatch a third of the calculated number of offsprings (1/3 per month over 3 months)
    init-birth                     ; and give them their initial parameters
  ]
end 


; ===============
; =============================================Updates:
; ===============

;_-_-_-_-_-_-_-_-_Update the state of the population:

to update-pop
  background-mortality  ; apply background mortality rates on the population
  ask patches [check-temperature]     ; check mortality induced by critical temperature.
  calc-density   ; calculations for the pop structure
  calc-pop-varb  ; calculations for all individuals variables in the pop
end 

;_-_-_-_-_-_-_-_-_Apply background mortality:

to background-mortality
  let juvzombies count juveniles                           ; temporary variable with the number of juveniles in the model
  ask n-of (round ((0.41 / 12) * juvzombies)) juveniles [  ; 41% of juveniles die each year
    if deceased != "on" [                                  ; check that the individual hasn't already died from another cause
      set bgdeath_juv bgdeath_juv + 1                      ; add to the account of deaths
      set deceased "on"                                    ; indicate the individual is dead
    ]
  ]

  let aduzombies count turtles with [U_H >= U_H^p]         ; temporary variable with the number of adults in the model
  ask n-of (round ((0.24 / 12) * aduzombies)) turtles with [U_H >= U_H^p] [  ; 24% of adults die each year
    if deceased != "on" [                                  ; check that the individual hasn't already died from another cause
      set bgdeath_adu bgdeath_adu + 1                      ; add to the account of deaths
      set deceased_bg "on"                                 ; indicate the individual is dead of this specific cause
      set deceased "on"                                    ; indicate the individual is dead
    ]
  ]
end 

;_-_-_-_-_-_-_-_-_Check mortality by temperature:

to check-temperature
   ; to get the temperature from the month before on the list:
  ifelse projection = "present"                         ; for projections under current conditions
   [ifelse ticks = 0
     [set Tbefore select-temp-before timeMark avgTemp 1]     ; for setup
     [set Tbefore select-temp-before timeMark avgTemp ticks] ; fot the run
  ]
                                                        ; for projections under one of the other scenarios
   [ifelse ticks = 0
     [set Tbefore select-temp-before timeMark avgTemp_fut 1]     ; for setup
     [set Tbefore select-temp-before timeMark avgTemp_fut ticks] ; for the run
  ]

  let zombies count turtles                  ; temporary variable with the number of individuals in the model

;Choice of population with:
 ;;; a lower proportion of individuals sensitive to high temperatures (can withstand for 1 but not 2 months):
  if sensitivity = "resistant" [

  ifelse T >= 12
    [if Tbefore >= 12 [ask turtles [set tempdeath tempdeath + 1 die]]]                              ; if avg temperature is >=12 for two months, 100% die
    [ifelse  T >= 11
     [if Tbefore >= 11 [ask n-of (0.30 * zombies) turtles [set tempdeath tempdeath + 1 die]]]       ; if avg temperature is >=11 for two months, 30% die
     [ifelse T >= 9.5
      [if Tbefore >= 9.5 [ask n-of (0.20 * zombies) turtles [set tempdeath tempdeath + 1 die]]]     ; if avg temperature is >=11 for two months, 20% die
      [if T >= 8
        [if Tbefore >= 8 [ask n-of (0.10 * zombies) turtles [set tempdeath tempdeath + 1 die]]]]    ; if avg temperature is >=11 for two months, 10% die
      ]
    ]
  ]

 ;;; individuals not able to withstand high temperatures for 1 month:
  if sensitivity = "intermediate" [

    ifelse T >= 12
      [ask turtles [set tempdeath tempdeath + 1 die]]                               ; if avg temperature is >=12 for one month, 100% die
      [ifelse T >= 11
        [ask n-of (0.30 * zombies) turtles [set tempdeath tempdeath + 1 die]]         ; if avg temperature is >=12 for one month, 30% die
        [ifelse T >= 9.5
           [ask n-of (0.20 * zombies) turtles [set tempdeath tempdeath + 1 die]]        ; if avg temperature is >=12 for one month, 20% die
           [if T >= 8 [ask n-of (0.10 * zombies) turtles [set tempdeath tempdeath + 1 die]]]]]          ; if avg temperature is >=12 for one month, 10% die
  ]

 ;;; a higher proportion of individuals sensitive to high temperatures (can withstand for 1 but not 2 months):
  if sensitivity = "vulnerable" [

  ifelse T >= 12
    [if Tbefore >= 12 [ask turtles [set tempdeath tempdeath + 1 die]]]                           ; if avg temperature is >=12 for two months, 100% die
    [ifelse  T >= 11
     [if Tbefore >= 11 [ask n-of (0.45 * zombies) turtles [set tempdeath tempdeath + 1 die]]]    ; if avg temperature is >=11 for two months, 45% die
     [ifelse T >= 9.5
      [if Tbefore >= 9.5 [ask n-of (0.35 * zombies) turtles [set tempdeath tempdeath + 1 die]]]  ; if avg temperature is >=10 for two months, 35% die
      [if T >= 8
        [if Tbefore >= 8 [ask n-of (0.25 * zombies) turtles [set tempdeath tempdeath + 1 die]]]] ; if avg temperature is >=9 for two months, 25% die
      ]
    ]
  ]
end 

;_-_reporting procedure to get the temperature from the month before on the list:

to-report select-temp-before [list1 list2 timing]   ; get the avg temp for the month before, that is at position m - 1
  let m timing                          ; create a temporary variable m with the value of the tick
  let P 0                               ; create a temporary variable P
  if ((timing / 72) >= 1) [    ; if the end of the file has been reached,
    set m (timing mod 72)]     ; start counting from the beginning of the file to obtain the temp:

  ifelse m = 0                       ; when it's the first line of the file,
   [set P (position 71 list1)]       ; get the temp from the last line.
   [set P ((position m list1) - 1) ] ; otherwise simply get it from the line before

  report item P list2          ; give the corresponding temp
end 


;_-_-_-_-_-_-_-_-_Get the density data for the month:

to calc-density
  let indiv count turtles with [U_H >= U_H^b]    ; count the number of individuals that are DEBborn
  let space count patches                        ; count the number of 1m2 patches (here, only 1 in the current implementation)
  set pop_density (indiv / space)                ; calculate density of total population
  let adu ((count females) + (count males))
  set density_adults (adu / space)               ; calculate density of adults only
  let juve count juveniles
  set density_juveniles (juve / space)           ; calculate density of juveniles only
end 


;_-_-_-_-_-_-_-_-_Get the state variables data for the month:

to calc-pop-varb
  ifelse any? females [
    set avg_UR_fem mean [U_R] of females              ; reproduction buffer of females
    set min_UR_fem min [U_R] of females
    set max_UR_fem max [U_R] of females

    set avg_dUR_fem mean [dU_R * 30.5] of females
    set min_dUR_fem min [dU_R * 30.5 ] of females
    set max_dUR_fem max [dU_R * 30.5 ] of females

    set avg_UE_fem mean [U_E] of females              ; energy reserve of females
    set min_UE_fem min [U_E] of females
    set max_UE_fem max [U_E] of females

    set avg_dUE_fem mean [dU_E * 30.5] of females
    set min_dUE_fem min [dU_E * 30.5] of females
    set max_dUE_fem max [dU_E * 30.5] of females
  ]
  [    ; if there is no female, set a mock value that can be removed when processing the outputs
    set avg_UR_fem 500
    set min_UR_fem 500
    set max_UR_fem 500

    set avg_dUR_fem 50
    set min_dUR_fem 50
    set max_dUR_fem 50

    set avg_UE_fem 1500
    set min_UE_fem 1500
    set max_UE_fem 1500

    set avg_dUE_fem 100
    set min_dUE_fem 100
    set max_dUE_fem 100
  ]

  ifelse any? turtles with [U_H >= U_H^p] [
    set avg_UE_adu mean [U_E] of turtles with [U_H >= U_H^p]             ; energy reserve of adults only
    set min_UE_adu min [U_E] of turtles with [U_H >= U_H^p]
    set max_UE_adu max [U_E] of turtles with [U_H >= U_H^p]

    set avg_dUE_adu mean [dU_E * 30.5] of turtles with [U_H >= U_H^p]
    set min_dUE_adu min [dU_E * 30.5] of turtles with [U_H >= U_H^p]
    set max_dUE_adu max [dU_E * 30.5] of turtles with [U_H >= U_H^p]


    ask turtles [set Lphy L / del_M]             ; physical length of all individuals
    set avg_Lphy_adu mean [Lphy] of turtles with [U_H >= U_H^p]
    set min_Lphy_adu min [Lphy] of turtles with [U_H >= U_H^p]
    set max_Lphy_adu max [Lphy] of turtles with [U_H >= U_H^p]
  ]
  [     ; if there is no adult, set a mock value that can be removed when processing the outputs afterwards
    set avg_UE_adu 1500
    set min_UE_adu 1500
    set max_UE_adu 1500

    set avg_dUE_adu 100
    set min_dUE_adu 100
    set max_dUE_adu 100

    set avg_Lphy_adu 10
    set min_Lphy_adu 10
    set max_Lphy_adu 10
  ]


  ifelse any? turtles with [U_H >= U_H^b and U_H < U_H^p] [
    set avg_UE_juv mean [U_E] of turtles with [U_H >= U_H^b and U_H < U_H^p]          ; energy reserve of juveniles only
    set min_UE_juv min [U_E] of turtles with [U_H >= U_H^b and U_H < U_H^p]
    set max_UE_juv max [U_E] of turtles with [U_H >= U_H^b and U_H < U_H^p]

    set avg_dUE_juv mean [dU_E * 30.5] of turtles with [U_H >= U_H^b and U_H < U_H^p]
    set min_dUE_juv min [dU_E * 30.5] of turtles with [U_H >= U_H^b and U_H < U_H^p]
    set max_dUE_juv max [dU_E * 30.5] of turtles with [U_H >= U_H^b and U_H < U_H^p]
  ]
  [     ; if there is no juvenile, set a mock value that can be removed when processing the outputs afterwards
    set avg_UE_juv 1500
    set min_UE_juv 1500
    set max_UE_juv 1500

    set avg_dUE_juv 100
    set min_dUE_juv 100
    set max_dUE_juv 100
  ]

  ifelse any? turtles [
    set avg_UE mean [U_E] of turtles             ; energy reserve of all individuals
    set min_UE min [U_E] of turtles
    set max_UE max [U_E] of turtles

    set avg_dUE mean [dU_E * 30.5] of turtles
    set min_dUE min [dU_E * 30.5] of turtles
    set max_dUE max [dU_E * 30.5] of turtles

    set avg_dL mean [dL * 30.5] of turtles
    set min_dL min [dL * 30.5] of turtles
    set max_dL max [dL * 30.5] of turtles

    ask turtles [set Lphy L / del_M]             ; physical length of all individuals
    set avg_Lphy mean [Lphy] of turtles
    set min_Lphy min [Lphy] of turtles
    set max_Lphy max [Lphy] of turtles
  ]
  [     ; if there is no individual, set a mock value that can be removed when processing the outputs afterwards
    set avg_UE 1500
    set min_UE 1500
    set max_UE 1500

    set avg_dUE 100
    set min_dUE 100
    set max_dUE 100

    set avg_dL 1
    set min_dL 1
    set max_dL 1

    set avg_Lphy 10
    set min_Lphy 10
    set max_Lphy 10
  ]
end 


;_-_-_-_-_-_-_-_-_Updating of the other timings:

to update-time
  set time time + 1
  set year year + (1 / 12)
end 





  ;;;;;;;;;;;END;;;;;;;;;;;;;;

There are 4 versions of this model.

Uploaded by When Description Download
Margot Minju Arnould-Pétré over 4 years ago correction of GSI formula in the info tab (no change to the model) Download this version
Margot Minju Arnould-Pétré about 5 years ago Minor change in code (f competition) Download this version
Margot Minju Arnould-Pétré over 5 years ago minor modification in info tab Download this version
Margot Minju Arnould-Pétré over 5 years ago Initial upload Download this version

Attached files

File Type Description Last updated
DEB-IBM for Abatus cordatus.png preview Schematic representation of the model over 5 years ago, by Margot Minju Arnould-Pétré Download
DEB-IBM_Acordatus_info.png png Preview of info tab over 5 years ago, by Margot Minju Arnould-Pétré Download
inputRSces_M_f_Delille.txt data Input file for resources at Anse du Halage (necessary!) over 5 years ago, by Margot Minju Arnould-Pétré Download
ODD (Appendix H).pdf pdf ODD (+ instructions to run the model) over 4 years ago, by Margot Minju Arnould-Pétré Download
temp_time_monthavg_Couvreux.txt data Input file for temperatures at Port Couvreux (optional) over 5 years ago, by Margot Minju Arnould-Pétré Download
temp_time_monthavg_Halage.txt data Input file for temperatures at Anse du Halage (necessary!) over 5 years ago, by Margot Minju Arnould-Pétré Download
temp_time_monthavg_Haute.txt data Input file for temperatures at Ile Haute (optional) over 5 years ago, by Margot Minju Arnould-Pétré Download

This model does not have any ancestors.

This model does not have any descendants.