hestia-earth-models 0.67.0__py3-none-any.whl → 0.67.1__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.
- hestia_earth/models/cml2001Baseline/resourceUseEnergyDepletionDuringCycle.py +5 -10
- hestia_earth/models/cycle/completeness/freshForage.py +7 -3
- hestia_earth/models/cycle/inorganicFertiliser.py +67 -17
- hestia_earth/models/environmentalFootprintV3_1/environmentalFootprintSingleOverallScore.py +42 -37
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandTransformation.py +22 -14
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexTotalLandUseEffects.py +17 -15
- hestia_earth/models/hestia/landTransformation100YearAverageDuringCycle.py +1 -1
- hestia_earth/models/hestia/landTransformation20YearAverageDuringCycle.py +1 -1
- hestia_earth/models/ipcc2019/aboveGroundBiomass.py +1 -1
- hestia_earth/models/ipcc2019/belowGroundBiomass.py +1 -1
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +4 -4
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +1 -1
- hestia_earth/models/mocking/search-results.json +1173 -1041
- hestia_earth/models/utils/blank_node.py +64 -11
- hestia_earth/models/utils/ecoClimateZone.py +2 -2
- hestia_earth/models/utils/impact_assessment.py +5 -4
- hestia_earth/models/utils/lookup.py +3 -5
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.67.0.dist-info → hestia_earth_models-0.67.1.dist-info}/METADATA +1 -1
- {hestia_earth_models-0.67.0.dist-info → hestia_earth_models-0.67.1.dist-info}/RECORD +29 -29
- tests/models/cml2001Baseline/test_resourceUseEnergyDepletionDuringCycle.py +68 -35
- tests/models/environmentalFootprintV3_1/test_environmentalFootprintSingleOverallScore.py +38 -8
- tests/models/environmentalFootprintV3_1/test_soilQualityIndexLandTransformation.py +65 -36
- tests/models/site/test_management.py +1 -4
- tests/models/utils/test_blank_node.py +13 -165
- tests/orchestrator/models/test_transformations.py +4 -1
- {hestia_earth_models-0.67.0.dist-info → hestia_earth_models-0.67.1.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.67.0.dist-info → hestia_earth_models-0.67.1.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.67.0.dist-info → hestia_earth_models-0.67.1.dist-info}/top_level.txt +0 -0
@@ -22,91 +22,120 @@ def fake_rounded_indicator(value: float):
|
|
22
22
|
crop_land = {"@id": "cropland", "termType": "landCover"}
|
23
23
|
sea_land_cover = {"@id": "seaOrOcean", "termType": "landCover"}
|
24
24
|
forest = {"@id": "forest", "termType": "landCover"}
|
25
|
-
|
25
|
+
|
26
|
+
indicator_inputs_production = {
|
26
27
|
"@id": "landTransformation20YearAverageInputsProduction",
|
27
28
|
"termType": "resourceUse",
|
28
29
|
"units": "m2 / year"
|
29
30
|
}
|
31
|
+
|
32
|
+
indicator_during_cycle = {
|
33
|
+
"@id": "landTransformation20YearAverageDuringCycle",
|
34
|
+
"termType": "resourceUse",
|
35
|
+
"units": "m2 / year"
|
36
|
+
}
|
37
|
+
|
30
38
|
wrong_indicator = {"term": {"@id": "NOT_VALID_INDICATOR_ID", "termType": "resourceUse", "units": "m2 / year"},
|
31
39
|
"value": 0.5, "landCover": crop_land, "previousLandCover": forest}
|
32
40
|
|
33
41
|
indicator_no_land_cover = {
|
34
|
-
"term":
|
42
|
+
"term": indicator_during_cycle,
|
35
43
|
"previousLandCover": forest,
|
36
44
|
"value": 0.5}
|
37
45
|
|
38
46
|
indicator_no_previous_land_cover = {
|
39
|
-
"term":
|
47
|
+
"term": indicator_during_cycle,
|
40
48
|
"landCover": crop_land,
|
41
49
|
"value": 0.5}
|
42
50
|
|
43
51
|
indicator_bad_area_value = {
|
44
|
-
"term":
|
52
|
+
"term": indicator_during_cycle,
|
45
53
|
"value": -10,
|
46
54
|
"previousLandCover": forest,
|
47
55
|
"landCover": crop_land}
|
48
56
|
|
57
|
+
indicator_zero_area_value = {
|
58
|
+
"term": indicator_during_cycle,
|
59
|
+
"value": 0,
|
60
|
+
"previousLandCover": forest,
|
61
|
+
"landCover": crop_land}
|
62
|
+
|
49
63
|
inputs_production_indicator_from_forest_to_no_cf = {
|
50
|
-
"term":
|
64
|
+
"term": indicator_inputs_production,
|
65
|
+
"value": 0.5,
|
66
|
+
"previousLandCover": forest,
|
67
|
+
"landCover": sea_land_cover}
|
68
|
+
|
69
|
+
during_cycle_indicator_from_forest_to_no_cf = {
|
70
|
+
"term": indicator_during_cycle,
|
51
71
|
"value": 0.5,
|
52
72
|
"previousLandCover": forest,
|
53
73
|
"landCover": sea_land_cover}
|
54
74
|
|
55
75
|
good_inputs_production_indicator_from_forest_to_cropland = {
|
56
|
-
"term":
|
76
|
+
"term": indicator_inputs_production,
|
57
77
|
"value": 0.5,
|
58
78
|
"previousLandCover": forest,
|
59
79
|
"landCover": crop_land}
|
60
80
|
|
61
81
|
good_inputs_production_indicator_from_forest_to_forest = {
|
62
|
-
"term":
|
82
|
+
"term": indicator_inputs_production,
|
63
83
|
"value": 0.5,
|
64
84
|
"previousLandCover": forest,
|
65
85
|
"landCover": forest}
|
66
86
|
|
67
87
|
good_during_cycle_indicator_from_forest_to_cropland = {
|
68
|
-
"term":
|
88
|
+
"term": indicator_during_cycle,
|
69
89
|
"value": 0.5,
|
70
90
|
"previousLandCover": forest,
|
71
91
|
"landCover": crop_land}
|
72
92
|
|
73
93
|
good_during_cycle_indicator_from_forest_to_forest = {
|
74
|
-
"term":
|
94
|
+
"term": indicator_during_cycle,
|
75
95
|
"value": 0.5,
|
76
96
|
"previousLandCover": forest,
|
77
97
|
"landCover": forest}
|
78
98
|
|
79
99
|
|
80
100
|
@mark.parametrize(
|
81
|
-
"resources, expected, num_inputs",
|
101
|
+
"test_name, resources, expected, num_inputs",
|
82
102
|
[
|
83
|
-
([], False, 0),
|
84
|
-
([wrong_indicator], False, 0),
|
85
|
-
([indicator_no_land_cover], False, 0),
|
86
|
-
([indicator_no_previous_land_cover], False, 0),
|
87
|
-
([indicator_bad_area_value], False, 0),
|
88
|
-
(
|
89
|
-
|
90
|
-
|
91
|
-
([
|
92
|
-
(
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
103
|
+
("No emissionsResourceUse => no run, 0 dict", [], False, 0),
|
104
|
+
("Wrong indicator termid => no run, 0 dict", [wrong_indicator], False, 0),
|
105
|
+
("Indicator no landcover terms => no run", [indicator_no_land_cover], False, 0),
|
106
|
+
("Indicator no previousLandCover terms => no run", [indicator_no_previous_land_cover], False, 0),
|
107
|
+
("Bad m2 / year area value => no run", [indicator_bad_area_value], False, 0),
|
108
|
+
("One good and one Bad m2 / year area value => no run", [
|
109
|
+
good_during_cycle_indicator_from_forest_to_cropland,
|
110
|
+
indicator_bad_area_value], False, 1),
|
111
|
+
("One 0 m2 / year area value => filter and run, 0 dict", [indicator_zero_area_value], True, 1),
|
112
|
+
("One good during cycle transformation => run, 1 dict", [good_during_cycle_indicator_from_forest_to_cropland
|
113
|
+
], True, 1),
|
114
|
+
("One 0 during cycle transformation => run, 1 dict", [good_during_cycle_indicator_from_forest_to_forest
|
115
|
+
], True, 1),
|
116
|
+
("Only one good inputs production transformation => no run", [
|
117
|
+
good_inputs_production_indicator_from_forest_to_cropland], False, 1),
|
118
|
+
("Good during cycle AND inputs production transformation => run, 2 dict", [
|
119
|
+
good_during_cycle_indicator_from_forest_to_cropland,
|
120
|
+
good_inputs_production_indicator_from_forest_to_cropland], True, 2),
|
121
|
+
("One 0 inputs production transformation => no run", [
|
122
|
+
good_inputs_production_indicator_from_forest_to_forest], False, 1),
|
123
|
+
("Good during cycle AND inputs production 0 transformation => run, 2 dict", [
|
124
|
+
good_during_cycle_indicator_from_forest_to_cropland,
|
125
|
+
good_inputs_production_indicator_from_forest_to_forest], True, 2),
|
126
|
+
("One transformation with no CF (ocean) => run, 0 dict", [during_cycle_indicator_from_forest_to_no_cf
|
127
|
+
], True, 0),
|
128
|
+
("One good from transformation and One with no CF (ocean) => run, 1 dict", [
|
129
|
+
good_inputs_production_indicator_from_forest_to_cropland,
|
130
|
+
during_cycle_indicator_from_forest_to_no_cf], True, 1),
|
131
|
+
("Multiple good indicators => run, 2 dict", [good_inputs_production_indicator_from_forest_to_cropland,
|
132
|
+
good_during_cycle_indicator_from_forest_to_cropland], True, 2),
|
133
|
+
("One good, one wrong indicator => filter and run, 1 dict", [
|
134
|
+
good_during_cycle_indicator_from_forest_to_cropland,
|
135
|
+
wrong_indicator], True, 1),
|
136
|
+
]
|
108
137
|
)
|
109
|
-
def test_should_run(resources: list, expected: bool, num_inputs: int):
|
138
|
+
def test_should_run(test_name: str, resources: list, expected: bool, num_inputs: int):
|
110
139
|
with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
|
111
140
|
impact = json.load(f)
|
112
141
|
|
@@ -18,10 +18,7 @@ _LAND_COVER_TERM_BY_SITE_TYPE = {
|
|
18
18
|
_folders = [d for d in os.listdir(fixtures_folder) if os.path.isdir(os.path.join(fixtures_folder, d))]
|
19
19
|
|
20
20
|
|
21
|
-
@pytest.mark.parametrize(
|
22
|
-
"folder",
|
23
|
-
_folders
|
24
|
-
)
|
21
|
+
@pytest.mark.parametrize('folder', _folders)
|
25
22
|
@patch(
|
26
23
|
f"{class_path}.get_landCover_term_id_from_site_type",
|
27
24
|
side_effect=lambda site_type: _LAND_COVER_TERM_BY_SITE_TYPE[site_type]
|
@@ -30,178 +30,26 @@ from hestia_earth.models.utils.blank_node import (
|
|
30
30
|
|
31
31
|
|
32
32
|
class_path = "hestia_earth.models.utils.blank_node"
|
33
|
-
|
33
|
+
fixtures_folder = os.path.join(fixtures_path, 'utils', 'blank_node')
|
34
|
+
measurement_fixtures_folder = os.path.join(fixtures_path, 'utils', 'measurement')
|
35
|
+
|
36
|
+
condense_fixtures_folder = os.path.join(fixtures_folder, 'condense-nodes')
|
37
|
+
condense_folders = [
|
38
|
+
d for d in os.listdir(condense_fixtures_folder) if os.path.isdir(os.path.join(condense_fixtures_folder, d))
|
39
|
+
]
|
34
40
|
|
35
|
-
fixtures_path = os.path.join(fixtures_path, 'utils', 'blank_node')
|
36
41
|
|
42
|
+
@pytest.mark.parametrize('folder', condense_folders)
|
43
|
+
def test_condense_nodes(folder: str):
|
44
|
+
fixture_path = os.path.join(condense_fixtures_folder, folder)
|
37
45
|
|
38
|
-
|
39
|
-
with open(f"{fixtures_path}/condense-nodes/original.jsonld", encoding='utf-8') as f:
|
46
|
+
with open(f"{fixture_path}/original.jsonld", encoding='utf-8') as f:
|
40
47
|
original = json.load(f)
|
41
|
-
with open(f"{
|
48
|
+
with open(f"{fixture_path}/result.jsonld", encoding='utf-8') as f:
|
42
49
|
expected = json.load(f)
|
43
50
|
|
44
51
|
value = condense_nodes(original)
|
45
|
-
assert value == expected
|
46
|
-
|
47
|
-
|
48
|
-
@pytest.mark.parametrize(
|
49
|
-
"test_name,input_nodes,expected_output_nodes",
|
50
|
-
[
|
51
|
-
(
|
52
|
-
"No match",
|
53
|
-
[
|
54
|
-
{"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
|
55
|
-
"value": [2]},
|
56
|
-
{"startDate": "2003", "endDate": "2004", "term": {"@id": "bananaPlant", "units": "% area"},
|
57
|
-
"value": [2]},
|
58
|
-
],
|
59
|
-
[
|
60
|
-
{"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
|
61
|
-
"value": [2]},
|
62
|
-
{"startDate": "2003", "endDate": "2004", "term": {"@id": "bananaPlant", "units": "% area"},
|
63
|
-
"value": [2]},
|
64
|
-
],
|
65
|
-
),
|
66
|
-
(
|
67
|
-
"No continuity",
|
68
|
-
[
|
69
|
-
{"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
|
70
|
-
"value": [2]},
|
71
|
-
{"startDate": "2004", "endDate": "2005", "term": {"@id": "treeNutTree", "units": "% area"},
|
72
|
-
"value": [2]},
|
73
|
-
],
|
74
|
-
[
|
75
|
-
{"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
|
76
|
-
"value": [2]},
|
77
|
-
{"startDate": "2004", "endDate": "2005", "term": {"@id": "treeNutTree", "units": "% area"},
|
78
|
-
"value": [2]},
|
79
|
-
],
|
80
|
-
),
|
81
|
-
(
|
82
|
-
"No continuity (multiple values differ)",
|
83
|
-
[
|
84
|
-
{"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
|
85
|
-
"value": [10, 20]},
|
86
|
-
{"startDate": "2003", "endDate": "2004", "term": {"@id": "treeNutTree", "units": "% area"},
|
87
|
-
"value": [10, 30]},
|
88
|
-
],
|
89
|
-
[
|
90
|
-
{"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
|
91
|
-
"value": [10, 20]},
|
92
|
-
{"startDate": "2003", "endDate": "2004", "term": {"@id": "treeNutTree", "units": "% area"},
|
93
|
-
"value": [10, 30]},
|
94
|
-
],
|
95
|
-
),
|
96
|
-
(
|
97
|
-
"2-1 condense (YYYY dates)",
|
98
|
-
[
|
99
|
-
{"startDate": "2001", "endDate": "2001", "term": {"@id": "treeNutTree", "units": "% area"},
|
100
|
-
"value": [10, 20]},
|
101
|
-
{"startDate": "2002", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
|
102
|
-
"value": [10, 20]},
|
103
|
-
],
|
104
|
-
[
|
105
|
-
{"startDate": "2001", "endDate": "2002", "term": {"@id": "treeNutTree", "units": "% area"},
|
106
|
-
"value": [10, 20]}
|
107
|
-
],
|
108
|
-
),
|
109
|
-
(
|
110
|
-
"4-2 condense (YYYY-MM dates)",
|
111
|
-
[
|
112
|
-
{"startDate": "2001-01", "endDate": "2002-01", "term": {"@id": "treeNutTree", "units": "% area"},
|
113
|
-
"value": [2]},
|
114
|
-
{"startDate": "2002-01", "endDate": "2002-03", "term": {"@id": "treeNutTree", "units": "% area"},
|
115
|
-
"value": [2]},
|
116
|
-
],
|
117
|
-
[
|
118
|
-
{"startDate": "2001-01", "endDate": "2002-03", "term": {"@id": "treeNutTree", "units": "% area"},
|
119
|
-
"value": [2]}
|
120
|
-
],
|
121
|
-
),
|
122
|
-
(
|
123
|
-
"2-1 condense (YYYY-MM-DD dates)",
|
124
|
-
[
|
125
|
-
{"startDate": "2001-01-01", "endDate": "2001-12-31", "term": {"@id": "treeNutTree", "units": "% area"},
|
126
|
-
"value": [2]},
|
127
|
-
{"startDate": "2002-01-01", "endDate": "2002-05-04", "term": {"@id": "treeNutTree", "units": "% area"},
|
128
|
-
"value": [2]},
|
129
|
-
],
|
130
|
-
[
|
131
|
-
{"startDate": "2001-01-01", "endDate": "2002-05-04", "term": {"@id": "treeNutTree", "units": "% area"},
|
132
|
-
"value": [2]}
|
133
|
-
],
|
134
|
-
),
|
135
|
-
(
|
136
|
-
"3-1-condense",
|
137
|
-
[
|
138
|
-
{"startDate": "2001-01-01", "endDate": "2001-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
|
139
|
-
"value": [9]},
|
140
|
-
{"startDate": "2002-01-01", "endDate": "2002-10-31", "term": {"@id": "bananaPlant", "units": "% area"},
|
141
|
-
"value": [9]},
|
142
|
-
{"startDate": "2002-11-01", "endDate": "2004-04-05", "term": {"@id": "bananaPlant", "units": "% area"},
|
143
|
-
"value": [9]},
|
144
|
-
],
|
145
|
-
[
|
146
|
-
{"startDate": "2001-01-01", "endDate": "2004-04-05", "term": {"@id": "bananaPlant", "units": "% area"},
|
147
|
-
"value": [9]}
|
148
|
-
],
|
149
|
-
),
|
150
|
-
(
|
151
|
-
"3-2-partial-condense",
|
152
|
-
[
|
153
|
-
{"startDate": "2001-01-01", "endDate": "2001-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
|
154
|
-
"value": [9]},
|
155
|
-
{"startDate": "2012-02-01", "endDate": "2012-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
|
156
|
-
"value": [9]},
|
157
|
-
{"startDate": "2002-01-01", "endDate": "2003-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
|
158
|
-
"value": [9]},
|
159
|
-
],
|
160
|
-
[
|
161
|
-
{"startDate": "2001-01-01", "endDate": "2003-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
|
162
|
-
"value": [9]},
|
163
|
-
{"startDate": "2012-02-01", "endDate": "2012-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
|
164
|
-
"value": [9]},
|
165
|
-
],
|
166
|
-
),
|
167
|
-
(
|
168
|
-
"7-2-multi-condense",
|
169
|
-
[
|
170
|
-
{"startDate": "2001-01-01", "endDate": "2001-11-30", "term": {"@id": "bananaPlant", "units": "% area"},
|
171
|
-
"value": [7]},
|
172
|
-
{"startDate": "2012-02-01", "endDate": "2012-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
|
173
|
-
"value": [7]},
|
174
|
-
{"startDate": "2001-12-01", "endDate": "2001-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
|
175
|
-
"value": [7]},
|
176
|
-
{"startDate": "2002-01-01", "endDate": "2002-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
|
177
|
-
"value": [7]},
|
178
|
-
{"startDate": "2013-01-01", "endDate": "2013-05-20", "term": {"@id": "bananaPlant", "units": "% area"},
|
179
|
-
"value": [7]},
|
180
|
-
],
|
181
|
-
[
|
182
|
-
{"startDate": "2001-01-01", "endDate": "2002-12-31", "term": {"@id": "bananaPlant", "units": "% area"},
|
183
|
-
"value": [7]},
|
184
|
-
{"startDate": "2012-02-01", "endDate": "2013-05-20", "term": {"@id": "bananaPlant", "units": "% area"},
|
185
|
-
"value": [7]}
|
186
|
-
],
|
187
|
-
),
|
188
|
-
(
|
189
|
-
"same-blank-nodes-sum",
|
190
|
-
[
|
191
|
-
{"startDate": "2001-01-01", "endDate": "2001-11-30", "term": {"@id": "bananaPlant", "units": "% area"},
|
192
|
-
"value": [50]},
|
193
|
-
{"startDate": "2001-01-01", "endDate": "2001-11-30", "term": {"@id": "bananaPlant", "units": "% area"},
|
194
|
-
"value": [50]}
|
195
|
-
],
|
196
|
-
[
|
197
|
-
{"startDate": "2001-01-01", "endDate": "2001-11-30", "term": {"@id": "bananaPlant", "units": "% area"},
|
198
|
-
"value": [100]}
|
199
|
-
]
|
200
|
-
)
|
201
|
-
]
|
202
|
-
)
|
203
|
-
def test_condense_nodes_(test_name, input_nodes, expected_output_nodes):
|
204
|
-
assert condense_nodes(input_nodes) == expected_output_nodes
|
52
|
+
assert value == expected, folder
|
205
53
|
|
206
54
|
|
207
55
|
def test_run_required():
|
@@ -2,13 +2,16 @@ from unittest.mock import patch
|
|
2
2
|
import json
|
3
3
|
import os
|
4
4
|
|
5
|
-
from tests.utils import fixtures_path
|
5
|
+
from tests.utils import fixtures_path, fake_new_emission, fake_new_product, fake_new_input
|
6
6
|
from hestia_earth.orchestrator.models.transformations import run, _include_practice
|
7
7
|
|
8
8
|
folder_path = os.path.join(fixtures_path, 'orchestrator', 'transformation')
|
9
9
|
|
10
10
|
|
11
11
|
@patch('hestia_earth.orchestrator.strategies.merge._merge_version', return_value='0.0.0')
|
12
|
+
@patch('hestia_earth.models.transformation.input.excreta._new_input', side_effect=fake_new_input)
|
13
|
+
@patch('hestia_earth.models.transformation.product.excreta._new_product', side_effect=fake_new_product)
|
14
|
+
@patch('hestia_earth.models.ipcc2019.n2OToAirExcretaDirect._new_emission', side_effect=fake_new_emission)
|
12
15
|
def test_run(*args):
|
13
16
|
with open(os.path.join(folder_path, 'config.json'), encoding='utf-8') as f:
|
14
17
|
config = json.load(f)
|
File without changes
|
File without changes
|
File without changes
|