phytoplankton, microcosms, ode's, r.€¦ · ecology ode’s rodeo desolve shiny!...

Post on 10-Aug-2020

4 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Ecology ODE’s rodeo deSolve Shiny!

Phytoplankton, Microcosms, ODE’s, R.

Andrew M. Dolman

useR-Aalborg 01 July 2015

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Ecology

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Eutrophication

+N +P

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Bioassays

Davis et al (2015)

N limitation

Ctrl +N +P +NPC

hl. a

µg

L-1

Kolzau et al (2014)

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Standard statistics

●●

●●

●●●

●●●

●●

●●

−0.5

0.0

0.5

0.25 1 2.6 10 20 30DIN:TP

RR

P−limitationCo−limitationN−limitation

Kolzau et al (2014)RR = log(Presponse/Nresponse)

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

ODE’s

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Simulate the microcosm with ODE’s

Simulate the microcosm with ODE’s

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Simulate the microcosm with ODE’s

Phytoplankton (Cphy) + 1 resource (Nphy and DIN)

dCphydt =

Cphy INmax

(1−

Cphy INminNphy

)INmax −INmin

dNphydt =

Cphy

(INmax −

NphyCphy

)Nupmax DIN

(INmax −INmin) (DIN+KNup)

dDINdt = −

Cphy

(INmax −

NphyCphy

)Nupmax DIN

(INmax −INmin) (DIN+KNup)

Use numerical solvers to step forward in time from initial conditions.

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Simulate the microcosm with ODE’s

Technical challenges

I No standard implementationI Sharing (communication between modellers) is difficultI Re-use is difficultI No standard = hard to get started

I Theory and code entangledI Poor documentationI Collaboration with non-modellers is difficult

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

rodeo

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Definition in tables + Code generation

Definition in tables + Code generation

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Definition in tables + Code generation

rodeo - David Kneis

https://github.com/dkneis/rodeo

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Definition in tables + Code generation

Identifiers

1

2

3

4

5

6

7

8

9

10

name

C_phy

N_phy

DIN

r_max

IN_max

IN_min

UN_max

K_Nup

uptake

droop

type

v

v

v

p

p

p

p

p

f

f

unit

µgC/L

µgN/L

µgN/L

1/day

gN/gC

gN/gC

gN/gC/day

µgN/L

µg/µgC/d

µgC/µgC/d

description

Cellular C

Cellular N

External dissolved inorganic N

Max phytoplankton growth rate

Max internal N:C ratio

Min internal N:C ratio

Max N uptake rate

Half sat. for N uptake

uptake rate for N

realised growth rate of phytoplankton

tex

C_{phy}

N_{phy}

DIN

r_{max}

IN_{max}

IN_{min}

UP_{max}

K_{Nup}

uptake

droop

html

C_phy

N_phy

DIN

r_max

IN_max

IN_min

UN_max

K_Nup

uptake

droop

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Definition in tables + Code generation

Processes

1

2

name

Growth

U_DIN

unit

µgC/d

µgN/d

description

Growth

Uptake of DIN

expression

r_max * droop(IN_max, IN_min, N_phy/C_phy)

uptake(UN_max, IN_max, IN_min, K_Nup, DIN, N_phy/C_phy)

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Definition in tables + Code generation

Stoichiometry

1

2

3

variable

C_phy

N_phy

DIN

process

Growth

U_DIN

U_DIN

expression

C_phy

C_phy

−C_phy

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Definition in tables + Code generation

Define functions

uptake <- function(Umax, Qmax, Qmin, K_half, Ext, Int){Umax*((Ext*(Qmax-Int))/((K_half+Ext)*(Qmax-Qmin)))}

droop <- function(Qmax, Qmin, Int){(Qmax / (Qmax - Qmin)) * (1 - (Qmin / Int))}

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Neat documentation

Neat documentation

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Neat documentation

State variables

Symbol Unit DescriptionCphy µgC/L Cellular CNphy µgN/L Cellular NDIN µgN/L External dissolved inorganic N

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Neat documentation

Parameters

