hestia-earth-models 0.64.10__py3-none-any.whl → 0.64.12__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/cml2001Baseline/eutrophicationPotentialExcludingFate.py +2 -2
- hestia_earth/models/cml2001Baseline/terrestrialAcidificationPotentialIncludingFateAverageEurope.py +2 -2
- hestia_earth/models/cml2001NonBaseline/eutrophicationPotentialIncludingFateAverageEurope.py +2 -2
- hestia_earth/models/cml2001NonBaseline/terrestrialAcidificationPotentialExcludingFate.py +2 -2
- hestia_earth/models/cycle/completeness/cropResidue.py +15 -10
- hestia_earth/models/cycle/completeness/freshForage.py +60 -0
- hestia_earth/models/cycle/concentrateFeed.py +31 -19
- hestia_earth/models/edip2003/ozoneDepletionPotential.py +2 -2
- hestia_earth/models/fantkeEtAl2016/damageToHumanHealthParticulateMatterFormation.py +7 -17
- hestia_earth/models/faostat2018/utils.py +72 -12
- hestia_earth/models/hestia/__init__.py +13 -0
- hestia_earth/models/hestia/landCover.py +725 -0
- hestia_earth/models/ipcc2013ExcludingFeedbacks/gwp100.py +2 -2
- hestia_earth/models/ipcc2013IncludingFeedbacks/gwp100.py +2 -2
- hestia_earth/models/ipcc2019/animal/fatContent.py +1 -1
- hestia_earth/models/ipcc2019/animal/milkYieldPerAnimal.py +91 -0
- hestia_earth/models/ipcc2019/animal/trueProteinContent.py +1 -1
- hestia_earth/models/ipcc2019/animal/utils.py +17 -12
- hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChange.py +8 -4
- hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChange.py +7 -3
- hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +45 -3
- hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChange.py +7 -3
- hestia_earth/models/ipcc2021/gwp100.py +2 -2
- hestia_earth/models/lcImpactAllEffects100Years/damageToFreshwaterEcosystemsClimateChange.py +2 -2
- hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthClimateChange.py +2 -2
- hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthStratosphericOzoneDepletion.py +2 -2
- hestia_earth/models/lcImpactAllEffects100Years/damageToTerrestrialEcosystemsClimateChange.py +2 -2
- hestia_earth/models/lcImpactAllEffectsInfinite/damageToFreshwaterEcosystemsClimateChange.py +2 -2
- hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthClimateChange.py +2 -2
- hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthStratosphericOzoneDepletion.py +2 -2
- hestia_earth/models/lcImpactAllEffectsInfinite/damageToTerrestrialEcosystemsClimateChange.py +2 -2
- hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthClimateChange.py +2 -2
- hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthStratosphericOzoneDepletion.py +2 -2
- hestia_earth/models/lcImpactCertainEffects100Years/damageToTerrestrialEcosystemsClimateChange.py +2 -2
- hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthClimateChange.py +2 -2
- hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthStratosphericOzoneDepletion.py +2 -2
- hestia_earth/models/lcImpactCertainEffectsInfinite/damageToTerrestrialEcosystemsClimateChange.py +2 -2
- hestia_earth/models/mocking/search-results.json +335 -335
- hestia_earth/models/recipe2016Egalitarian/ecosystemDamageOzoneFormation.py +2 -2
- hestia_earth/models/recipe2016Egalitarian/freshwaterEutrophicationPotential.py +2 -2
- hestia_earth/models/recipe2016Egalitarian/humanDamageOzoneFormation.py +2 -2
- hestia_earth/models/recipe2016Egalitarian/marineEutrophicationPotential.py +2 -2
- hestia_earth/models/recipe2016Egalitarian/ozoneDepletionPotential.py +2 -2
- hestia_earth/models/recipe2016Egalitarian/terrestrialAcidificationPotential.py +2 -2
- hestia_earth/models/recipe2016Hierarchist/ecosystemDamageOzoneFormation.py +2 -2
- hestia_earth/models/recipe2016Hierarchist/freshwaterEutrophicationPotential.py +2 -2
- hestia_earth/models/recipe2016Hierarchist/humanDamageOzoneFormation.py +2 -2
- hestia_earth/models/recipe2016Hierarchist/marineEutrophicationPotential.py +2 -2
- hestia_earth/models/recipe2016Hierarchist/ozoneDepletionPotential.py +2 -2
- hestia_earth/models/recipe2016Hierarchist/terrestrialAcidificationPotential.py +2 -2
- hestia_earth/models/recipe2016Individualist/ecosystemDamageOzoneFormation.py +2 -2
- hestia_earth/models/recipe2016Individualist/freshwaterEutrophicationPotential.py +2 -2
- hestia_earth/models/recipe2016Individualist/humanDamageOzoneFormation.py +2 -2
- hestia_earth/models/recipe2016Individualist/marineEutrophicationPotential.py +2 -2
- hestia_earth/models/recipe2016Individualist/ozoneDepletionPotential.py +2 -2
- hestia_earth/models/recipe2016Individualist/terrestrialAcidificationPotential.py +2 -2
- hestia_earth/models/utils/impact_assessment.py +18 -8
- hestia_earth/models/utils/lookup.py +2 -1
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.64.10.dist-info → hestia_earth_models-0.64.12.dist-info}/METADATA +2 -2
- {hestia_earth_models-0.64.10.dist-info → hestia_earth_models-0.64.12.dist-info}/RECORD +71 -62
- tests/models/cycle/completeness/test_freshForage.py +21 -0
- tests/models/faostat2018/test_faostat_utils.py +84 -0
- tests/models/hestia/__init__.py +0 -0
- tests/models/hestia/test_landCover.py +209 -0
- tests/models/ipcc2019/animal/test_milkYieldPerAnimal.py +21 -0
- tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChange.py +48 -1
- tests/models/utils/test_impact_assessment.py +3 -3
- {hestia_earth_models-0.64.10.dist-info → hestia_earth_models-0.64.12.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.64.10.dist-info → hestia_earth_models-0.64.12.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.64.10.dist-info → hestia_earth_models-0.64.12.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
2
2
|
from hestia_earth.models.utils.indicator import _new_indicator
|
|
3
|
-
from hestia_earth.models.utils.impact_assessment import
|
|
3
|
+
from hestia_earth.models.utils.impact_assessment import impact_emission_lookup_value
|
|
4
4
|
from . import MODEL
|
|
5
5
|
|
|
6
6
|
REQUIREMENTS = {
|
|
@@ -26,7 +26,7 @@ def _indicator(value: float):
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def run(impact_assessment: dict):
|
|
29
|
-
value =
|
|
29
|
+
value = impact_emission_lookup_value(MODEL, TERM_ID, impact_assessment, LOOKUPS['emission'])
|
|
30
30
|
logRequirements(impact_assessment, model=MODEL, term=TERM_ID,
|
|
31
31
|
value=value)
|
|
32
32
|
logShouldRun(impact_assessment, MODEL, TERM_ID, True)
|
hestia_earth/models/cml2001Baseline/terrestrialAcidificationPotentialIncludingFateAverageEurope.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
2
2
|
from hestia_earth.models.utils.indicator import _new_indicator
|
|
3
|
-
from hestia_earth.models.utils.impact_assessment import
|
|
3
|
+
from hestia_earth.models.utils.impact_assessment import impact_emission_lookup_value
|
|
4
4
|
from . import MODEL
|
|
5
5
|
|
|
6
6
|
REQUIREMENTS = {
|
|
@@ -26,7 +26,7 @@ def _indicator(value: float):
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def run(impact_assessment: dict):
|
|
29
|
-
value =
|
|
29
|
+
value = impact_emission_lookup_value(MODEL, TERM_ID, impact_assessment, LOOKUPS['emission'])
|
|
30
30
|
logRequirements(impact_assessment, model=MODEL, term=TERM_ID,
|
|
31
31
|
value=value)
|
|
32
32
|
logShouldRun(impact_assessment, MODEL, TERM_ID, True)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
2
2
|
from hestia_earth.models.utils.indicator import _new_indicator
|
|
3
|
-
from hestia_earth.models.utils.impact_assessment import
|
|
3
|
+
from hestia_earth.models.utils.impact_assessment import impact_emission_lookup_value
|
|
4
4
|
from . import MODEL
|
|
5
5
|
|
|
6
6
|
REQUIREMENTS = {
|
|
@@ -26,7 +26,7 @@ def _indicator(value: float):
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def run(impact_assessment: dict):
|
|
29
|
-
value =
|
|
29
|
+
value = impact_emission_lookup_value(MODEL, TERM_ID, impact_assessment, LOOKUPS['emission'])
|
|
30
30
|
logRequirements(impact_assessment, model=MODEL, term=TERM_ID,
|
|
31
31
|
value=value)
|
|
32
32
|
logShouldRun(impact_assessment, MODEL, TERM_ID, True)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
2
2
|
from hestia_earth.models.utils.indicator import _new_indicator
|
|
3
|
-
from hestia_earth.models.utils.impact_assessment import
|
|
3
|
+
from hestia_earth.models.utils.impact_assessment import impact_emission_lookup_value
|
|
4
4
|
from . import MODEL
|
|
5
5
|
|
|
6
6
|
REQUIREMENTS = {
|
|
@@ -26,7 +26,7 @@ def _indicator(value: float):
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def run(impact_assessment: dict):
|
|
29
|
-
value =
|
|
29
|
+
value = impact_emission_lookup_value(MODEL, TERM_ID, impact_assessment, LOOKUPS['emission'])
|
|
30
30
|
logRequirements(impact_assessment, model=MODEL, term=TERM_ID,
|
|
31
31
|
value=value)
|
|
32
32
|
logShouldRun(impact_assessment, MODEL, TERM_ID, True)
|
|
@@ -5,6 +5,7 @@ This model checks if we have the requirements below and updates the
|
|
|
5
5
|
[Data Completeness](https://hestia.earth/schema/Completeness#cropResidue) value.
|
|
6
6
|
"""
|
|
7
7
|
from hestia_earth.utils.model import find_term_match
|
|
8
|
+
from hestia_earth.utils.tools import list_sum
|
|
8
9
|
|
|
9
10
|
from hestia_earth.models.log import logRequirements
|
|
10
11
|
from hestia_earth.models.utils.term import get_crop_residue_terms
|
|
@@ -14,15 +15,15 @@ REQUIREMENTS = {
|
|
|
14
15
|
"Cycle": {
|
|
15
16
|
"completeness.cropResidue": "False",
|
|
16
17
|
"products": [
|
|
17
|
-
{"@type": "Product", "value": "", "term.@id": "belowGroundCropResidue"},
|
|
18
|
-
{"@type": "Product", "value": "", "term.@id": "aboveGroundCropResidueTotal"}
|
|
18
|
+
{"@type": "Product", "value": ">= 0", "term.@id": "belowGroundCropResidue"},
|
|
19
|
+
{"@type": "Product", "value": "> 0", "term.@id": "aboveGroundCropResidueTotal"}
|
|
19
20
|
],
|
|
20
21
|
"optional": {
|
|
21
22
|
"products": [
|
|
22
|
-
{"@type": "Product", "value": "", "term.@id": "aboveGroundCropResidueRemoved"},
|
|
23
|
-
{"@type": "Product", "value": "", "term.@id": "aboveGroundCropResidueIncorporated"},
|
|
24
|
-
{"@type": "Product", "value": "", "term.@id": "aboveGroundCropResidueBurnt"},
|
|
25
|
-
{"@type": "Product", "value": "", "term.@id": "aboveGroundCropResidueLeftOnField"}
|
|
23
|
+
{"@type": "Product", "value": "> 0", "term.@id": "aboveGroundCropResidueRemoved"},
|
|
24
|
+
{"@type": "Product", "value": "> 0", "term.@id": "aboveGroundCropResidueIncorporated"},
|
|
25
|
+
{"@type": "Product", "value": "> 0", "term.@id": "aboveGroundCropResidueBurnt"},
|
|
26
|
+
{"@type": "Product", "value": "> 0", "term.@id": "aboveGroundCropResidueLeftOnField"}
|
|
26
27
|
]
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -44,17 +45,21 @@ def _optional_term_ids():
|
|
|
44
45
|
return [term for term in terms if term not in REQUIRED_TERM_IDS]
|
|
45
46
|
|
|
46
47
|
|
|
47
|
-
def _has_product(products):
|
|
48
|
+
def _has_product(products, zero_allowed=True):
|
|
48
49
|
def has_product(term_id: str):
|
|
49
|
-
|
|
50
|
+
value = list_sum(find_term_match(products, term_id).get('value', [-1]))
|
|
51
|
+
return (term_id, value >= 0 if zero_allowed else value > 0)
|
|
50
52
|
return has_product
|
|
51
53
|
|
|
52
54
|
|
|
53
55
|
def run(cycle: dict):
|
|
54
56
|
products = cycle.get('products', [])
|
|
55
57
|
# all required terms + at least one of the optional terms must be present
|
|
56
|
-
required_products_map =
|
|
57
|
-
|
|
58
|
+
required_products_map = [
|
|
59
|
+
_has_product(products, zero_allowed=True)('belowGroundCropResidue'),
|
|
60
|
+
_has_product(products, zero_allowed=False)('aboveGroundCropResidueTotal'),
|
|
61
|
+
]
|
|
62
|
+
optional_products_map = list(map(_has_product(products, zero_allowed=False), _optional_term_ids()))
|
|
58
63
|
|
|
59
64
|
has_required_products = all([has_product for _term_id, has_product in required_products_map])
|
|
60
65
|
has_optional_product = any([has_product for _term_id, has_product in optional_products_map])
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Completeness Fresh Forage
|
|
3
|
+
|
|
4
|
+
This model checks if we have the requirements below and updates the
|
|
5
|
+
[Data Completeness](https://hestia.earth/schema/Completeness#cropResidue) value.
|
|
6
|
+
"""
|
|
7
|
+
from hestia_earth.schema import SiteSiteType
|
|
8
|
+
from hestia_earth.utils.tools import list_sum
|
|
9
|
+
|
|
10
|
+
from hestia_earth.models.log import logRequirements
|
|
11
|
+
from hestia_earth.models.utils import is_from_model
|
|
12
|
+
from . import MODEL
|
|
13
|
+
|
|
14
|
+
REQUIREMENTS = {
|
|
15
|
+
"Cycle": {
|
|
16
|
+
"completeness.freshForage": "False",
|
|
17
|
+
"site": {
|
|
18
|
+
"@type": "Site",
|
|
19
|
+
"siteType": "permanent pasture"
|
|
20
|
+
},
|
|
21
|
+
"or": {
|
|
22
|
+
"inputs": [{"@type": "Input", "termType": "forage", "value": "> 0", "added": ["value"]}],
|
|
23
|
+
"animals": [{
|
|
24
|
+
"@type": "Animal",
|
|
25
|
+
"inputs": [{"@type": "Input", "termType": "forage", "value": "> 0", "added": ["value"]}]
|
|
26
|
+
}]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
RETURNS = {
|
|
31
|
+
"Completeness": {
|
|
32
|
+
"freshForage": ""
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
MODEL_KEY = 'freshForage'
|
|
36
|
+
ALLOWED_SITE_TYPES = [
|
|
37
|
+
SiteSiteType.PERMANENT_PASTURE.value
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _valid_input(input: dict): return is_from_model(input) and list_sum(input.get('value', [-1])) > 0
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def run(cycle: dict):
|
|
45
|
+
site_type = cycle.get('site', {}).get('siteType')
|
|
46
|
+
site_type_allowed = site_type in ALLOWED_SITE_TYPES
|
|
47
|
+
|
|
48
|
+
cycle_has_added_forage_input = any(map(_valid_input, cycle.get('inputs', [])))
|
|
49
|
+
|
|
50
|
+
animals = cycle.get('animals', [])
|
|
51
|
+
all_animals_have_added_forage_input = bool(animals) and all([
|
|
52
|
+
any(map(_valid_input, animal.get('inputs', []))) for animal in animals
|
|
53
|
+
])
|
|
54
|
+
|
|
55
|
+
logRequirements(cycle, model=MODEL, term=None, key=MODEL_KEY,
|
|
56
|
+
site_type_allowed=site_type_allowed,
|
|
57
|
+
cycle_has_added_forage_input=cycle_has_added_forage_input,
|
|
58
|
+
all_animals_have_added_forage_input=all_animals_have_added_forage_input)
|
|
59
|
+
|
|
60
|
+
return all([site_type_allowed, cycle_has_added_forage_input or all_animals_have_added_forage_input])
|
|
@@ -8,7 +8,7 @@ from hestia_earth.schema import TermTermType
|
|
|
8
8
|
from hestia_earth.utils.model import find_primary_product
|
|
9
9
|
from hestia_earth.utils.tools import list_sum, non_empty_list, flatten
|
|
10
10
|
|
|
11
|
-
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
11
|
+
from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
|
|
12
12
|
from hestia_earth.models.utils.blank_node import merge_blank_nodes
|
|
13
13
|
from hestia_earth.models.utils.property import _new_property, get_node_property_value, get_property_lookup_value
|
|
14
14
|
from hestia_earth.models.utils.term import get_digestible_energy_terms, get_energy_digestibility_terms
|
|
@@ -42,7 +42,6 @@ LOOKUPS = {
|
|
|
42
42
|
"property": "commonToSupplementInAnimalFeed"
|
|
43
43
|
}
|
|
44
44
|
TERM_ID = 'concentrateFeedBlend,concentrateFeedUnspecified,feedMix'
|
|
45
|
-
FIRST_TERM_ID = TERM_ID.split(',')[0]
|
|
46
45
|
INPUT_TERM_TYPES = [
|
|
47
46
|
TermTermType.CROP.value,
|
|
48
47
|
TermTermType.FORAGE.value,
|
|
@@ -70,40 +69,53 @@ def _weighted_value(values: list):
|
|
|
70
69
|
|
|
71
70
|
|
|
72
71
|
def _calculate_value(cycle: dict, product: dict, inputs: list, property_id: str, values: list):
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
valid_values = [
|
|
73
|
+
(value.get('property-value'), value.get('input-value'))
|
|
74
|
+
for value in values
|
|
75
|
+
if all([value.get('property-value'), value.get('input-value')])
|
|
76
|
+
]
|
|
77
|
+
ratio_inputs_with_props = len(valid_values) / len(inputs) if len(inputs) and len(valid_values) else 0
|
|
75
78
|
min_ratio = _min_ratio(property_id)
|
|
76
79
|
|
|
77
80
|
term_id = product.get('term', {}).get('@id')
|
|
78
81
|
logRequirements(cycle, model=MODEL, term=term_id, property=property_id,
|
|
79
82
|
nb_inputs=len(inputs),
|
|
80
|
-
nb_inputs_with_prop=len(
|
|
83
|
+
nb_inputs_with_prop=len(valid_values),
|
|
81
84
|
ratio_inputs_with_props=ratio_inputs_with_props,
|
|
82
|
-
min_ratio=min_ratio
|
|
85
|
+
min_ratio=min_ratio,
|
|
86
|
+
details=log_as_table(values))
|
|
83
87
|
|
|
84
88
|
should_run = all([ratio_inputs_with_props >= min_ratio])
|
|
85
89
|
logShouldRun(cycle, MODEL, term_id, should_run, property=property_id)
|
|
86
90
|
|
|
87
|
-
return [(property_id, _weighted_value(
|
|
91
|
+
return [(property_id, _weighted_value(valid_values))] if should_run else []
|
|
88
92
|
|
|
89
93
|
|
|
90
94
|
def _calculate_default_value(cycle: dict, product: dict, inputs: list, property_id: str):
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
list_sum(i.get('value', []))
|
|
95
|
-
|
|
95
|
+
term_id = product.get('term', {}).get('@id')
|
|
96
|
+
values = [{
|
|
97
|
+
'input-id': i.get('term', {}).get('@id'),
|
|
98
|
+
'input-value': list_sum(i.get('value', [])),
|
|
99
|
+
'property-id': property_id,
|
|
100
|
+
'property-value': get_node_property_value(
|
|
101
|
+
MODEL, i, property_id, handle_percents=False, term=term_id, property=property_id
|
|
102
|
+
),
|
|
103
|
+
} for i in inputs]
|
|
96
104
|
return _calculate_value(cycle, product, inputs, property_id, values)
|
|
97
105
|
|
|
98
106
|
|
|
99
107
|
def _calculate_N_value(cycle: dict, product: dict, inputs: list, property_id: str):
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
term_id = product.get('term', {}).get('@id')
|
|
109
|
+
values = [{
|
|
110
|
+
'input-id': i.get('term', {}).get('@id'),
|
|
111
|
+
'input-value': list_sum(i.get('value', [])),
|
|
112
|
+
'property-id': property_id,
|
|
113
|
+
'property-value': get_node_property_value(
|
|
114
|
+
MODEL, i, property_id, handle_percents=False, term=term_id, property=property_id
|
|
115
|
+
) or get_node_property_value(
|
|
116
|
+
MODEL, i, 'crudeProteinContent', default=0, handle_percents=False, term=term_id, property=property_id
|
|
117
|
+
) * 0.16
|
|
118
|
+
} for i in inputs]
|
|
107
119
|
return _calculate_value(cycle, product, inputs, property_id, values)
|
|
108
120
|
|
|
109
121
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
2
2
|
from hestia_earth.models.utils.indicator import _new_indicator
|
|
3
|
-
from hestia_earth.models.utils.impact_assessment import
|
|
3
|
+
from hestia_earth.models.utils.impact_assessment import impact_emission_lookup_value
|
|
4
4
|
from . import MODEL
|
|
5
5
|
|
|
6
6
|
REQUIREMENTS = {
|
|
@@ -27,7 +27,7 @@ def _indicator(value: float):
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
def run(impact_assessment: dict):
|
|
30
|
-
value =
|
|
30
|
+
value = impact_emission_lookup_value(MODEL, TERM_ID, impact_assessment, LOOKUPS['emission'])
|
|
31
31
|
logRequirements(impact_assessment, model=MODEL, term=TERM_ID,
|
|
32
32
|
value=value)
|
|
33
33
|
logShouldRun(impact_assessment, MODEL, TERM_ID, True)
|
|
@@ -1,33 +1,23 @@
|
|
|
1
|
-
from hestia_earth.utils.lookup import column_name
|
|
2
|
-
|
|
3
1
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
2
|
+
from hestia_earth.models.utils.impact_assessment import impact_emission_lookup_value
|
|
3
|
+
from hestia_earth.models.utils.indicator import _new_indicator
|
|
4
4
|
from . import MODEL
|
|
5
|
-
from ..utils.impact_assessment import impact_lookup_value
|
|
6
|
-
from ..utils.indicator import _new_indicator
|
|
7
5
|
|
|
8
6
|
REQUIREMENTS = {
|
|
9
7
|
"ImpactAssessment": {
|
|
10
|
-
"emissionsResourceUse": [
|
|
11
|
-
{
|
|
12
|
-
"@type": "Indicator", "value": "", "term.termType": "emission"
|
|
13
|
-
}
|
|
14
|
-
]
|
|
8
|
+
"emissionsResourceUse": [{"@type": "Indicator", "value": "", "term.termType": "emission"}]
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
|
-
|
|
18
|
-
TERM_ID = 'damageToHumanHealthParticulateMatterFormation'
|
|
19
|
-
|
|
20
11
|
LOOKUPS = {
|
|
21
12
|
"emission": "damageToHumanHealthParticulateMatterFormationFantkeEtAl2016"
|
|
22
13
|
}
|
|
23
|
-
|
|
24
14
|
RETURNS = {
|
|
25
15
|
"Indicator": {
|
|
26
16
|
"value": ""
|
|
27
17
|
}
|
|
28
18
|
}
|
|
29
19
|
|
|
30
|
-
|
|
20
|
+
TERM_ID = 'damageToHumanHealthParticulateMatterFormation'
|
|
31
21
|
|
|
32
22
|
|
|
33
23
|
def _indicator(value: float):
|
|
@@ -37,9 +27,9 @@ def _indicator(value: float):
|
|
|
37
27
|
|
|
38
28
|
|
|
39
29
|
def run(impact_assessment: dict):
|
|
40
|
-
value =
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
value = impact_emission_lookup_value(
|
|
31
|
+
model=MODEL, term_id=TERM_ID, impact=impact_assessment, lookup_col=LOOKUPS['emission'], grouped_key='default'
|
|
32
|
+
)
|
|
43
33
|
logRequirements(impact_assessment, model=MODEL, term=TERM_ID,
|
|
44
34
|
value=value)
|
|
45
35
|
|
|
@@ -2,6 +2,7 @@ from hestia_earth.schema import TermTermType
|
|
|
2
2
|
from hestia_earth.utils.api import download_hestia
|
|
3
3
|
from hestia_earth.utils.lookup import download_lookup, get_table_value, column_name, extract_grouped_data_closest_date
|
|
4
4
|
from hestia_earth.utils.tools import safe_parse_float
|
|
5
|
+
from numpy import recarray
|
|
5
6
|
|
|
6
7
|
from hestia_earth.models.log import logger, debugMissingLookup
|
|
7
8
|
from hestia_earth.models.utils.animalProduct import (
|
|
@@ -53,7 +54,7 @@ def product_equivalent_value(product: dict, year: int, country: str):
|
|
|
53
54
|
return conv_value
|
|
54
55
|
|
|
55
56
|
|
|
56
|
-
def
|
|
57
|
+
def _split_delta(table_value: str, start_year: int, end_year: int):
|
|
57
58
|
start_value = extract_grouped_data_closest_date(table_value, start_year)
|
|
58
59
|
end_value = extract_grouped_data_closest_date(table_value, end_year)
|
|
59
60
|
return safe_parse_float(end_value) - safe_parse_float(start_value) if all([
|
|
@@ -61,22 +62,81 @@ def _cropland_split_delta(table_value: str, start_year: int, end_year: int):
|
|
|
61
62
|
]) else None
|
|
62
63
|
|
|
63
64
|
|
|
64
|
-
def
|
|
65
|
+
def get_sum_of_columns(lookup: recarray, country: str, year: int, columns_list: list) -> float:
|
|
66
|
+
return sum(
|
|
67
|
+
[safe_parse_float(
|
|
68
|
+
extract_grouped_data_closest_date(
|
|
69
|
+
data=get_table_value(lookup, 'termid', country, column_name(col)),
|
|
70
|
+
year=year
|
|
71
|
+
)
|
|
72
|
+
) for col in columns_list]
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def get_single_delta(country: str, start_year: int, end_year: int, column: str):
|
|
65
77
|
lookup = download_lookup('region-faostatArea.csv')
|
|
66
|
-
|
|
67
|
-
get_table_value(lookup, 'termid', country, column_name(
|
|
78
|
+
return _split_delta(
|
|
79
|
+
get_table_value(lookup, 'termid', country, column_name(column)), start_year, end_year
|
|
68
80
|
)
|
|
69
81
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
82
|
+
|
|
83
|
+
def get_land_ratio(
|
|
84
|
+
country: str, start_year: int, end_year: int, first_column: str, second_column: str, total_column: str = None
|
|
85
|
+
):
|
|
86
|
+
"""
|
|
87
|
+
total_column is optional. Assumes that, if missing, total is the sum of values from first and second.
|
|
88
|
+
"""
|
|
89
|
+
lookup = download_lookup('region-faostatArea.csv')
|
|
90
|
+
first_delta = _split_delta(
|
|
91
|
+
get_table_value(lookup, 'termid', country, column_name(first_column)), start_year, end_year
|
|
92
|
+
)
|
|
93
|
+
second_delta = _split_delta(
|
|
94
|
+
get_table_value(lookup, 'termid', country, column_name(second_column)), start_year, end_year
|
|
73
95
|
)
|
|
74
|
-
|
|
75
|
-
|
|
96
|
+
total_delta = (
|
|
97
|
+
get_sum_of_columns(
|
|
98
|
+
lookup=lookup,
|
|
99
|
+
country=country,
|
|
100
|
+
year=end_year,
|
|
101
|
+
columns_list=[first_column, second_column]
|
|
102
|
+
) - get_sum_of_columns(
|
|
103
|
+
lookup=lookup,
|
|
104
|
+
country=country,
|
|
105
|
+
year=start_year,
|
|
106
|
+
columns_list=[first_column, second_column]
|
|
107
|
+
)
|
|
108
|
+
) if total_column is None else _split_delta(
|
|
109
|
+
get_table_value(lookup, 'termid', country, column_name(total_column)), start_year, end_year
|
|
76
110
|
)
|
|
77
111
|
|
|
78
112
|
return (None, None, None) if any([
|
|
79
113
|
total_delta is None,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
]) else (total_delta,
|
|
114
|
+
first_delta is None,
|
|
115
|
+
second_delta is None
|
|
116
|
+
]) else (total_delta, first_delta, second_delta)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def get_cropland_ratio(country: str, start_year: int, end_year: int):
|
|
120
|
+
return get_land_ratio(
|
|
121
|
+
country=country,
|
|
122
|
+
start_year=start_year,
|
|
123
|
+
end_year=end_year,
|
|
124
|
+
first_column='Permanent crops',
|
|
125
|
+
second_column='Arable land',
|
|
126
|
+
total_column='Cropland'
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def get_change_in_harvested_area_for_crop(country_id: str, crop_name: str, start_year: int, end_year: int = 0):
|
|
131
|
+
lookup = download_lookup('region-crop-cropGroupingFaostatProduction-areaHarvested.csv')
|
|
132
|
+
if end_year == 0 or end_year == start_year:
|
|
133
|
+
return safe_parse_float(
|
|
134
|
+
extract_grouped_data_closest_date(
|
|
135
|
+
data=get_table_value(lookup, 'termid', country_id, column_name(crop_name)),
|
|
136
|
+
year=start_year
|
|
137
|
+
)
|
|
138
|
+
)
|
|
139
|
+
else:
|
|
140
|
+
return _split_delta(
|
|
141
|
+
get_table_value(lookup, 'termid', country_id, column_name(crop_name)), start_year, end_year
|
|
142
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from os.path import dirname, abspath
|
|
2
|
+
import sys
|
|
3
|
+
from importlib import import_module
|
|
4
|
+
|
|
5
|
+
from hestia_earth.models.utils.blank_node import run_if_required
|
|
6
|
+
|
|
7
|
+
CURRENT_DIR = dirname(abspath(__file__)) + '/'
|
|
8
|
+
sys.path.append(CURRENT_DIR)
|
|
9
|
+
MODEL = 'hestia'
|
|
10
|
+
PKG = '.'.join(['hestia_earth', 'models', MODEL])
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def run(model: str, data): return run_if_required(MODEL, model, data, import_module(f".{model}", package=PKG))
|