Skip to content

laser.measles.demographics.raster_patch

raster_patch

Raster patch generator for demographic data. You can use this to generate initial conditions (e.g, population, MCV1 coverage) for a laser-measles scenario.

RasterPatchGenerator(config, verbose=True)

Generate a scenario DataFrame by clipping raster data to shapefile boundaries.

This is the primary tool for the prepare scenario stage. Given population and vaccination-coverage rasters plus an admin-boundary shapefile, it produces a Polars DataFrame with one row per patch containing id, pop, lat, lon, mcv1, and optionally mcv2 columns — ready to pass to any model constructor.

Results are cached on disk; subsequent calls with the same configuration skip the raster-clipping step.

Parameters:

Name Type Description Default
config RasterPatchParams

A RasterPatchParams specifying inputs.

required
verbose bool

Print progress messages.

True

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from laser.measles.demographics.raster_patch import (
    RasterPatchGenerator, RasterPatchParams,
)

config = RasterPatchParams(
    id="nga_admin2",
    region="NGA",
    shapefile="gadm41_NGA_2.shp",
    population_raster="nga_ppp_2020.tif",
    mcv1_raster="nga_mcv1_2020.tif",
)
generator = RasterPatchGenerator(config)
scenario_df = generator.generate_demographics()

clear_cache()

Remove all cached entries for this configuration's ID.

generate_birth_rates()

Generate birth-rate data (not yet implemented).

generate_demographics()

Run the full demographic extraction pipeline.

Clips population (and optionally MCV1) rasters to the shapefile boundaries and stores results in self.population and self.mcv1.

generate_mcv1()

MCV1 coverage, population weighted

generate_mortality_rates()

Generate mortality-rate data (not yet implemented).

generate_population()

Population, counts

get_cache_key(key)

Build a namespaced cache key for this configuration.

Parameters:

Name Type Description Default
key str

One of "shapefile", "population", or "mcv1".

required

Returns:

Type Description
str

Cache key string in the form "{config.id}:{key}".

RasterPatchParams

Bases: BaseModel

Configuration for raster-based demographic data extraction.

Specifies the geographic region, shapefile boundaries, and raster data sources used by RasterPatchGenerator to build a scenario DataFrame during the prepare scenario stage.

Attributes:

Name Type Description
id str

Unique identifier for this scenario configuration.

region str

ISO-3166 alpha-3 country code (e.g. "NGA").

shapefile str | Path

Path to the admin-boundary shapefile (.shp).

population_raster str | Path | None

Path to a population-count raster (GeoTIFF).

mcv1_raster str | Path | None

Path to a MCV1 coverage raster (GeoTIFF).

mcv2_raster str | Path | None

Path to a MCV2 coverage raster (GeoTIFF).

Examples:

1
2
3
from laser.measles.demographics.raster_patch import RasterPatchParams

params = RasterPatchParams(admin_level=2)

shapefile_exists(v, info)

Verify the shapefile path exists on disk.