hestia-earth-models 0.64.2__py3-none-any.whl → 0.64.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of hestia-earth-models might be problematic. Click here for more details.

Files changed (57) hide show
  1. hestia_earth/models/agribalyse2016/machineryInfrastructureDepreciatedAmountPerCycle.py +2 -2
  2. hestia_earth/models/cycle/animal/input/hestiaAggregatedData.py +5 -2
  3. hestia_earth/models/cycle/animal/input/properties.py +2 -1
  4. hestia_earth/models/cycle/animal/milkYield.py +2 -1
  5. hestia_earth/models/cycle/concentrateFeed.py +8 -8
  6. hestia_earth/models/cycle/cycleDuration.py +4 -5
  7. hestia_earth/models/cycle/siteDuration.py +15 -5
  8. hestia_earth/models/cycle/startDateDefinition.py +3 -4
  9. hestia_earth/models/cycle/stockingDensityAnimalHousingAverage.py +52 -0
  10. hestia_earth/models/fantkeEtAl2016/__init__.py +13 -0
  11. hestia_earth/models/fantkeEtAl2016/damageToHumanHealthParticulateMatterFormation.py +49 -0
  12. hestia_earth/models/frischknechtEtAl2000/__init__.py +13 -0
  13. hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +90 -0
  14. hestia_earth/models/ipcc2019/aboveGroundBiomass.py +762 -0
  15. hestia_earth/models/ipcc2019/aboveGroundBiomass_utils.py +180 -0
  16. hestia_earth/models/ipcc2019/animal/liveweightGain.py +89 -0
  17. hestia_earth/models/ipcc2019/animal/liveweightPerHead.py +89 -0
  18. hestia_earth/models/ipcc2019/animal/pastureGrass.py +51 -42
  19. hestia_earth/models/ipcc2019/animal/utils.py +20 -0
  20. hestia_earth/models/ipcc2019/animal/weightAtMaturity.py +15 -19
  21. hestia_earth/models/ipcc2019/ch4ToAirExcreta.py +2 -2
  22. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +37 -50
  23. hestia_earth/models/ipcc2019/organicCarbonPerHa_utils.py +0 -19
  24. hestia_earth/models/ipcc2019/pastureGrass.py +44 -31
  25. hestia_earth/models/ipcc2019/pastureGrass_utils.py +38 -22
  26. hestia_earth/models/mocking/search-results.json +228 -228
  27. hestia_earth/models/poschEtAl2008/terrestrialEutrophicationPotentialAccumulatedExceedance.py +40 -0
  28. hestia_earth/models/site/soilMeasurement.py +2 -2
  29. hestia_earth/models/utils/blank_node.py +20 -1
  30. hestia_earth/models/utils/crop.py +4 -0
  31. hestia_earth/models/utils/ecoClimateZone.py +99 -0
  32. hestia_earth/models/utils/emission.py +6 -2
  33. hestia_earth/models/utils/impact_assessment.py +10 -5
  34. hestia_earth/models/utils/lookup.py +5 -3
  35. hestia_earth/models/utils/productivity.py +1 -1
  36. hestia_earth/models/utils/property.py +2 -2
  37. hestia_earth/models/version.py +1 -1
  38. {hestia_earth_models-0.64.2.dist-info → hestia_earth_models-0.64.4.dist-info}/METADATA +1 -1
  39. {hestia_earth_models-0.64.2.dist-info → hestia_earth_models-0.64.4.dist-info}/RECORD +57 -35
  40. tests/models/cycle/test_siteDuration.py +22 -0
  41. tests/models/cycle/test_stockingDensityAnimalHousingAverage.py +42 -0
  42. tests/models/fantkeEtAl2016/__init__.py +0 -0
  43. tests/models/fantkeEtAl2016/test_damageToHumanHealthParticulateMatterFormation.py +20 -0
  44. tests/models/frischknechtEtAl2000/__init__.py +0 -0
  45. tests/models/frischknechtEtAl2000/test_ionisingRadiationKbqU235Eq.py +70 -0
  46. tests/models/ipcc2019/animal/test_liveweightGain.py +20 -0
  47. tests/models/ipcc2019/animal/test_liveweightPerHead.py +20 -0
  48. tests/models/ipcc2019/animal/test_pastureGrass.py +1 -1
  49. tests/models/ipcc2019/test_aboveGroundBiomass.py +182 -0
  50. tests/models/ipcc2019/test_aboveGroundBiomass_utils.py +92 -0
  51. tests/models/ipcc2019/test_organicCarbonPerHa_tier_1_utils.py +3 -2
  52. tests/models/ipcc2019/test_pastureGrass.py +2 -2
  53. tests/models/poschEtAl2008/test_terrestrialEutrophicationPotentialAccumulatedExceedance.py +44 -0
  54. tests/models/utils/test_ecoClimateZone.py +152 -0
  55. {hestia_earth_models-0.64.2.dist-info → hestia_earth_models-0.64.4.dist-info}/LICENSE +0 -0
  56. {hestia_earth_models-0.64.2.dist-info → hestia_earth_models-0.64.4.dist-info}/WHEEL +0 -0
  57. {hestia_earth_models-0.64.2.dist-info → hestia_earth_models-0.64.4.dist-info}/top_level.txt +0 -0