Symbol Unit Descriptionrmax 1/day Max phytoplankton growth rateINmax gN/gC Max internal N:C ratioINmin gN/gC Min internal N:C ratioUPmax gN/gC/day Max N uptake rateKNup µgN/L Half sat. for N uptake

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Code generation

Code generation

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Code generation

Instantiate model object

model <- new("rodeo", vars=subset(identifiers,type=="v"), pars=subset(identifiers,type=="p"), funs=subset(identifiers,type=="f"), pros=processes, stoi=stoichiometry)

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Code generation

Generate code

R or Fortran95

code <- model$generate(name="derivs",lang="r")derivs <- eval(parse(text=code))

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Code generation

Provide parameter and starting values

pars <- list(r_max=1, K_Nup=100, UN_max=0.2, IN_max=0.13 * (14/12), IN_min=0.05 * (14/12))

init_C_phy <- 2000init_DIN <- 80

vars <- list(C_phy=init_C_phy, DIN=init_DIN, N_phy=(2*pars[["IN_min"]])*init_C_phy)

p <- model$arrangePars(pars)v <- model$arrangeVars(vars)

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Code generation

Test the derivative function

derivs(time, v, p, NLVL = 1)

## $dydt## [1] 1625.00000 66.66667 -66.66667#### $pro## [1] 0.81250000 0.03333333

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

deSolve

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Solve the ODE system

Solve the ODE system

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Solve the ODE system

Pass parameters and starting values at runtime

t <- seq(0, 5, length.out=100)

system.time({out_R1 <- ode(y=v, times=t, func=derivs

, parms=p, NLVL=1)})

## user system elapsed## 0.06 0.00 0.08

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Solve the ODE system

Plot output

0 1 2 3 4 5

2000

3500

5000

C_phy

time0 1 2 3 4 5

240

260

280

300

N_phy

time0 1 2 3 4 5

020

4060

80

DIN

time

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Shiny!

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

More ecology

I N or P limit growth rateI Effect of light (I) is multiplicative

dCphydt = f (I) ·min{f (N), f (P)}

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Shiny app demonstration

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Packages

I rodeo (David Kneis) https://github.com/dkneis/rodeoI Standard definition of ODE’s in tablesI Definition is the documentationI Code generation in R or F95 (250x faster)

I deSolve (Soetaert, Petzoldt, Setzer)I Numeric solvers for DE

I Shiny (Chang, Cheng, Allaire, Xie and McPherson)

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

AcknowledgmentsI David Kneis rodeo @TU Dresden

I https://github.com/dkneis/rodeo

I Thomas Petzoldt @TU DresdenI Sebastian Kolzau, Jacqueline Rücker, Claudia Wiedner @BTUI Nitrolimit www.nitrolimit.deI BMBF FONA 033L041A and 0033W015AN

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Petersen matrix

(Cphy Nphy DINGrowth Cphy 0 0U DIN 0 Cphy −Cphy

) Rate expressions

f (NphyCphy

, INmax , INmin)

f (DIN,NphyCphy

, Nupmax , . . . )

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

Literature cited

I Davis, T.W., Bullerjahn, G.S., Tuttle, T., McKay, R.M. &Watson, S.B. (2015) Effects of Increasing Nitrogen andPhosphorus Concentrations on Phytoplankton CommunityGrowth and Toxicity During Planktothrix Blooms in SanduskyBay, Lake Erie. Environmental Science & Technology, 49,7197–7207.

I Karline Soetaert, Thomas Petzoldt, R. Woodrow Setzer (2010).Solving Differential Equations in R: Package deSolve Journalof Statistical Software, 33(9), 1–25. URLhttp://www.jstatsoft.org/v33/i09/.

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

Ecology ODE’s rodeo deSolve Shiny!

I Kolzau, S., Wiedner, C., Rücker, J., Köhler, J., Köhler, A. &Dolman, A.M. (2014) Seasonal patterns of nitrogen andphosphorus limitation in four German lakes and thepredictability of limitation status from ambient nutrientconcentrations. PLoS ONE, 9, e96065.

Andrew M. DolmanPhytoplankton, Microcosms, ODE’s, R.

top related