-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4caa167
commit 54bfaee
Showing
4 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
etl/steps/data/garden/demography/2024-12-18/mean_age_childbearing.meta.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# NOTE: To learn more about the fields, hover over their names. | ||
definitions: | ||
common: | ||
presentation: | ||
topic_tags: | ||
- Fertility Rate | ||
|
||
# Learn more about the available fields: | ||
# http://docs.owid.io/projects/etl/architecture/metadata/reference/ | ||
dataset: | ||
update_period_days: 365 | ||
title: Mean age at childbearing (HFD; UN WPP) | ||
|
||
tables: | ||
mean_age_childbearing: | ||
variables: | ||
mean_age_childbearing: | ||
title: Mean age at childbearing | ||
unit: years | ||
description_short: &cb_description_short |- | ||
Mean age of mothers at the birth of their children if women were subject throughout their lives to the age-specific fertility rates observed in a given year. UN Medium projections for 2024-2100. | ||
description_processing: |- | ||
This indicator is constructed by combining data from multiple sources: | ||
- Before 1949: Historical estimates by Human Fertility Database (2024). | ||
- 1950-2023: Population records by the UN World Population Prospects (2024 revision). | ||
- 2024-2100: Projections based on Medium variant by the UN World Population Prospects (2024 revision). | ||
presentation: | ||
title_public: |- | ||
Mean age at childbearing | ||
grapher_config: | ||
subtitle: *cb_description_short | ||
|
||
mean_age_childbearing_hist: | ||
title: Mean age at childbearing, historical | ||
unit: years | ||
description_short: &cb_description_short_hist |- | ||
Mean age of mothers at the birth of their children if women were subject throughout their lives to the age-specific fertility rates observed in a given year. | ||
description_processing: |- | ||
This indicator is constructed by combining data from multiple sources: | ||
- Before 1949: Historical estimates by Human Fertility Database (2024). | ||
- 1950-2023: Population records by the UN World Population Prospects (2024 revision). | ||
presentation: | ||
title_public: |- | ||
Mean age at childbearing | ||
grapher_config: | ||
subtitle: *cb_description_short_hist |
69 changes: 69 additions & 0 deletions
69
etl/steps/data/garden/demography/2024-12-18/mean_age_childbearing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"""Load a meadow dataset and create a garden dataset.""" | ||
|
||
import pandas as pd | ||
from owid.catalog import processing as pr | ||
|
||
from etl.helpers import PathFinder, create_dataset | ||
|
||
# Get paths and naming conventions for current step. | ||
paths = PathFinder(__file__) | ||
|
||
|
||
# Year constants | ||
YEAR_WPP_START = 1950 | ||
YEAR_WPP_PROJ_START = 2023 | ||
# Table names | ||
TABLE_NAME_WPP = "mean_age_childbearing" | ||
TABLE_NAME_HFD = "period" | ||
TABLE_NAME_NEW = "mean_age_childbearing" | ||
# Metric names | ||
COLUMN_NAME_WPP = "mean_age_childbearing" | ||
COLUMN_NAME_HFD = "mab" | ||
COLUMN_NEW_NAME = "mean_age_childbearing" | ||
|
||
|
||
def run(dest_dir: str) -> None: | ||
# | ||
# Load inputs. | ||
# | ||
# Load meadow dataset. | ||
ds_hfd = paths.load_dataset("hfd") | ||
ds_un = paths.load_dataset("un_wpp") | ||
|
||
# Read table from meadow dataset. | ||
tb_hfd = ds_hfd.read(TABLE_NAME_HFD) | ||
tb_un = ds_un.read(TABLE_NAME_WPP) | ||
|
||
# UN: estimates + medium, | ||
tb_un = tb_un.loc[ | ||
(tb_un["sex"] == "all") & (tb_un["variant"].isin(["medium", "estimates"]) & (tb_un["age"] == "all")), | ||
["country", "year", COLUMN_NAME_WPP], | ||
].rename(columns={COLUMN_NAME_WPP: COLUMN_NEW_NAME}) | ||
|
||
# HFD: tfr, birth_order=total, | ||
tb_hfd = tb_hfd.loc[ | ||
((tb_hfd["birth_order"] == "total") & (tb_hfd["year"] < YEAR_WPP_START)), ["country", "year", COLUMN_NAME_HFD] | ||
].rename(columns={COLUMN_NAME_HFD: COLUMN_NEW_NAME}) | ||
|
||
# Concatenate | ||
tb = pr.concat([tb_hfd, tb_un], ignore_index=True, short_name=TABLE_NAME_NEW) | ||
|
||
# Add historical variant | ||
tb[f"{COLUMN_NEW_NAME}_hist"] = tb[COLUMN_NEW_NAME].copy() | ||
tb.loc[tb["year"] > YEAR_WPP_PROJ_START, f"{COLUMN_NEW_NAME}_hist"] = pd.NA | ||
|
||
# Format | ||
tb = tb.format(["country", "year"]) | ||
|
||
# | ||
# Save outputs. | ||
# | ||
# Create a new garden dataset with the same metadata as the meadow dataset. | ||
ds_garden = create_dataset( | ||
dest_dir, | ||
tables=[tb], | ||
check_variables_metadata=True, | ||
) | ||
|
||
# Save changes in the new garden dataset. | ||
ds_garden.save() |
28 changes: 28 additions & 0 deletions
28
etl/steps/data/grapher/demography/2024-12-18/mean_age_childbearing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Load a garden dataset and create a grapher dataset.""" | ||
|
||
from etl.helpers import PathFinder, create_dataset | ||
|
||
# Get paths and naming conventions for current step. | ||
paths = PathFinder(__file__) | ||
|
||
|
||
def run(dest_dir: str) -> None: | ||
# | ||
# Load inputs. | ||
# | ||
# Load garden dataset. | ||
ds_garden = paths.load_dataset("mean_age_childbearing") | ||
|
||
# Read table from garden dataset. | ||
tb = ds_garden.read("mean_age_childbearing", reset_index=False) | ||
|
||
# | ||
# Save outputs. | ||
# | ||
# Create a new grapher dataset with the same metadata as the garden dataset. | ||
ds_grapher = create_dataset( | ||
dest_dir, tables=[tb], check_variables_metadata=True, default_metadata=ds_garden.metadata | ||
) | ||
|
||
# Save changes in the new grapher dataset. | ||
ds_grapher.save() |