@@ -59,3 +59,25 @@ def test_run():
59
59
 
60
60
  value = run(data)
61
61
  assert float(value) == float(expected)
62
+
63
+
64
+ def test_run_temporary_crop():
65
+ with open(f"{fixtures_folder}/temporary-crop/cycle.jsonld", encoding='utf-8') as f:
66
+ data = json.load(f)
67
+
68
+ with open(f"{fixtures_folder}/result.txt", encoding='utf-8') as f:
69
+ expected = f.read().strip()
70
+
71
+ value = run(data)
72
+ assert float(value) == float(expected)
73
+
74
+
75
+ def test_run_permanent_crop():
76
+ with open(f"{fixtures_folder}/permanent-crop/cycle.jsonld", encoding='utf-8') as f:
77
+ data = json.load(f)
78
+
79
+ with open(f"{fixtures_folder}/result.txt", encoding='utf-8') as f:
80
+ expected = f.read().strip()
81
+
82
+ value = run(data)
83
+ assert float(value) == float(expected)
@@ -0,0 +1,42 @@
1
+ from unittest.mock import patch
2
+ import pytest
3
+ import json
4
+ from tests.utils import fixtures_path, fake_new_practice
5
+
6
+ from hestia_earth.models.cycle.stockingDensityAnimalHousingAverage import MODEL, TERM_ID, run, _should_run
7
+
8
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
9
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
+
11
+
12
+ @pytest.mark.parametrize(
13
+ 'test_name,cycle,expected_should_run',
14
+ [
15
+ (
16
+ 'no live animal => no run',
17
+ {'products': [{'term': {'termType': 'crop'}}]},
18
+ False
19
+ ),
20
+ (
21
+ 'with live animal => run',
22
+ {'products': [{'term': {'termType': 'liveAnimal'}}]},
23
+ True
24
+ ),
25
+ ]
26
+ )
27
+ @patch(f"{class_path}.get_lookup_value", return_value=10)
28
+ def test_should_run(mock_lookup, test_name, cycle, expected_should_run):
29
+ should_run, *args = _should_run(cycle)
30
+ assert should_run == expected_should_run, test_name
31
+
32
+
33
+ @patch(f"{class_path}._new_practice", side_effect=fake_new_practice)
34
+ def test_run(*args):
35
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
36
+ cycle = json.load(f)
37
+
38
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
39
+ expected = json.load(f)
40
+
41
+ result = run(cycle)
42
+ assert result == expected
File without changes
@@ -0,0 +1,20 @@
1
+ import json
2
+ from unittest.mock import patch
3
+
4
+ from hestia_earth.models.fantkeEtAl2016.damageToHumanHealthParticulateMatterFormation import MODEL, TERM_ID, run
5
+ from tests.utils import fixtures_path, fake_new_indicator
6
+
7
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
+
10
+
11
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
12
+ def test_run(mocked_indicator):
13
+ with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
14
+ impactassessment = json.load(f)
15
+
16
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
17
+ expected = json.load(f)
18
+
19
+ value = run(impactassessment)
20
+ assert value == expected
File without changes
@@ -0,0 +1,70 @@
1
+ import json
2
+ import pytest
3
+ from unittest.mock import patch
4
+ from tests.utils import fixtures_path, fake_new_indicator
5
+
6
+ from hestia_earth.models.frischknechtEtAl2000.ionisingRadiationKbqU235Eq import MODEL, TERM_ID, run, _should_run
7
+
8
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
9
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
+
11
+
12
+ @pytest.mark.parametrize(
13
+ 'test_name,impact,expected_should_run',
14
+ [
15
+ (
16
+ 'no emissionsResourceUse => no run',
17
+ {},
18
+ False
19
+ ),
20
+ (
21
+ 'no emissions in the lookups list => no run',
22
+ {
23
+ 'emissionsResourceUse': [
24
+ {
25
+ 'term': {'@id': 'co2ToAirInputsProduction'}
26
+ }
27
+ ]
28
+ },
29
+ False
30
+ ),
31
+ (
32
+ 'with emissions in the lookup list but no waste inputs => no run',
33
+ {
34
+ 'emissionsResourceUse': [
35
+ {
36
+ 'term': {'@id': 'ionisingCompoundsToAirInputsProduction'}
37
+ }
38
+ ]
39
+ },
40
+ False
41
+ ),
42
+ (
43
+ 'with emissions in the lookup list and waste inputs => run',
44
+ {
45
+ 'emissionsResourceUse': [
46
+ {
47
+ 'term': {'@id': 'ionisingCompoundsToAirInputsProduction'},
48
+ 'inputs': [{'termType': 'waste'}]
49
+ }
50
+ ]
51
+ },
52
+ True
53
+ )
54
+ ]
55
+ )
56
+ def test_should_run(test_name, impact, expected_should_run):
57
+ should_run, *args = _should_run(impact)
58
+ assert should_run == expected_should_run, test_name
59
+
60
+
61
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
62
+ def test_run(*args):
63
+ with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
64
+ impactassessment = json.load(f)
65
+
66
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
67
+ expected = json.load(f)
68
+
69
+ value = run(impactassessment)
70
+ assert value == expected
@@ -0,0 +1,20 @@
1
+ from unittest.mock import patch
2
+ import json
3
+ from tests.utils import fixtures_path, fake_new_property
4
+
5
+ from hestia_earth.models.ipcc2019.animal.liveweightGain import MODEL, TERM_ID, run
6
+
7
+ class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
8
+ fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
9
+
10
+
11
+ @patch(f"{class_path}._new_property", side_effect=fake_new_property)
12
+ def test_run(*args):
13
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
14
+ cycle = json.load(f)
15
+
16
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
17
+ expected = json.load(f)
18
+
19
+ value = run(cycle)
20
+ assert value == expected
@@ -0,0 +1,20 @@
1
+ from unittest.mock import patch
2
+ import json
3
+ from tests.utils import fixtures_path, fake_new_property
4
+
5
+ from hestia_earth.models.ipcc2019.animal.liveweightPerHead import MODEL, TERM_ID, run
6
+
7
+ class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
8
+ fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
9
+
10
+
11
+ @patch(f"{class_path}._new_property", side_effect=fake_new_property)
12
+ def test_run(*args):
13
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
14
+ cycle = json.load(f)
15
+
16
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
17
+ expected = json.load(f)
18
+
19
+ value = run(cycle)
20
+ assert value == expected
@@ -10,7 +10,7 @@ class_path_utils = f"hestia_earth.models.{MODEL}.pastureGrass_utils"
10
10
  fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{MODEL_KEY}"
