hestia-earth-models 0.65.3__py3-none-any.whl → 0.65.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/agribalyse2016/fuelElectricity.py +41 -35
- hestia_earth/models/aware/scarcityWeightedWaterUse.py +1 -1
- hestia_earth/models/cache_sites.py +2 -0
- hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsLandOccupation.py +1 -1
- hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsLandTransformation.py +1 -1
- hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsTotalLandUseEffects.py +1 -1
- hestia_earth/models/cycle/completeness/__init__.py +1 -1
- hestia_earth/models/cycle/completeness/electricityFuel.py +4 -2
- hestia_earth/models/emepEea2019/nh3ToAirInorganicFertiliser.py +1 -1
- hestia_earth/models/geospatialDatabase/precipitationAnnual.py +2 -2
- hestia_earth/models/geospatialDatabase/precipitationLongTermAnnualMean.py +2 -2
- hestia_earth/models/geospatialDatabase/precipitationMonthly.py +2 -2
- hestia_earth/models/geospatialDatabase/temperatureAnnual.py +2 -2
- hestia_earth/models/geospatialDatabase/temperatureLongTermAnnualMean.py +2 -2
- hestia_earth/models/geospatialDatabase/temperatureMonthly.py +2 -2
- hestia_earth/models/hestia/landCover.py +31 -46
- hestia_earth/models/hestia/landTransformation100YearAverageDuringCycle.py +49 -0
- hestia_earth/models/hestia/landTransformation20YearAverageDuringCycle.py +49 -0
- hestia_earth/models/hestia/resourceUse_utils.py +200 -0
- hestia_earth/models/hestia/seed_emissions.py +37 -28
- hestia_earth/models/hestia/utils.py +48 -0
- hestia_earth/models/impact_assessment/emissions.py +20 -5
- hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +66 -28
- hestia_earth/models/ipcc2019/croppingDuration.py +5 -0
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +26 -142
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +3 -3
- hestia_earth/models/ipcc2019/organicCarbonPerHa_utils.py +8 -5
- hestia_earth/models/linkedImpactAssessment/freshwaterWithdrawalsInputsProduction.py +2 -1
- hestia_earth/models/linkedImpactAssessment/landOccupationInputsProduction.py +1 -0
- hestia_earth/models/linkedImpactAssessment/landTransformation100YearAverageInputsProduction.py +1 -0
- hestia_earth/models/linkedImpactAssessment/landTransformation20YearAverageInputsProduction.py +1 -0
- hestia_earth/models/linkedImpactAssessment/utils.py +25 -20
- hestia_earth/models/mocking/search-results.json +670 -654
- hestia_earth/models/pooreNemecek2018/freshwaterWithdrawalsDuringCycle.py +4 -1
- hestia_earth/models/schererPfister2015/nErosionSoilFlux.py +23 -14
- hestia_earth/models/schererPfister2015/pErosionSoilFlux.py +23 -15
- hestia_earth/models/schererPfister2015/utils.py +3 -5
- hestia_earth/models/site/management.py +2 -2
- hestia_earth/models/utils/__init__.py +9 -0
- hestia_earth/models/utils/blank_node.py +28 -0
- hestia_earth/models/utils/ecoClimateZone.py +1 -4
- hestia_earth/models/utils/fuel.py +4 -1
- hestia_earth/models/utils/impact_assessment.py +7 -5
- hestia_earth/models/utils/lookup.py +8 -2
- hestia_earth/models/utils/pesticideAI.py +1 -0
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.65.3.dist-info → hestia_earth_models-0.65.5.dist-info}/METADATA +2 -2
- {hestia_earth_models-0.65.3.dist-info → hestia_earth_models-0.65.5.dist-info}/RECORD +59 -53
- tests/models/hestia/test_landTransformation100YearAverageDuringCycle.py +30 -0
- tests/models/hestia/test_landTransformation20YearAverageDuringCycle.py +31 -0
- tests/models/ipcc2019/test_co2ToAirAboveGroundBiomassStockChange.py +3 -1
- tests/models/ipcc2019/test_co2ToAirBelowGroundBiomassStockChange.py +3 -1
- tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChange.py +3 -1
- tests/models/ipcc2019/test_organicCarbonPerHa.py +3 -2
- tests/models/ipcc2019/test_organicCarbonPerHa_tier_1_utils.py +15 -11
- tests/models/utils/test_blank_node.py +22 -7
- {hestia_earth_models-0.65.3.dist-info → hestia_earth_models-0.65.5.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.65.3.dist-info → hestia_earth_models-0.65.5.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.65.3.dist-info → hestia_earth_models-0.65.5.dist-info}/top_level.txt +0 -0
|
@@ -66,7 +66,10 @@ def _run(impact_assessment: dict, product: dict, irrigation: float):
|
|
|
66
66
|
conveyancing = _get_conveyancing_efficiency(impact_assessment, product)
|
|
67
67
|
# convert from m3 to litre
|
|
68
68
|
value = convert_value_from_cycle(
|
|
69
|
-
|
|
69
|
+
impact_assessment,
|
|
70
|
+
product,
|
|
71
|
+
irrigation / conveyancing * 1000 if irrigation > 0 else 0,
|
|
72
|
+
model=MODEL, term_id=TERM_ID
|
|
70
73
|
)
|
|
71
74
|
debugValues(impact_assessment, model=MODEL, term=TERM_ID,
|
|
72
75
|
value=value)
|
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
from hestia_earth.schema import EmissionMethodTier
|
|
2
|
+
from hestia_earth.utils.tools import list_sum
|
|
2
3
|
|
|
3
4
|
from hestia_earth.models.log import debugValues, logRequirements, logShouldRun
|
|
4
5
|
from hestia_earth.models.utils.emission import _new_emission
|
|
5
6
|
from hestia_earth.models.utils.measurement import most_relevant_measurement_value
|
|
6
|
-
from .utils import get_pcorr, get_p_ef_c1, get_ef_p_c2, get_practice_factor,
|
|
7
|
+
from .utils import get_pcorr, get_p_ef_c1, get_ef_p_c2, get_practice_factor, get_water_input, calculate_R, calculate_A
|
|
7
8
|
from . import MODEL
|
|
8
9
|
|
|
9
10
|
REQUIREMENTS = {
|
|
10
11
|
"Cycle": {
|
|
11
12
|
"endDate": "",
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
"or": {
|
|
14
|
+
"inputs": [
|
|
15
|
+
{"@type": "Input", "value": "> 0", "term.termType": "water"}
|
|
16
|
+
],
|
|
17
|
+
"site": {
|
|
18
|
+
"@type": "Site",
|
|
19
|
+
"measurements": [
|
|
20
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "precipitationAnnual"}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
15
24
|
"site": {
|
|
16
25
|
"@type": "Site",
|
|
17
26
|
"country": {"@type": "Term", "termType": "region"},
|
|
18
27
|
"measurements": [
|
|
19
|
-
{"@type": "Measurement", "value": "", "term.@id": "nutrientLossToAquaticEnvironment"},
|
|
20
|
-
{"@type": "Measurement", "value": "", "term.@id": "heavyWinterPrecipitation"},
|
|
21
|
-
{"@type": "Measurement", "value": "", "term.@id": "totalNitrogenPerKgSoil"},
|
|
22
|
-
{"@type": "Measurement", "value": "", "term.@id": "
|
|
23
|
-
{"@type": "Measurement", "value": "", "term.@id": "
|
|
24
|
-
{"@type": "Measurement", "value": "", "term.@id": "
|
|
25
|
-
{"@type": "Measurement", "value": "", "term.@id": "slope"}
|
|
28
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "nutrientLossToAquaticEnvironment"},
|
|
29
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "heavyWinterPrecipitation"},
|
|
30
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "totalNitrogenPerKgSoil"},
|
|
31
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "erodibility"},
|
|
32
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "slopeLength"},
|
|
33
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "slope"}
|
|
26
34
|
]
|
|
27
35
|
}
|
|
28
36
|
}
|
|
@@ -82,7 +90,7 @@ def _should_run(cycle: dict):
|
|
|
82
90
|
heavy_winter_precipitation = _get_measurement_content('heavyWinterPrecipitation')
|
|
83
91
|
|
|
84
92
|
precipitation = _get_measurement_content('precipitationAnnual')
|
|
85
|
-
|
|
93
|
+
inputs_water = get_water_input(cycle)
|
|
86
94
|
|
|
87
95
|
practice_factor = get_practice_factor(TERM_ID, site)
|
|
88
96
|
pcorr = get_pcorr(slope / 100) if slope is not None else None
|
|
@@ -92,7 +100,7 @@ def _should_run(cycle: dict):
|
|
|
92
100
|
list_of_contents_for_A = [
|
|
93
101
|
practice_factor, erodibility, slope_length,
|
|
94
102
|
pcorr, p_ef_c1, ef_p_c2]
|
|
95
|
-
list_of_contents_for_R = [heavy_winter_precipitation,
|
|
103
|
+
list_of_contents_for_R = [heavy_winter_precipitation, list_sum([(inputs_water or 0)/10, precipitation or 0])]
|
|
96
104
|
list_of_contents_for_value = [nla_environment, soil_nitrogen_content]
|
|
97
105
|
|
|
98
106
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
@@ -104,7 +112,8 @@ def _should_run(cycle: dict):
|
|
|
104
112
|
p_ef_c1=p_ef_c1,
|
|
105
113
|
ef_p_c2=ef_p_c2,
|
|
106
114
|
heavy_winter_precipitation=heavy_winter_precipitation,
|
|
107
|
-
|
|
115
|
+
inputs_water=inputs_water,
|
|
116
|
+
precipitationAnnual=precipitation,
|
|
108
117
|
nla_environment=nla_environment,
|
|
109
118
|
soil_nitrogen_content=soil_nitrogen_content)
|
|
110
119
|
|
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
from hestia_earth.schema import EmissionMethodTier
|
|
2
|
+
from hestia_earth.utils.tools import list_sum
|
|
2
3
|
|
|
3
4
|
from hestia_earth.models.log import debugValues, logRequirements, logShouldRun
|
|
4
5
|
from hestia_earth.models.utils.emission import _new_emission
|
|
5
6
|
from hestia_earth.models.utils.measurement import most_relevant_measurement_value
|
|
6
|
-
from .utils import get_pcorr, get_p_ef_c1, get_ef_p_c2, get_practice_factor,
|
|
7
|
+
from .utils import get_pcorr, get_p_ef_c1, get_ef_p_c2, get_practice_factor, get_water_input, calculate_R, calculate_A
|
|
7
8
|
from . import MODEL
|
|
8
9
|
|
|
9
10
|
REQUIREMENTS = {
|
|
10
11
|
"Cycle": {
|
|
11
12
|
"endDate": "",
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
"or": {
|
|
14
|
+
"inputs": [
|
|
15
|
+
{"@type": "Input", "value": "> 0", "term.termType": "water"}
|
|
16
|
+
],
|
|
17
|
+
"site": {
|
|
18
|
+
"@type": "Site",
|
|
19
|
+
"measurements": [
|
|
20
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "precipitationAnnual"}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
15
24
|
"site": {
|
|
16
25
|
"@type": "Site",
|
|
17
26
|
"country": {"@type": "Term", "termType": "region"},
|
|
18
27
|
"measurements": [
|
|
19
|
-
{"@type": "Measurement", "value": "", "term.@id": "nutrientLossToAquaticEnvironment"},
|
|
20
|
-
{"@type": "Measurement", "value": "", "term.@id": "heavyWinterPrecipitation"},
|
|
21
|
-
{"@type": "Measurement", "value": "", "term.@id": "totalPhosphorusPerKgSoil"},
|
|
22
|
-
{"@type": "Measurement", "value": "", "term.@id": "
|
|
23
|
-
{"@type": "Measurement", "value": "", "term.@id": "
|
|
24
|
-
{"@type": "Measurement", "value": "", "term.@id": "
|
|
25
|
-
{"@type": "Measurement", "value": "", "term.@id": "slopeLength"},
|
|
26
|
-
{"@type": "Measurement", "value": "", "term.@id": "slope"}
|
|
28
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "nutrientLossToAquaticEnvironment"},
|
|
29
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "heavyWinterPrecipitation"},
|
|
30
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "totalPhosphorusPerKgSoil"},
|
|
31
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "erodibility"},
|
|
32
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "slopeLength"},
|
|
33
|
+
{"@type": "Measurement", "value": "> 0", "term.@id": "slope"}
|
|
27
34
|
]
|
|
28
35
|
}
|
|
29
36
|
}
|
|
@@ -83,7 +90,7 @@ def _should_run(cycle: dict):
|
|
|
83
90
|
heavy_winter_precipitation = _get_measurement_content('heavyWinterPrecipitation')
|
|
84
91
|
|
|
85
92
|
precipitation = _get_measurement_content('precipitationAnnual')
|
|
86
|
-
|
|
93
|
+
inputs_water = get_water_input(cycle)
|
|
87
94
|
|
|
88
95
|
practice_factor = get_practice_factor(TERM_ID, site)
|
|
89
96
|
pcorr = get_pcorr(slope / 100) if slope is not None else None
|
|
@@ -93,7 +100,7 @@ def _should_run(cycle: dict):
|
|
|
93
100
|
list_of_contents_for_A = [
|
|
94
101
|
practice_factor, erodibility, slope_length,
|
|
95
102
|
pcorr, p_ef_c1, ef_p_c2]
|
|
96
|
-
list_of_contents_for_R = [heavy_winter_precipitation,
|
|
103
|
+
list_of_contents_for_R = [heavy_winter_precipitation, list_sum([(inputs_water or 0)/10, precipitation or 0])]
|
|
97
104
|
list_of_contents_for_value = [nla_environment, soil_phosphorus_content]
|
|
98
105
|
|
|
99
106
|
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
@@ -105,7 +112,8 @@ def _should_run(cycle: dict):
|
|
|
105
112
|
p_ef_c1=p_ef_c1,
|
|
106
113
|
ef_p_c2=ef_p_c2,
|
|
107
114
|
heavy_winter_precipitation=heavy_winter_precipitation,
|
|
108
|
-
|
|
115
|
+
inputs_water=inputs_water,
|
|
116
|
+
precipitationAnnual=precipitation,
|
|
109
117
|
nla_environment=nla_environment,
|
|
110
118
|
soil_phosphorus_content=soil_phosphorus_content)
|
|
111
119
|
|
|
@@ -64,11 +64,9 @@ def get_ef_p_c2(term_id: str, cycle: dict):
|
|
|
64
64
|
get_lookup_value(country, 'EF_P_C2', model=MODEL, term=term_id), None)
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
def
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
irrigation = list_sum(get_total_value(filter_irrigation))
|
|
71
|
-
return list_sum([irrigation/10, precipitation or 0])
|
|
67
|
+
def get_water_input(cycle: dict):
|
|
68
|
+
inputs_water = filter_list_term_type(cycle.get('inputs', []), TermTermType.WATER)
|
|
69
|
+
return list_sum(get_total_value(inputs_water), default=None)
|
|
72
70
|
|
|
73
71
|
|
|
74
72
|
def calculate_R(heavy_winter_precipitation: bool, water: float):
|
|
@@ -20,7 +20,7 @@ from hestia_earth.utils.tools import safe_parse_float, flatten
|
|
|
20
20
|
from hestia_earth.utils.blank_node import get_node_value
|
|
21
21
|
|
|
22
22
|
from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
|
|
23
|
-
from hestia_earth.models.utils import _include, _omit
|
|
23
|
+
from hestia_earth.models.utils import _include, _omit, group_by
|
|
24
24
|
from hestia_earth.models.utils.management import _new_management
|
|
25
25
|
from hestia_earth.models.utils.term import get_lookup_value
|
|
26
26
|
from hestia_earth.models.utils.blank_node import condense_nodes
|
|
@@ -330,7 +330,7 @@ def run(site: dict):
|
|
|
330
330
|
nodes = flatten([_run_cycle(site, cycle) for cycle in cycles])
|
|
331
331
|
|
|
332
332
|
# group nodes with same `id` to display as a single log per node
|
|
333
|
-
grouped_nodes =
|
|
333
|
+
grouped_nodes = group_by(nodes, ['id'])
|
|
334
334
|
for id, values in grouped_nodes.items():
|
|
335
335
|
logRequirements(
|
|
336
336
|
site,
|
|
@@ -7,6 +7,7 @@ import sys
|
|
|
7
7
|
import datetime
|
|
8
8
|
from functools import reduce
|
|
9
9
|
import operator
|
|
10
|
+
from pydash.objects import get
|
|
10
11
|
from typing import Any, Callable, Union
|
|
11
12
|
from hestia_earth.schema import SchemaType
|
|
12
13
|
from hestia_earth.utils.api import download_hestia
|
|
@@ -26,6 +27,14 @@ def cached_value(node: dict, key: str = None, default=None):
|
|
|
26
27
|
return cache.get(key, default) if key else cache
|
|
27
28
|
|
|
28
29
|
|
|
30
|
+
def group_by(values: list, keys: list):
|
|
31
|
+
def _group_by(group: dict, value: dict):
|
|
32
|
+
group_key = ';'.join(non_empty_list([get(value, key) for key in keys]))
|
|
33
|
+
group[group_key] = group.get(group_key, []) + [value]
|
|
34
|
+
return group
|
|
35
|
+
return reduce(_group_by, values, {})
|
|
36
|
+
|
|
37
|
+
|
|
29
38
|
def _term_id(term): return term.get('@id') if isinstance(term, dict) else term
|
|
30
39
|
|
|
31
40
|
|
|
@@ -663,6 +663,7 @@ DATESTR_FORMAT_TO_EXPECTED_LENGTH = {
|
|
|
663
663
|
|
|
664
664
|
DatestrGapfillMode = Enum("DatestrGapfillMode", [
|
|
665
665
|
"START",
|
|
666
|
+
"MIDDLE",
|
|
666
667
|
"END"
|
|
667
668
|
])
|
|
668
669
|
"""
|
|
@@ -738,8 +739,25 @@ def _gapfill_datestr_end(datestr: str, format: DatestrFormat) -> str:
|
|
|
738
739
|
return datestr + completion_str[len(datestr):]
|
|
739
740
|
|
|
740
741
|
|
|
742
|
+
def _gapfill_datestr_middle(datestr: str, format: DatestrFormat) -> str:
|
|
743
|
+
"""
|
|
744
|
+
Gap-fill an incomplete datestr with the middle value, halfway between the latest and earliest values.
|
|
745
|
+
"""
|
|
746
|
+
start_date_obj = datetime.strptime(
|
|
747
|
+
_gapfill_datestr_start(datestr),
|
|
748
|
+
DatestrFormat.YEAR_MONTH_DAY_HOUR_MINUTE_SECOND.value
|
|
749
|
+
)
|
|
750
|
+
end_date_obj = datetime.strptime(
|
|
751
|
+
_gapfill_datestr_end(datestr, format=format),
|
|
752
|
+
DatestrFormat.YEAR_MONTH_DAY_HOUR_MINUTE_SECOND.value
|
|
753
|
+
)
|
|
754
|
+
middle_date = start_date_obj + (end_date_obj - start_date_obj) / 2
|
|
755
|
+
return datetime.strftime(middle_date, DatestrFormat.YEAR_MONTH_DAY_HOUR_MINUTE_SECOND.value)
|
|
756
|
+
|
|
757
|
+
|
|
741
758
|
DATESTR_GAPFILL_MODE_TO_GAPFILL_FUNCTION = {
|
|
742
759
|
DatestrGapfillMode.START: _gapfill_datestr_start,
|
|
760
|
+
DatestrGapfillMode.MIDDLE: _gapfill_datestr_middle,
|
|
743
761
|
DatestrGapfillMode.END: _gapfill_datestr_end
|
|
744
762
|
}
|
|
745
763
|
|
|
@@ -757,6 +775,16 @@ def _gapfill_datestr(datestr: str, mode: DatestrGapfillMode = DatestrGapfillMode
|
|
|
757
775
|
return DATESTR_GAPFILL_MODE_TO_GAPFILL_FUNCTION[mode](_datestr, format) if should_run else _datestr
|
|
758
776
|
|
|
759
777
|
|
|
778
|
+
def _str_dates_match(date_str_one: str, date_str_two: str, mode=DatestrGapfillMode.END) -> bool:
|
|
779
|
+
"""
|
|
780
|
+
Comparison of non-gap-filled string dates.
|
|
781
|
+
example: For end dates, '2010' would match '2010-12-31', but not '2010-01-01'
|
|
782
|
+
"""
|
|
783
|
+
return (
|
|
784
|
+
_gapfill_datestr(datestr=date_str_one, mode=mode) == _gapfill_datestr(datestr=date_str_two, mode=mode)
|
|
785
|
+
)
|
|
786
|
+
|
|
787
|
+
|
|
760
788
|
def _datetime_within_range(datetime: datetime, range: DatetimeRange) -> bool:
|
|
761
789
|
"""
|
|
762
790
|
Determine whether or not a `datetime` falls within a `DatetimeRange`.
|
|
@@ -118,10 +118,7 @@ def get_ecoClimateZone_lookup_grouped_value(
|
|
|
118
118
|
code = int(str(eco_climate_zone))
|
|
119
119
|
data = _get_single_table_value(lookup, column_name('ecoClimateZone'), code, column_name(col_name))
|
|
120
120
|
grouped_data = reduce(
|
|
121
|
-
lambda prev, curr: {
|
|
122
|
-
**prev,
|
|
123
|
-
**{curr.split(':')[0]: safe_parse_float(curr.split(':')[1])}
|
|
124
|
-
},
|
|
121
|
+
lambda prev, curr: prev | {curr.split(':')[0]: safe_parse_float(curr.split(':')[1])},
|
|
125
122
|
data.split(';'),
|
|
126
123
|
{}
|
|
127
124
|
) if data is not None and isinstance(data, str) and len(data) > 1 else default
|
|
@@ -13,7 +13,10 @@ def impact_lookup_value(model: str, term_id: str, impact_assessment: dict, looku
|
|
|
13
13
|
fuels = filter_list_term_type(cycle.get('inputs', []), TermTermType.FUEL)
|
|
14
14
|
has_fuels_inputs = len(fuels) > 0
|
|
15
15
|
fuels_total_value = convert_value_from_cycle(
|
|
16
|
-
|
|
16
|
+
impact_assessment,
|
|
17
|
+
product,
|
|
18
|
+
cycle_lookup_value(model, term_id, cycle, fuels, lookup_col),
|
|
19
|
+
model=model, term_id=term_id
|
|
17
20
|
) if has_fuels_inputs else None
|
|
18
21
|
logRequirements(impact_assessment, model=model, term=term_id,
|
|
19
22
|
term_type_electricityFuel_complete=fuel_complete,
|
|
@@ -4,7 +4,7 @@ from hestia_earth.utils.lookup import download_lookup
|
|
|
4
4
|
from hestia_earth.utils.model import find_term_match, filter_list_term_type
|
|
5
5
|
from hestia_earth.utils.tools import list_sum, safe_parse_date
|
|
6
6
|
|
|
7
|
-
from hestia_earth.models.log import
|
|
7
|
+
from hestia_earth.models.log import debugValues, log_as_table
|
|
8
8
|
from .lookup import all_factor_value, _term_factor_value, _aware_factor_value, fallback_country
|
|
9
9
|
from .product import find_by_product
|
|
10
10
|
from .site import region_level_1_id
|
|
@@ -244,13 +244,15 @@ def emission_value(impact_assessment: dict, term_id: str):
|
|
|
244
244
|
return find_term_match(impact_assessment.get('emissionsResourceUse', []), term_id).get('value')
|
|
245
245
|
|
|
246
246
|
|
|
247
|
-
def convert_value_from_cycle(
|
|
247
|
+
def convert_value_from_cycle(
|
|
248
|
+
log_node: dict, product: dict, value: float, default=None, model: str = None, term_id: str = None
|
|
249
|
+
):
|
|
248
250
|
pyield = list_sum(product.get('value', [])) if product else 0
|
|
249
251
|
economic_value = product.get('economicValueShare') if product else 0
|
|
250
252
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
253
|
+
debugValues(log_node, model=model, term=term_id,
|
|
254
|
+
product_yield=pyield,
|
|
255
|
+
economicValueShare=economic_value)
|
|
254
256
|
|
|
255
257
|
return (value / pyield) * economic_value / 100 if all([
|
|
256
258
|
value is not None, pyield > 0, economic_value
|
|
@@ -77,7 +77,10 @@ def _term_factor_value(model: str, term_id: str, lookup_name: str, lookup_term_i
|
|
|
77
77
|
coefficient = get_table_value(lookup, 'termid', lookup_term_id, column_name(node_term_id))
|
|
78
78
|
coefficient = safe_parse_float(extract_grouped_data(coefficient, group_key) if group_key else coefficient)
|
|
79
79
|
if value is not None and coefficient is not None:
|
|
80
|
-
debugValues(data, model=model, term=term_id,
|
|
80
|
+
debugValues(data, model=model, term=term_id,
|
|
81
|
+
node=node_term_id,
|
|
82
|
+
value=value,
|
|
83
|
+
coefficient=coefficient)
|
|
81
84
|
return {'id': node_term_id, 'value': value, 'coefficient': coefficient}
|
|
82
85
|
return get_value
|
|
83
86
|
|
|
@@ -93,7 +96,10 @@ def _aware_factor_value(model: str, term_id: str, lookup_name: str, aware_id: st
|
|
|
93
96
|
coefficient = _get_single_table_value(lookup, lookup_col, int(aware_id), column_name(node_term_id))
|
|
94
97
|
coefficient = safe_parse_float(extract_grouped_data(coefficient, group_key)) if group_key else coefficient
|
|
95
98
|
if value is not None and coefficient is not None:
|
|
96
|
-
debugValues(data, model=model, term=term_id,
|
|
99
|
+
debugValues(data, model=model, term=term_id,
|
|
100
|
+
node=node_term_id,
|
|
101
|
+
value=value,
|
|
102
|
+
coefficient=coefficient)
|
|
97
103
|
return value * coefficient
|
|
98
104
|
return None
|
|
99
105
|
except ValueError: # factor does not exist
|
|
@@ -22,6 +22,7 @@ def impact_lookup_value(model: str, term_id: str, impact_assessment: dict, looku
|
|
|
22
22
|
get_pesticides_from_inputs(cycle)
|
|
23
23
|
has_pesticides_inputs = len(pesticides) > 0
|
|
24
24
|
pesticides_total_value = convert_value_from_cycle(
|
|
25
|
+
log_node=impact_assessment,
|
|
25
26
|
product=product,
|
|
26
27
|
value=cycle_lookup_value(model, term_id, cycle, pesticides, lookup_col),
|
|
27
28
|
default=None,
|
hestia_earth/models/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = '0.65.
|
|
1
|
+
VERSION = '0.65.5'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: hestia-earth-models
|
|
3
|
-
Version: 0.65.
|
|
3
|
+
Version: 0.65.5
|
|
4
4
|
Summary: HESTIA's set of modules for filling gaps in the activity data using external datasets (e.g. populating soil properties with a geospatial dataset using provided coordinates) and internal lookups (e.g. populating machinery use from fuel use). Includes rules for when gaps should be filled versus not (e.g. never gap fill yield, gap fill crop residue if yield provided etc.).
|
|
5
5
|
Home-page: https://gitlab.com/hestia-earth/hestia-engine-models
|
|
6
6
|
Author: HESTIA Team
|
|
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3.6
|
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: hestia-earth-schema==30.*
|
|
15
|
-
Requires-Dist: hestia-earth-utils>=0.13.
|
|
15
|
+
Requires-Dist: hestia-earth-utils>=0.13.14
|
|
16
16
|
Requires-Dist: python-dateutil>=2.8.1
|
|
17
17
|
Requires-Dist: CurrencyConverter==0.16.8
|
|
18
18
|
Requires-Dist: haversine>=2.7.0
|