laser.measles.migration
laser.measles.migration
laser.measles.migration.get_diffusion_matrix(df, scale, func, f_kwargs, enforce_scale=True)
Build a row-stochastic diffusion matrix from a migration kernel.
Computes a raw migration matrix using func(**f_kwargs), normalises it
so the average row sum equals 1, scales by scale, then fills the
diagonal so every row sums exactly to 1. The result can be used directly
as a spatial mixing matrix in infection components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Scenario DataFrame (only its length is used to handle the single-patch edge case). |
required |
scale
|
float
|
Average fraction of a patch's population that travels per
tick. Capped automatically when |
required |
func
|
Callable
|
Migration kernel function (e.g.,
[ |
required |
f_kwargs
|
dict
|
Keyword arguments forwarded to |
required |
enforce_scale
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Row-stochastic diffusion matrix of shape |
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
laser.measles.migration.init_gravity_diffusion(df, scale, dist_exp, enforce_scale=True)
Initialize a gravity diffusion matrix for population mixing. The diffusion matrix is a square matrix where each row represents the outbound migration from a given patch to all other patches e.g., [i,j] = [from_i, to_j].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with 'pop', 'lat', and 'lon' columns |
required |
scale
|
float
|
Scaling factor for the diffusion matrix, i.e., the average total outbound migration |
required |
dist_exp
|
float
|
Distance exponent for the gravity model, i.e., the sensitivity of migration to distance |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Normalized diffusion matrix where each row sums to 1 |
laser.measles.migration.pairwise_haversine(df)
Pairwise distances for all (lon, lat) points using the Haversine formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Polars DataFrame with 'lon' and 'lat' columns |
required |
Returns:
| Type | Description |
|---|---|
|
Pairwise distances in kilometers |