This project uses Covasim to simulate the spread of COVID-19 within a defined region and estimate viral shedding into wastewater. The region is modeled as a grid (default: 2×2), allowing infections and viral load to be tracked spatially over time.
Install Covasim via pip:
pip install covasimsrc/run_sim.py— Main script for running the simulationsrc/plots— Viral loads visualized in a heatmaps for example test cases.
python src/run_sim.py --pop_size 100 --pop_type hybrid --n_days 180 --location zambiaThe simulation consists of several key steps:
Simulation parameters are configured in the define_sim_parameters() function.
Core parameters include:
pop_size— Total population sizepop_type— Population structure (e.g., random, hybrid)location— Country/region name (used for demographic data)n_days— Number of simulation dayspop_infected— Initial number of infected individualsn_imports— Daily number of imported infections
Additional spatial parameters:
n_rows— Number of rows in the region grid (default: 2)n_cols— Number of columns in the region grid (default: 2)
Infection initialization parameters:
n_init_inf— Number of initial infections in a regionr_init_inf— Row index of initial infectionsc_init_inf— Column index of initial infections
Full parameter list:
python src/run_sim.py --help
--pop_size POP_SIZE
--pop_type POP_TYPE
--n_days N_DAYS
--location LOCATION
--pop_infected POP_INFECTED
--n_imports N_IMPORTS
--n_rows N_ROWS
--n_cols N_COLS
--n_init_inf N_INIT_INF
--r_init_inf R_INIT_INF
--c_init_inf C_INIT_INFNote: Covasim automatically includes demographic data (age distribution and household sizes) based on the specified location.
-
The function
check_age_household_dist()validates whether data exists for the given location. -
Errors from this function typically indicate:
- A typo in the location name, or
- Missing data for that region
For more details on Covasim parameters, refer to: Covasim toturial
The function assign_people() randomly assigns individuals to regions in the grid.
- Uses NumPy’s shuffle for randomness
- Returns an array of length
N(population size) - Each value represents a region ID (0 to total_regions − 1)
Initial infections are seeded using:
n_init_infr_init_infc_init_inf
These define:
- How many individuals are infected
- The specific region (by row and column) where infections begin
By default:
pop_infected = 0n_imports = 0
The simulation is executed to track infections over time.
The function calculate_new_infections():
-
Determines when each individual becomes infected
-
Maps individuals to regions
-
Aggregates infection counts per:
- Region
- Time step
Viral shedding is computed for each region over time using two approaches:
A basic model that assumes:
- Uniform viral shedding behavior across individuals
- No variation due to age or other characteristics
This model provides a simplified estimate based on predefined shedding parameters.
Covasim internally calculates viral load per individual at each time step.
This project leverages that data to compute shedding:
get_viral_loads(sim, t_start, t_end)viral_shedding_covasim(sim, start, end)
Method:
- Extract per-individual viral loads
- Sum loads across individuals within each region
- Aggregate over time
Reference implementation: Covasim original paper
This pipeline:
-
Configures a population and spatial grid
-
Simulates infection spread using Covasim
-
Tracks infections by region and time
-
Estimates wastewater viral shedding using:
- A simplified model
- Covasim’s internal viral load calculations