hestia-earth-models 0.62.2__py3-none-any.whl → 0.62.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.
- hestia_earth/models/agribalyse2016/fuelElectricity.py +1 -1
- hestia_earth/models/cycle/animal/input/hestiaAggregatedData.py +1 -1
- hestia_earth/models/cycle/cycleDuration.py +7 -2
- hestia_earth/models/cycle/input/hestiaAggregatedData.py +1 -1
- hestia_earth/models/cycle/product/price.py +5 -1
- hestia_earth/models/cycle/product/revenue.py +6 -7
- hestia_earth/models/ecoinventV3/__init__.py +25 -52
- hestia_earth/models/ecoinventV3/utils.py +40 -0
- hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py +92 -91
- hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +15 -105
- hestia_earth/models/faostat2018/liveweightPerHead.py +1 -1
- hestia_earth/models/faostat2018/product/price.py +1 -2
- hestia_earth/models/geospatialDatabase/croppingIntensity.py +2 -1
- hestia_earth/models/geospatialDatabase/utils.py +1 -1
- hestia_earth/models/ipcc2019/aboveGroundCropResidueTotal.py +15 -10
- hestia_earth/models/ipcc2019/belowGroundCropResidue.py +16 -11
- hestia_earth/models/ipcc2019/carbonContent.py +1 -1
- hestia_earth/models/ipcc2019/croppingDuration.py +2 -2
- hestia_earth/models/ipcc2019/ligninContent.py +1 -1
- hestia_earth/models/ipcc2019/nitrogenContent.py +1 -1
- hestia_earth/models/ipcc2019/organicCarbonPerHa.py +3 -3
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +5 -5
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +17 -17
- hestia_earth/models/koble2014/cropResidueManagement.py +1 -1
- hestia_earth/models/linkedImpactAssessment/emissions.py +15 -14
- hestia_earth/models/log.py +1 -1
- hestia_earth/models/mocking/search-results.json +8 -16
- hestia_earth/models/pooreNemecek2018/longFallowPeriod.py +1 -1
- hestia_earth/models/preload_requests.py +1 -1
- hestia_earth/models/requirements.py +6 -6
- hestia_earth/models/site/management.py +38 -35
- hestia_earth/models/site/organicCarbonPerHa.py +1 -1
- hestia_earth/models/utils/__init__.py +1 -1
- hestia_earth/models/utils/blank_node.py +14 -9
- hestia_earth/models/utils/cycle.py +12 -12
- hestia_earth/models/utils/measurement.py +3 -3
- hestia_earth/models/utils/site.py +1 -1
- hestia_earth/models/utils/term.py +2 -1
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.62.2.dist-info → hestia_earth_models-0.62.4.dist-info}/METADATA +12 -12
- {hestia_earth_models-0.62.2.dist-info → hestia_earth_models-0.62.4.dist-info}/RECORD +50 -49
- {hestia_earth_models-0.62.2.dist-info → hestia_earth_models-0.62.4.dist-info}/WHEEL +1 -1
- tests/models/cycle/product/test_revenue.py +0 -3
- tests/models/cycle/test_cycleDuration.py +1 -1
- tests/models/faostat2018/test_liveweightPerHead.py +9 -0
- tests/models/site/test_management.py +31 -12
- tests/models/test_ecoinventV3.py +12 -0
- tests/models/test_ecoinventV3AndEmberClimate.py +5 -72
- {hestia_earth_models-0.62.2.dist-info → hestia_earth_models-0.62.4.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.62.2.dist-info → hestia_earth_models-0.62.4.dist-info}/top_level.txt +0 -0
|
@@ -152,7 +152,7 @@ def _get_cached_data(term: str, site: dict, data: dict):
|
|
|
152
152
|
|
|
153
153
|
def download(term: str, site: dict, data: dict, only_coordinates=False) -> dict:
|
|
154
154
|
"""
|
|
155
|
-
Downloads data from
|
|
155
|
+
Downloads data from HESTIA Earth Engine API.
|
|
156
156
|
|
|
157
157
|
Returns
|
|
158
158
|
-------
|
|
@@ -2,7 +2,7 @@ from hestia_earth.schema import TermTermType
|
|
|
2
2
|
from hestia_earth.utils.model import filter_list_term_type
|
|
3
3
|
from hestia_earth.utils.tools import list_sum
|
|
4
4
|
|
|
5
|
-
from hestia_earth.models.log import debugValues, logRequirements, logShouldRun
|
|
5
|
+
from hestia_earth.models.log import debugValues, logRequirements, logShouldRun, log_as_table
|
|
6
6
|
from hestia_earth.models.utils.completeness import _is_term_type_incomplete
|
|
7
7
|
from hestia_earth.models.utils.product import _new_product
|
|
8
8
|
from hestia_earth.models.utils.property import get_node_property
|
|
@@ -46,16 +46,21 @@ def _product_value(product: dict):
|
|
|
46
46
|
value = list_sum(product.get('value'))
|
|
47
47
|
dm = get_node_property(product, PROPERTY_KEY).get('value', 0)
|
|
48
48
|
yield_dm = get_yield_dm(TERM_ID, term) or 0
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
total = value * dm / 100 * yield_dm
|
|
50
|
+
return {
|
|
51
|
+
'id': term_id,
|
|
52
|
+
'value': value,
|
|
53
|
+
'dryMatter': dm,
|
|
54
|
+
'RatioYieldDM': yield_dm,
|
|
55
|
+
'total': total
|
|
56
|
+
}
|
|
55
57
|
|
|
56
58
|
|
|
57
|
-
def _run(products: list):
|
|
58
|
-
|
|
59
|
+
def _run(cycle: dict, products: list):
|
|
60
|
+
values = list(map(_product_value, products))
|
|
61
|
+
debugValues(cycle, model=MODEL, term=TERM_ID,
|
|
62
|
+
details=log_as_table(values))
|
|
63
|
+
value = sum([value.get('total', 0) for value in values])
|
|
59
64
|
return [_product(value)]
|
|
60
65
|
|
|
61
66
|
|
|
@@ -85,4 +90,4 @@ def _should_run(cycle: dict):
|
|
|
85
90
|
|
|
86
91
|
def run(cycle: dict):
|
|
87
92
|
should_run, products = _should_run(cycle)
|
|
88
|
-
return _run(products) if should_run else []
|
|
93
|
+
return _run(cycle, products) if should_run else []
|
|
@@ -2,7 +2,7 @@ from hestia_earth.schema import TermTermType
|
|
|
2
2
|
from hestia_earth.utils.model import filter_list_term_type
|
|
3
3
|
from hestia_earth.utils.tools import list_sum, safe_parse_float
|
|
4
4
|
|
|
5
|
-
from hestia_earth.models.log import debugValues, logRequirements, logShouldRun
|
|
5
|
+
from hestia_earth.models.log import debugValues, logRequirements, logShouldRun, log_as_table
|
|
6
6
|
from hestia_earth.models.utils.completeness import _is_term_type_incomplete
|
|
7
7
|
from hestia_earth.models.utils.product import _new_product
|
|
8
8
|
from hestia_earth.models.utils.property import get_node_property
|
|
@@ -52,17 +52,22 @@ def _product_value(product: dict):
|
|
|
52
52
|
dm = get_node_property(product, PROPERTY_KEY).get('value', 0)
|
|
53
53
|
yield_dm = get_yield_dm(TERM_ID, term) or 0
|
|
54
54
|
ratio = _get_lookup_value(term, 'IPCC_2019_Ratio_BGRes_AGRes') or 0
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
total = value * dm / 100 * yield_dm * ratio
|
|
56
|
+
return {
|
|
57
|
+
'id': term_id,
|
|
58
|
+
'value': value,
|
|
59
|
+
'dryMatter': dm,
|
|
60
|
+
'RatioYieldDM': yield_dm,
|
|
61
|
+
'RatioAboveGroundToBelowGround': ratio,
|
|
62
|
+
'total': total
|
|
63
|
+
}
|
|
62
64
|
|
|
63
65
|
|
|
64
|
-
def _run(products: list):
|
|
65
|
-
|
|
66
|
+
def _run(cycle: dict, products: list):
|
|
67
|
+
values = list(map(_product_value, products))
|
|
68
|
+
debugValues(cycle, model=MODEL, term=TERM_ID,
|
|
69
|
+
details=log_as_table(values))
|
|
70
|
+
value = sum([value.get('total', 0) for value in values])
|
|
66
71
|
return [_product(value)]
|
|
67
72
|
|
|
68
73
|
|
|
@@ -92,4 +97,4 @@ def _should_run(cycle: dict):
|
|
|
92
97
|
|
|
93
98
|
def run(cycle: dict):
|
|
94
99
|
should_run, products = _should_run(cycle)
|
|
95
|
-
return _run(products) if should_run else []
|
|
100
|
+
return _run(cycle, products) if should_run else []
|
|
@@ -114,7 +114,7 @@ def _multiple_product_values(crop: dict, residue_id: str):
|
|
|
114
114
|
# LIGNIN_CONTENT_AG_CROP_RESIDUE or LIGNIN_CONTENT_BG_CROP_RESIDUE
|
|
115
115
|
c_content = _get_lookup_value(term, _crop_residue_lookup_col(residue_id))
|
|
116
116
|
ratio = _get_lookup_value(term, 'IPCC_2019_Ratio_BGRes_AGRes') if residue_id == 'belowGroundCropResidue' else 1
|
|
117
|
-
debugValues(crop, model=MODEL, term=residue_id,
|
|
117
|
+
debugValues(crop, model=MODEL, term=residue_id, property=TERM_ID,
|
|
118
118
|
crop=term_id,
|
|
119
119
|
dryMatter=dm,
|
|
120
120
|
ratio_yield_dm=yield_dm,
|
|
@@ -80,11 +80,11 @@ def _should_run(cycle: dict):
|
|
|
80
80
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
81
81
|
country=country,
|
|
82
82
|
has_flooded_rice=flooded_rice,
|
|
83
|
-
cycleDuration=cycleDuration,
|
|
83
|
+
cycleDuration=cycle.get('cycleDuration'),
|
|
84
84
|
croppingDuration=croppingDuration,
|
|
85
85
|
croppingDuration_below_cycleDuration=croppingDuration_below_cycleDuration)
|
|
86
86
|
|
|
87
|
-
should_run = all([country, cycleDuration, flooded_rice])
|
|
87
|
+
should_run = all([country, cycleDuration > 0, croppingDuration_below_cycleDuration, flooded_rice])
|
|
88
88
|
logShouldRun(cycle, MODEL, TERM_ID, should_run)
|
|
89
89
|
return should_run, country
|
|
90
90
|
|
|
@@ -114,7 +114,7 @@ def _multiple_product_values(crop: dict, residue_id: str):
|
|
|
114
114
|
# LIGNIN_CONTENT_AG_CROP_RESIDUE or LIGNIN_CONTENT_BG_CROP_RESIDUE
|
|
115
115
|
l_content = _get_lookup_value(term, _crop_residue_lookup_col(residue_id))
|
|
116
116
|
ratio = _get_lookup_value(term, 'IPCC_2019_Ratio_BGRes_AGRes') if residue_id == 'belowGroundCropResidue' else 1
|
|
117
|
-
debugValues(crop, model=MODEL, term=residue_id,
|
|
117
|
+
debugValues(crop, model=MODEL, term=residue_id, property=TERM_ID,
|
|
118
118
|
crop=term_id,
|
|
119
119
|
dryMatter=dm,
|
|
120
120
|
ratio_yield_dm=yield_dm,
|
|
@@ -114,7 +114,7 @@ def _multiple_product_value(crop: dict, residue_id: str):
|
|
|
114
114
|
# N_Content_AG_Residue or N_Content_BG_Residue
|
|
115
115
|
n_content = _get_lookup_value(term, _crop_residue_lookup_col(residue_id))
|
|
116
116
|
ratio = _get_lookup_value(term, 'IPCC_2019_Ratio_BGRes_AGRes') if residue_id == 'belowGroundCropResidue' else 1
|
|
117
|
-
debugValues(crop, model=MODEL, term=residue_id,
|
|
117
|
+
debugValues(crop, model=MODEL, term=residue_id, property=TERM_ID,
|
|
118
118
|
crop=term_id,
|
|
119
119
|
dryMatter=dm,
|
|
120
120
|
ratio_yield_dm=yield_dm,
|
|
@@ -8,7 +8,7 @@ Both tier methodologies are run as Monte Carlo simulations with 10000 iterations
|
|
|
8
8
|
|
|
9
9
|
The requirements in this file are for the Tier 1 methodology only, as it has simpler requirements. The requirements for
|
|
10
10
|
the Tier 2 methodology can be found in the
|
|
11
|
-
[
|
|
11
|
+
[HESTIA SOC wiki](https://gitlab.com/hestia-earth/hestia-engine-models/-/wikis/Soil-organic-carbon-modelling)
|
|
12
12
|
alongside data recommendations, examples and explanations for both tiers.
|
|
13
13
|
"""
|
|
14
14
|
from functools import reduce
|
|
@@ -130,12 +130,12 @@ def run(site: dict) -> list[dict]:
|
|
|
130
130
|
Parameters
|
|
131
131
|
----------
|
|
132
132
|
site : dict
|
|
133
|
-
A
|
|
133
|
+
A HESTIA `Site` node, see: https://www.hestia.earth/schema/Site.
|
|
134
134
|
|
|
135
135
|
Returns
|
|
136
136
|
-------
|
|
137
137
|
list[dict]
|
|
138
|
-
A list of
|
|
138
|
+
A list of HESTIA `Measurement` nodes containing the calculated SOC stocks and additional relevant data.
|
|
139
139
|
"""
|
|
140
140
|
should_run, run_data = _should_run(site)
|
|
141
141
|
_log_data(site, should_run, run_data)
|
|
@@ -5,7 +5,7 @@ management changes.
|
|
|
5
5
|
The model cannot not run on Sites with polar moist (ecoClimateZone 5) or polar dry (ecoClimateZone 6).
|
|
6
6
|
|
|
7
7
|
More information on this model, including data requirements **and** recommendations, and examples can be found in the
|
|
8
|
-
[
|
|
8
|
+
[HESTIA SOC wiki](https://gitlab.com/hestia-earth/hestia-engine-models/-/wikis/Soil-organic-carbon-modelling).
|
|
9
9
|
|
|
10
10
|
Source: [IPCC 2019, Vol. 4, Chapter 2](https://www.ipcc-nggip.iges.or.jp/public/2019rf/vol4.html).
|
|
11
11
|
"""
|
|
@@ -92,7 +92,7 @@ def _measurement(
|
|
|
92
92
|
descriptive_stats_dict: dict
|
|
93
93
|
) -> dict:
|
|
94
94
|
"""
|
|
95
|
-
Build a
|
|
95
|
+
Build a HESTIA `Measurement` node to contain a value and descriptive statistics calculated by the models.
|
|
96
96
|
|
|
97
97
|
The `descriptive_stats_dict` parameter should include the following keys and values from the
|
|
98
98
|
[Measurement](https://www-staging.hestia.earth/schema/Measurement) schema:
|
|
@@ -117,7 +117,7 @@ def _measurement(
|
|
|
117
117
|
Returns
|
|
118
118
|
-------
|
|
119
119
|
dict
|
|
120
|
-
A valid
|
|
120
|
+
A valid HESTIA `Measurement` node, see: https://www.hestia.earth/schema/Measurement.
|
|
121
121
|
"""
|
|
122
122
|
measurement = _new_measurement(_TERM_ID) | descriptive_stats_dict
|
|
123
123
|
measurement["dates"] = [f"{year}-12-31" for year in timestamps]
|
|
@@ -640,7 +640,7 @@ def should_run(site: dict) -> tuple[bool, dict, dict]:
|
|
|
640
640
|
Parameters
|
|
641
641
|
----------
|
|
642
642
|
site : dict
|
|
643
|
-
A
|
|
643
|
+
A HESTIA `Site` node, see: https://www.hestia.earth/schema/Site.
|
|
644
644
|
|
|
645
645
|
Returns
|
|
646
646
|
-------
|
|
@@ -694,7 +694,7 @@ def run(
|
|
|
694
694
|
) -> list[dict]:
|
|
695
695
|
"""
|
|
696
696
|
Run the IPCC (2019) Tier 1 methodology for calculating SOC stocks (in kg C ha-1) for each year in the inventory
|
|
697
|
-
and wrap each of the calculated values in
|
|
697
|
+
and wrap each of the calculated values in HESTIA measurement nodes. To avoid any errors, the `inventory` parameter
|
|
698
698
|
must be pre-validated by the `should_run` function.
|
|
699
699
|
|
|
700
700
|
See [IPCC (2019) Vol. 4, Ch. 2](https://www.ipcc-nggip.iges.or.jp/public/2019rf/vol4.html) for more information.
|
|
@@ -3,7 +3,7 @@ The IPCC Tier 2 methodology for estimating soil organic carbon stock changes in
|
|
|
3
3
|
management changes.
|
|
4
4
|
|
|
5
5
|
More information on this model, including data requirements **and** recommendations, and examples can be found in the
|
|
6
|
-
[
|
|
6
|
+
[HESTIA SOC wiki](https://gitlab.com/hestia-earth/hestia-engine-models/-/wikis/Soil-organic-carbon-modelling).
|
|
7
7
|
|
|
8
8
|
Source: [IPCC 2019, Vol. 4, Chapter 5](https://www.ipcc-nggip.iges.or.jp/public/2019rf/vol4.html).
|
|
9
9
|
"""
|
|
@@ -105,7 +105,7 @@ def _measurement(
|
|
|
105
105
|
descriptive_stats_dict: dict
|
|
106
106
|
) -> dict:
|
|
107
107
|
"""
|
|
108
|
-
Build a
|
|
108
|
+
Build a HESTIA `Measurement` node to contain a value and descriptive statistics calculated by the models.
|
|
109
109
|
|
|
110
110
|
The `descriptive_stats_dict` parameter should include the following keys and values from the
|
|
111
111
|
[Measurement](https://www-staging.hestia.earth/schema/Measurement) schema:
|
|
@@ -130,7 +130,7 @@ def _measurement(
|
|
|
130
130
|
Returns
|
|
131
131
|
-------
|
|
132
132
|
dict
|
|
133
|
-
A valid
|
|
133
|
+
A valid HESTIA `Measurement` node, see: https://www.hestia.earth/schema/Measurement.
|
|
134
134
|
"""
|
|
135
135
|
measurement = _new_measurement(_TERM_ID) | descriptive_stats_dict
|
|
136
136
|
measurement["dates"] = [f"{year}-12-31" for year in timestamps]
|
|
@@ -384,7 +384,7 @@ def should_run(site: dict) -> tuple[bool, dict, dict]:
|
|
|
384
384
|
Parameters
|
|
385
385
|
----------
|
|
386
386
|
site : dict
|
|
387
|
-
A
|
|
387
|
+
A HESTIA `Site` node, see: https://www.hestia.earth/schema/Site.
|
|
388
388
|
|
|
389
389
|
Returns
|
|
390
390
|
-------
|
|
@@ -1318,12 +1318,12 @@ def _get_carbon_sources(cycle: dict) -> list[CarbonSource]:
|
|
|
1318
1318
|
"""
|
|
1319
1319
|
Extract and format the carbon source data from a cycle's inputs and products.
|
|
1320
1320
|
|
|
1321
|
-
Carbon sources can be either a
|
|
1321
|
+
Carbon sources can be either a HESTIA `Product` node (e.g. crop residue) or `Input` node (e.g. organic amendment).
|
|
1322
1322
|
|
|
1323
1323
|
Parameters
|
|
1324
1324
|
----------
|
|
1325
1325
|
cycle : list[dict]
|
|
1326
|
-
A
|
|
1326
|
+
A HESTIA `Cycle` node, see: https://www.hestia.earth/schema/Cycle.
|
|
1327
1327
|
|
|
1328
1328
|
Returns
|
|
1329
1329
|
-------
|
|
@@ -1346,7 +1346,7 @@ def _should_run_carbon_source_ag_residue(node: dict) -> bool:
|
|
|
1346
1346
|
Parameters
|
|
1347
1347
|
----------
|
|
1348
1348
|
node : dict
|
|
1349
|
-
A
|
|
1349
|
+
A HESTIA [Input](https://www.hestia.earth/schema/Input) or [Product](https://www.hestia.earth/schema/Product)
|
|
1350
1350
|
node.
|
|
1351
1351
|
|
|
1352
1352
|
Returns
|
|
@@ -1368,7 +1368,7 @@ def _calc_carbon_source_ag_crop_residue(node: dict, cycle: dict) -> Union[Carbon
|
|
|
1368
1368
|
Parameters
|
|
1369
1369
|
----------
|
|
1370
1370
|
node : dict
|
|
1371
|
-
A
|
|
1371
|
+
A HESTIA [Product](https://www.hestia.earth/schema/Product) node with `term.termType` == `landCover`.
|
|
1372
1372
|
|
|
1373
1373
|
Returns
|
|
1374
1374
|
-------
|
|
@@ -1397,7 +1397,7 @@ def _should_run_carbon_source_cover_crop(node: dict) -> bool:
|
|
|
1397
1397
|
Parameters
|
|
1398
1398
|
----------
|
|
1399
1399
|
node : dict
|
|
1400
|
-
A
|
|
1400
|
+
A HESTIA [Input](https://www.hestia.earth/schema/Input) or [Product](https://www.hestia.earth/schema/Product)
|
|
1401
1401
|
node.
|
|
1402
1402
|
|
|
1403
1403
|
Returns
|
|
@@ -1427,7 +1427,7 @@ def _calc_carbon_source_cover_crop(node: dict, *_) -> Union[CarbonSource, None]:
|
|
|
1427
1427
|
Parameters
|
|
1428
1428
|
----------
|
|
1429
1429
|
node : dict
|
|
1430
|
-
A
|
|
1430
|
+
A HESTIA [Product](https://www.hestia.earth/schema/Product) node with `term.termType` == `landCover`.
|
|
1431
1431
|
|
|
1432
1432
|
Returns
|
|
1433
1433
|
-------
|
|
@@ -1451,7 +1451,7 @@ def _should_run_carbon_source(node: dict) -> bool:
|
|
|
1451
1451
|
Parameters
|
|
1452
1452
|
----------
|
|
1453
1453
|
node : dict
|
|
1454
|
-
A
|
|
1454
|
+
A HESTIA [Input](https://www.hestia.earth/schema/Input) or [Product](https://www.hestia.earth/schema/Product)
|
|
1455
1455
|
node.
|
|
1456
1456
|
|
|
1457
1457
|
Returns
|
|
@@ -1472,7 +1472,7 @@ def _calc_carbon_source(node: dict, *_) -> Union[CarbonSource, None]:
|
|
|
1472
1472
|
Parameters
|
|
1473
1473
|
----------
|
|
1474
1474
|
node : dict
|
|
1475
|
-
A
|
|
1475
|
+
A HESTIA [Input](https://www.hestia.earth/schema/Input) or [Product](https://www.hestia.earth/schema/Product)
|
|
1476
1476
|
node.
|
|
1477
1477
|
|
|
1478
1478
|
Returns
|
|
@@ -1496,7 +1496,7 @@ def _retrieve_carbon_source_properties(node: dict) -> tuple[float, float, float]
|
|
|
1496
1496
|
Parameters
|
|
1497
1497
|
----------
|
|
1498
1498
|
node : dict
|
|
1499
|
-
A
|
|
1499
|
+
A HESTIA [Input](https://www.hestia.earth/schema/Input) or [Product](https://www.hestia.earth/schema/Product)
|
|
1500
1500
|
node.
|
|
1501
1501
|
|
|
1502
1502
|
Returns
|
|
@@ -1619,12 +1619,12 @@ def _assign_tier_2_ipcc_tillage_management_category(
|
|
|
1619
1619
|
default: IpccManagementCategory = IpccManagementCategory.OTHER
|
|
1620
1620
|
) -> IpccManagementCategory:
|
|
1621
1621
|
"""
|
|
1622
|
-
Assigns a tillage `IpccManagementCategory` to a list of
|
|
1622
|
+
Assigns a tillage `IpccManagementCategory` to a list of HESTIA `Cycle`s.
|
|
1623
1623
|
|
|
1624
1624
|
Parameters
|
|
1625
1625
|
----------
|
|
1626
1626
|
cycles : list[dict])
|
|
1627
|
-
A list of
|
|
1627
|
+
A list of HESTIA `Cycle` nodes, see: https://www.hestia.earth/schema/Cycle.
|
|
1628
1628
|
|
|
1629
1629
|
Returns
|
|
1630
1630
|
-------
|
|
@@ -1668,7 +1668,7 @@ def _check_cycle_tillage_management_category(
|
|
|
1668
1668
|
Parameters
|
|
1669
1669
|
----------
|
|
1670
1670
|
cycle : dict
|
|
1671
|
-
A
|
|
1671
|
+
A HESTIA `Cycle` node, see: https://www.hestia.earth/schema/Cycle.
|
|
1672
1672
|
key : IpccManagementCategory
|
|
1673
1673
|
The `IpccManagementCategory` to match.
|
|
1674
1674
|
|
|
@@ -1703,7 +1703,7 @@ def _check_zero_tillages(practices: list[dict]) -> bool:
|
|
|
1703
1703
|
Parameters
|
|
1704
1704
|
----------
|
|
1705
1705
|
practices : list[dict]
|
|
1706
|
-
A list of
|
|
1706
|
+
A list of HESTIA `Practice` nodes, see: https://www.hestia.earth/schema/Practice.
|
|
1707
1707
|
|
|
1708
1708
|
Returns
|
|
1709
1709
|
-------
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Residue
|
|
3
3
|
|
|
4
4
|
Re-scale all [crop residue management](https://hestia.earth/glossary?termType=cropResidueManagement) Practices
|
|
5
|
-
to make sure they all add up to 100%. Note: only practices added by
|
|
5
|
+
to make sure they all add up to 100%. Note: only practices added by HESTIA will be recalculated.
|
|
6
6
|
"""
|
|
7
7
|
from hestia_earth.schema import TermTermType
|
|
8
8
|
from hestia_earth.utils.model import filter_list_term_type
|
|
@@ -8,7 +8,7 @@ from hestia_earth.schema import EmissionMethodTier
|
|
|
8
8
|
from hestia_earth.utils.lookup import download_lookup, get_table_value, column_name
|
|
9
9
|
from hestia_earth.utils.tools import flatten, list_sum
|
|
10
10
|
|
|
11
|
-
from hestia_earth.models.log import
|
|
11
|
+
from hestia_earth.models.log import logShouldRun, debugValues, log_as_table
|
|
12
12
|
from hestia_earth.models.utils.emission import _new_emission
|
|
13
13
|
from hestia_earth.models.utils.input import load_impacts
|
|
14
14
|
from hestia_earth.models.utils.blank_node import group_by_keys
|
|
@@ -65,25 +65,29 @@ def _emission(model: str, term_id: str, value: float, input: dict, operation={},
|
|
|
65
65
|
return emission
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
def _run_emission(cycle: dict,
|
|
68
|
+
def _run_emission(cycle: dict, emission_term_id: str, data: dict):
|
|
69
69
|
def run_input(values: dict):
|
|
70
70
|
value = values.get('value', 0)
|
|
71
|
-
|
|
71
|
+
input_term = values.get('term', {})
|
|
72
|
+
input_term_id = input_term.get('@id')
|
|
72
73
|
operation = values.get('operation', {})
|
|
73
74
|
animal = values.get('animal', {})
|
|
74
75
|
is_aggregated = any(values.get('aggregated', []))
|
|
75
76
|
model = MODEL_AGGREGATED if is_aggregated else MODEL
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
logRequirements(cycle, model=model, term=term_id, key=MODEL_KEY,
|
|
79
|
-
values=log_as_table([{'impact-assessment-id': key} | value for key, value in details.items()]))
|
|
78
|
+
logShouldRun(cycle, model, input_term_id, True, methodTier=TIER)
|
|
80
79
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
# log run on each emission so we know it did run
|
|
81
|
+
details = values.get('details', {})
|
|
82
|
+
debugValues(cycle, model=model, term=emission_term_id,
|
|
83
|
+
value=value,
|
|
84
|
+
coefficient=1,
|
|
85
|
+
details=log_as_table([{'impact-assessment-id': key} | value for key, value in details.items()]),
|
|
86
|
+
input=input_term_id,
|
|
87
|
+
operation=operation.get('@id'),
|
|
88
|
+
animal=animal.get('@id'))
|
|
85
89
|
|
|
86
|
-
return _emission(model,
|
|
90
|
+
return _emission(model, emission_term_id, value, input=input_term, operation=operation, animal=animal)
|
|
87
91
|
|
|
88
92
|
return list(map(run_input, data.values()))
|
|
89
93
|
|
|
@@ -158,9 +162,6 @@ def run(cycle: dict):
|
|
|
158
162
|
inputs = reduce(group_by_keys(['term', 'operation', 'animal']), inputs, {})
|
|
159
163
|
inputs = {key: list(map(_group_input_emissions, value)) for key, value in inputs.items()}
|
|
160
164
|
|
|
161
|
-
debugValues(cycle, model=MODEL, key=MODEL_KEY,
|
|
162
|
-
nb_inputs=len(inputs))
|
|
163
|
-
|
|
164
165
|
# finally group everything by emission so we can log inputs together
|
|
165
166
|
# emissions = {'co2ToAirInputsProduct': {'group-id':{'term':{},'value':10,'details':{}}}}
|
|
166
167
|
emissions = reduce(_group_inputs, inputs.items(), {})
|
hestia_earth/models/log.py
CHANGED
|
@@ -63,7 +63,7 @@ def logShouldRun(log_node: dict, model: str, term: Union[str, None], should_run:
|
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
def debugMissingLookup(lookup_name: str, row: str, row_value: str, col: str, value, **kwargs):
|
|
66
|
-
if value is None:
|
|
66
|
+
if value is None or value == '':
|
|
67
67
|
extra = (', ' + _join_args(**kwargs)) if len(kwargs.keys()) > 0 else ''
|
|
68
68
|
logger.warn('Missing lookup=%s, %s=%s, column=%s' + extra, lookup_name, row, row_value, col)
|
|
69
69
|
|
|
@@ -1219,19 +1219,11 @@
|
|
|
1219
1219
|
"results": [
|
|
1220
1220
|
{
|
|
1221
1221
|
"@type": "Term",
|
|
1222
|
-
"
|
|
1223
|
-
"termType": "electricity",
|
|
1224
|
-
"@id": "electricityGridMarketMix",
|
|
1225
|
-
"units": "kWh",
|
|
1226
|
-
"_score": 29.020527
|
|
1222
|
+
"@id": "electricityGridMarketMix"
|
|
1227
1223
|
},
|
|
1228
1224
|
{
|
|
1229
1225
|
"@type": "Term",
|
|
1230
|
-
"
|
|
1231
|
-
"termType": "electricity",
|
|
1232
|
-
"@id": "electricityGridRenewableMix",
|
|
1233
|
-
"units": "kWh",
|
|
1234
|
-
"_score": 29.020527
|
|
1226
|
+
"@id": "electricityGridRenewableMix"
|
|
1235
1227
|
}
|
|
1236
1228
|
]
|
|
1237
1229
|
},
|
|
@@ -1494,7 +1486,7 @@
|
|
|
1494
1486
|
"@type": "Term",
|
|
1495
1487
|
"name": "Generic crop, seed",
|
|
1496
1488
|
"@id": "genericCropSeed",
|
|
1497
|
-
"_score": 25.
|
|
1489
|
+
"_score": 25.968466
|
|
1498
1490
|
}
|
|
1499
1491
|
]
|
|
1500
1492
|
},
|
|
@@ -1736,7 +1728,7 @@
|
|
|
1736
1728
|
"@type": "Term",
|
|
1737
1729
|
"name": "River or stream",
|
|
1738
1730
|
"@id": "riverOrStream",
|
|
1739
|
-
"_score": 50.
|
|
1731
|
+
"_score": 50.06671
|
|
1740
1732
|
},
|
|
1741
1733
|
{
|
|
1742
1734
|
"@type": "Term",
|
|
@@ -1748,7 +1740,7 @@
|
|
|
1748
1740
|
"@type": "Term",
|
|
1749
1741
|
"name": "Natural forest",
|
|
1750
1742
|
"@id": "naturalForest",
|
|
1751
|
-
"_score": 31.
|
|
1743
|
+
"_score": 31.252472
|
|
1752
1744
|
},
|
|
1753
1745
|
{
|
|
1754
1746
|
"@type": "Term",
|
|
@@ -1760,7 +1752,7 @@
|
|
|
1760
1752
|
"@type": "Term",
|
|
1761
1753
|
"name": "Animal housing",
|
|
1762
1754
|
"@id": "animalHousing",
|
|
1763
|
-
"_score": 26.
|
|
1755
|
+
"_score": 26.769783
|
|
1764
1756
|
},
|
|
1765
1757
|
{
|
|
1766
1758
|
"@type": "Term",
|
|
@@ -1772,13 +1764,13 @@
|
|
|
1772
1764
|
"@type": "Term",
|
|
1773
1765
|
"name": "High intensity grazing pasture",
|
|
1774
1766
|
"@id": "highIntensityGrazingPasture",
|
|
1775
|
-
"_score": 23.
|
|
1767
|
+
"_score": 23.502655
|
|
1776
1768
|
},
|
|
1777
1769
|
{
|
|
1778
1770
|
"@type": "Term",
|
|
1779
1771
|
"name": "Permanent cropland",
|
|
1780
1772
|
"@id": "permanentCropland",
|
|
1781
|
-
"_score": 20.
|
|
1773
|
+
"_score": 20.467493
|
|
1782
1774
|
},
|
|
1783
1775
|
{
|
|
1784
1776
|
"@type": "Term",
|
|
@@ -45,7 +45,7 @@ def _should_run(cycle: dict):
|
|
|
45
45
|
product = next((p for p in cycle.get('products', []) if _should_run_product(p)), None)
|
|
46
46
|
|
|
47
47
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
48
|
-
|
|
48
|
+
crop_product_id=(product or {}).get('term', {}).get('@id'))
|
|
49
49
|
|
|
50
50
|
should_run = all([product])
|
|
51
51
|
logShouldRun(cycle, MODEL, TERM_ID, should_run)
|
|
@@ -10,7 +10,7 @@ from .mocking import RESULTS_PATH, enable_mock as _mock
|
|
|
10
10
|
|
|
11
11
|
def enable_preload(filepath: str = RESULTS_PATH, node: dict = None):
|
|
12
12
|
"""
|
|
13
|
-
Prefetch calls to
|
|
13
|
+
Prefetch calls to HESTIA API in a local file.
|
|
14
14
|
|
|
15
15
|
Parameters
|
|
16
16
|
----------
|
|
@@ -353,7 +353,7 @@ def get_single_returns(model: str, key: str):
|
|
|
353
353
|
Returns
|
|
354
354
|
-------
|
|
355
355
|
list
|
|
356
|
-
The returned data following
|
|
356
|
+
The returned data following HESTIA's schema.
|
|
357
357
|
"""
|
|
358
358
|
returns = _model_returns({'model': model, 'key': key})
|
|
359
359
|
return_type = list(returns.keys())[0] if returns else None
|
|
@@ -368,7 +368,7 @@ def list_models(
|
|
|
368
368
|
termType: str = None, tier: str = None, productTermId: str = None, productTermType: str = None, siteType: str = None
|
|
369
369
|
) -> list:
|
|
370
370
|
"""
|
|
371
|
-
Return list of models present in
|
|
371
|
+
Return list of models present in HESTIA.
|
|
372
372
|
|
|
373
373
|
Parameters
|
|
374
374
|
----------
|
|
@@ -410,7 +410,7 @@ def get_models(termId: str):
|
|
|
410
410
|
Returns
|
|
411
411
|
-------
|
|
412
412
|
list
|
|
413
|
-
The list of modelscurrently in
|
|
413
|
+
The list of modelscurrently in HESTIA that are matching this Term (as `{"model": model, "key": key}`).
|
|
414
414
|
"""
|
|
415
415
|
return list(filter(lambda m: m.get('key') == termId, ALL_MODELS))
|
|
416
416
|
|
|
@@ -420,7 +420,7 @@ def get_all(
|
|
|
420
420
|
termType: str = None, tier: str = None, productTermId: str = None, productTermType: str = None, siteType: str = None
|
|
421
421
|
) -> list:
|
|
422
422
|
"""
|
|
423
|
-
Get the requirements to run all the models in
|
|
423
|
+
Get the requirements to run all the models in HESTIA.
|
|
424
424
|
|
|
425
425
|
Parameters
|
|
426
426
|
----------
|
|
@@ -441,7 +441,7 @@ def get_all(
|
|
|
441
441
|
Returns
|
|
442
442
|
-------
|
|
443
443
|
list
|
|
444
|
-
The data requirements following
|
|
444
|
+
The data requirements following HESTIA's schema as multiple nodes.
|
|
445
445
|
"""
|
|
446
446
|
models = list_models(
|
|
447
447
|
termType=termType, tier=tier, productTermId=productTermId, productTermType=productTermType, siteType=siteType
|
|
@@ -469,7 +469,7 @@ def get_single(model: str, key: str) -> list:
|
|
|
469
469
|
Returns
|
|
470
470
|
-------
|
|
471
471
|
list
|
|
472
|
-
The data requirements following
|
|
472
|
+
The data requirements following HESTIA's schema as multiple nodes.
|
|
473
473
|
"""
|
|
474
474
|
model = {'model': model, 'key': key}
|
|
475
475
|
linked_models = _recursive_linked_models(model)
|