hestia-earth-models 0.47.5__py3-none-any.whl → 0.49.0__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 +33 -18
- hestia_earth/models/agribalyse2016/machineryInfrastructureDepreciatedAmountPerCycle.py +1 -1
- hestia_earth/models/blonkConsultants2016/{co2ToAirSoilCarbonStockChangeManagementChange.py → co2ToAirAboveGroundBiomassStockChangeLandUseChange.py} +1 -1
- hestia_earth/models/deRuijterEtAl2010/nh3ToAirCropResidueDecomposition.py +1 -1
- hestia_earth/models/faostat2018/product/price.py +1 -1
- hestia_earth/models/faostat2018/seed.py +1 -1
- hestia_earth/models/haversineFormula/transport/distance.py +27 -8
- hestia_earth/models/impact_assessment/freshwaterWithdrawalsDuringCycle.py +5 -1
- hestia_earth/models/impact_assessment/product/economicValueShare.py +2 -1
- hestia_earth/models/ipcc2006/aboveGroundCropResidueRemoved.py +1 -1
- hestia_earth/models/ipcc2006/aboveGroundCropResidueTotal.py +1 -1
- hestia_earth/models/ipcc2006/belowGroundCropResidue.py +2 -2
- hestia_earth/models/ipcc2006/n2OToAirCropResidueDecompositionIndirect.py +1 -1
- hestia_earth/models/ipcc2006/n2OToAirExcretaDirect.py +1 -1
- hestia_earth/models/ipcc2006/n2OToAirExcretaIndirect.py +1 -1
- hestia_earth/models/ipcc2006/n2OToAirInorganicFertiliserDirect.py +1 -1
- hestia_earth/models/ipcc2006/n2OToAirInorganicFertiliserIndirect.py +1 -1
- hestia_earth/models/ipcc2006/n2OToAirOrganicFertiliserDirect.py +1 -1
- hestia_earth/models/ipcc2006/n2OToAirOrganicFertiliserIndirect.py +1 -1
- hestia_earth/models/ipcc2019/aboveGroundCropResidueTotal.py +1 -1
- hestia_earth/models/ipcc2019/belowGroundCropResidue.py +1 -1
- hestia_earth/models/ipcc2019/n2OToAirCropResidueDecompositionDirect.py +1 -1
- hestia_earth/models/koble2014/aboveGroundCropResidue.py +1 -1
- hestia_earth/models/mocking/search-results.json +240 -192
- hestia_earth/models/pooreNemecek2018/aboveGroundCropResidueTotal.py +1 -1
- hestia_earth/models/pooreNemecek2018/belowGroundCropResidue.py +1 -1
- hestia_earth/models/pooreNemecek2018/saplings.py +1 -1
- hestia_earth/models/site/cationExchangeCapacityPerKgSoil.py +11 -6
- hestia_earth/models/site/organicCarbonPerHa.py +32 -15
- hestia_earth/models/utils/pesticideAI.py +1 -1
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.47.5.dist-info → hestia_earth_models-0.49.0.dist-info}/METADATA +7 -7
- {hestia_earth_models-0.47.5.dist-info → hestia_earth_models-0.49.0.dist-info}/RECORD +40 -40
- {hestia_earth_models-0.47.5.dist-info → hestia_earth_models-0.49.0.dist-info}/WHEEL +1 -1
- tests/models/blonkConsultants2016/{test_co2ToAirSoilCarbonStockChangeManagementChange.py → test_co2ToAirAboveGroundBiomassStockChangeLandUseChange.py} +1 -1
- tests/models/faostat2018/product/test_price.py +7 -1
- tests/models/site/test_cationExchangeCapacityPerKgSoil.py +6 -4
- tests/models/site/test_organicCarbonPerHa.py +6 -4
- {hestia_earth_models-0.47.5.dist-info → hestia_earth_models-0.49.0.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.47.5.dist-info → hestia_earth_models-0.49.0.dist-info}/top_level.txt +0 -0
|
@@ -3,6 +3,7 @@ Fuel and Electricity
|
|
|
3
3
|
|
|
4
4
|
This model calculates fuel and electricity data from the number of hours each machine is operated for using.
|
|
5
5
|
"""
|
|
6
|
+
from functools import reduce
|
|
6
7
|
from hestia_earth.schema import InputStatsDefinition, TermTermType
|
|
7
8
|
from hestia_earth.utils.model import filter_list_term_type
|
|
8
9
|
from hestia_earth.utils.tools import flatten, list_sum, non_empty_list
|
|
@@ -44,34 +45,49 @@ def _input(term_id: str, value: float, operation: dict):
|
|
|
44
45
|
return input
|
|
45
46
|
|
|
46
47
|
|
|
48
|
+
def _operation_input(operation: dict):
|
|
49
|
+
input = operation.get('input', {})
|
|
50
|
+
return _input(input.get('id'), input.get('value') * operation.get('value'), operation.get('term', {}))
|
|
51
|
+
|
|
52
|
+
|
|
47
53
|
def _run_operation(cycle: dict):
|
|
48
|
-
def exec(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
def exec(operations: list):
|
|
55
|
+
input_term_id = operations[0].get('input').get('id')
|
|
56
|
+
values_logs = ';'.join([
|
|
57
|
+
f"id:{p.get('term').get('@id')}_value:{p.get('value')}_coefficient:{p.get('input').get('value')}"
|
|
58
|
+
for p in operations
|
|
59
|
+
])
|
|
54
60
|
|
|
55
61
|
debugValues(cycle, model=MODEL, term=input_term_id,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
logShouldRun(cycle, MODEL, input_term_id, True, model_key=MODEL_KEY, operation=operation.get('@id'))
|
|
62
|
+
values=values_logs)
|
|
63
|
+
|
|
64
|
+
logShouldRun(cycle, MODEL, input_term_id, True, model_key=MODEL_KEY)
|
|
60
65
|
|
|
61
|
-
return
|
|
66
|
+
return list(map(_operation_input, operations))
|
|
62
67
|
return exec
|
|
63
68
|
|
|
64
69
|
|
|
70
|
+
def _group_operations(operations: list):
|
|
71
|
+
def grouper(group: dict, operation: dict):
|
|
72
|
+
input_term_id = operation.get('input').get('id')
|
|
73
|
+
group[input_term_id] = group.get(input_term_id, [])
|
|
74
|
+
group[input_term_id].append(operation)
|
|
75
|
+
return group
|
|
76
|
+
|
|
77
|
+
return reduce(grouper, operations, {})
|
|
78
|
+
|
|
79
|
+
|
|
65
80
|
def _should_run_operation(cycle: dict):
|
|
66
81
|
def exec(practice: dict):
|
|
67
82
|
term = practice.get('term', {})
|
|
68
83
|
term_id = term.get('@id')
|
|
69
|
-
|
|
84
|
+
values = practice.get('value', [])
|
|
85
|
+
value = list_sum(values) if all([not isinstance(v, str) for v in values]) else 0 # str allowed for Practice
|
|
70
86
|
has_value = value > 0
|
|
71
87
|
|
|
72
88
|
coeffs = get_lookup_value(term, LOOKUPS['operation'], model=MODEL, model_key=MODEL_KEY)
|
|
73
89
|
values = non_empty_list(coeffs.split(';')) if coeffs else []
|
|
74
|
-
inputs = [{'
|
|
90
|
+
inputs = [{'id': c.split(':')[0], 'value': float(c.split(':')[1])} for c in values]
|
|
75
91
|
has_lookup_value = len(inputs) > 0
|
|
76
92
|
|
|
77
93
|
logRequirements(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
|
@@ -80,10 +96,7 @@ def _should_run_operation(cycle: dict):
|
|
|
80
96
|
|
|
81
97
|
should_run = all([has_value, has_lookup_value])
|
|
82
98
|
logShouldRun(cycle, MODEL, term_id, should_run, model_key=MODEL_KEY)
|
|
83
|
-
return [{
|
|
84
|
-
**practice,
|
|
85
|
-
'input': input
|
|
86
|
-
} for input in inputs] if should_run else []
|
|
99
|
+
return [{'term': term, 'value': value, 'input': input} for input in inputs] if should_run else []
|
|
87
100
|
return exec
|
|
88
101
|
|
|
89
102
|
|
|
@@ -105,4 +118,6 @@ def _should_run(cycle: dict):
|
|
|
105
118
|
|
|
106
119
|
def run(cycle: dict):
|
|
107
120
|
should_run, operations = _should_run(cycle)
|
|
108
|
-
|
|
121
|
+
# group operations by input to show logs as table
|
|
122
|
+
grouped_operations = _group_operations(operations)
|
|
123
|
+
return flatten(map(_run_operation(cycle), grouped_operations.values())) if should_run else []
|
|
@@ -79,7 +79,7 @@ def _should_run(cycle: dict):
|
|
|
79
79
|
|
|
80
80
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
81
81
|
site_type_valid=site_type_valid,
|
|
82
|
-
|
|
82
|
+
term_type_material_incomplete=term_type_incomplete)
|
|
83
83
|
|
|
84
84
|
should_run = all([site_type_valid, term_type_incomplete])
|
|
85
85
|
logShouldRun(cycle, MODEL, TERM_ID, should_run)
|
|
@@ -77,7 +77,7 @@ def _should_run(cycle: dict):
|
|
|
77
77
|
])
|
|
78
78
|
|
|
79
79
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
80
|
-
|
|
80
|
+
term_type_cropResidue_complete=term_type_complete,
|
|
81
81
|
left_on_field_residue=left_on_field_residue,
|
|
82
82
|
total_nitrogenContent=total_nitrogenContent)
|
|
83
83
|
|
|
@@ -67,7 +67,7 @@ def _lookup_data(
|
|
|
67
67
|
data = get_table_value(lookup, 'termid', country_id, column_name(grouping))
|
|
68
68
|
debugMissingLookup(lookup_name, 'termid', country_id, grouping, data,
|
|
69
69
|
model=MODEL, term=term_id, key=MODEL_KEY)
|
|
70
|
-
price = extract_grouped_data(data, str(year))
|
|
70
|
+
price = extract_grouped_data(data, str(year)) or extract_grouped_data(data, 'Average_price_per_tonne')
|
|
71
71
|
return safe_parse_float(price, None)
|
|
72
72
|
|
|
73
73
|
|
|
@@ -69,7 +69,7 @@ def _should_run(cycle: dict):
|
|
|
69
69
|
term_type_incomplete = _is_term_type_incomplete(cycle, TERM_ID)
|
|
70
70
|
|
|
71
71
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
72
|
-
|
|
72
|
+
term_type_other_incomplete=term_type_incomplete,
|
|
73
73
|
has_products=has_products,
|
|
74
74
|
product_ids=product_ids)
|
|
75
75
|
|
|
@@ -74,18 +74,37 @@ def _run_input(cycle: dict, site_country: dict):
|
|
|
74
74
|
return exec
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
def _should_run_input(
|
|
77
|
+
def _should_run_input(site_country_id: str):
|
|
78
78
|
def exec(input: dict):
|
|
79
|
-
input_country = input.get('country', {})
|
|
79
|
+
input_country = input.get('country', {}) or {}
|
|
80
|
+
input_country_id = input_country.get('@id')
|
|
81
|
+
input_country = download_hestia(input_country_id)
|
|
80
82
|
has_transports = len(input.get('transport', [])) > 0
|
|
81
|
-
should_run = all([
|
|
83
|
+
should_run = input_country and all([
|
|
84
|
+
input_country.get('latitude'), input_country.get('latitude'),
|
|
85
|
+
has_transports, input_country_id != site_country_id
|
|
86
|
+
])
|
|
82
87
|
return should_run
|
|
83
88
|
return exec
|
|
84
89
|
|
|
85
90
|
|
|
86
|
-
def
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
def _should_run(cycle: dict):
|
|
92
|
+
country = cycle.get('site', {}).get('country', {})
|
|
93
|
+
country_id = cycle.get('site', {}).get('country', {}).get('@id')
|
|
94
|
+
inputs = list(filter(_should_run_input(country_id), cycle.get('inputs', [])))
|
|
89
95
|
# download full term to get coordinates only if there is anything to run
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
country = download_hestia(country_id) if len(inputs) > 0 else {}
|
|
97
|
+
|
|
98
|
+
# can only run if the site country has centroid coordinates
|
|
99
|
+
logRequirements(cycle, model=MODEL, term=None, key=MODEL_KEY,
|
|
100
|
+
latitude=country.get('latitude'),
|
|
101
|
+
longitude=country.get('latitude'),
|
|
102
|
+
has_inputs_transport=len(inputs) > 0)
|
|
103
|
+
should_run = all([country.get('latitude'), country.get('latitude'), len(inputs) > 0])
|
|
104
|
+
logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY)
|
|
105
|
+
return should_run, country, inputs
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def run(cycle: dict):
|
|
109
|
+
should_run, country, inputs = _should_run(cycle)
|
|
110
|
+
return non_empty_list(map(_run_input(cycle, country), inputs)) if should_run else []
|
|
@@ -36,7 +36,11 @@ RETURNS = {
|
|
|
36
36
|
}
|
|
37
37
|
LOOKUPS = {
|
|
38
38
|
"crop": "cropGroupingFAO",
|
|
39
|
-
"region": [
|
|
39
|
+
"region": [
|
|
40
|
+
"Conveyancing_Efficiency_Annual_crops",
|
|
41
|
+
"Conveyancing_Efficiency_Permanent_crops",
|
|
42
|
+
"Conveyancing_Efficiency_Perennial_crops"
|
|
43
|
+
]
|
|
40
44
|
}
|
|
41
45
|
TERM_ID = 'freshwaterWithdrawalsDuringCycle'
|
|
42
46
|
|
|
@@ -26,7 +26,8 @@ MODEL_KEY = 'economicValueShare'
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def _run(impact: dict, product: dict):
|
|
29
|
-
|
|
29
|
+
value = product.get(MODEL_KEY)
|
|
30
|
+
return {**impact.get('product'), MODEL_KEY: value} if value is not None else None
|
|
30
31
|
|
|
31
32
|
|
|
32
33
|
def _should_run(impact: dict):
|
|
@@ -70,7 +70,7 @@ def _should_run(cycle: dict):
|
|
|
70
70
|
|
|
71
71
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
72
72
|
has_products_with_dryMatter=has_products_with_dryMatter,
|
|
73
|
-
|
|
73
|
+
term_type_cropResidue_incomplete=term_type_incomplete)
|
|
74
74
|
|
|
75
75
|
should_run = all([has_products_with_dryMatter, term_type_incomplete])
|
|
76
76
|
logShouldRun(cycle, MODEL, TERM_ID, should_run)
|
|
@@ -81,7 +81,7 @@ def _should_run(cycle: dict):
|
|
|
81
81
|
single_crop_product=single_crop_product,
|
|
82
82
|
nb_products=len(products),
|
|
83
83
|
dryMatter=dm_property.get('value'),
|
|
84
|
-
|
|
84
|
+
term_type_cropResidue_incomplete=term_type_incomplete)
|
|
85
85
|
|
|
86
86
|
should_run = all([term_type_incomplete, single_crop_product, dm_property])
|
|
87
87
|
logShouldRun(cycle, MODEL, TERM_ID, should_run)
|
|
@@ -22,7 +22,7 @@ REQUIREMENTS = {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
LOOKUPS = {
|
|
25
|
-
"crop": ["Crop_residue_intercept", "Crop_residue_slope", "
|
|
25
|
+
"crop": ["Crop_residue_intercept", "Crop_residue_slope", "IPCC_2019_Ratio_BGRes_AGRes"]
|
|
26
26
|
}
|
|
27
27
|
RETURNS = {
|
|
28
28
|
"Product": [{
|
|
@@ -95,7 +95,7 @@ def _should_run(cycle: dict):
|
|
|
95
95
|
single_crop_product=single_crop_product,
|
|
96
96
|
nb_products=len(products),
|
|
97
97
|
dryMatter=dm_property.get('value'),
|
|
98
|
-
|
|
98
|
+
term_type_cropResidue_incomplete=term_type_incomplete)
|
|
99
99
|
|
|
100
100
|
should_run = all([term_type_incomplete, single_crop_product, dm_property])
|
|
101
101
|
logShouldRun(cycle, MODEL, TERM_ID, should_run)
|
|
@@ -52,7 +52,7 @@ def _should_run(cycle: dict):
|
|
|
52
52
|
no3_n=no3_n,
|
|
53
53
|
nh3_n=nh3_n,
|
|
54
54
|
nox_n=nox_n,
|
|
55
|
-
|
|
55
|
+
term_type_cropResidue_complete=term_type_complete)
|
|
56
56
|
|
|
57
57
|
should_run = all([no3_n, nh3_n, nox_n]) or term_type_complete
|
|
58
58
|
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
@@ -52,7 +52,7 @@ def _should_run(cycle: dict):
|
|
|
52
52
|
|
|
53
53
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
54
54
|
N_total=N_total,
|
|
55
|
-
|
|
55
|
+
term_type_excreta_complete=term_type_complete)
|
|
56
56
|
|
|
57
57
|
should_run = any([N_total, term_type_complete])
|
|
58
58
|
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
@@ -68,7 +68,7 @@ def _should_run(cycle: dict):
|
|
|
68
68
|
|
|
69
69
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
70
70
|
N_total=N_total,
|
|
71
|
-
|
|
71
|
+
term_type_excreta_complete=term_type_complete)
|
|
72
72
|
|
|
73
73
|
should_run = any([N_total, term_type_complete])
|
|
74
74
|
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
@@ -52,7 +52,7 @@ def _should_run(cycle: dict):
|
|
|
52
52
|
|
|
53
53
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
54
54
|
N_total=N_total,
|
|
55
|
-
|
|
55
|
+
term_type_fertiliser_complete=term_type_complete)
|
|
56
56
|
|
|
57
57
|
should_run = any([N_total, term_type_complete])
|
|
58
58
|
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
@@ -68,7 +68,7 @@ def _should_run(cycle: dict):
|
|
|
68
68
|
|
|
69
69
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
70
70
|
N_total=N_total,
|
|
71
|
-
|
|
71
|
+
term_type_fertiliser_complete=term_type_complete)
|
|
72
72
|
|
|
73
73
|
should_run = any([N_total, term_type_complete])
|
|
74
74
|
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
@@ -55,7 +55,7 @@ def _should_run(cycle: dict):
|
|
|
55
55
|
|
|
56
56
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
57
57
|
N_total=N_total,
|
|
58
|
-
|
|
58
|
+
term_type_fertiliser_complete=term_type_complete)
|
|
59
59
|
|
|
60
60
|
should_run = any([N_total, term_type_complete])
|
|
61
61
|
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
@@ -68,7 +68,7 @@ def _should_run(cycle: dict):
|
|
|
68
68
|
|
|
69
69
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
70
70
|
N_total=N_total,
|
|
71
|
-
|
|
71
|
+
term_type_fertiliser_complete=term_type_complete)
|
|
72
72
|
|
|
73
73
|
should_run = any([N_total, term_type_complete])
|
|
74
74
|
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
@@ -75,7 +75,7 @@ def _should_run(cycle: dict):
|
|
|
75
75
|
|
|
76
76
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
77
77
|
has_crop_products=has_crop_products,
|
|
78
|
-
|
|
78
|
+
term_type_cropResidue_incomplete=term_type_incomplete)
|
|
79
79
|
|
|
80
80
|
should_run = all([term_type_incomplete, has_crop_products])
|
|
81
81
|
logShouldRun(cycle, MODEL, TERM_ID, should_run)
|
|
@@ -81,7 +81,7 @@ def _should_run(cycle: dict):
|
|
|
81
81
|
|
|
82
82
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
83
83
|
has_crop_products=has_crop_products,
|
|
84
|
-
|
|
84
|
+
term_type_cropResidue_incomplete=term_type_incomplete)
|
|
85
85
|
|
|
86
86
|
should_run = all([term_type_incomplete, has_crop_products])
|
|
87
87
|
logShouldRun(cycle, MODEL, TERM_ID, should_run)
|
|
@@ -119,7 +119,7 @@ def _should_run(cycle: dict):
|
|
|
119
119
|
ecoClimateZone = get_ecoClimateZone(cycle)
|
|
120
120
|
|
|
121
121
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
122
|
-
|
|
122
|
+
term_type_cropResidue_complete=term_type_complete,
|
|
123
123
|
N_crop_residue=N_crop_residue,
|
|
124
124
|
ecoClimateZone=ecoClimateZone)
|
|
125
125
|
|
|
@@ -130,7 +130,7 @@ def _should_run(cycle: dict):
|
|
|
130
130
|
should_run = all([has_aboveGroundCropResidueTotal, term_type_incomplete])
|
|
131
131
|
for term_id in TERM_ID.split(','):
|
|
132
132
|
logRequirements(cycle, model=MODEL, term=term_id,
|
|
133
|
-
|
|
133
|
+
term_type_cropResidue_incomplete=term_type_incomplete,
|
|
134
134
|
has_aboveGroundCropResidueTotal=has_aboveGroundCropResidueTotal)
|
|
135
135
|
logShouldRun(cycle, MODEL, term_id, should_run)
|
|
136
136
|
|