hestia-earth-models 0.73.6__py3-none-any.whl → 0.73.8__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/config/Cycle.json +116 -26
- hestia_earth/models/config/ImpactAssessment.json +239 -199
- hestia_earth/models/dammgen2009/noxToAirExcreta.py +11 -9
- hestia_earth/models/ecoalimV9/cycle.py +29 -39
- hestia_earth/models/ecoalimV9/impact_assessment.py +38 -40
- hestia_earth/models/ecoalimV9/utils.py +82 -16
- hestia_earth/models/ecoinventV3/__init__.py +3 -3
- hestia_earth/models/emepEea2019/n2OToAirFuelCombustionDirect.py +2 -2
- hestia_earth/models/hestia/default_emissions.py +2 -6
- hestia_earth/models/hestia/default_resourceUse.py +2 -5
- hestia_earth/models/hestia/landCover.py +3 -3
- hestia_earth/models/hestia/pastureSystem.py +1 -1
- hestia_earth/models/hestia/seed_emissions.py +7 -3
- hestia_earth/models/impact_assessment/emissions.py +3 -5
- hestia_earth/models/ipcc2019/biocharOrganicCarbonPerHa.py +9 -3
- hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChange.py +1 -5
- hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChange.py +1 -5
- hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +1 -33
- hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChange.py +1 -5
- hestia_earth/models/ipcc2019/n2OToAirAquacultureSystemsIndirect.py +44 -0
- hestia_earth/models/ipcc2019/n2OToAirCropResidueBurningIndirect.py +43 -0
- hestia_earth/models/ipcc2019/n2OToAirCropResidueDecompositionIndirect.py +13 -70
- hestia_earth/models/ipcc2019/n2OToAirExcretaIndirect.py +13 -70
- hestia_earth/models/ipcc2019/n2OToAirFuelCombustionIndirect.py +43 -0
- hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserIndirect.py +13 -70
- hestia_earth/models/ipcc2019/n2OToAirNaturalVegetationBurningIndirect.py +43 -0
- hestia_earth/models/ipcc2019/n2OToAirOrganicFertiliserIndirect.py +13 -70
- hestia_earth/models/ipcc2019/n2OToAirOrganicSoilBurningIndirect.py +43 -0
- hestia_earth/models/ipcc2019/n2OToAirOrganicSoilCultivationIndirect.py +43 -0
- hestia_earth/models/ipcc2019/n2OToAir_indirect_emissions_utils.py +112 -0
- hestia_earth/models/ipcc2019/utils.py +0 -25
- hestia_earth/models/jarvisAndPain1994/n2ToAirExcreta.py +11 -9
- hestia_earth/models/linkedImpactAssessment/emissions.py +24 -15
- hestia_earth/models/linkedImpactAssessment/utils.py +5 -1
- hestia_earth/models/mocking/search-results.json +1284 -1284
- hestia_earth/models/utils/background_emissions.py +17 -10
- hestia_earth/models/utils/emission.py +18 -8
- hestia_earth/models/utils/impact_assessment.py +3 -3
- hestia_earth/models/utils/indicator.py +8 -1
- hestia_earth/models/utils/lookup.py +38 -21
- hestia_earth/models/utils/productivity.py +1 -1
- hestia_earth/models/version.py +1 -1
- hestia_earth/orchestrator/strategies/merge/merge_list.py +41 -54
- {hestia_earth_models-0.73.6.dist-info → hestia_earth_models-0.73.8.dist-info}/METADATA +3 -3
- {hestia_earth_models-0.73.6.dist-info → hestia_earth_models-0.73.8.dist-info}/RECORD +64 -49
- tests/models/dammgen2009/test_noxToAirExcreta.py +2 -2
- tests/models/ecoalimV9/test_cycle.py +1 -1
- tests/models/ecoalimV9/test_impact_assessment.py +1 -1
- tests/models/ecoalimV9/test_utils.py +13 -0
- tests/models/ipcc2019/test_biocharOrganicCarbonPerHa.py +2 -1
- tests/models/ipcc2019/test_n2OToAirAquacultureSystemsIndirect.py +45 -0
- tests/models/ipcc2019/test_n2OToAirCropResidueBurningIndirect.py +45 -0
- tests/models/ipcc2019/test_n2OToAirCropResidueDecompositionIndirect.py +6 -32
- tests/models/ipcc2019/test_n2OToAirExcretaIndirect.py +6 -32
- tests/models/ipcc2019/test_n2OToAirFuelCombustionIndirect.py +45 -0
- tests/models/ipcc2019/test_n2OToAirInorganicFertiliserIndirect.py +6 -32
- tests/models/ipcc2019/test_n2OToAirNaturalVegetationBurningIndirect.py +45 -0
- tests/models/ipcc2019/test_n2OToAirOrganicFertiliserIndirect.py +6 -32
- tests/models/ipcc2019/test_n2OToAirOrganicSoilBurningIndirect.py +45 -0
- tests/models/ipcc2019/test_n2OToAirOrganicSoilCultivationIndirect.py +45 -0
- tests/models/ipcc2019/test_n2OToAir_indirect_emissions_utils.py +19 -0
- {hestia_earth_models-0.73.6.dist-info → hestia_earth_models-0.73.8.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.73.6.dist-info → hestia_earth_models-0.73.8.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.73.6.dist-info → hestia_earth_models-0.73.8.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from hestia_earth.schema import EmissionMethodTier
|
|
2
|
+
|
|
3
|
+
from .n2OToAir_indirect_emissions_utils import run as run_emission
|
|
4
|
+
|
|
5
|
+
REQUIREMENTS = {
|
|
6
|
+
"Cycle": {
|
|
7
|
+
"completeness.cropResidue": "True",
|
|
8
|
+
"emissions": [
|
|
9
|
+
{"@type": "Emission", "value": "", "term.@id": "nh3ToAirOrganicSoilBurning"},
|
|
10
|
+
{"@type": "Emission", "value": "", "term.@id": "noxToAirOrganicSoilBurning"}
|
|
11
|
+
],
|
|
12
|
+
"optional": {
|
|
13
|
+
"site": {
|
|
14
|
+
"@type": "Site",
|
|
15
|
+
"measurements": [
|
|
16
|
+
{"@type": "Measurement", "value": "", "term.@id": "ecoClimateZone"}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
LOOKUPS = {
|
|
23
|
+
"emission": [
|
|
24
|
+
"IPCC_2019_EF4_FACTORS", "IPCC_2019_EF4_FACTORS-max", "IPCC_2019_EF4_FACTORS-min",
|
|
25
|
+
"IPCC_2019_EF5_FACTORS", "IPCC_2019_EF5_FACTORS-max", "IPCC_2019_EF5_FACTORS-min"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
RETURNS = {
|
|
29
|
+
"Emission": [{
|
|
30
|
+
"value": "",
|
|
31
|
+
"methodTier": "tier 1"
|
|
32
|
+
}]
|
|
33
|
+
}
|
|
34
|
+
TERM_ID = 'n2OToAirOrganicSoilBurningIndirect'
|
|
35
|
+
TIER = EmissionMethodTier.TIER_1.value
|
|
36
|
+
_NO3_TERM_ID = None
|
|
37
|
+
_NH3_TERM_ID = 'nh3ToAirOrganicSoilBurning'
|
|
38
|
+
_NOX_TERM_ID = 'noxToAirOrganicSoilBurning'
|
|
39
|
+
_EMISSION_IDS = [_NH3_TERM_ID, _NO3_TERM_ID, _NOX_TERM_ID]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def run(cycle: dict):
|
|
43
|
+
return run_emission(TERM_ID, _EMISSION_IDS, cycle)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from hestia_earth.schema import EmissionMethodTier
|
|
2
|
+
|
|
3
|
+
from .n2OToAir_indirect_emissions_utils import run as run_emission
|
|
4
|
+
|
|
5
|
+
REQUIREMENTS = {
|
|
6
|
+
"Cycle": {
|
|
7
|
+
"completeness.cropResidue": "True",
|
|
8
|
+
"emissions": [
|
|
9
|
+
{"@type": "Emission", "value": "", "term.@id": "nh3ToAirOrganicSoilCultivation"},
|
|
10
|
+
{"@type": "Emission", "value": "", "term.@id": "noxToAirOrganicSoilCultivation"}
|
|
11
|
+
],
|
|
12
|
+
"optional": {
|
|
13
|
+
"site": {
|
|
14
|
+
"@type": "Site",
|
|
15
|
+
"measurements": [
|
|
16
|
+
{"@type": "Measurement", "value": "", "term.@id": "ecoClimateZone"}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
LOOKUPS = {
|
|
23
|
+
"emission": [
|
|
24
|
+
"IPCC_2019_EF4_FACTORS", "IPCC_2019_EF4_FACTORS-max", "IPCC_2019_EF4_FACTORS-min",
|
|
25
|
+
"IPCC_2019_EF5_FACTORS", "IPCC_2019_EF5_FACTORS-max", "IPCC_2019_EF5_FACTORS-min"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
RETURNS = {
|
|
29
|
+
"Emission": [{
|
|
30
|
+
"value": "",
|
|
31
|
+
"methodTier": "tier 1"
|
|
32
|
+
}]
|
|
33
|
+
}
|
|
34
|
+
TERM_ID = 'n2OToAirOrganicSoilCultivationIndirect'
|
|
35
|
+
TIER = EmissionMethodTier.TIER_1.value
|
|
36
|
+
_NO3_TERM_ID = None
|
|
37
|
+
_NH3_TERM_ID = 'nh3ToAirOrganicSoilCultivation'
|
|
38
|
+
_NOX_TERM_ID = 'noxToAirOrganicSoilCultivation'
|
|
39
|
+
_EMISSION_IDS = [_NH3_TERM_ID, _NO3_TERM_ID, _NOX_TERM_ID]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def run(cycle: dict):
|
|
43
|
+
return run_emission(TERM_ID, _EMISSION_IDS, cycle)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
from hestia_earth.schema import EmissionMethodTier, EmissionStatsDefinition, TermTermType
|
|
2
|
+
from hestia_earth.utils.lookup import extract_grouped_data
|
|
3
|
+
from hestia_earth.utils.tools import safe_parse_float, non_empty_list, list_sum
|
|
4
|
+
|
|
5
|
+
from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
|
|
6
|
+
from hestia_earth.models.utils import multiply_values
|
|
7
|
+
from hestia_earth.models.utils.constant import Units, get_atomic_conversion
|
|
8
|
+
from hestia_earth.models.utils.emission import _new_emission, get_nh3_no3_nox_to_n
|
|
9
|
+
from hestia_earth.models.utils.cycle import get_ecoClimateZone
|
|
10
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
|
11
|
+
from .utils import _is_wet
|
|
12
|
+
from . import MODEL
|
|
13
|
+
|
|
14
|
+
_TIER = EmissionMethodTier.TIER_1.value
|
|
15
|
+
_EF_4_FACTOR_NAME = 'IPCC_2019_EF4_FACTORS'
|
|
16
|
+
_EF_5_FACTOR_NAME = 'IPCC_2019_EF5_FACTORS'
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _get_emission_factors(log_term: str, emission_id: str, ecoClimateZone: str = None):
|
|
20
|
+
is_wet = _is_wet(ecoClimateZone)
|
|
21
|
+
factors_key = 'default' if is_wet is None else 'wet' if is_wet else 'dry'
|
|
22
|
+
|
|
23
|
+
emission = {'@id': emission_id, 'termType': TermTermType.EMISSION.value}
|
|
24
|
+
|
|
25
|
+
# emission either contains EF4 or EF5
|
|
26
|
+
ef4_factor = get_lookup_value(emission, _EF_4_FACTOR_NAME, model=MODEL, term=log_term)
|
|
27
|
+
ef5_factor = get_lookup_value(emission, _EF_5_FACTOR_NAME, model=MODEL, term=log_term) if not ef4_factor else None
|
|
28
|
+
values = {
|
|
29
|
+
'ef4-factor': extract_grouped_data(
|
|
30
|
+
data=ef4_factor,
|
|
31
|
+
key=factors_key
|
|
32
|
+
),
|
|
33
|
+
'ef4-factor-min': extract_grouped_data(
|
|
34
|
+
data=get_lookup_value(emission, _EF_4_FACTOR_NAME + '-min', model=MODEL, term=log_term),
|
|
35
|
+
key=factors_key
|
|
36
|
+
),
|
|
37
|
+
'ef4-factor-max': extract_grouped_data(
|
|
38
|
+
data=get_lookup_value(emission, _EF_4_FACTOR_NAME + '-max', model=MODEL, term=log_term),
|
|
39
|
+
key=factors_key
|
|
40
|
+
),
|
|
41
|
+
} if ef4_factor else {
|
|
42
|
+
'ef5-factor': ef5_factor,
|
|
43
|
+
'ef5-factor-min': get_lookup_value(emission, _EF_5_FACTOR_NAME + '-min', model=MODEL, term=log_term),
|
|
44
|
+
'ef5-factor-max': get_lookup_value(emission, _EF_5_FACTOR_NAME + '-max', model=MODEL, term=log_term),
|
|
45
|
+
} if ef5_factor else {}
|
|
46
|
+
return {
|
|
47
|
+
k: safe_parse_float(v, default=None) for k, v in values.items()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _emission(emission_id: str, value: float, min: float, max: float, aggregated: bool = False):
|
|
52
|
+
emission = _new_emission(emission_id, MODEL)
|
|
53
|
+
emission['value'] = [value]
|
|
54
|
+
if min is not None:
|
|
55
|
+
emission['min'] = [min]
|
|
56
|
+
if max is not None:
|
|
57
|
+
emission['max'] = [max]
|
|
58
|
+
emission['methodTier'] = _TIER
|
|
59
|
+
emission['statsDefinition'] = EmissionStatsDefinition.MODELLED.value
|
|
60
|
+
emission['methodModelDescription'] = 'Aggregated version' if aggregated else 'Disaggregated version'
|
|
61
|
+
return emission
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _calculate_value(values: list, suffix: str = ''):
|
|
65
|
+
value = list_sum(non_empty_list([
|
|
66
|
+
multiply_values([
|
|
67
|
+
value.get('emission-value'),
|
|
68
|
+
value.get('ef4-factor' + suffix) or value.get('ef5-factor' + suffix)
|
|
69
|
+
])
|
|
70
|
+
for value in values
|
|
71
|
+
]), default=None)
|
|
72
|
+
return value * get_atomic_conversion(Units.KG_N2O, Units.TO_N) if value is not None else None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _run(emission_id: str, values: list, ecoClimateZone: str = None):
|
|
76
|
+
value = _calculate_value(values)
|
|
77
|
+
min = _calculate_value(values, suffix='-min')
|
|
78
|
+
max = _calculate_value(values, suffix='-max')
|
|
79
|
+
return [_emission(emission_id, value, min, max, aggregated=ecoClimateZone is None)]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _should_run(emission_id: str, emission_ids: list, cycle: dict):
|
|
83
|
+
ecoClimateZone = get_ecoClimateZone(cycle)
|
|
84
|
+
|
|
85
|
+
emission_values = get_nh3_no3_nox_to_n(cycle, *emission_ids)
|
|
86
|
+
values = [
|
|
87
|
+
{
|
|
88
|
+
'emission-id': emission_id,
|
|
89
|
+
'emission-value': emission_values[index]
|
|
90
|
+
} | _get_emission_factors(emission_id, emission_id, ecoClimateZone)
|
|
91
|
+
for index, emission_id in enumerate(emission_ids)
|
|
92
|
+
if emission_id is not None
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
logRequirements(cycle, model=MODEL, term=emission_id,
|
|
96
|
+
ecoClimateZone=ecoClimateZone,
|
|
97
|
+
values=log_as_table(values))
|
|
98
|
+
|
|
99
|
+
should_run = all([
|
|
100
|
+
all([
|
|
101
|
+
value.get('emission-value') is not None,
|
|
102
|
+
value.get('ef4-factor') or value.get('ef5-factor') is not None
|
|
103
|
+
])
|
|
104
|
+
for value in values
|
|
105
|
+
])
|
|
106
|
+
logShouldRun(cycle, MODEL, emission_id, should_run, methodTier=_TIER)
|
|
107
|
+
return should_run, values, ecoClimateZone
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def run(emission_id: str, emission_ids: list, cycle: dict):
|
|
111
|
+
should_run, values, ecoClimateZone = _should_run(emission_id, emission_ids, cycle)
|
|
112
|
+
return _run(emission_id, values, ecoClimateZone) if should_run else []
|
|
@@ -120,31 +120,6 @@ N2O_FACTORS = {
|
|
|
120
120
|
'max': 0.029
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
EF4_FACTORS = {
|
|
124
|
-
'dry': {
|
|
125
|
-
'value': 0.005,
|
|
126
|
-
'min': 0,
|
|
127
|
-
'max': 0.011
|
|
128
|
-
|
|
129
|
-
},
|
|
130
|
-
'wet': {
|
|
131
|
-
'value': 0.014,
|
|
132
|
-
'min': 0.011,
|
|
133
|
-
'max': 0.017
|
|
134
|
-
},
|
|
135
|
-
'default': {
|
|
136
|
-
'value': 0.01,
|
|
137
|
-
'min': 0.002,
|
|
138
|
-
'max': 0.018
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
EF5_FACTORS = {
|
|
142
|
-
'default': {
|
|
143
|
-
'value': 0.011,
|
|
144
|
-
'min': 0.0,
|
|
145
|
-
'max': 0.02
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
123
|
|
|
149
124
|
|
|
150
125
|
def _get_waterRegime_lookup(model_term_id: str, practice: dict, col: str):
|
|
@@ -22,7 +22,7 @@ RETURNS = {
|
|
|
22
22
|
}
|
|
23
23
|
TERM_ID = 'n2ToAirExcreta'
|
|
24
24
|
TIER = EmissionMethodTier.TIER_1.value
|
|
25
|
-
|
|
25
|
+
_N2O_TERM_ID = 'n2OToAirExcretaDirect'
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def _emission(value: float):
|
|
@@ -32,21 +32,23 @@ def _emission(value: float):
|
|
|
32
32
|
return emission
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
def _run(
|
|
36
|
-
value = 3 *
|
|
35
|
+
def _run(n2o_value: float):
|
|
36
|
+
value = 3 * n2o_value / get_atomic_conversion(Units.KG_N2O, Units.TO_N)
|
|
37
37
|
return [_emission(value)]
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
def _should_run(cycle: dict):
|
|
41
|
-
n2o = find_term_match(cycle.get('emissions', []),
|
|
41
|
+
n2o = find_term_match(cycle.get('emissions', []), _N2O_TERM_ID)
|
|
42
|
+
n2o_value = list_sum(n2o.get("value", []), default=None)
|
|
42
43
|
|
|
43
|
-
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
44
|
+
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
45
|
+
**{_N2O_TERM_ID: n2o_value})
|
|
44
46
|
|
|
45
|
-
should_run = all([
|
|
47
|
+
should_run = all([n2o_value is not None])
|
|
46
48
|
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
47
|
-
return should_run,
|
|
49
|
+
return should_run, n2o_value
|
|
48
50
|
|
|
49
51
|
|
|
50
52
|
def run(cycle: dict):
|
|
51
|
-
should_run,
|
|
52
|
-
return _run(
|
|
53
|
+
should_run, n2o_value = _should_run(cycle)
|
|
54
|
+
return _run(n2o_value) if should_run else []
|
|
@@ -4,6 +4,7 @@ from hestia_earth.utils.lookup import download_lookup, get_table_value, column_n
|
|
|
4
4
|
from hestia_earth.utils.tools import flatten, list_sum
|
|
5
5
|
|
|
6
6
|
from hestia_earth.models.log import logShouldRun, debugValues, log_as_table
|
|
7
|
+
from hestia_earth.models.utils import _include
|
|
7
8
|
from hestia_earth.models.utils.emission import _new_emission
|
|
8
9
|
from hestia_earth.models.utils.input import load_impacts
|
|
9
10
|
from hestia_earth.models.utils.blank_node import group_by_keys
|
|
@@ -49,18 +50,17 @@ LOOKUPS = {
|
|
|
49
50
|
MODEL_KEY = 'emissions'
|
|
50
51
|
MODEL_AGGREGATED = 'hestiaAggregatedData'
|
|
51
52
|
TIER = EmissionMethodTier.BACKGROUND.value
|
|
53
|
+
_GROUP_BY_KEYS = ['term', 'key', 'operation', 'animal']
|
|
52
54
|
|
|
53
55
|
|
|
54
|
-
def _emission(model: str, term_id: str, value: float, input: dict,
|
|
56
|
+
def _emission(model: str, term_id: str, value: float, input: dict, animal={}, extra={}):
|
|
55
57
|
emission = _new_emission(term_id, model)
|
|
56
58
|
emission['value'] = [value]
|
|
57
59
|
emission['methodTier'] = TIER
|
|
58
60
|
emission['inputs'] = [input]
|
|
59
|
-
if operation:
|
|
60
|
-
emission['operation'] = operation
|
|
61
61
|
if animal:
|
|
62
62
|
emission['animals'] = [animal]
|
|
63
|
-
return emission
|
|
63
|
+
return emission | extra
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
def _run_emission(cycle: dict, emission_term_id: str, data: dict):
|
|
@@ -68,6 +68,7 @@ def _run_emission(cycle: dict, emission_term_id: str, data: dict):
|
|
|
68
68
|
value = values.get('value', 0)
|
|
69
69
|
input_term = values.get('term', {})
|
|
70
70
|
input_term_id = input_term.get('@id')
|
|
71
|
+
key = values.get('key', {})
|
|
71
72
|
operation = values.get('operation', {})
|
|
72
73
|
animal = values.get('animal', {})
|
|
73
74
|
is_aggregated = any(values.get('aggregated', []))
|
|
@@ -83,10 +84,18 @@ def _run_emission(cycle: dict, emission_term_id: str, data: dict):
|
|
|
83
84
|
coefficient=1,
|
|
84
85
|
details=log_as_table([{'impact-assessment-id': key} | value for key, value in details.items()]),
|
|
85
86
|
input=input_term_id,
|
|
87
|
+
key=key.get('@id'),
|
|
86
88
|
operation=operation.get('@id'),
|
|
87
89
|
animal=animal.get('@id'))
|
|
88
90
|
|
|
89
|
-
return _emission(
|
|
91
|
+
return _emission(
|
|
92
|
+
model=model,
|
|
93
|
+
term_id=emission_term_id,
|
|
94
|
+
value=value,
|
|
95
|
+
input=input_term,
|
|
96
|
+
animal=animal,
|
|
97
|
+
extra=_include(values, ['key', 'operation'])
|
|
98
|
+
)
|
|
90
99
|
|
|
91
100
|
return list(map(run_input, data.values()))
|
|
92
101
|
|
|
@@ -130,14 +139,14 @@ def _group_inputs(group: dict, values: tuple):
|
|
|
130
139
|
for emission_term_id, emission_value in emissions.items():
|
|
131
140
|
group[emission_term_id] = group.get(emission_term_id, {})
|
|
132
141
|
|
|
133
|
-
grouped_inputs =
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
grouped_inputs = (
|
|
143
|
+
group[emission_term_id].get(input_group_key) or
|
|
144
|
+
_include(input, _GROUP_BY_KEYS) | {
|
|
145
|
+
'value': 0,
|
|
146
|
+
'aggregated': [],
|
|
147
|
+
'details': {}
|
|
148
|
+
}
|
|
149
|
+
)
|
|
141
150
|
grouped_inputs['aggregated'].append(input.get('impactAssessment', {}).get('agregated', False))
|
|
142
151
|
grouped_inputs['value'] = grouped_inputs['value'] + (emission_value * input_value)
|
|
143
152
|
# for logging
|
|
@@ -156,9 +165,9 @@ def run(cycle: dict):
|
|
|
156
165
|
)
|
|
157
166
|
inputs = [i for i in inputs if list_sum(i.get('value', [])) > 0]
|
|
158
167
|
|
|
159
|
-
# group inputs with same term/operation/animal to avoid adding emissions twice
|
|
168
|
+
# group inputs with same term/key/operation/animal to avoid adding emissions twice
|
|
160
169
|
# inputs = {'group-id': [{'term': {},'value':[10],'impactAssessment': {}}]}
|
|
161
|
-
inputs = reduce(group_by_keys(
|
|
170
|
+
inputs = reduce(group_by_keys(_GROUP_BY_KEYS), inputs, {})
|
|
162
171
|
inputs = {key: list(map(_group_input_emissions, value)) for key, value in inputs.items()}
|
|
163
172
|
|
|
164
173
|
# finally group everything by emission so we can log inputs together
|
|
@@ -42,13 +42,16 @@ def _run_indicators(impact_assessment: dict, product: dict, term_id: str, model:
|
|
|
42
42
|
def _run_inputs_production(impact_assessment: dict, product: dict, term_id: str, model: str):
|
|
43
43
|
cycle = impact_assessment.get('cycle', {})
|
|
44
44
|
|
|
45
|
+
inputs = load_impacts(cycle.get('inputs', []))
|
|
46
|
+
inputs_with_impact = [i for i in inputs if i.get('impactAssessment')]
|
|
47
|
+
|
|
45
48
|
# group all indicators per `landCover` and `previousLandCover`
|
|
46
49
|
all_indicators = flatten([
|
|
47
50
|
{
|
|
48
51
|
'indicator': indicator,
|
|
49
52
|
'input': input
|
|
50
53
|
}
|
|
51
|
-
for input in
|
|
54
|
+
for input in inputs
|
|
52
55
|
for indicator in (
|
|
53
56
|
input.get('impactAssessment', {}).get('emissionsResourceUse', []) +
|
|
54
57
|
input.get('impactAssessment', {}).get('impacts', [])
|
|
@@ -72,6 +75,7 @@ def _run_inputs_production(impact_assessment: dict, product: dict, term_id: str,
|
|
|
72
75
|
has_indicators = bool(valid_indicators)
|
|
73
76
|
|
|
74
77
|
logRequirements(impact_assessment, model=model, term=term_id,
|
|
78
|
+
inputs_with_linked_impact_assessment=len(inputs_with_impact),
|
|
75
79
|
indicators=log_as_table([
|
|
76
80
|
{
|
|
77
81
|
'indicator-id': value.get('indicator').get('term', {}).get('@id'),
|