laser.measles.demographics.wpp
laser.measles.demographics.wpp
laser.measles.demographics.wpp.WPP(country_code)
World Population Prospects (WPP) population data access and processing.
This class provides access to United Nations World Population Prospects data for population trajectories, demographic estimates, and population pyramids. It uses the pyvd library to retrieve and process population data for specific countries, including mortality rates, birth rates, and age-structured population data.
The class supports interpolation of population pyramids for any year within the available data range, making it useful for demographic modeling and population projection analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
country_code |
str
|
The ISO country code for the selected country. |
year_vec |
ndarray
|
Vector of years available in the WPP dataset. |
pop_mat |
ndarray
|
Population matrix with shape (age_bins, years). |
vd_tup |
tuple
|
Demographic vital data tuple containing: - mort_year: Mortality year reference - mort_mat: Mortality matrix - birth_rate: Birth rate data - br_mult_x: Birth rate multiplier x values - br_mult_y: Birth rate multiplier y values |
age_vec |
ndarray
|
Age vector in days, representing age bins. |
pyramid_spline |
Interpolating spline for population pyramid data. |
Example
wpp = WPP("USA") pyramid_2020 = wpp.get_population_pyramid(2020) print(f"Population pyramid shape: {pyramid_2020.shape}")
Initialize WPP data access for a specific country.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
country_code
|
str
|
ISO country code (e.g., "USA", "GBR", "CHN"). The code will be converted to uppercase automatically. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the country code is invalid or data is unavailable. |
Note
Population data is adjusted by adding 0.1 to avoid zero values that could cause issues in demographic calculations.
laser.measles.demographics.wpp.WPP.get_population_pyramid(year)
Get the population pyramid for a given year.
Retrieves the age-structured population data for the specified year using spline interpolation. The population pyramid represents the distribution of population across different age groups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
The target year for population pyramid data. Must be within the available data range. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Population pyramid array with shape (age_bins,), representing population counts for each age group. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the requested year is outside the available data range (before first year or after last year). |
Example
wpp = WPP("USA") pyramid_2020 = wpp.get_population_pyramid(2020) print(f"Age groups: {len(pyramid_2020)}") print(f"Total population: {pyramid_2020.sum():.0f}")