compartmental.lshtm_ode
compartmental.lshtm_ode
Define compartmental TB models.
TB_ODE is a translation of the R model (lshtm_ode.R) into Python, integrated with scipy.odeint. TB_SS is a Starsim implementation of the same compartmental model, with Euler integration.
State and parameter names are aligned with the agent-based tbsim.TB class. The ODE keeps CLEARED split into three sub-states (CLEARED, RECOVERED, TREATED) so that the appropriate reinfection multiplier can be applied to each pathway, matching the per-agent rr_reinfection_cleared / rr_reinfection_rec / rr_reinfection_treat mechanism in tbsim.TB. Treatment dynamics (theta, phi, delta) are off by default — enable explicitly when modelling a post-treatment-era period.
Classes
| Name | Description |
|---|---|
| TB_ODE | Continuous-time compartmental TB model integrated with scipy.odeint. |
| TB_SS | Compartmental Starsim implementation of the LSHTM TB model (Euler integration). |
TB_ODE
compartmental.lshtm_ode.TB_ODE(**kwargs)Continuous-time compartmental TB model integrated with scipy.odeint.
See default_pars for parameter definitions.
Example
::
from tbsim.compartmental.lshtm_ode import TB_ODE
tb = TB_ODE()
tb.run()
tb.plot()
Methods
| Name | Description |
|---|---|
| plot | Plot all results, each in a separate axes. |
| run | Integrate the ODE system from start_time to end_time and store results. |
plot
compartmental.lshtm_ode.TB_ODE.plot(**kwargs)Plot all results, each in a separate axes.
run
compartmental.lshtm_ode.TB_ODE.run(start_time=1500, end_time=2020)Integrate the ODE system from start_time to end_time and store results.
TB_SS
compartmental.lshtm_ode.TB_SS(**kwargs)Compartmental Starsim implementation of the LSHTM TB model (Euler integration).
Self-contained: does not need a network or People (operates on aggregate compartments).
See default_pars for parameter definitions.
Example:
import starsim as ss
import tbsim.compartmental as tbc
tb = tbc.TB_SS()
sim = ss.Sim(modules=tb, start=1920, stop=2020, dt=0.1, n_agents=1)
sim.run()
sim.plot()
Methods
| Name | Description |
|---|---|
| init_post | Set initial conditions: 1% start in SYMPTOMATIC active TB. |
| init_results | Initialize results. |
| plot | Plot all results, each in a separate axes. |
| step | Euler integration of the ODE system. |
| update_results | Store the current state. |
init_post
compartmental.lshtm_ode.TB_SS.init_post()Set initial conditions: 1% start in SYMPTOMATIC active TB.
init_results
compartmental.lshtm_ode.TB_SS.init_results()Initialize results.
plot
compartmental.lshtm_ode.TB_SS.plot(**kwargs)Plot all results, each in a separate axes.
step
compartmental.lshtm_ode.TB_SS.step()Euler integration of the ODE system.
update_results
compartmental.lshtm_ode.TB_SS.update_results()Store the current state.