In [36]:
%matplotlib inline
Copy-paste into Spyder's EDITOR
In [37]:
days = 365 * 2 # Two years
dt = 0.01 # units: days
Copy-paste into Spyder's CONSOLE
In [38]:
days
Out[38]:
In [39]:
dt
Out[39]:
In [40]:
type(days)
Out[40]:
In [41]:
type(dt)
Out[41]:
Make time vector
Copy-paste into Spyder's EDITOR
In [42]:
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Setup the framework # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<
NoSTEPS = int(days / dt) # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<
Copy-paste into Spyder's CONSOLE
In [43]:
NoSTEPS
Out[43]:
In [44]:
type(NoSTEPS)
Out[44]:
Copy-paste into Spyder's EDITOR
In [45]:
import numpy as np # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS) # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<
Copy-paste into Spyder's CONSOLE
In [46]:
time
Out[46]:
In [47]:
time[0]
Out[47]:
In [48]:
time[-1]
Out[48]:
In [49]:
time[:10]
Out[49]:
In [50]:
time[-10:]
Out[50]:
In [51]:
type(time)
Out[51]:
In [52]:
len(time)
Out[52]:
In [53]:
time.shape
Out[53]:
Lets make one "dummy" variable. For now, lets call it Biomass (B). Lets start with and empty vector.
Copy-paste into Spyder's EDITOR
In [54]:
import numpy as np
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float) # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<
Copy-paste into Spyder's CONSOLE
In [55]:
B
Out[55]:
In [56]:
type(B)
Out[56]:
In [57]:
B[0]
Out[57]:
In [58]:
B[-1]
Out[58]:
In [59]:
B[:10]
Out[59]:
Make our first plot
Copy-paste into Spyder's EDITOR
In [60]:
import numpy as np
import matplotlib.pyplot as plt # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float)
# Make plot
fig, (ax) = plt.subplots(1,1) # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<
Make initial condition for B
In [61]:
import numpy as np
import matplotlib.pyplot as plt
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float)
# Make plot
fig, (ax) = plt.subplots(1,1)
ax.plot(time/365,B,'b-') # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<
Out[61]:
In [62]:
import numpy as np
import matplotlib.pyplot as plt
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float)
# Make plot
fig, (ax) = plt.subplots(1,1)
ax.plot(time/365,B,'b-')
ax.set_xlabel('Time (years)'); ax.set_ylabel('B') # <<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<
Out[62]:
In [63]:
import numpy as np
import matplotlib.pyplot as plt
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Initial conditions
InitCond = {} # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<
InitCond['B'] = 0.1 # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float)
# Make plot
fig, (ax) = plt.subplots(1,1)
ax.plot(time/365,B,'b-')
ax.set_xlabel('Time (years)'); ax.set_ylabel('B')
Out[63]:
Copy-paste into Spyder's CONSOLE
In [64]:
InitCond
Out[64]:
In [65]:
type(InitCond)
Out[65]:
In [66]:
InitCond.keys()
Out[66]:
In [67]:
InitCond['B']
Out[67]:
Initialize B
Copy-paste into Spyder's EDITOR
In [68]:
import numpy as np
import matplotlib.pyplot as plt
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Initial conditions
InitCond = {}
InitCond['B'] = 0.1
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float)
# Initilizing
B[0] = InitCond['B'] # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<
# Make plot
fig, (ax) = plt.subplots(1,1)
ax.plot(time/365,B,'b-')
ax.set_xlabel('Time (years)'); ax.set_ylabel('B')
Out[68]:
Copy-paste into Spyder's CONSOLE
In [69]:
B[:10]
Out[69]:
Copy-paste into Spyder's EDITOR
First lets ad a "for" loop. I'll just ad a "print" statement for demostration purposes.
In [70]:
import numpy as np
import matplotlib.pyplot as plt
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Initial conditions
InitCond = {}
InitCond['B'] = 0.1
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float)
# Initilizing
B[0] = InitCond['B']
# MAIN MODEL LOOP ************************************************************************
#for t in range(0,NoSTEPS-1):
#print t
# end of main model LOOP******************************************************************
# Make plot
fig, (ax) = plt.subplots(1,1)
ax.plot(time/365,B,'b-')
ax.set_xlabel('Time (years)'); ax.set_ylabel('B')
Out[70]:
Lets change the "print" for the an actual "dummy model". At its minimum... it needs a dBdt
and a B[t+1]
equations
In [71]:
import numpy as np
import matplotlib.pyplot as plt
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Initial conditions
InitCond = {}
InitCond['B'] = 0.1
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float)
# Initilizing
B[0] = InitCond['B']
# MAIN MODEL LOOP ************************************************************************
for t in range(0,NoSTEPS-1):
dBdt = 0
# Time stepping
B[t+1] = B[t] + (dBdt * dt)
# end of main model LOOP******************************************************************
# Make plot
fig, (ax) = plt.subplots(1,1)
ax.plot(time/365,B,'b-')
ax.set_xlabel('Time (years)'); ax.set_ylabel('B')
Out[71]:
Copy-paste into Spyder's CONSOLE
In [72]:
B[:10]
Out[72]:
(1) $$ \frac{\partial B}{\partial t} = A - R $$
(2) $$ A = \epsilon \cdot IE \cdot AE \cdot Food $$
(3) $$ Food = \gamma \cdot B $$
(4) $$ R = (B \cdot m) + ( \beta \cdot A) $$
Symbol | ----------Units------------- | Value | Description |
---|---|---|---|
$B$ | $mmol N \cdot ind^{-3}$ | Initial B = 1104 | Fish biomass |
$A$ | $mmol N \cdot ind^{-3} \cdot d^{-1}$ | - | Assimilation rate |
$R$ | $mmol N \cdot ind^{-3} \cdot d^{-1}$ | - | Respiration rate |
$Food$ | $mmol N \cdot ind^{-3} \cdot d^{-1}$ | - | Amount of food delivered to individual fish per day |
$\gamma$ | $d^{-1}$ | 0.0085 | Food delivery rate |
$\epsilon$ | $dimensionless$ | 0.92 | Fraction of food swallowed by fish (part of this is spit out) |
$IE$ | $dimensionless$ | 0.95 | Ingestion Efficiency: Fraction of swallowed food that makes it to the stomach |
$AE$ | $dimensionless$ | 0.885 | Absorption Efficiency: Fraction of ingested food that is digestible |
$m$ | $d^{-1}$ | 0.001225 | Weight-specific maintenance respiration rate |
$\beta$ | $dimensionless$ | 0.44 | Cost of growth coefficient |
Copy-paste into Spyder's EDITOR
In [73]:
import numpy as np
import matplotlib.pyplot as plt
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Initial conditions
InitCond = {}
InitCond['B'] = 0.1
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float)
# Initilizing
B[0] = InitCond['B']
# MAIN MODEL LOOP ************
for t in range(0,NoSTEPS-1):
A = 0 # Eq. 2 TO DO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<<<<<<<<<
R = 0 # Eq. 3 TO DO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<<<<<<<<<
dBdt = A - R # Eq.1<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<<<<<<<<<
# Time stepping
B[t+1] = B[t] + (dBdt * dt)
# end of main model LOOP******
# Make plot
fig, (ax) = plt.subplots(1,1)
ax.plot(time/365,B,'b-')
ax.set_xlabel('Time (years)'); ax.set_ylabel('B')
Out[73]:
Ad parameters
In [74]:
import numpy as np
import matplotlib.pyplot as plt
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Parameters
par = {} # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<<<<<<<<<
par['gamma'] = 0.0085 # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<<<<<<<<<
par['epsilon'] = 0.92 # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<<<<<<<<<
par['IE'] = 0.95 # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<<<<<<<<<
par['AE'] = 0.885 # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<<<<<<<<<
par['m'] = 0.001225 # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<<<<<<<<<
par['beta'] = 0.44 # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<<<<<<<<<
# Initial conditions
InitCond = {}
InitCond['B'] = 0.1
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float)
# Initilizing
B[0] = InitCond['B']
# MAIN MODEL LOOP ************
for t in range(0,NoSTEPS-1):
A = 0 # Eq. 2 TO DO
R = 0 # Eq. 3 TO DO
dBdt = A - R # Eq.1
# Time stepping
B[t+1] = B[t] + (dBdt * dt)
# end of main model LOOP******
# Make plot
fig, (ax) = plt.subplots(1,1)
ax.plot(time/365,B,'b-')
ax.set_xlabel('Time (years)'); ax.set_ylabel('B')
Out[74]:
In [75]:
par
Out[75]:
In [76]:
par.keys()
Out[76]:
In [77]:
type(par)
Out[77]:
Add Assimilation Eq.
In [78]:
import numpy as np
import matplotlib.pyplot as plt
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Initial conditions
InitCond = {}
InitCond['B'] = 0.1
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float)
# Initilizing
B[0] = InitCond['B']
# MAIN MODEL LOOP ************
for t in range(0,NoSTEPS-1):
Food = 1 # TO DO # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<<<<<<<
A = par['epsilon'] * par['IE'] * par['AE'] * Food # <<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<
R = 0 # TO DO
dBdt = A - R
# Time stepping
B[t+1] = B[t] + (dBdt * dt)
# end of main model LOOP******
# Make plot
fig, (ax) = plt.subplots(1,1)
ax.plot(time/365,B,'b-')
ax.set_xlabel('Time (years)'); ax.set_ylabel('B')
Out[78]:
Ad Food Eq.
In [79]:
import numpy as np
import matplotlib.pyplot as plt
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Initial conditions
InitCond = {}
InitCond['B'] = 0.1
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float)
# Initilizing
B[0] = InitCond['B']
# MAIN MODEL LOOP ************
for t in range(0,NoSTEPS-1):
Food = par['gamma'] * B[t] # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<
A = par['epsilon'] * par['IE'] * par['AE'] * Food
R = 0 # TO DO
dBdt = A - R
# Time stepping
B[t+1] = B[t] + (dBdt * dt)
# end of main model LOOP******
# Make plot
fig, (ax) = plt.subplots(1,1)
ax.plot(time/365,B,'b-')
ax.set_xlabel('Time (years)'); ax.set_ylabel('B')
Out[79]:
In [80]:
import numpy as np
import matplotlib.pyplot as plt
days = 365 * 2 # Two years
dt = 0.01 # units: days
# Initial conditions
InitCond = {}
InitCond['B'] = 0.1
# Setup the framework
NoSTEPS = int(days / dt)
time = np.linspace(0,days,NoSTEPS)
B = np.zeros((NoSTEPS,),float)
# Initilizing
B[0] = InitCond['B']
# MAIN MODEL LOOP ************
for t in range(0,NoSTEPS-1):
Food = par['gamma'] * B[t]
A = par['epsilon'] * par['IE'] * par['AE'] * Food
R = (par['m']* B[t]) + (par['beta']*A) # <<<<<<<<<<<<<<<<<<< NEW LINE <<<<<<<<<<<<<<<<<<
dBdt = A - R
# Time stepping
B[t+1] = B[t] + (dBdt * dt)
# end of main model LOOP******
# Make plot
fig, (ax) = plt.subplots(1,1)
ax.plot(time/365,B,'b-')
ax.set_xlabel('Time (years)'); ax.set_ylabel('B')
Out[80]:
In [ ]: