-
-
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
704afce
commit ea87b56
Showing
6 changed files
with
124 additions
and
1 deletion.
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
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
32 changes: 32 additions & 0 deletions
32
etl/steps/data/meadow/agriculture/2024-05-23/jonsson_1998.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,32 @@ | ||
"""Load a snapshot and create a meadow 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. | ||
# | ||
# Retrieve snapshot and read its data. | ||
snap = paths.load_snapshot("jonsson_1998.csv") | ||
tb = snap.read() | ||
|
||
# | ||
# Process data. | ||
# | ||
# Add a country column. | ||
tb["country"] = "Iceland" | ||
|
||
# Format table conveniently. | ||
tb = tb.format() | ||
|
||
# | ||
# Save outputs. | ||
# | ||
# Create a new meadow dataset. | ||
ds_meadow = create_dataset(dest_dir, tables=[tb], check_variables_metadata=True) | ||
ds_meadow.save() |
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
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,30 @@ | ||
# Learn more at: | ||
# http://docs.owid.io/projects/etl/architecture/metadata/reference/ | ||
meta: | ||
origin: | ||
# Data product / Snapshot | ||
title: Changes in food consumption in Iceland, 1770-1940 | ||
title_snapshot: Changes in food consumption in Iceland, 1770-1940 - Daily calories in Iceland | ||
description: |- | ||
This dataset contains daily energy from Table 5 of Jonsson (1998) paper: "Changes in food consumption in Iceland, 1770-1940". | ||
date_published: "1998-01-01" | ||
|
||
# Citation | ||
producer: Jonsson | ||
citation_full: |- | ||
Jonsson, G.R. (1998), "Changes in food consumption in Iceland, 1770-1940". Scandinavian Economic History Review, 46, 24-41. | ||
Data extracted from Table 5. | ||
attribution_short: Jonsson (1998) | ||
|
||
# Files | ||
url_main: https://www.tandfonline.com/doi/abs/10.1080/03585522.1998.10414677 | ||
date_accessed: 2024-05-27 | ||
|
||
# License | ||
license: | ||
name: © Scandinavian Economic History Review 1998 | ||
url: https://www.tandfonline.com/doi/abs/10.1080/03585522.1998.10414677 | ||
outs: | ||
- md5: 9637e39deb3ff3064e125c5141d273f1 | ||
size: 180 | ||
path: jonsson_1998.csv |
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,50 @@ | ||
"""Script to create a snapshot of dataset.""" | ||
|
||
from io import StringIO | ||
from pathlib import Path | ||
|
||
import click | ||
import pandas as pd | ||
|
||
from etl.snapshot import Snapshot | ||
|
||
# Version for current snapshot dataset. | ||
SNAPSHOT_VERSION = Path(__file__).parent.name | ||
|
||
|
||
@click.command() | ||
@click.option("--upload/--skip-upload", default=True, type=bool, help="Upload dataset to Snapshot") | ||
def main(upload: bool) -> None: | ||
# Create a new snapshot. | ||
snap = Snapshot(f"agriculture/{SNAPSHOT_VERSION}/jonsson_1998.csv") | ||
|
||
# Data extracted using chatGPT 4o (and manually inspected and corrected). | ||
data = """ | ||
year,daily_calories | ||
1770,3048 | ||
1784,2322 | ||
1795,2724 | ||
1819,2887 | ||
1840,3080 | ||
1849,3381 | ||
1855,2917 | ||
1863,2885 | ||
1870,2573 | ||
1880,3002 | ||
1890,3106 | ||
1900,3316 | ||
1910,3499 | ||
1920,3610 | ||
1930,4207 | ||
1938,4066 | ||
""" | ||
|
||
# Create a dataframe with the extracted data. | ||
df = pd.read_csv(StringIO(data)) | ||
|
||
# Create snapshot. | ||
snap.create_snapshot(upload=upload, data=df) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |