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
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
from hestia_earth.schema import
|
|
1
|
+
from hestia_earth.schema import EmissionMethodTier
|
|
2
2
|
|
|
3
3
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
4
|
-
from hestia_earth.models.utils.blank_node import cumulative_nodes_term_match
|
|
5
4
|
from hestia_earth.models.utils.emission import _new_emission
|
|
6
5
|
|
|
7
6
|
from .organicCarbonPerHa_tier_1 import _assign_ipcc_land_use_category, get_valid_management_nodes
|
|
@@ -19,7 +18,7 @@ REQUIREMENTS = {
|
|
|
19
18
|
"dates": "",
|
|
20
19
|
"depthUpper": "0",
|
|
21
20
|
"depthLower": "30",
|
|
22
|
-
"term.@id": "
|
|
21
|
+
"term.@id": "organicCarbonPerHa"
|
|
23
22
|
}
|
|
24
23
|
]
|
|
25
24
|
},
|
|
@@ -52,13 +51,6 @@ _DEPTH_LOWER = 30
|
|
|
52
51
|
|
|
53
52
|
_CARBON_STOCK_TERM_ID = 'organicCarbonPerHa'
|
|
54
53
|
|
|
55
|
-
_SITE_TYPE_SYSTEMS_MAPPING = {
|
|
56
|
-
SiteSiteType.GLASS_OR_HIGH_ACCESSIBLE_COVER.value: [
|
|
57
|
-
"protectedCroppingSystemSoilBased",
|
|
58
|
-
"protectedCroppingSystemSoilAndSubstrateBased"
|
|
59
|
-
]
|
|
60
|
-
}
|
|
61
|
-
|
|
62
54
|
|
|
63
55
|
def _emission(
|
|
64
56
|
*,
|
|
@@ -119,14 +111,16 @@ def run(cycle: dict) -> list[dict]:
|
|
|
119
111
|
-------
|
|
120
112
|
list[dict]
|
|
121
113
|
A list of [Emission nodes](https://www.hestia.earth/schema/Emission) containing model results.
|
|
114
|
+
|
|
122
115
|
"""
|
|
123
116
|
should_run_exec = create_should_run_function(
|
|
124
|
-
|
|
117
|
+
_CARBON_STOCK_TERM_ID,
|
|
118
|
+
depth_upper=_DEPTH_UPPER,
|
|
119
|
+
depth_lower=_DEPTH_LOWER,
|
|
120
|
+
measurements_mandatory=False, # Model can allocate zero emissions to LUC with enough landCover data
|
|
125
121
|
get_valid_management_nodes_func=get_valid_management_nodes,
|
|
126
|
-
should_compile_inventory_func=_should_compile_inventory_func,
|
|
127
122
|
summarise_land_use_func=lambda nodes: _assign_ipcc_land_use_category(nodes, None),
|
|
128
|
-
detect_land_use_change_func=lambda a, b: a != b
|
|
129
|
-
should_run_measurement_func=_should_run_measurement_func,
|
|
123
|
+
detect_land_use_change_func=lambda a, b: a != b
|
|
130
124
|
)
|
|
131
125
|
|
|
132
126
|
run_exec = create_run_function(
|
|
@@ -135,81 +129,10 @@ def run(cycle: dict) -> list[dict]:
|
|
|
135
129
|
management_change_emission_term_id=_MG_EMISSION_TERM_ID
|
|
136
130
|
)
|
|
137
131
|
|
|
138
|
-
should_run,
|
|
132
|
+
should_run, cycle_id, inventory, logs = should_run_exec(cycle)
|
|
139
133
|
|
|
140
134
|
for term_id in [_LU_EMISSION_TERM_ID, _MG_EMISSION_TERM_ID]:
|
|
141
135
|
logRequirements(cycle, model=MODEL, term=term_id, **logs)
|
|
142
136
|
logShouldRun(cycle, MODEL, term_id, should_run)
|
|
143
137
|
|
|
144
|
-
return run_exec(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
def _should_run_measurement_func(node: dict) -> bool:
|
|
148
|
-
"""
|
|
149
|
-
Validate a [Measurement](https://www.hestia.earth/schema/Measurement) to determine whether it is a valid
|
|
150
|
-
`organicCarbonPerHa` node.
|
|
151
|
-
|
|
152
|
-
Parameters
|
|
153
|
-
----------
|
|
154
|
-
node : dict
|
|
155
|
-
The node to be validated.
|
|
156
|
-
|
|
157
|
-
Returns
|
|
158
|
-
-------
|
|
159
|
-
bool
|
|
160
|
-
`True` if the node passes all validation criteria, `False` otherwise.
|
|
161
|
-
"""
|
|
162
|
-
return all([
|
|
163
|
-
node.get("depthLower") == _DEPTH_LOWER,
|
|
164
|
-
node.get("depthUpper") == _DEPTH_UPPER
|
|
165
|
-
])
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
def _should_compile_inventory_func(
|
|
169
|
-
site: dict, cycles: list[dict], carbon_stock_measurements: list[dict]
|
|
170
|
-
) -> tuple[bool, dict]:
|
|
171
|
-
"""
|
|
172
|
-
Determine whether a site is suitable and has enough data to compile a carbon stock inventory.
|
|
173
|
-
|
|
174
|
-
Parameters
|
|
175
|
-
----------
|
|
176
|
-
site : dict
|
|
177
|
-
A HESTIA (Site node)[https://www.hestia.earth/schema/Site]
|
|
178
|
-
cycles : list[dict]
|
|
179
|
-
A list of HESTIA (Cycle nodes)[https://www.hestia.earth/schema/Cycle] that are related to the site.
|
|
180
|
-
carbon_stock_measurements : list[dict]
|
|
181
|
-
A list of HESTIA carbon stock (Measurement nodes)[https://www.hestia.earth/schema/Measurement] that are related
|
|
182
|
-
to the site.
|
|
183
|
-
|
|
184
|
-
Returns
|
|
185
|
-
-------
|
|
186
|
-
tuple[bool, dict]
|
|
187
|
-
`(should_run, logs)`.
|
|
188
|
-
"""
|
|
189
|
-
site_type = site.get("siteType")
|
|
190
|
-
has_soil = site_type not in _SITE_TYPE_SYSTEMS_MAPPING or all(
|
|
191
|
-
cumulative_nodes_term_match(
|
|
192
|
-
cycle.get("practices", []),
|
|
193
|
-
target_term_ids=_SITE_TYPE_SYSTEMS_MAPPING[site_type],
|
|
194
|
-
cumulative_threshold=0
|
|
195
|
-
) for cycle in cycles
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
has_cycles = len(cycles) > 0
|
|
199
|
-
has_functional_unit_1_ha = all(cycle.get('functionalUnit') == CycleFunctionalUnit._1_HA.value for cycle in cycles)
|
|
200
|
-
|
|
201
|
-
should_run = all([
|
|
202
|
-
has_soil,
|
|
203
|
-
has_cycles,
|
|
204
|
-
has_functional_unit_1_ha
|
|
205
|
-
])
|
|
206
|
-
|
|
207
|
-
logs = {
|
|
208
|
-
"site_type": site_type,
|
|
209
|
-
"has_soil": has_soil,
|
|
210
|
-
"carbon_stock_term": _CARBON_STOCK_TERM_ID,
|
|
211
|
-
"has_cycles": has_cycles,
|
|
212
|
-
"has_functional_unit_1_ha": has_functional_unit_1_ha,
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return should_run, logs
|
|
138
|
+
return run_exec(cycle_id, inventory) if should_run else []
|
|
@@ -7,9 +7,9 @@ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
7
7
|
RESULTS_PATH = os.path.join(CURRENT_DIR, 'search-results.json')
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def enable_mock(filepath: str, node: dict = None):
|
|
10
|
+
def enable_mock(filepath: str, node: dict = None, keep_in_memory: bool = False):
|
|
11
11
|
# apply mocks on search results
|
|
12
|
-
mock_search(filepath)
|
|
12
|
+
mock_search(filepath, keep_in_memory)
|
|
13
13
|
|
|
14
14
|
if node is not None:
|
|
15
15
|
# skip fetch bibliography data
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
+
from functools import cache
|
|
2
3
|
|
|
3
4
|
from hestia_earth.models.utils import term
|
|
4
5
|
|
|
@@ -6,31 +7,40 @@ _original_search_func = term.search
|
|
|
6
7
|
_original_find_node_func = term.find_node
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
def _load_results(filepath: str):
|
|
10
|
+
def _load_results(filepath: str) -> dict:
|
|
10
11
|
with open(filepath) as f:
|
|
11
12
|
return json.load(f)
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
_load_results_cached = cache(_load_results)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _find_search_result(filepath: str, query: dict, keep_in_memory: bool):
|
|
19
|
+
_load_results_func = _load_results_cached if keep_in_memory else _load_results
|
|
20
|
+
search_results = _load_results_func(filepath)
|
|
16
21
|
res = next((n for n in search_results if n['query'] == query), None)
|
|
17
22
|
return None if res is None else res.get('results', [])
|
|
18
23
|
|
|
19
24
|
|
|
20
|
-
def _mocked_search(filepath: str):
|
|
25
|
+
def _mocked_search(filepath: str, keep_in_memory: bool):
|
|
21
26
|
def mock(query: dict, **kwargs):
|
|
22
|
-
result = _find_search_result(filepath, query)
|
|
27
|
+
result = _find_search_result(filepath, query, keep_in_memory)
|
|
23
28
|
return _original_search_func(query, **kwargs) if result is None else result
|
|
24
29
|
return mock
|
|
25
30
|
|
|
26
31
|
|
|
27
|
-
def _mocked_find_node(filepath: str):
|
|
32
|
+
def _mocked_find_node(filepath: str, keep_in_memory: bool):
|
|
28
33
|
def mock(node_type: str, query: dict, **kwargs):
|
|
29
|
-
result = _find_search_result(filepath, query)
|
|
34
|
+
result = _find_search_result(filepath, query, keep_in_memory)
|
|
30
35
|
return _original_find_node_func(node_type, query, **kwargs) if result is None else result
|
|
31
36
|
return mock
|
|
32
37
|
|
|
33
38
|
|
|
34
|
-
def mock(filepath: str):
|
|
35
|
-
term.search = _mocked_search(filepath)
|
|
36
|
-
term.find_node = _mocked_find_node(filepath)
|
|
39
|
+
def mock(filepath: str, keep_in_memory: bool):
|
|
40
|
+
term.search = _mocked_search(filepath, keep_in_memory)
|
|
41
|
+
term.find_node = _mocked_find_node(filepath, keep_in_memory)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def unmock():
|
|
45
|
+
term.search = _original_search_func
|
|
46
|
+
term.find_node = _original_find_node_func
|