# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
# Configure Jupyter so figures appear in the notebook
# %matplotlib inline

# Configure Jupyter to display the assigned value after an assignment
# %config InteractiveShell.ast_node_interactivity='last_expr_or_assign'

# import functions from the modsim.py module
from modsim import *

# +
body = State(R=200,
             L=0,
             E=0,
             V=4e-7)

system = System(gamma=1.36, #per day
                mu=1.36e-3,
                tau=0.2,
                beta=0.00027,
                p=0.1,
                alpha=3.6e-2,
                sigma=2,
                delta=0.33,
                pi=100)


# +
def update_R(state, system,in_day):
    dR = (gamma/in_day * tau) - (mu/in_day * state.R) - (beta/in_day * state.R * state.V)
    return dR + state.R

def update_L(state, system,in_day):
    dL = (p * beta/in_day * state.R * state.V) - (mu/in_day * state.L) - (alpha/in_day * state.L)
    return dL + state.L

def update_E(state, system,in_day):
    dE = ((1 - p) * beta/in_day * state.R * state.V) + (alpha/in_day * state.L) - (delta/in_day * state.E)
    return dE + state.E

def update_V(state, system,in_day):
    dV = (pi/in_day * state.E) - (sigma/in_day * state.V)
    return dV + state.V

def update_body(state, system,in_day):    
 
    for i in range(in_day):
        nr = update_R(state, system, in_day)
        nl = update_L(state, system, in_day)
        ne = update_E(state, system, in_day)
        nv = update_V(state, system, in_day)
        state = State(R=nr, L=nl, E=ne, V=nv)
    
    return State(R=nr, L=nl, E=ne, V=nv)


# -

def run_simulation(state, system, update_func, days, steps_per_day):
    unpack(system)
    
    frame = TimeFrame(columns=state.index)
    frame.row[0] = state
    
    for t in linrange(0, days):
        frame.row[t + 1] = update_func(frame.row[t], system, steps_per_day)
    
    return frame


sim=run_simulation(body, system, update_body, 14,24*60)
sim.plot()
sim










StarcoderdataJupyterScriptsDedupFiltered