Skip to content

Commit

Permalink
Correct temperature use case
Browse files Browse the repository at this point in the history
  • Loading branch information
ismael-lajaaiti committed Mar 8, 2024
1 parent 7f1cafa commit bbce1b6
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions use_cases/tritrophic-biomass-vs-temperature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@ import ColorSchemes: tol_light
using CairoMakie
using DataFrames
using EcologicalNetworksDynamics
import EcologicalNetworksDynamics: ExtinctionCallback

# Temperature gradient from 0 to 40°C, converted to Kelvin, with increments of 1°.
T0 = 273.15 # 0°C in Kelvin.
T40 = T0 + 40 # 40°C in Kelvin.
T_values = values(T0:1:T40)

# DataFrame to store the simulations outputs.
df = DataFrame(; T = Float64[], trophic_level = Int64[], Beq = Float64[])
# `set_temperature!()` expresses rates in seconds,
# then simulation time is expressed in seconds as well.
# Simulation length and time steps are taken from Binzer et al., 2012.
tmax = 315_360_000_000 # From Binzer et al., 2012.
verbose = false # Do not show '@info' messages during simulation run.
# callback = ExtinctionCallback(1e-6, params, verbose) # Remove TerminateSteadyState callback.
trophic_lvl = [1, 2, 3]
callback_function(m) = ExtinctionCallback(1e-12, m._value, verbose)

# Run simulations for each temperature across gradient.
@info "Start simulations..."
for T in T_values
m = default_model(Foodweb([3 => 2, 2 => 1]), ClassicResponse(; h = 1), Temperature(T))
m = default_model(Foodweb([3 => 2, 2 => 1]), Temperature(T))
m.h = 1 # Set hill exponent to 1.
B0 = m.K[1] / 8 # Inital biomass.
solution = simulate(m, [B0]; tmax)
callback = callback_function(m)
solution = simulate(m, B0; tmax, callback)
Beq_vec = solution[end]
for (Beq, tlvl) in zip(Beq_vec, trophic_lvl)
push!(df, [T, tlvl, Beq])
Expand Down Expand Up @@ -54,6 +53,5 @@ Legend(
tellheight = true, # Adjust top subfigure height to legend height.
tellwidth = false, # Do not adjust bottom subfigure width to legend width.
)

# To save the figure, uncomment and execute the line below.
save("/tmp/plot.png", fig; resolution = (450, 300), px_per_unit = 3)
save("/tmp/plot.png", fig; size = (450, 300), px_per_unit = 3)

0 comments on commit bbce1b6

Please sign in to comment.