-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from primap-community/read-dataset
Read dataset
- Loading branch information
Showing
21 changed files
with
1,298 additions
and
507 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
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 @@ | ||
Add a scripts that converts the downloaded data into IF and primap2 native format |
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,58 @@ | ||
""" | ||
Define tasks to download and read the FAO data set. | ||
""" | ||
import datalad.api | ||
|
||
|
||
def task_download(): | ||
""" | ||
Download latest data | ||
""" | ||
|
||
def datalad_run_download(): | ||
datalad.api.run( | ||
cmd="python3 scripts/download_all_domains.py", | ||
outputs="downloaded_data", | ||
) | ||
|
||
return {"actions": [datalad_run_download]} | ||
|
||
|
||
def task_read(): | ||
""" | ||
read data set | ||
""" | ||
|
||
def read_dataset(save_path, run_id): | ||
print(f"Reading dataset for {save_path=} and {run_id=}") | ||
cmd = ( | ||
f"python3 scripts/read_data_set.py " | ||
f"--save_path {save_path} --run_id {run_id}" | ||
) | ||
|
||
datalad.api.run( | ||
cmd=cmd, | ||
message="Read data set", | ||
outputs=f"{save_path}", | ||
) | ||
|
||
return { | ||
"actions": [read_dataset], | ||
"params": [ | ||
{ | ||
"name": "save_path", | ||
"short": "s", | ||
"long": "save_path", | ||
"default": "extracted_data", | ||
"help": "Path to save the data.", | ||
}, | ||
{ | ||
"name": "run_id", | ||
"long": "run_id", | ||
"short": "r", | ||
"default": "2024", | ||
"help": "Run identifier.", | ||
}, | ||
], | ||
"verbosity": 2, | ||
} |
1 change: 1 addition & 0 deletions
1
extracted_data/v2024-11-14/FAOSTAT_Agrifood_system_emissions_v2024-11-14.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 @@ | ||
../../.git/annex/objects/fQ/4m/MD5E-s4236841--55a238326c11e125114380c4502d7cf4.csv/MD5E-s4236841--55a238326c11e125114380c4502d7cf4.csv |
1 change: 1 addition & 0 deletions
1
extracted_data/v2024-11-14/FAOSTAT_Agrifood_system_emissions_v2024-11-14.nc
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 @@ | ||
../../.git/annex/objects/FX/kw/MD5E-s2607829--fa792e6284b6dc663c97a0c587210e07.nc/MD5E-s2607829--fa792e6284b6dc663c97a0c587210e07.nc |
22 changes: 22 additions & 0 deletions
22
extracted_data/v2024-11-14/FAOSTAT_Agrifood_system_emissions_v2024-11-14.yaml
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,22 @@ | ||
attrs: | ||
references: https://www.fao.org/faostat | ||
rights: Creative Commons Attribution-4.0 International licence (CC BY 4.0) | ||
contact: [email protected] | ||
title: Agrifood systems emissions | ||
comment: Published by Food and Agriculture Organization of the United Nations (FAO), | ||
converted to PRIMAP2 format by Daniel Busch | ||
institution: Food and Agriculture Organization of the United Nations | ||
area: area (ISO3) | ||
cat: category (FAOSTAT) | ||
scen: scenario (FAO) | ||
time_format: '%Y' | ||
dimensions: | ||
'*': | ||
- time | ||
- source | ||
- category (FAOSTAT) | ||
- area (ISO3) | ||
- scenario (FAO) | ||
- entity | ||
- unit | ||
data_file: FAOSTAT_Agrifood_system_emissions_v2024-11-14.csv |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,8 @@ | ||
"""Read the latest release of all available domains.""" | ||
|
||
from faostat_data_primap.read import ( | ||
read_latest_data, | ||
) | ||
|
||
if __name__ == "__main__": | ||
read_latest_data() |
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,31 @@ | ||
"""Read selected domains and versions.""" | ||
from pathlib import Path | ||
|
||
import click | ||
|
||
from faostat_data_primap.helper.definitions import domains_and_releases_to_read | ||
from faostat_data_primap.helper.paths import ( | ||
extracted_data_path, | ||
) | ||
from faostat_data_primap.read import ( | ||
read_data, | ||
) | ||
|
||
|
||
@click.command() | ||
@click.option("--run_id", default="2024", help="Configuration to run") | ||
@click.option("--save_path", default=None, help="Where to save data in root directory.") | ||
def run(run_id, save_path): | ||
"""Prepare and run read data function""" | ||
if not save_path: | ||
save_path = extracted_data_path | ||
else: | ||
save_path = Path(save_path) | ||
read_data( | ||
domains_and_releases_to_read=domains_and_releases_to_read[run_id], | ||
save_path=save_path, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
run() |
Oops, something went wrong.