Skip to content

laser.measles.demographics.base

laser.measles.demographics.base

laser.measles.demographics.base.BaseShapefile

Bases: BaseModel

Pydantic base for shapefile wrappers.

Validates that the shapefile path exists on disk and provides a get_dataframe method to read records into a Polars DataFrame.

Parameters:

Name Type Description Default
shapefile

Path to a .shp file.

required

Example:

1
2
3
4
5
6
```python
from laser.measles.demographics.gadm import GADMShapefile

shapefile = GADMShapefile("NGA")
df = shapefile.get_dataframe()
```

laser.measles.demographics.base.BaseShapefile.add_dotname()

Add a DOTNAME field — subclasses override with real logic.

laser.measles.demographics.base.BaseShapefile.convert_to_path(v) classmethod

Convert string paths to Path and verify existence.

laser.measles.demographics.base.BaseShapefile.get_dataframe()

Get a Polars DataFrame containing the shapefile data and fields.

Returns:

Type Description
DataFrame

A Polars DataFrame.

laser.measles.demographics.base.DemographicsGeneratorProtocol

Bases: Protocol

Protocol for demographic data generators.

Implementations provide population counts, birth rates, and mortality rates for the prepare scenario stage of the researcher workflow. See RasterPatchGenerator for the primary implementation.

Example:

1
2
3
4
5
6
7
8
```python
from laser.measles.demographics.raster_patch import RasterPatchGenerator, RasterPatchParams
from laser.measles.demographics.gadm import GADMShapefile

shapefile = GADMShapefile("NGA")
generator = RasterPatchGenerator(shapefile, RasterPatchParams(admin_level=2))
scenario = generator.generate_demographics()
```

laser.measles.demographics.base.DemographicsGeneratorProtocol.generate_birth_rates()

Generate birth-rate data for all patches.

laser.measles.demographics.base.DemographicsGeneratorProtocol.generate_mortality_rates()

Generate mortality-rate data for all patches.

laser.measles.demographics.base.DemographicsGeneratorProtocol.generate_population()

Generate a population DataFrame for all patches.

laser.measles.demographics.base.ShapefileProtocol

Bases: Protocol

Protocol for shapefile readers used by the demographics pipeline.

Example:

1
2
3
4
5
6
```python
from laser.measles.demographics.gadm import GADMShapefile

shapefile = GADMShapefile("NGA")  # Nigeria
df = shapefile.get_dataframe()
```

laser.measles.demographics.base.ShapefileProtocol.add_dotname()

Add a DOTNAME field to the shapefile for hierarchical naming.

laser.measles.demographics.base.ShapefileProtocol.get_dataframe()

Return shapefile records as a Polars DataFrame.