hestia-earth-models 0.74.2__py3-none-any.whl → 0.74.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/config/Cycle.json +23 -0
- hestia_earth/models/config/ImpactAssessment.json +22 -11
- hestia_earth/models/cycle/aboveGroundCropResidueTotal.py +50 -0
- hestia_earth/models/cycle/completeness/freshForage.py +2 -2
- hestia_earth/models/emepEea2019/co2ToAirFuelCombustion.py +2 -27
- hestia_earth/models/emepEea2019/fuelCombustion_utils.py +107 -0
- hestia_earth/models/emepEea2019/n2OToAirFuelCombustionDirect.py +2 -27
- hestia_earth/models/emepEea2019/nh3ToAirFuelCombustion.py +33 -0
- hestia_earth/models/emepEea2019/noxToAirFuelCombustion.py +2 -27
- hestia_earth/models/emepEea2019/so2ToAirFuelCombustion.py +2 -27
- hestia_earth/models/emepEea2019/utils.py +1 -73
- hestia_earth/models/hestia/landOccupationDuringCycle.py +264 -0
- hestia_earth/models/hestia/management.py +61 -11
- hestia_earth/models/ipcc2006/aboveGroundCropResidueTotal.py +20 -11
- hestia_earth/models/ipcc2019/aboveGroundCropResidueTotal.py +37 -28
- hestia_earth/models/ipcc2019/animal/pastureGrass.py +6 -4
- hestia_earth/models/mocking/search-results.json +704 -704
- hestia_earth/models/utils/cropResidue.py +5 -0
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.74.2.dist-info → hestia_earth_models-0.74.4.dist-info}/METADATA +1 -1
- {hestia_earth_models-0.74.2.dist-info → hestia_earth_models-0.74.4.dist-info}/RECORD +35 -28
- tests/models/cycle/test_aboveGroundCropResidueTotal.py +20 -0
- tests/models/emepEea2019/test_co2ToAirFuelCombustion.py +2 -1
- tests/models/emepEea2019/test_n2OToAirFuelCombustionDirect.py +2 -1
- tests/models/emepEea2019/test_nh3ToAirFuelCombustion.py +34 -0
- tests/models/emepEea2019/test_noxToAirFuelCombustion.py +2 -1
- tests/models/emepEea2019/test_so2ToAirFuelCombustion.py +2 -1
- tests/models/environmentalFootprintV3_1/test_scarcityWeightedWaterUse.py +0 -1
- tests/models/hestia/test_landCover.py +1 -1
- tests/models/hestia/test_landOccupationDuringCycle.py +68 -0
- tests/models/ipcc2006/test_aboveGroundCropResidueTotal.py +9 -6
- tests/models/ipcc2019/test_aboveGroundCropResidueTotal.py +16 -42
- {hestia_earth_models-0.74.2.dist-info → hestia_earth_models-0.74.4.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.74.2.dist-info → hestia_earth_models-0.74.4.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.74.2.dist-info → hestia_earth_models-0.74.4.dist-info}/top_level.txt +0 -0
|
@@ -246,6 +246,14 @@
|
|
|
246
246
|
"mergeStrategy": "list",
|
|
247
247
|
"stage": 1
|
|
248
248
|
},
|
|
249
|
+
{
|
|
250
|
+
"key": "products",
|
|
251
|
+
"model": "cycle",
|
|
252
|
+
"value": "aboveGroundCropResidueTotal",
|
|
253
|
+
"runStrategy": "add_blank_node_if_missing",
|
|
254
|
+
"mergeStrategy": "list",
|
|
255
|
+
"stage": 1
|
|
256
|
+
},
|
|
249
257
|
[
|
|
250
258
|
{
|
|
251
259
|
"key": "practices",
|
|
@@ -1763,6 +1771,21 @@
|
|
|
1763
1771
|
},
|
|
1764
1772
|
"stage": 2
|
|
1765
1773
|
},
|
|
1774
|
+
{
|
|
1775
|
+
"key": "emissions",
|
|
1776
|
+
"model": "emepEea2019",
|
|
1777
|
+
"value": "nh3ToAirFuelCombustion",
|
|
1778
|
+
"runStrategy": "add_blank_node_if_missing",
|
|
1779
|
+
"runArgs": {
|
|
1780
|
+
"runNonMeasured": true,
|
|
1781
|
+
"runNonAddedTerm": true
|
|
1782
|
+
},
|
|
1783
|
+
"mergeStrategy": "list",
|
|
1784
|
+
"mergeArgs": {
|
|
1785
|
+
"replaceThreshold": ["value", 0.01]
|
|
1786
|
+
},
|
|
1787
|
+
"stage": 2
|
|
1788
|
+
},
|
|
1766
1789
|
{
|
|
1767
1790
|
"key": "emissions",
|
|
1768
1791
|
"model": "emepEea2019",
|
|
@@ -67,18 +67,29 @@
|
|
|
67
67
|
},
|
|
68
68
|
"stage": 1
|
|
69
69
|
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
{
|
|
71
|
+
"key": "emissionsResourceUse",
|
|
72
|
+
"model": "hestia",
|
|
73
|
+
"value": "landOccupationDuringCycle",
|
|
74
|
+
"runStrategy": "always",
|
|
75
|
+
"mergeStrategy": "list",
|
|
76
|
+
"mergeArgs": {
|
|
77
|
+
"replaceThreshold": ["value", 0.01]
|
|
78
|
+
},
|
|
79
|
+
"stage": 1
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"key": "emissionsResourceUse",
|
|
83
|
+
"model": "pooreNemecek2018",
|
|
84
|
+
"value": "landOccupationDuringCycle",
|
|
85
|
+
"runStrategy": "always",
|
|
86
|
+
"mergeStrategy": "list",
|
|
87
|
+
"mergeArgs": {
|
|
88
|
+
"replaceThreshold": ["value", 0.01]
|
|
81
89
|
},
|
|
90
|
+
"stage": 1
|
|
91
|
+
},
|
|
92
|
+
[
|
|
82
93
|
{
|
|
83
94
|
"key": "emissionsResourceUse",
|
|
84
95
|
"model": "linkedImpactAssessment",
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
2
|
+
from hestia_earth.models.utils.completeness import _is_term_type_incomplete
|
|
3
|
+
from hestia_earth.models.utils.product import _new_product
|
|
4
|
+
from hestia_earth.models.utils.cropResidue import sum_above_ground_crop_residue
|
|
5
|
+
from . import MODEL
|
|
6
|
+
|
|
7
|
+
REQUIREMENTS = {
|
|
8
|
+
"Cycle": {
|
|
9
|
+
"completeness.cropResidue": "False",
|
|
10
|
+
"products": [{
|
|
11
|
+
"@type": "Product",
|
|
12
|
+
"value": "> 0",
|
|
13
|
+
"term.@id": [
|
|
14
|
+
"aboveGroundCropResidueRemoved",
|
|
15
|
+
"aboveGroundCropResidueIncorporated",
|
|
16
|
+
"aboveGroundCropResidueBurnt",
|
|
17
|
+
"aboveGroundCropResidueLeftOnField"
|
|
18
|
+
]
|
|
19
|
+
}]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
RETURNS = {
|
|
23
|
+
"Product": [{
|
|
24
|
+
"value": ""
|
|
25
|
+
}]
|
|
26
|
+
}
|
|
27
|
+
TERM_ID = 'aboveGroundCropResidueTotal'
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _product(value: float):
|
|
31
|
+
product = _new_product(TERM_ID, value)
|
|
32
|
+
return product
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _should_run(cycle: dict):
|
|
36
|
+
term_type_incomplete = _is_term_type_incomplete(cycle, TERM_ID)
|
|
37
|
+
value = sum_above_ground_crop_residue(cycle)
|
|
38
|
+
|
|
39
|
+
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
40
|
+
term_type_cropResidue_incomplete=term_type_incomplete,
|
|
41
|
+
sum_above_ground_crop_residue=value)
|
|
42
|
+
|
|
43
|
+
should_run = all([term_type_incomplete, value > 0])
|
|
44
|
+
logShouldRun(cycle, MODEL, TERM_ID, should_run)
|
|
45
|
+
return should_run, value
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def run(cycle: dict):
|
|
49
|
+
should_run, value = _should_run(cycle)
|
|
50
|
+
return [_product(value)] if should_run else []
|
|
@@ -15,10 +15,10 @@ REQUIREMENTS = {
|
|
|
15
15
|
"siteType": "permanent pasture"
|
|
16
16
|
},
|
|
17
17
|
"or": {
|
|
18
|
-
"inputs": [{"@type": "Input", "termType": "forage", "value": "
|
|
18
|
+
"inputs": [{"@type": "Input", "termType": "forage", "value": ">= 0", "added": ["value"]}],
|
|
19
19
|
"animals": [{
|
|
20
20
|
"@type": "Animal",
|
|
21
|
-
"inputs": [{"@type": "Input", "termType": "forage", "value": "
|
|
21
|
+
"inputs": [{"@type": "Input", "termType": "forage", "value": ">= 0", "added": ["value"]}]
|
|
22
22
|
}]
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
from hestia_earth.schema import EmissionMethodTier
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from hestia_earth.models.utils.completeness import _is_term_type_complete
|
|
5
|
-
from .utils import get_fuel_inputs, group_fuel_inputs, _emission, _run_inputs
|
|
6
|
-
from . import MODEL
|
|
3
|
+
from .fuelCombustion_utils import run as run_fuelCombustion
|
|
7
4
|
|
|
8
5
|
REQUIREMENTS = {
|
|
9
6
|
"Cycle": {
|
|
@@ -33,26 +30,4 @@ TERM_ID = 'co2ToAirFuelCombustion'
|
|
|
33
30
|
TIER = EmissionMethodTier.TIER_1.value
|
|
34
31
|
|
|
35
32
|
|
|
36
|
-
def
|
|
37
|
-
electricity_complete = _is_term_type_complete(cycle, 'electricityFuel')
|
|
38
|
-
fuel_inputs, valid_inputs = get_fuel_inputs(TERM_ID, cycle, LOOKUPS['fuel'])
|
|
39
|
-
|
|
40
|
-
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
41
|
-
termType_electricityFuel_complete=electricity_complete,
|
|
42
|
-
fuel_inputs=log_as_table(fuel_inputs))
|
|
43
|
-
|
|
44
|
-
should_run = any([bool(valid_inputs), electricity_complete])
|
|
45
|
-
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
46
|
-
return should_run, group_fuel_inputs(valid_inputs)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def run(cycle: dict):
|
|
50
|
-
should_run, fuel_inputs = _should_run(cycle)
|
|
51
|
-
return (
|
|
52
|
-
[
|
|
53
|
-
_run_inputs(inputs, tier=TIER, term_id=TERM_ID)
|
|
54
|
-
for inputs in fuel_inputs.values()
|
|
55
|
-
] if fuel_inputs else [
|
|
56
|
-
_emission(value=0, tier=TIER, term_id=TERM_ID)
|
|
57
|
-
]
|
|
58
|
-
) if should_run else []
|
|
33
|
+
def run(cycle: dict): return run_fuelCombustion(cycle, term_id=TERM_ID)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
from hestia_earth.schema import EmissionMethodTier, TermTermType
|
|
2
|
+
from hestia_earth.utils.model import filter_list_term_type
|
|
3
|
+
from hestia_earth.utils.lookup import extract_grouped_data
|
|
4
|
+
from hestia_earth.utils.blank_node import group_by_keys
|
|
5
|
+
from hestia_earth.utils.tools import list_sum, safe_parse_float
|
|
6
|
+
|
|
7
|
+
from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
|
|
8
|
+
from hestia_earth.models.utils.completeness import _is_term_type_complete
|
|
9
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
|
10
|
+
from .utils import _emission
|
|
11
|
+
from . import MODEL
|
|
12
|
+
|
|
13
|
+
_TIER = EmissionMethodTier.TIER_1.value
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _run_inputs(inputs: list, tier: str, term_id: str):
|
|
17
|
+
total_value = list_sum([
|
|
18
|
+
(i.get('input-value') or 0) * (i.get('operation-factor') or i.get('input-default-factor') or 0)
|
|
19
|
+
for i in inputs
|
|
20
|
+
])
|
|
21
|
+
input_term = {
|
|
22
|
+
'@type': 'Term',
|
|
23
|
+
'@id': inputs[0].get('input-id'),
|
|
24
|
+
'termType': inputs[0].get('input-termType'),
|
|
25
|
+
'units': inputs[0].get('input-units'),
|
|
26
|
+
}
|
|
27
|
+
operation_term = {
|
|
28
|
+
'@type': 'Term',
|
|
29
|
+
'@id': inputs[0].get('operation-id'),
|
|
30
|
+
'termType': inputs[0].get('operation-termType'),
|
|
31
|
+
'units': inputs[0].get('operation-units'),
|
|
32
|
+
} if inputs[0].get('operation-id') else None
|
|
33
|
+
return _emission(
|
|
34
|
+
value=total_value,
|
|
35
|
+
tier=tier,
|
|
36
|
+
term_id=term_id,
|
|
37
|
+
input=input_term,
|
|
38
|
+
operation=operation_term
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _fuel_input_data(term_id: str, lookup_col: str, input: dict):
|
|
43
|
+
input_term = input.get('term', {})
|
|
44
|
+
input_term_id = input_term.get('@id')
|
|
45
|
+
operation_term = input.get('operation', {})
|
|
46
|
+
input_value = list_sum(input.get('value', []), None)
|
|
47
|
+
|
|
48
|
+
operation_factor = extract_grouped_data(
|
|
49
|
+
data=get_lookup_value(operation_term, lookup_col, model=MODEL, term=term_id),
|
|
50
|
+
key=input_term_id
|
|
51
|
+
) if operation_term else None
|
|
52
|
+
input_factor = get_lookup_value(input_term, lookup_col, model=MODEL, term=term_id)
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
'input-id': input_term_id,
|
|
56
|
+
'input-termType': input_term.get('termType'),
|
|
57
|
+
'input-units': input_term.get('units'),
|
|
58
|
+
'input-value': input_value,
|
|
59
|
+
'input-default-factor': safe_parse_float(input_factor, default=None),
|
|
60
|
+
'operation-id': operation_term.get('@id'),
|
|
61
|
+
'operation-termType': operation_term.get('termType'),
|
|
62
|
+
'operation-units': operation_term.get('units'),
|
|
63
|
+
'operation-factor': safe_parse_float(operation_factor, default=None)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def get_fuel_inputs(term_id: str, cycle: dict, lookup_col: str):
|
|
68
|
+
inputs = [
|
|
69
|
+
_fuel_input_data(term_id, lookup_col, i)
|
|
70
|
+
for i in filter_list_term_type(cycle.get('inputs', []), TermTermType.FUEL)
|
|
71
|
+
]
|
|
72
|
+
valid_inputs = [
|
|
73
|
+
i for i in inputs if all([
|
|
74
|
+
i.get('input-value') is not None,
|
|
75
|
+
(i.get('operation-factor') or i.get('input-default-factor')) is not None
|
|
76
|
+
])
|
|
77
|
+
]
|
|
78
|
+
return inputs, valid_inputs
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def group_fuel_inputs(inputs: list):
|
|
82
|
+
return group_by_keys(inputs, ['input-id', 'operation-id']) if len(inputs) > 0 else None
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _should_run(cycle: dict, term_id: str, lookup_prefix: str = None):
|
|
86
|
+
electricity_complete = _is_term_type_complete(cycle, 'electricityFuel')
|
|
87
|
+
fuel_inputs, valid_inputs = get_fuel_inputs(term_id, cycle, f"{lookup_prefix or term_id}EmepEea2019")
|
|
88
|
+
|
|
89
|
+
logRequirements(cycle, model=MODEL, term=term_id,
|
|
90
|
+
termType_electricityFuel_complete=electricity_complete,
|
|
91
|
+
fuel_inputs=log_as_table(fuel_inputs))
|
|
92
|
+
|
|
93
|
+
should_run = any([bool(valid_inputs), electricity_complete])
|
|
94
|
+
logShouldRun(cycle, MODEL, term_id, should_run, methodTier=_TIER)
|
|
95
|
+
return should_run, group_fuel_inputs(valid_inputs)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def run(cycle: dict, term_id: str, lookup_prefix: str = None):
|
|
99
|
+
should_run, fuel_inputs = _should_run(cycle, term_id, lookup_prefix)
|
|
100
|
+
return (
|
|
101
|
+
[
|
|
102
|
+
_run_inputs(inputs, tier=_TIER, term_id=term_id)
|
|
103
|
+
for inputs in fuel_inputs.values()
|
|
104
|
+
] if fuel_inputs else [
|
|
105
|
+
_emission(value=0, tier=_TIER, term_id=term_id)
|
|
106
|
+
]
|
|
107
|
+
) if should_run else []
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
from hestia_earth.schema import EmissionMethodTier
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from hestia_earth.models.utils.completeness import _is_term_type_complete
|
|
5
|
-
from .utils import get_fuel_inputs, group_fuel_inputs, _emission, _run_inputs
|
|
6
|
-
from . import MODEL
|
|
3
|
+
from .fuelCombustion_utils import run as run_fuelCombustion
|
|
7
4
|
|
|
8
5
|
REQUIREMENTS = {
|
|
9
6
|
"Cycle": {
|
|
@@ -33,26 +30,4 @@ TERM_ID = 'n2OToAirFuelCombustionDirect'
|
|
|
33
30
|
TIER = EmissionMethodTier.TIER_1.value
|
|
34
31
|
|
|
35
32
|
|
|
36
|
-
def
|
|
37
|
-
electricity_complete = _is_term_type_complete(cycle, 'electricityFuel')
|
|
38
|
-
fuel_inputs, valid_inputs = get_fuel_inputs(TERM_ID, cycle, LOOKUPS['fuel'])
|
|
39
|
-
|
|
40
|
-
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
41
|
-
termType_electricityFuel_complete=electricity_complete,
|
|
42
|
-
fuel_inputs=log_as_table(fuel_inputs))
|
|
43
|
-
|
|
44
|
-
should_run = any([bool(valid_inputs), electricity_complete])
|
|
45
|
-
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
46
|
-
return should_run, group_fuel_inputs(valid_inputs)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def run(cycle: dict):
|
|
50
|
-
should_run, fuel_inputs = _should_run(cycle)
|
|
51
|
-
return (
|
|
52
|
-
[
|
|
53
|
-
_run_inputs(inputs, tier=TIER, term_id=TERM_ID)
|
|
54
|
-
for inputs in fuel_inputs.values()
|
|
55
|
-
] if fuel_inputs else [
|
|
56
|
-
_emission(value=0, tier=TIER, term_id=TERM_ID)
|
|
57
|
-
]
|
|
58
|
-
) if should_run else []
|
|
33
|
+
def run(cycle: dict): return run_fuelCombustion(cycle, term_id=TERM_ID, lookup_prefix='n2oToAirFuelCombustion')
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from hestia_earth.schema import EmissionMethodTier
|
|
2
|
+
|
|
3
|
+
from .fuelCombustion_utils import run as run_fuelCombustion
|
|
4
|
+
|
|
5
|
+
REQUIREMENTS = {
|
|
6
|
+
"Cycle": {
|
|
7
|
+
"or": {
|
|
8
|
+
"inputs": [
|
|
9
|
+
{"@type": "Input", "value": "", "term.termType": "fuel", "optional": {
|
|
10
|
+
"operation": ""
|
|
11
|
+
}}
|
|
12
|
+
],
|
|
13
|
+
"completeness.electricityFuel": "True"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
RETURNS = {
|
|
18
|
+
"Emission": [{
|
|
19
|
+
"value": "",
|
|
20
|
+
"inputs": "",
|
|
21
|
+
"operation": "",
|
|
22
|
+
"methodTier": "tier 1"
|
|
23
|
+
}]
|
|
24
|
+
}
|
|
25
|
+
LOOKUPS = {
|
|
26
|
+
"fuel": "nh3ToAirFuelCombustionEmepEea2019",
|
|
27
|
+
"operation": "nh3ToAirFuelCombustionEmepEea2019"
|
|
28
|
+
}
|
|
29
|
+
TERM_ID = 'nh3ToAirFuelCombustion'
|
|
30
|
+
TIER = EmissionMethodTier.TIER_1.value
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def run(cycle: dict): return run_fuelCombustion(cycle, term_id=TERM_ID)
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
from hestia_earth.schema import EmissionMethodTier
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from hestia_earth.models.utils.completeness import _is_term_type_complete
|
|
5
|
-
from .utils import get_fuel_inputs, group_fuel_inputs, _emission, _run_inputs
|
|
6
|
-
from . import MODEL
|
|
3
|
+
from .fuelCombustion_utils import run as run_fuelCombustion
|
|
7
4
|
|
|
8
5
|
REQUIREMENTS = {
|
|
9
6
|
"Cycle": {
|
|
@@ -33,26 +30,4 @@ TERM_ID = 'noxToAirFuelCombustion'
|
|
|
33
30
|
TIER = EmissionMethodTier.TIER_1.value
|
|
34
31
|
|
|
35
32
|
|
|
36
|
-
def
|
|
37
|
-
electricity_complete = _is_term_type_complete(cycle, 'electricityFuel')
|
|
38
|
-
fuel_inputs, valid_inputs = get_fuel_inputs(TERM_ID, cycle, LOOKUPS['fuel'])
|
|
39
|
-
|
|
40
|
-
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
41
|
-
termType_electricityFuel_complete=electricity_complete,
|
|
42
|
-
fuel_inputs=log_as_table(fuel_inputs))
|
|
43
|
-
|
|
44
|
-
should_run = any([bool(valid_inputs), electricity_complete])
|
|
45
|
-
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
46
|
-
return should_run, group_fuel_inputs(valid_inputs)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def run(cycle: dict):
|
|
50
|
-
should_run, fuel_inputs = _should_run(cycle)
|
|
51
|
-
return (
|
|
52
|
-
[
|
|
53
|
-
_run_inputs(inputs, tier=TIER, term_id=TERM_ID)
|
|
54
|
-
for inputs in fuel_inputs.values()
|
|
55
|
-
] if fuel_inputs else [
|
|
56
|
-
_emission(value=0, tier=TIER, term_id=TERM_ID)
|
|
57
|
-
]
|
|
58
|
-
) if should_run else []
|
|
33
|
+
def run(cycle: dict): return run_fuelCombustion(cycle, term_id=TERM_ID)
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
from hestia_earth.schema import EmissionMethodTier
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from hestia_earth.models.utils.completeness import _is_term_type_complete
|
|
5
|
-
from .utils import get_fuel_inputs, group_fuel_inputs, _emission, _run_inputs
|
|
6
|
-
from . import MODEL
|
|
3
|
+
from .fuelCombustion_utils import run as run_fuelCombustion
|
|
7
4
|
|
|
8
5
|
REQUIREMENTS = {
|
|
9
6
|
"Cycle": {
|
|
@@ -33,26 +30,4 @@ TERM_ID = 'so2ToAirFuelCombustion'
|
|
|
33
30
|
TIER = EmissionMethodTier.TIER_1.value
|
|
34
31
|
|
|
35
32
|
|
|
36
|
-
def
|
|
37
|
-
electricity_complete = _is_term_type_complete(cycle, 'electricityFuel')
|
|
38
|
-
fuel_inputs, valid_inputs = get_fuel_inputs(TERM_ID, cycle, LOOKUPS['fuel'])
|
|
39
|
-
|
|
40
|
-
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
41
|
-
termType_electricityFuel_complete=electricity_complete,
|
|
42
|
-
fuel_inputs=log_as_table(fuel_inputs))
|
|
43
|
-
|
|
44
|
-
should_run = any([bool(valid_inputs), electricity_complete])
|
|
45
|
-
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
46
|
-
return should_run, group_fuel_inputs(valid_inputs)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def run(cycle: dict):
|
|
50
|
-
should_run, fuel_inputs = _should_run(cycle)
|
|
51
|
-
return (
|
|
52
|
-
[
|
|
53
|
-
_run_inputs(inputs, tier=TIER, term_id=TERM_ID)
|
|
54
|
-
for inputs in fuel_inputs.values()
|
|
55
|
-
] if fuel_inputs else [
|
|
56
|
-
_emission(value=0, tier=TIER, term_id=TERM_ID)
|
|
57
|
-
]
|
|
58
|
-
) if should_run else []
|
|
33
|
+
def run(cycle: dict): return run_fuelCombustion(cycle, term_id=TERM_ID)
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
from hestia_earth.schema import
|
|
2
|
-
from hestia_earth.utils.model import filter_list_term_type
|
|
3
|
-
from hestia_earth.utils.lookup import extract_grouped_data
|
|
4
|
-
from hestia_earth.utils.blank_node import group_by_keys
|
|
1
|
+
from hestia_earth.schema import SiteSiteType
|
|
5
2
|
from hestia_earth.utils.tools import list_sum, safe_parse_float
|
|
6
3
|
|
|
7
4
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
@@ -23,75 +20,6 @@ def _emission(value: float, tier: str, term_id: str, input: dict = None, operati
|
|
|
23
20
|
return emission
|
|
24
21
|
|
|
25
22
|
|
|
26
|
-
def _run_inputs(inputs: list, tier: str, term_id: str):
|
|
27
|
-
total_value = list_sum([
|
|
28
|
-
(i.get('input-value') or 0) * (i.get('operation-factor') or i.get('input-default-factor') or 0)
|
|
29
|
-
for i in inputs
|
|
30
|
-
])
|
|
31
|
-
input_term = {
|
|
32
|
-
'@type': 'Term',
|
|
33
|
-
'@id': inputs[0].get('input-id'),
|
|
34
|
-
'termType': inputs[0].get('input-termType'),
|
|
35
|
-
'units': inputs[0].get('input-units'),
|
|
36
|
-
}
|
|
37
|
-
operation_term = {
|
|
38
|
-
'@type': 'Term',
|
|
39
|
-
'@id': inputs[0].get('operation-id'),
|
|
40
|
-
'termType': inputs[0].get('operation-termType'),
|
|
41
|
-
'units': inputs[0].get('operation-units'),
|
|
42
|
-
} if inputs[0].get('operation-id') else None
|
|
43
|
-
return _emission(
|
|
44
|
-
value=total_value,
|
|
45
|
-
tier=tier,
|
|
46
|
-
term_id=term_id,
|
|
47
|
-
input=input_term,
|
|
48
|
-
operation=operation_term
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def _fuel_input_data(term_id: str, lookup_col: str, input: dict):
|
|
53
|
-
input_term = input.get('term', {})
|
|
54
|
-
input_term_id = input_term.get('@id')
|
|
55
|
-
operation_term = input.get('operation', {})
|
|
56
|
-
input_value = list_sum(input.get('value', []), None)
|
|
57
|
-
|
|
58
|
-
operation_factor = extract_grouped_data(
|
|
59
|
-
data=get_lookup_value(operation_term, lookup_col, model=MODEL, term=term_id),
|
|
60
|
-
key=input_term_id
|
|
61
|
-
) if operation_term else None
|
|
62
|
-
input_factor = get_lookup_value(input_term, lookup_col, model=MODEL, term=term_id)
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
'input-id': input_term_id,
|
|
66
|
-
'input-termType': input_term.get('termType'),
|
|
67
|
-
'input-units': input_term.get('units'),
|
|
68
|
-
'input-value': input_value,
|
|
69
|
-
'input-default-factor': safe_parse_float(input_factor, default=None),
|
|
70
|
-
'operation-id': operation_term.get('@id'),
|
|
71
|
-
'operation-termType': operation_term.get('termType'),
|
|
72
|
-
'operation-units': operation_term.get('units'),
|
|
73
|
-
'operation-factor': safe_parse_float(operation_factor, default=None)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def get_fuel_inputs(term_id: str, cycle: dict, lookup_col: str):
|
|
78
|
-
inputs = [
|
|
79
|
-
_fuel_input_data(term_id, lookup_col, i)
|
|
80
|
-
for i in filter_list_term_type(cycle.get('inputs', []), TermTermType.FUEL)
|
|
81
|
-
]
|
|
82
|
-
valid_inputs = [
|
|
83
|
-
i for i in inputs if all([
|
|
84
|
-
i.get('input-value') is not None,
|
|
85
|
-
(i.get('operation-factor') or i.get('input-default-factor')) is not None
|
|
86
|
-
])
|
|
87
|
-
]
|
|
88
|
-
return inputs, valid_inputs
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
def group_fuel_inputs(inputs: list):
|
|
92
|
-
return group_by_keys(inputs, ['input-id', 'operation-id']) if len(inputs) > 0 else None
|
|
93
|
-
|
|
94
|
-
|
|
95
23
|
def _get_emissions_factor(animal: dict, lookup_col: str) -> float:
|
|
96
24
|
return safe_parse_float(
|
|
97
25
|
get_lookup_value(animal.get("term", {}), lookup_col, model=MODEL, term=animal.get("term", "")),
|