sim
sim
TB simulation class – a convenience wrapper around ss.Sim with TB-specific defaults.
Classes
| Name | Description |
|---|---|
| Sim | A subclass of ss.Sim specifically designed for TB simulations. |
Sim
sim.Sim(
pars=None,
sim_pars=None,
tb_pars=None,
tb_model=None,
name='tb',
**kwargs,
)A subclass of ss.Sim specifically designed for TB simulations.
Parses input parameters among the sim and the TB module, and provides default demographics (births and deaths), networks (random), and disease (TB).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| pars | dict | Flat parameter dict; keys are auto-routed to sim vs TB pars. | None |
| sim_pars | dict | Explicit sim-level parameter overrides. | None |
| tb_pars | dict | Explicit TB parameter overrides. | None |
| tb_model | str / Disease |
Which TB model to use. Options: ‘default’ (default), or a pre-built Disease instance. | None |
| location | str | Placeholder for future location-based data. | required |
| **kwargs | Additional parameters (auto-routed like pars). |
{} |
Examples::
import tbsim
# Simplest usage -- all defaults
sim = tbsim.Sim()
sim.run()
sim.plot()
# Override TB and sim parameters via flat dict
sim = tbsim.Sim(n_agents=2000, beta=ss.peryear(0.3), start=1990, stop=2020)
# Pass a pre-built TB instance
tb = tbsim.TB(pars=dict(beta=ss.peryear(0.5)))
sim = tbsim.Sim(tb_model=tb)
Methods
| Name | Description |
|---|---|
| get_dx | Get a DxDelivery instance. Returns None if not found. |
| get_hsb | Get the HealthSeekingBehavior instance. Returns None if not found. |
| get_tb | Get the TB disease module from this sim. |
| plot | Plot sim results. If key is ‘tb’, shows a curated panel of TB results. |
get_dx
sim.Sim.get_dx(name=None, result_state=None)Get a DxDelivery instance. Returns None if not found.
get_hsb
sim.Sim.get_hsb()Get the HealthSeekingBehavior instance. Returns None if not found.
get_tb
sim.Sim.get_tb(which=None)Get the TB disease module from this sim.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| which | type | Class of TB module to find (e.g. TB). If None, returns the first BaseTB subclass found. | None |
Returns
| Name | Type | Description |
|---|---|---|
| The TB disease module instance. |
plot
sim.Sim.plot(key=None, **kwargs)Plot sim results. If key is ‘tb’, shows a curated panel of TB results. Otherwise falls back to the standard starsim plot.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| key | str / list | Result key(s) to plot, or ‘tb’ for curated TB panel. | None |
| **kwargs | Passed to ss.Sim.plot(). | {} |
Returns
| Name | Type | Description |
|---|---|---|
| matplotlib.figure.Figure |
Functions
| Name | Description |
|---|---|
| demo | Create a demo TB simulation. |
demo
sim.demo(run=True, plot=True, **kwargs)Create a demo TB simulation.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| run | bool | Whether to run the sim. | True |
| plot | bool | Whether to plot results (only if run=True). | True |
| **kwargs | Passed to Sim(). | {} |
Returns
| Name | Type | Description |
|---|---|---|
| Sim | Configured (and optionally run) simulation. |
Examples::
import tbsim
tbsim.demo() # Run simple default demo
sim = tbsim.demo(run=False, n_agents=500) # Just create it