Create Epigrass epidemiological models through step-by-step guided specification. Build metapopulation models (SIR, SEIR, SEIS, SIS, SI) with geographic networks. Supports GeoPackage import for real-world spatial data.
Guide users through creating epidemiological metapopulation models using Epigrass.
Epigrass (Epidemiological Geo-referenced Analysis and Simulation System) is a Python library for simulating disease spread across geographic networks. It supports metapopulation models where multiple sites (cities, regions) are connected through a network.
| Model | Compartments | Use Case |
|---|---|---|
| SIR | S, I, R | Diseases with lifelong immunity (measles, chickenpox) |
| SEIR | S, E, I, R | Diseases with latent period (dengue, COVID-19) |
| SEIS | S, E, I | Diseases with temporary immunity (influenza) |
| SIS | S, I | Diseases with no immunity (common cold) |
| SI |
| S, I |
| Fatal diseases (HIV/AIDS) |
| Custom | User-defined | Specialized scenarios |
When a user asks to create an Epigrass model, guide them through these 5 steps:
Present the available models and help the user choose:
🦠 Epigrass Model Creation - Step 1/5: Model Selection
| # | Model | Description | Best For |
|---|-------|-------------|----------|
| 1 | SIR | Susceptible-Infectious-Recovered | Diseases with lifelong immunity |
| 2 | SEIR | Susceptible-Exposed-Infectious-Recovered | Diseases with incubation period |
| 3 | SEIS | Susceptible-Exposed-Infectious-Susceptible | Diseases with temporary immunity |
| 4 | SIS | Susceptible-Infectious-Susceptible | Diseases with no immunity |
| 5 | SI | Susceptible-Infectious | Fatal diseases |
| 6 | Custom | User-defined compartments | Specialized scenarios |
Which model type would you like to use?
Help the user define geographic sites. Offer these options:
For GeoPackage import:
Example prompt:
Step 2/5: Define Sites
Options:
1. Enter sites manually (Name, Lat, Lon, Pop, Geocode)
2. List Brazilian cities (I'll fetch coordinates)
3. Create a grid layout (e.g., 5x5)
4. Import from GeoPackage (.gpkg) file
How would you like to define your sites?
Collect model parameters based on the selected model type:
Common parameters:
beta (β): Transmission rate (0.1-1.0)gamma (γ): Recovery rate = 1/infectious_period_daysalpha (α): Non-linear exponent (1.0 = mass action)delta (δ): Immunity loss rate (0 = permanent)SEIR/SEIS additional:
sigma (σ): Incubation rate = 1/latent_period_daysExample prompt:
Step 3/5: Model Parameters
For a 7-day infectious period: γ = 1/7 ≈ 0.14
For a 5-day incubation period: σ = 1/5 = 0.2
Enter parameters (format: parameter=value):
Define how sites connect:
Calculate flows using Haversine distance formula:
Collect simulation configuration:
timestep: Duration of each step in days (default: 1)iterations: Number of time steps (default: 365 for 1 year)output_dir: Where to save resultsGenerate these files in the output directory:
Epigrass script with model configuration:
# Epigrass Model Script
model_type = 'SEIR'
sites_file = 'sites.csv'
edges_file = 'edges.csv'
# Parameters
beta = 0.4
gamma = 0.14
sigma = 0.2
# Simulation
timestep = 1
iterations = 365
Site data with coordinates and population:
X,Y,City,Pop,Geocode
-23.5505,-46.6333,Sao_Paulo,12300000,3550308
-22.9068,-43.1729,Rio_de_Janeiro,6750000,3304557
Network connections with distance-based flow:
Source,Dest,flowSD,flowDS,Distance,geoSource,geoDest
Sao_Paulo,Rio_de_Janeiro,500,500,358.5,3550308,3304557
Complete specification in JSON format for reproducibility.
Use this formula to calculate distances between sites:
import math
def haversine(lat1, lon1, lat2, lon2):
R = 6371 # Earth's radius in km
lat1_rad = math.radians(lat1)
lat2_rad = math.radians(lat2)
delta_lat = math.radians(lat2 - lat1)
delta_lon = math.radians(lon2 - lon1)
a = math.sin(delta_lat/2)**2 + math.cos(lat1_rad) * math.cos(lat2_rad) * math.sin(delta_lon/2)**2
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
return R * c
Calculate flow inversely proportional to distance:
flow = max(10, int(1000 / (distance_km + 1)))
Before creating models, ensure the user has:
pip install epigrasspip install geopandas or pip install fionaExample 1: Simple SIR model
User: Create a simple SIR model for 3 cities
Agent: I'll help you create an SIR model. Let's start:
Step 1: Selected SIR model (diseases with lifelong immunity)
Step 2: Please provide your 3 cities:
Format: Name, Latitude, Longitude, Population, Geocode
Example 2: Dengue SEIR model
User: Build a dengue model for Brazilian state capitals
Agent: Dengue has an incubation period, so SEIR is the best choice.
Step 1: Selected SEIR model
Step 2: Which capitals would you like to include?
Options: São Paulo, Rio de Janeiro, Belo Horizonte, Brasília, Salvador, etc.
Example 3: GeoPackage import
User: Create a model using my municipalities.gpkg file
Agent: I'll import sites from your GeoPackage.
Step 2: Reading municipalities.gpkg...
Found 5570 features with columns: [name, population, geocode, geometry]
Column mapping:
- Site name column [name]:
- Population column [population]:
- Geocode column [geocode]:
Imported 5570 sites successfully!
After generating files, provide a summary:
✅ Model Created Successfully!
Model Type: SEIR
Sites: 10
Edges: 45
Parameters: beta=0.4, gamma=0.14, sigma=0.2
Files generated in ./epigrass_model/:
- model.epg (Epigrass script)
- sites.csv (Site data)
- edges.csv (Network connections)
- model_spec.json (Full specification)
To run the simulation:
cd epigrass_model && epirunner model.epg
Use this skill when the user:
Ask clarifying questions if the target disease, region, or model requirements are unclear.