11
11
 
12
12
 
13
- def fake_download_hestia(term_id: str, *args): return TERMS_BY_ID[term_id]
13
+ def fake_download_hestia(term_id: str, *args): return TERMS_BY_ID.get(term_id, {})
14
14
 
15
15
 
16
16
  @patch(f"{class_path_utils}.download_hestia", side_effect=fake_download_hestia)
@@ -0,0 +1,182 @@
1
+ import json
2
+ from numpy.typing import NDArray
3
+ from os.path import isfile
4
+ from pytest import mark
5
+ from unittest.mock import MagicMock, patch
6
+
7
+ from hestia_earth.models.ipcc2019.aboveGroundBiomass import (
8
+ _is_lcc_event, _rescale_category_cover, _should_run, MODEL, run, TERM_ID
9
+ )
10
+ from hestia_earth.models.ipcc2019.aboveGroundBiomass_utils import BiomassCategory, sample_constant
11
+
12
+ from tests.utils import fake_new_measurement, fixtures_path
13
+
14
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
15
+ utils_path = f"hestia_earth.models.{MODEL}.{TERM_ID}_utils"
16
+ term_path = "hestia_earth.models.utils.term"
17
+ property_path = "hestia_earth.models.utils.property"
18
+
19
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
20
+
21
+ _ITERATIONS = 1000
22
+
23
+
24
+ def _load_fixture(path: str, default=None):
25
+ if isfile(path):
26
+ with open(path, encoding="utf-8") as f:
27
+ return json.load(f)
28
+ return default
29
+
30
+
31
+ def _fake_calc_descriptive_stats(arr: NDArray, *_args, **_kwargs):
32
+ return {"value": [round(row[0], 6) for row in arr]}
33
+
34
+
35
+ # subfolder, should_run
36
+ PARAMS_SHOULD_RUN = [
37
+ ("forest-to-cropland", True),
38
+ ("forest-to-cropland-greater-than-100", True),
39
+ ("forest-to-cropland-less-than-100", True),
40
+ ("forest-to-cropland-lcc-q2", True),
41
+ ("forest-to-cropland-lcc-q3", True),
42
+ ("forest-to-cropland-lcc-q4", True),
43
+ ("forest-to-orchard", True),
44
+ ("forest-to-orchard-with-backup-factors", True),
45
+ ("forest-to-orchard-with-in-category-lcc", True),
46
+ ("historical-land-cover-mix", True),
47
+ ("historical-argentina-pasture", True),
48
+ ("historical-brazil-maize", True),
49
+ ("perennial-to-grassland-with-pasture-condition", True)
50
+ ]
51
+ IDS_SHOULD_RUN = [p[0] for p in PARAMS_SHOULD_RUN]
52
+
53
+
54
+ @mark.parametrize("subfolder, should_run", PARAMS_SHOULD_RUN, ids=IDS_SHOULD_RUN)
55
+ def test_should_run(subfolder: str, should_run: bool):
56
+ folder = f"{fixtures_folder}/{subfolder}"
57
+
58
+ site = _load_fixture(f"{folder}/site.jsonld", {})
59
+
60
+ result, *_ = _should_run(site)
61
+ assert result == should_run
62
+
63
+
64
+ def test_should_run_no_data():
65
+ SITE = {}
66
+ EXPECTED = False
67
+
68
+ result, *_ = _should_run(SITE)
69
+ assert result == EXPECTED
70
+
71
+
72
+ PARAMS_RUN = [subfolder for subfolder, should_run in PARAMS_SHOULD_RUN if should_run]
73
+
74
+
75
+ @mark.parametrize("subfolder", PARAMS_RUN)
76
+ @patch(f"{class_path}.calc_descriptive_stats", side_effect=_fake_calc_descriptive_stats)
77
+ @patch(f"{class_path}._new_measurement", side_effect=fake_new_measurement)
78
+ @patch(f"{utils_path}._get_sample_func", return_value=sample_constant)
79
+ def test_run(
80
+ _get_sample_func_mock: MagicMock,
81
+ _new_measurement_mock: MagicMock,
82
+ _calc_descriptive_stats_mock: MagicMock,
83
+ subfolder: str
84
+ ):
85
+ folder = f"{fixtures_folder}/{subfolder}"
86
+
87
+ site = _load_fixture(f"{folder}/site.jsonld", {})
88
+ expected = _load_fixture(f"{folder}/result.jsonld", [])
89
+
90
+ with patch(f"{class_path}._ITERATIONS", _ITERATIONS):
91
+ result = run(site)
92
+
93
+ assert result == expected
94
+
95
+
96
+ # subfolder
97
+ PARAMS_RUN_WITH_STATS = [
98
+ "forest-to-cropland-with-stats",
99
+ "forest-to-orchard-with-in-category-lcc-with-stats",
100
+ "historical-land-cover-mix-with-stats"
101
+ ]
102
+
103
+
104
+ @mark.parametrize("subfolder", PARAMS_RUN_WITH_STATS)
105
+ @patch(f"{class_path}._new_measurement", side_effect=fake_new_measurement)
106
+ def test_run_with_stats(
107
+ _new_measurement_mock: MagicMock,
108
+ subfolder: str
109
+ ):
110
+ folder = f"{fixtures_folder}/{subfolder}"
111
+
112
+ site = _load_fixture(f"{folder}/site.jsonld", {})
113
+ expected = _load_fixture(f"{folder}/result.jsonld", [])
114
+
115
+ with patch(f"{class_path}._ITERATIONS", _ITERATIONS):
116
+ result = run(site)
117
+
118
+ assert result == expected
119
+
120
+
121
+ # input, expected
122
+ PARAMS_RESCALE_CATEGORY_COVER = [
123
+ (
124
+ {BiomassCategory.ANNUAL_CROPS: 90},
125
+ {BiomassCategory.ANNUAL_CROPS: 90, BiomassCategory.OTHER: 10}
126
+ ),
127
+ (
128
+ {BiomassCategory.OTHER: 90},
129
+ {BiomassCategory.OTHER: 100}
130
+ ),
131
+ (
132
+ {BiomassCategory.ANNUAL_CROPS: 60, BiomassCategory.VINE: 60},
133
+ {BiomassCategory.ANNUAL_CROPS: 50, BiomassCategory.VINE: 50}
134
+ ),
135
+ (
136
+ {BiomassCategory.NATURAL_FOREST: 100},
137
+ {BiomassCategory.NATURAL_FOREST: 100}
138
+ )
139
+ ]
140
+ IDS_RESCALE_CATEGORY_COVER = ["fill", "fill w/ other", "squash", "do nothing"]
141
+
142
+
143
+ @mark.parametrize("input, expected", PARAMS_RESCALE_CATEGORY_COVER, ids=IDS_RESCALE_CATEGORY_COVER)
144
+ def test_rescale_category_cover(input: dict, expected: dict):
145
+ assert _rescale_category_cover(input) == expected
146
+
147
+
148
+ # a, b, expected
149
+ PARAMS_IS_LCC_EVENT = [
150
+ (
151
+ {
152
+ "appleTree": 33.333,
153
+ "pearTree": 33.333,
154
+ BiomassCategory.ANNUAL_CROPS: 33.334,
155
+ },
156
+ {
157
+ "appleTree": 33.33333,
158
+ "pearTree": 33.33333,
159
+ BiomassCategory.ANNUAL_CROPS: 33.33334,
160
+ },
161
+ True
162
+ ),
163
+ (
164
+ {
165
+ "appleTree": 33.3333,
166
+ "pearTree": 33.3333,
167
+ BiomassCategory.ANNUAL_CROPS: 33.3334,
168
+ },
169
+ {
170
+ "appleTree": 33.33333,
171
+ "pearTree": 33.33333,
172
+ BiomassCategory.ANNUAL_CROPS: 33.33334,
173
+ },
174
+ False
175
+ )
176
+ ]
177
+ IDS_IS_LCC_EVENT = ["True", "False"]
178
+
179
+
180
+ @mark.parametrize("a, b, expected", PARAMS_IS_LCC_EVENT, ids=IDS_IS_LCC_EVENT)
181
+ def test_is_lcc_event(a: dict, b: dict, expected: bool):
182
+ assert _is_lcc_event(a, b) is expected
@@ -0,0 +1,92 @@
1
+ from pytest import mark
2
+
3
+ from itertools import product
4
+ from hestia_earth.models.ipcc2019.aboveGroundBiomass_utils import (
5
+ _build_col_name, _get_sample_func, assign_biomass_category, BiomassCategory, EcoClimateZone,
6
+ sample_biomass_equilibrium, sample_constant, sample_plus_minus_error
7
+ )
8
+
9
+ _ITERATIONS = 1000
10
+
11
+
12
+ # kwargs, sample_func, expected_shape
13
+ PARAMS_GET_SAMPLE_FUNC = [
14
+ ({"value": 1}, sample_constant),
15
+ ({"value": 1, "error": 10}, sample_plus_minus_error),
16
+ ]
17
+ IDS_GET_SAMPLE_FUNC = ["constant", "+/- error"]
18
+
19
+
20
+ @mark.parametrize("kwargs, sample_func", PARAMS_GET_SAMPLE_FUNC, ids=IDS_GET_SAMPLE_FUNC)
21
+ def test_get_sample_func(kwargs, sample_func):
22
+ result = _get_sample_func(kwargs)
23
+ assert result == sample_func
24
+
25
+
26
+ PARAMS_BIOMASS = [p for p in product(BiomassCategory, EcoClimateZone)]
27
+ IDS_BIOMASS = [f"{p[0].name} + {p[1].name}" for p in PARAMS_BIOMASS]
28
+
29
+
30
+ @mark.parametrize("biomass_category, eco_climate_zone", PARAMS_BIOMASS, ids=IDS_BIOMASS)
31
+ def test_sample_biomass_equilibrium(biomass_category, eco_climate_zone):
32
+ EXPECTED_SHAPE = (1, _ITERATIONS)
33
+ result = sample_biomass_equilibrium(_ITERATIONS, biomass_category, eco_climate_zone)
34
+ assert result.shape == EXPECTED_SHAPE
35
+
36
+
37
+ # input, expected
38
+ PARAMS_ASSIGN_BIOMASS_CATEGORY = [
39
+ ("Annual crops", BiomassCategory.ANNUAL_CROPS),
40
+ ("Coconut", BiomassCategory.COCONUT),
41
+ ("Forest", BiomassCategory.FOREST),
42
+ ("Grassland", BiomassCategory.GRASSLAND),
43
+ ("Jatropha", BiomassCategory.JATROPHA),
44
+ ("Jojoba", BiomassCategory.JOJOBA),
45
+ ("Natural forest", BiomassCategory.NATURAL_FOREST),
46
+ ("Oil palm", BiomassCategory.OIL_PALM),
47
+ ("Olive", BiomassCategory.OLIVE),
48
+ ("Orchard", BiomassCategory.ORCHARD),
49
+ ("Other", BiomassCategory.OTHER),
50
+ ("Plantation forest", BiomassCategory.PLANTATION_FOREST),
51
+ ("Rubber", BiomassCategory.RUBBER),
52
+ ("Short rotation coppice", BiomassCategory.SHORT_ROTATION_COPPICE),
53
+ ("Tea", BiomassCategory.TEA),
54
+ ("Vine", BiomassCategory.VINE),
55
+ ("Woody perennial", BiomassCategory.WOODY_PERENNIAL),
56
+ ("Miscellaneous value", None)
57
+ ]
58
+ IDS_ASSIGN_BIOMASS_CATEGORY = [p[0] for p in PARAMS_ASSIGN_BIOMASS_CATEGORY]
59
+
60
+
61
+ @mark.parametrize("input, expected", PARAMS_ASSIGN_BIOMASS_CATEGORY, ids=IDS_ASSIGN_BIOMASS_CATEGORY)
62
+ def test_assign_biomass_category(input: str, expected: BiomassCategory):
63
+ assert assign_biomass_category(input) == expected
64
+
65
+
66
+ # input, expected
67
+ PARAMS_BUILD_COLUMN_NAME = [
68
+ (BiomassCategory.ANNUAL_CROPS, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_ANNUAL_CROPS"),
69
+ (BiomassCategory.COCONUT, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_COCONUT"),
70
+ (BiomassCategory.FOREST, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_FOREST"),
71
+ (BiomassCategory.GRASSLAND, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_GRASSLAND"),
72
+ (BiomassCategory.JATROPHA, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_JATROPHA"),
73
+ (BiomassCategory.JOJOBA, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_JOJOBA"),
74
+ (BiomassCategory.NATURAL_FOREST, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_NATURAL_FOREST"),
75
+ (BiomassCategory.OIL_PALM, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_OIL_PALM"),
76
+ (BiomassCategory.OLIVE, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_OLIVE"),
77
+ (BiomassCategory.ORCHARD, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_ORCHARD"),
78
+ (BiomassCategory.OTHER, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_OTHER"),
79
+ (BiomassCategory.PLANTATION_FOREST, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_PLANTATION_FOREST"),
80
+ (BiomassCategory.RUBBER, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_RUBBER"),
81
+ (BiomassCategory.SHORT_ROTATION_COPPICE, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_SHORT_ROTATION_COPPICE"),
82
+ (BiomassCategory.TEA, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_TEA"),
83
+ (BiomassCategory.VINE, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_VINE"),
84
+ (BiomassCategory.WOODY_PERENNIAL, "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_WOODY_PERENNIAL"),
85
+ ("Miscellaneous value", "AG_BIOMASS_EQUILIBRIUM_KG_C_HECTARE_OTHER")
86
+ ]
87
+ IDS_BUILD_COLUMN_NAME = [p[0] for p in PARAMS_BUILD_COLUMN_NAME]
88
+
89
+
90
+ @mark.parametrize("input, expected", PARAMS_BUILD_COLUMN_NAME, ids=IDS_BUILD_COLUMN_NAME)
91
+ def test_build_col_name(input: BiomassCategory, expected: str):
92
+ assert _build_col_name(input) == expected
@@ -5,10 +5,11 @@ from numpy.testing import assert_array_almost_equal
5
5
  from pytest import mark
6
6
  from unittest.mock import MagicMock, patch
7
7
 
8
+ from hestia_earth.models.utils.ecoClimateZone import EcoClimateZone
8
9
  from hestia_earth.models.ipcc2019.organicCarbonPerHa import MODEL, TERM_ID
9
10
  from hestia_earth.models.ipcc2019.organicCarbonPerHa_utils import (
10
- EcoClimateZone, IpccCarbonInputCategory, IpccLandUseCategory, IpccManagementCategory,
11
- IpccSoilCategory, sample_constant, sample_plus_minus_error, sample_plus_minus_uncertainty
11
+ IpccCarbonInputCategory, IpccLandUseCategory, IpccManagementCategory, IpccSoilCategory, sample_constant,
12
+ sample_plus_minus_error, sample_plus_minus_uncertainty
12
13
  )
13
14
  from hestia_earth.models.ipcc2019.organicCarbonPerHa_tier_1_utils import (
14
15
  _assign_ipcc_carbon_input_category, _assign_ipcc_land_use_category, _assign_ipcc_management_category,
@@ -27,11 +27,11 @@ TERMS_BY_ID = {
27
27
  ]
28
28
  },
29
29
  'energyContentHigherHeatingValue': {'units': 'MJ / kg'},
30
- 'energyDigestibilityRuminants': {'units': '%'},
30
+ 'energyDigestibilityRuminants': {'units': '%'}
31
31
  }
32
32
 
33
33
 
34
- def fake_download_hestia(term_id: str, *args): return TERMS_BY_ID[term_id]
34
+ def fake_download_hestia(term_id: str, *args): return TERMS_BY_ID.get(term_id, {})
35
35
 
36
36
 
37
37
  @patch(f"{class_path_utils}.download_hestia", side_effect=fake_download_hestia)
@@ -0,0 +1,44 @@
1
+ import json
2
+ from unittest.mock import patch
3
+
4
+ from hestia_earth.models.poschEtAl2008.terrestrialEutrophicationPotentialAccumulatedExceedance import MODEL, TERM_ID, \
5
+ run
6
+ from tests.utils import fixtures_path, fake_new_indicator
7
+
8
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
9
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
+
11
+
12
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
13
+ def test_run(*args):
14
+ with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
15
+ cycle = json.load(f)
16
+
17
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
+ expected = json.load(f)
19
+
20
+ value = run(cycle)
21
+ assert value == expected
22
+
23
+
24
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
25
+ def test_lookup_to_bad_country(*args):
26
+ with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
27
+ cycle = json.load(f)
28
+ cycle['country']['@id'] = "example-land-not-real"
29
+
30
+ value = run(cycle)
31
+ assert value['value'] is None
32
+
33
+
34
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
35
+ def test_lookup_no_term_type(*args):
36
+ """
37
+ We currently do not filter out bad termTypes so this is expected behavior.
38
+ """
39
+ with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
40
+ cycle = json.load(f)
41
+ del cycle['emissionsResourceUse'][0]['term']['termType']
42
+
43
+ value = run(cycle)
44
+ assert value['value'] == 7.47