laser.measles.migration
laser.measles.migration
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 |