hestia-earth-models 0.74.4__py3-none-any.whl → 0.74.5__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.
- hestia_earth/models/cml2001Baseline/abioticResourceDepletionMineralsAndMetals.py +0 -1
- hestia_earth/models/config/Cycle.json +15 -0
- hestia_earth/models/config/ImpactAssessment.json +9 -1
- hestia_earth/models/cycle/animal/input/hestiaAggregatedData.py +3 -3
- hestia_earth/models/cycle/completeness/seed.py +1 -1
- hestia_earth/models/cycle/input/hestiaAggregatedData.py +25 -16
- hestia_earth/models/data/hestiaAggregatedData/__init__.py +73 -0
- hestia_earth/models/environmentalFootprintV3_1/scarcityWeightedWaterUse.py +1 -1
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandOccupation.py +5 -6
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandTransformation.py +10 -13
- hestia_earth/models/fantkeEtAl2016/damageToHumanHealthParticulateMatterFormation.py +1 -1
- hestia_earth/models/hestia/landCover.py +24 -0
- hestia_earth/models/hestia/landOccupationDuringCycle.py +80 -51
- hestia_earth/models/hestia/landTransformation100YearAverageDuringCycle.py +7 -1
- hestia_earth/models/hestia/landTransformation20YearAverageDuringCycle.py +7 -1
- hestia_earth/models/hestia/resourceUse_utils.py +58 -119
- hestia_earth/models/hestia/waterSalinity.py +57 -12
- hestia_earth/models/impact_assessment/post_checks/__init__.py +3 -2
- hestia_earth/models/impact_assessment/post_checks/remove_cache_fields.py +9 -0
- hestia_earth/models/impact_assessment/pre_checks/cache_emissionsResourceUse.py +21 -0
- hestia_earth/models/impact_assessment/pre_checks/cycle.py +5 -0
- hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChange.py +6 -64
- hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChange.py +9 -87
- hestia_earth/models/ipcc2019/co2ToAirBiocharStockChange.py +140 -0
- hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +329 -217
- hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChange.py +10 -87
- hestia_earth/models/mocking/__init__.py +2 -2
- hestia_earth/models/mocking/mock_search.py +20 -10
- hestia_earth/models/mocking/search-results.json +1 -7679
- hestia_earth/models/pooreNemecek2018/landOccupationDuringCycle.py +8 -7
- hestia_earth/models/poschEtAl2008/terrestrialAcidificationPotentialAccumulatedExceedance.py +1 -1
- hestia_earth/models/poschEtAl2008/terrestrialEutrophicationPotentialAccumulatedExceedance.py +1 -1
- hestia_earth/models/preload_requests.py +18 -4
- hestia_earth/models/schmidt2007/utils.py +3 -3
- hestia_earth/models/utils/__init__.py +4 -1
- hestia_earth/models/utils/aggregated.py +21 -68
- hestia_earth/models/utils/cycle.py +3 -3
- hestia_earth/models/utils/impact_assessment.py +45 -41
- hestia_earth/models/utils/lookup.py +92 -67
- hestia_earth/models/version.py +1 -1
- hestia_earth/orchestrator/models/__init__.py +47 -10
- hestia_earth/orchestrator/models/transformations.py +3 -1
- hestia_earth/orchestrator/strategies/merge/__init__.py +1 -2
- hestia_earth/orchestrator/strategies/merge/merge_list.py +31 -8
- hestia_earth/orchestrator/utils.py +29 -0
- {hestia_earth_models-0.74.4.dist-info → hestia_earth_models-0.74.5.dist-info}/METADATA +2 -3
- {hestia_earth_models-0.74.4.dist-info → hestia_earth_models-0.74.5.dist-info}/RECORD +62 -55
- tests/models/cycle/animal/input/test_hestiaAggregatedData.py +3 -3
- tests/models/cycle/input/test_hestiaAggregatedData.py +9 -18
- tests/models/data/__init__.py +0 -0
- tests/models/data/test_hestiaAggregatedData.py +32 -0
- tests/models/hestia/test_landCover.py +32 -1
- tests/models/hestia/test_waterSalinity.py +16 -4
- tests/models/ipcc2019/test_co2ToAirAboveGroundBiomassStockChange.py +1 -6
- tests/models/ipcc2019/test_co2ToAirBelowGroundBiomassStockChange.py +1 -6
- tests/models/ipcc2019/test_co2ToAirBiocharStockChange.py +90 -0
- tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChange.py +1 -6
- tests/models/pooreNemecek2018/test_landOccupationDuringCycle.py +1 -0
- tests/orchestrator/strategies/merge/test_merge_list.py +5 -0
- {hestia_earth_models-0.74.4.dist-info → hestia_earth_models-0.74.5.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.74.4.dist-info → hestia_earth_models-0.74.5.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.74.4.dist-info → hestia_earth_models-0.74.5.dist-info}/top_level.txt +0 -0
|
@@ -61,13 +61,11 @@ RUN_IDS = [f"{param[0]}, cycle{param[2]}" for param in RUN_PARAMS]
|
|
|
61
61
|
@mark.parametrize("subfolder, num_cycles, cycle_index", RUN_PARAMS, ids=RUN_IDS)
|
|
62
62
|
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
63
63
|
@patch(f"{utils_path}.related_cycles")
|
|
64
|
-
@patch(f"{utils_path}._get_site")
|
|
65
64
|
@patch(f"{biomass_utils_path}.get_cover_crop_property_terms", return_value=COVER_CROP_PROPERTY_TERM_IDS)
|
|
66
65
|
@patch(f"{term_path}.search")
|
|
67
66
|
def test_run(
|
|
68
67
|
search_mock: MagicMock,
|
|
69
68
|
get_cover_crop_property_terms_mock: MagicMock,
|
|
70
|
-
get_site_mock: MagicMock,
|
|
71
69
|
related_cycles_mock: MagicMock,
|
|
72
70
|
_new_emission_mock: MagicMock,
|
|
73
71
|
subfolder: str,
|
|
@@ -85,7 +83,7 @@ def test_run(
|
|
|
85
83
|
_load_fixture(f"{fixtures_folder}/{subfolder}/cycle{i}.jsonld") for i in range(num_cycles)
|
|
86
84
|
]
|
|
87
85
|
|
|
88
|
-
|
|
86
|
+
cycle["site"] = site
|
|
89
87
|
related_cycles_mock.return_value = cycles
|
|
90
88
|
|
|
91
89
|
result = run(cycle)
|
|
@@ -97,13 +95,11 @@ def test_run(
|
|
|
97
95
|
|
|
98
96
|
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
99
97
|
@patch(f"{utils_path}.related_cycles")
|
|
100
|
-
@patch(f"{utils_path}._get_site")
|
|
101
98
|
@patch(f"{biomass_utils_path}.get_cover_crop_property_terms", return_value=COVER_CROP_PROPERTY_TERM_IDS)
|
|
102
99
|
@patch(f"{term_path}.search")
|
|
103
100
|
def test_run_empty(
|
|
104
101
|
search_mock: MagicMock,
|
|
105
102
|
get_cover_crop_property_terms_mock: MagicMock,
|
|
106
|
-
get_site_mock: MagicMock,
|
|
107
103
|
related_cycles_mock: MagicMock,
|
|
108
104
|
_new_emission_mock: MagicMock
|
|
109
105
|
):
|
|
@@ -113,7 +109,6 @@ def test_run_empty(
|
|
|
113
109
|
CYCLE = {}
|
|
114
110
|
EXPECTED = []
|
|
115
111
|
|
|
116
|
-
get_site_mock.return_value = {}
|
|
117
112
|
related_cycles_mock.return_value = [CYCLE]
|
|
118
113
|
|
|
119
114
|
result = run(CYCLE)
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from functools import reduce
|
|
2
|
+
import json
|
|
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.co2ToAirBiocharStockChange import MODEL, run
|
|
8
|
+
|
|
9
|
+
from tests.utils import fake_new_emission, fixtures_path
|
|
10
|
+
|
|
11
|
+
class_path = f"hestia_earth.models.{MODEL}.co2ToAirBiocharStockChange"
|
|
12
|
+
utils_path = f"hestia_earth.models.{MODEL}.co2ToAirCarbonStockChange_utils"
|
|
13
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/co2ToAirBiocharStockChange"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _load_fixture(path: str, default=None):
|
|
17
|
+
if isfile(path):
|
|
18
|
+
with open(path, encoding="utf-8") as f:
|
|
19
|
+
return json.load(f)
|
|
20
|
+
return default
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
RUN_SCENARIOS = [
|
|
24
|
+
("basic-case", 1),
|
|
25
|
+
("no-overlapping-cycles", 3),
|
|
26
|
+
("overlapping-cycles", 4),
|
|
27
|
+
("complex-overlapping-cycles", 5),
|
|
28
|
+
("missing-measurement-dates", 3),
|
|
29
|
+
("no-biomass-measurements", 1),
|
|
30
|
+
("non-consecutive-biomass-measurements", 1),
|
|
31
|
+
("multiple-method-classifications", 5),
|
|
32
|
+
("non-soil-based-gohac-system", 3),
|
|
33
|
+
("with-gapfilled-start-date-end-date", 1)
|
|
34
|
+
]
|
|
35
|
+
"""List of (subfolder: str, num_cycles: int)."""
|
|
36
|
+
|
|
37
|
+
RUN_PARAMS = reduce(
|
|
38
|
+
lambda params, scenario: params + [(scenario[0], scenario[1], i) for i in range(scenario[1])],
|
|
39
|
+
RUN_SCENARIOS,
|
|
40
|
+
list()
|
|
41
|
+
)
|
|
42
|
+
"""List of (subfolder: str, num_cycles: int, cycle_index: int)."""
|
|
43
|
+
|
|
44
|
+
RUN_IDS = [f"{param[0]}, cycle{param[2]}" for param in RUN_PARAMS]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@mark.parametrize("subfolder, num_cycles, cycle_index", RUN_PARAMS, ids=RUN_IDS)
|
|
48
|
+
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
49
|
+
@patch(f"{utils_path}.related_cycles")
|
|
50
|
+
def test_run(
|
|
51
|
+
related_cycles_mock: MagicMock,
|
|
52
|
+
_new_emission_mock: MagicMock,
|
|
53
|
+
subfolder: str,
|
|
54
|
+
num_cycles: int,
|
|
55
|
+
cycle_index: int
|
|
56
|
+
):
|
|
57
|
+
"""
|
|
58
|
+
Test `run` function for each cycle in each scenario.
|
|
59
|
+
"""
|
|
60
|
+
site = _load_fixture(f"{fixtures_folder}/{subfolder}/site.jsonld")
|
|
61
|
+
cycle = _load_fixture(f"{fixtures_folder}/{subfolder}/cycle{cycle_index}.jsonld")
|
|
62
|
+
expected = _load_fixture(f"{fixtures_folder}/{subfolder}/result{cycle_index}.jsonld", default=[])
|
|
63
|
+
|
|
64
|
+
cycles = [
|
|
65
|
+
_load_fixture(f"{fixtures_folder}/{subfolder}/cycle{i}.jsonld") for i in range(num_cycles)
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
cycle["site"] = site
|
|
69
|
+
related_cycles_mock.return_value = cycles
|
|
70
|
+
|
|
71
|
+
result = run(cycle)
|
|
72
|
+
assert result == expected
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
76
|
+
@patch(f"{utils_path}.related_cycles")
|
|
77
|
+
def test_run_empty(
|
|
78
|
+
related_cycles_mock: MagicMock,
|
|
79
|
+
_new_emission_mock: MagicMock
|
|
80
|
+
):
|
|
81
|
+
"""
|
|
82
|
+
Test `run` function for each cycle in each scenario.
|
|
83
|
+
"""
|
|
84
|
+
CYCLE = {}
|
|
85
|
+
EXPECTED = []
|
|
86
|
+
|
|
87
|
+
related_cycles_mock.return_value = [CYCLE]
|
|
88
|
+
|
|
89
|
+
result = run(CYCLE)
|
|
90
|
+
assert result == EXPECTED
|
|
@@ -86,7 +86,6 @@ RUN_IDS = [f"{param[0]}, cycle{param[2]}" for param in RUN_PARAMS]
|
|
|
86
86
|
@mark.parametrize("subfolder, num_cycles, cycle_index", RUN_PARAMS, ids=RUN_IDS)
|
|
87
87
|
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
88
88
|
@patch(f"{utils_path}.related_cycles")
|
|
89
|
-
@patch(f"{utils_path}._get_site")
|
|
90
89
|
@patch(f"{soc_tier_1_utils_path}.get_upland_rice_land_cover_terms", return_value=UPLAND_RICE_LAND_COVER_TERM_IDS)
|
|
91
90
|
@patch(f"{soc_utils_path}.get_irrigated_terms", return_value=IRRIGATED_TERM_IDS)
|
|
92
91
|
@patch(f"{soc_utils_path}.get_cover_crop_property_terms", return_value=COVER_CROP_PROPERTY_TERM_IDS)
|
|
@@ -96,7 +95,6 @@ def test_run(
|
|
|
96
95
|
_get_cover_crop_property_terms_mock: MagicMock,
|
|
97
96
|
_get_irrigated_terms_mock: MagicMock,
|
|
98
97
|
_get_upland_rice_land_cover_terms_mock: MagicMock,
|
|
99
|
-
get_site_mock: MagicMock,
|
|
100
98
|
related_cycles_mock: MagicMock,
|
|
101
99
|
_new_emission_mock: MagicMock,
|
|
102
100
|
subfolder: str,
|
|
@@ -114,7 +112,7 @@ def test_run(
|
|
|
114
112
|
_load_fixture(f"{fixtures_folder}/{subfolder}/cycle{i}.jsonld") for i in range(num_cycles)
|
|
115
113
|
]
|
|
116
114
|
|
|
117
|
-
|
|
115
|
+
cycle["site"] = site
|
|
118
116
|
related_cycles_mock.return_value = cycles
|
|
119
117
|
|
|
120
118
|
result = run(cycle)
|
|
@@ -126,7 +124,6 @@ def test_run(
|
|
|
126
124
|
|
|
127
125
|
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
128
126
|
@patch(f"{utils_path}.related_cycles")
|
|
129
|
-
@patch(f"{utils_path}._get_site")
|
|
130
127
|
@patch(f"{soc_tier_1_utils_path}.get_upland_rice_land_cover_terms", return_value=UPLAND_RICE_LAND_COVER_TERM_IDS)
|
|
131
128
|
@patch(f"{soc_utils_path}.get_irrigated_terms", return_value=IRRIGATED_TERM_IDS)
|
|
132
129
|
@patch(f"{soc_utils_path}.get_cover_crop_property_terms", return_value=COVER_CROP_PROPERTY_TERM_IDS)
|
|
@@ -136,7 +133,6 @@ def test_run_empty(
|
|
|
136
133
|
_get_cover_crop_property_terms_mock: MagicMock,
|
|
137
134
|
_get_irrigated_terms_mock: MagicMock,
|
|
138
135
|
_get_upland_rice_land_cover_terms_mock: MagicMock,
|
|
139
|
-
get_site_mock: MagicMock,
|
|
140
136
|
related_cycles_mock: MagicMock,
|
|
141
137
|
_new_emission_mock: MagicMock
|
|
142
138
|
):
|
|
@@ -146,7 +142,6 @@ def test_run_empty(
|
|
|
146
142
|
CYCLE = {}
|
|
147
143
|
EXPECTED = []
|
|
148
144
|
|
|
149
|
-
get_site_mock.return_value = {}
|
|
150
145
|
related_cycles_mock.return_value = [CYCLE]
|
|
151
146
|
|
|
152
147
|
result = run(CYCLE)
|
|
@@ -19,6 +19,7 @@ def test_should_run(mock_land_occupation, *args):
|
|
|
19
19
|
assert not should_run
|
|
20
20
|
|
|
21
21
|
# with product value and economicValueShare => run
|
|
22
|
+
impact['product'] = {'economicValueShare': 10}
|
|
22
23
|
mock_land_occupation.return_value = 10
|
|
23
24
|
should_run, *args = _should_run(impact)
|
|
24
25
|
assert should_run is True
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from unittest.mock import patch
|
|
2
2
|
import pydash
|
|
3
3
|
|
|
4
|
+
from hestia_earth.orchestrator.utils import reset_index
|
|
4
5
|
from hestia_earth.orchestrator.strategies.merge.merge_list import merge, _get_value
|
|
5
6
|
|
|
6
7
|
class_path = 'hestia_earth.orchestrator.strategies.merge.merge_list'
|
|
@@ -66,6 +67,7 @@ def test_merge_existing_node(*args):
|
|
|
66
67
|
'depthUpper': 50
|
|
67
68
|
}], version, model=model, node_type=node_type)
|
|
68
69
|
assert len(result) == 3
|
|
70
|
+
reset_index()
|
|
69
71
|
|
|
70
72
|
node_type = 'Cycle'
|
|
71
73
|
model = {'key': 'emissions'}
|
|
@@ -79,6 +81,7 @@ def test_merge_existing_node(*args):
|
|
|
79
81
|
'inputs': [{'@id': 'input-1'}]
|
|
80
82
|
}], version, model=model, node_type=node_type)
|
|
81
83
|
assert len(result) == 1
|
|
84
|
+
reset_index()
|
|
82
85
|
|
|
83
86
|
# with different inputs => should not merge
|
|
84
87
|
result = merge([{
|
|
@@ -89,6 +92,7 @@ def test_merge_existing_node(*args):
|
|
|
89
92
|
'inputs': [{'@id': 'input-2'}]
|
|
90
93
|
}], version, model=model, node_type=node_type)
|
|
91
94
|
assert len(result) == 2
|
|
95
|
+
reset_index()
|
|
92
96
|
|
|
93
97
|
result = merge([{
|
|
94
98
|
**old_node,
|
|
@@ -98,6 +102,7 @@ def test_merge_existing_node(*args):
|
|
|
98
102
|
'inputs': [{'@id': 'input-1'}, {'@id': 'input-2'}]
|
|
99
103
|
}], version, model=model, node_type=node_type)
|
|
100
104
|
assert len(result) == 2
|
|
105
|
+
reset_index()
|
|
101
106
|
|
|
102
107
|
# with no inputs => should not merge
|
|
103
108
|
result = merge([old_node], [{
|
|
File without changes
|
|
File without changes
|
|
File without changes
|