Skip to content

Commit

Permalink
[DATALAD] Recorded changes
Browse files Browse the repository at this point in the history
  • Loading branch information
crdanielbusch committed Dec 27, 2024
1 parent eb76af3 commit 9d44195
Showing 1 changed file with 157 additions and 13 deletions.
170 changes: 157 additions & 13 deletions tests/unit/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,164 @@ def test_conversion_from_FAO_to_IPCC2006_PRIMAP():
# drop UNFCCC data
ds = ds.drop_sel(source="UNFCCC")

# We need a comversion CSV file for each entity
# agg_info_fao = {
# "category (FAOSTAT)" : {
# "4" : {
# "sources" : [
# "4.A",
# "4.B",
# ],
# "sel": {"variable": ["CO2"]},
# },
# }
# }
# ds_checked = ds.pr.add_aggregates_coordinates(agg_info=agg_info_fao)
# Checking consistency of category tree in FAO categorisation
# There are discrepancies of up to 100% due to rounding errors for small values
# theoretical example, 0.0001 (rounded from 0.00006) + 0.0004 (rounded from 0.00036)
# = 0.00042 which is then rounded to 0.0004, while the consistency check expects 0.0005
agg_info_fao = {
"category (FAOSTAT)": {
"1": {
"tolerance": 0.01,
"sources": [
"1.A",
"1.B",
],
"sel": {"variable": ["N2O", "CH4"]},
},
# 1.A.1 wheat
# rounding errors
"1.A.1.a": {
"tolerance": 1,
"sources": [
"1.A.1.a.i",
"1.A.1.a.ii",
],
"sel": {"variable": ["N2O"]},
},
"1.A.1": {
"tolerance": 0.01,
"sources": [
"1.A.1.a",
"1.A.1.b",
],
"sel": {"variable": ["N2O", "CH4"]},
},
# 1.A.2 rice
# rounding errors
"1.A.2.a": {
"tolerance": 1,
"sources": [
"1.A.2.a.i",
"1.A.2.a.ii",
],
"sel": {"variable": ["N2O"]},
},
"1.A.2": {
"tolerance": 0.01,
"sources": [
"1.A.2.a",
"1.A.2.b",
"1.A.2.c", # rice cultivation CH4
],
"sel": {"variable": ["N2O", "CH4"]},
},
# "1.A" : {
# "tolerance" : 0.01,
# "sources" : [
# "1.A.1",
# "1.A.2",
# "1.A.3",
# "1.A.4",
# "1.A.5",
# "1.A.6",
# "1.A.7",
# "1.A.8",
# "1.A.9",
# "1.A.10",
# "1.A.10",
# ],
# },
# potatoes
"1.A.3.a": {
"tolerance": 1,
"sources": [
"1.A.3.a.i",
"1.A.3.a.ii",
],
"sel": {"variable": ["N2O"]},
},
"1.A.3": {
"tolerance": 0.01,
"sources": [
"1.A.3.a",
],
"sel": {"variable": ["N2O"]},
},
# millet
"1.A.4.a": {
"tolerance": 1,
"sources": [
"1.A.4.a.i",
"1.A.4.a.ii",
],
"sel": {"variable": ["N2O"]},
},
"1.A.4": {
"tolerance": 0.01,
"sources": [
"1.A.4.a",
],
"sel": {"variable": ["N2O"]},
},
# barley
"1.A.5.a": {
"tolerance": 1,
"sources": [
"1.A.5.a.i",
"1.A.5.a.ii",
],
"sel": {"variable": ["N2O"]},
},
"1.A.5": {
"tolerance": 0.01,
"sources": [
"1.A.5.a",
],
"sel": {"variable": ["N2O"]},
},
# barley
"1.A.6.a": {
"tolerance": 1,
"sources": [
"1.A.6.a.i",
"1.A.6.a.ii",
],
"sel": {"variable": ["N2O"]},
},
"1.A.6": {
"tolerance": 0.01,
"sources": [
"1.A.6.a",
"1.A.6.b",
],
"sel": {"variable": ["N2O", "CH4"]},
},
"4": {
"tolerance": 0.01,
"sources": [
"4.A",
"4.B",
],
"sel": {"variable": ["CO2"]},
},
"6.B": {
# rounding errors, NLD looks problematic but hard to tell which value is right
"tolerance": 1,
"sources": [
"6.B.1",
"6.B.2",
"6.B.3",
"6.B.4",
"6.B.5",
],
"sel": {"variable": ["CH4", "N2O", "CO2"]},
},
}
}
ds_checked = ds.pr.add_aggregates_coordinates(agg_info=agg_info_fao) # noqa: F841

# ds_checked_if = ds_checked.pr.to_interchange_format()
# We need a comversion CSV file for each entity
# That's a temporary workaround until convert function can filter for data variables (entities)
conv = {}
gases = ["CO2", "CH4", "N2O"]
Expand Down

0 comments on commit 9d44195

Please sign in to comment.