Skip to content

Commit

Permalink
📊 mean paternal age at birth (#3694)
Browse files Browse the repository at this point in the history
* 📊 mean paternal age at birth

* wip

* typo in short_name

* add multiple reading from RData files

* wip

* meadow

* wip

* remove spurious rows

* add reading function

* fix condition

* working grapher

* wip
  • Loading branch information
lucasrodes authored Dec 11, 2024
1 parent 897ea01 commit 7d89c47
Show file tree
Hide file tree
Showing 12 changed files with 2,157 additions and 2 deletions.
10 changes: 9 additions & 1 deletion dag/demography.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,15 @@ steps:
- data://garden/hmd/2024-12-01/hmd
data://grapher/hmd/2024-12-03/hmd_country:
- data://garden/hmd/2024-12-03/hmd_country


# Patternal ages (Kai & Klüssner)
data://meadow/demography/2024-12-05/paternal_ages:
- snapshot://demography/2024-12-04/paternal_ages.rdata
data://garden/demography/2024-12-05/paternal_ages:
- data://meadow/demography/2024-12-05/paternal_ages
data://grapher/demography/2024-12-05/paternal_ages:
- data://garden/demography/2024-12-05/paternal_ages

########################################################################
# OTHERS
########################################################################
Expand Down
25 changes: 24 additions & 1 deletion etl/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import tempfile
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Iterator, Optional, Union, cast
from typing import Any, Dict, Iterator, Optional, Union, cast

import owid.catalog.processing as pr
import pandas as pd
Expand Down Expand Up @@ -229,6 +229,29 @@ def read_rda(self, *args, **kwargs) -> Table:
"""Read R data .rda file into a Table and populate it with metadata."""
return pr.read_rda(self.path, *args, metadata=self.to_table_metadata(), origin=self.metadata.origin, **kwargs)

def read_rda_multiple(self, *args, **kwargs) -> Dict[str, Table]:
"""Read R data .rda file into multiple Tables and populate it with metadata.
RData objects can contain multiple dataframes.
Read specific dataframes from an RData file:
```python
tables = snap.read_rda_multiple(["tname1", "tname2"])
```
If you don't provide any table names, all tables will be read:
```python
tables = snap.read_rda_multiple()
```
where tables is a key-value dictionary, and keys are the names of the tables (same as table short_names too).
"""
return pr.read_rda_multiple(
self.path, *args, metadata=self.to_table_metadata(), origin=self.metadata.origin, **kwargs
)

def read_fwf(self, *args, **kwargs) -> Table:
"""Read a table of fixed-width formatted lines with metadata."""
return pr.read_fwf(self.path, *args, metadata=self.to_table_metadata(), origin=self.metadata.origin, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"ALB": "Albania",
"AND": "Andorra",
"ANT": "Netherlands Antilles",
"ARG": "Argentina",
"ARM": "Armenia",
"ASM": "American Samoa",
"AUS": "Australia",
"AUT": "Austria",
"AZE": "Azerbaijan",
"BEL": "Belgium",
"BGR": "Bulgaria",
"BHR": "Bahrain",
"BHS": "Bahamas",
"BIH": "Bosnia and Herzegovina",
"BLR": "Belarus",
"BLZ": "Belize",
"BOL": "Bolivia",
"BRB": "Barbados",
"BRN": "Brunei",
"CAF": "Central African Republic",
"CAN": "Canada",
"CHE": "Switzerland",
"CHL": "Chile",
"COG": "Congo",
"COL": "Colombia",
"CRI": "Costa Rica",
"CUB": "Cuba",
"CYP": "Cyprus",
"CZE": "Czechia",
"DEU": "Germany",
"DNK": "Denmark",
"DOM": "Dominican Republic",
"DZA": "Algeria",
"ECU": "Ecuador",
"EGY": "Egypt",
"ESP": "Spain",
"EST": "Estonia",
"FIN": "Finland",
"FJI": "Fiji",
"FRA": "France",
"FRO": "Faroe Islands",
"GEO": "Georgia",
"GIN": "Guinea",
"GLP": "Guadeloupe",
"GRC": "Greece",
"GRL": "Greenland",
"GTM": "Guatemala",
"GUF": "French Guiana",
"GUM": "Guam",
"GUY": "Guyana",
"HND": "Honduras",
"HRV": "Croatia",
"HUN": "Hungary",
"IRL": "Ireland",
"IRQ": "Iraq",
"ISL": "Iceland",
"ISR": "Israel",
"ITA": "Italy",
"JAM": "Jamaica",
"JOR": "Jordan",
"JPN": "Japan",
"KAZ": "Kazakhstan",
"KGZ": "Kyrgyzstan",
"KOR": "South Korea",
"KWT": "Kuwait",
"LBY": "Libya",
"LTU": "Lithuania",
"LUX": "Luxembourg",
"LVA": "Latvia",
"MAC": "Macao",
"MAR": "Morocco",
"MCO": "Monaco",
"MDA": "Moldova",
"MDV": "Maldives",
"MEX": "Mexico",
"MKD": "North Macedonia",
"MLT": "Malta",
"MNG": "Mongolia",
"MTQ": "Martinique",
"MUS": "Mauritius",
"MYS": "Malaysia",
"MYT": "Mayotte",
"NAM": "Namibia",
"NCL": "New Caledonia",
"NIC": "Nicaragua",
"NLD": "Netherlands",
"NOR": "Norway",
"NRU": "Nauru",
"NZL": "New Zealand",
"OMN": "Oman",
"PAK": "Pakistan",
"PAN": "Panama",
"PER": "Peru",
"PHL": "Philippines",
"PLW": "Palau",
"PNG": "Papua New Guinea",
"POL": "Poland",
"PRI": "Puerto Rico",
"PRT": "Portugal",
"PYF": "French Polynesia",
"QAT": "Qatar",
"REU": "Reunion",
"ROM": "Romania",
"RUS": "Russia",
"SGP": "Singapore",
"SHN": "Saint Helena",
"SLV": "El Salvador",
"SMR": "San Marino",
"SPM": "Saint Pierre and Miquelon",
"SRB": "Serbia",
"SVK": "Slovakia",
"SVN": "Slovenia",
"SWE": "Sweden",
"SYC": "Seychelles",
"TJK": "Tajikistan",
"TTO": "Trinidad and Tobago",
"TUN": "Tunisia",
"TUR": "Turkey",
"TWN": "Taiwan",
"UKR": "Ukraine",
"URY": "Uruguay",
"USA": "United States",
"UZB": "Uzbekistan",
"VEN": "Venezuela",
"VIR": "United States Virgin Islands",
"WSM": "Samoa",
"ZAF": "South Africa",
"GBREW": "England and Wales",
"GBRNI": "Northern Ireland",
"GBRSC": "Scotland",
"MON": "Yugoslavia"
}
Loading

0 comments on commit 7d89c47

Please sign in to comment.