hestia-earth-models 0.69.0__py3-none-any.whl → 0.70.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hestia_earth/models/cache_sites.py +3 -2
- hestia_earth/models/cml2001Baseline/abioticResourceDepletionFossilFuels.py +2 -1
- hestia_earth/models/cml2001Baseline/abioticResourceDepletionMineralsAndMetals.py +3 -2
- hestia_earth/models/config/Cycle.json +35 -1
- hestia_earth/models/{koble2014 → cycle}/aboveGroundCropResidue.py +1 -3
- hestia_earth/models/cycle/aboveGroundCropResidueTotal.py +1 -1
- hestia_earth/models/cycle/animal/input/hestiaAggregatedData.py +1 -1
- hestia_earth/models/cycle/animal/input/properties.py +1 -1
- hestia_earth/models/cycle/cycleDuration.py +2 -2
- hestia_earth/models/cycle/energyContentLowerHeatingValue.py +1 -1
- hestia_earth/models/cycle/input/hestiaAggregatedData.py +12 -14
- hestia_earth/models/cycle/input/properties.py +1 -1
- hestia_earth/models/cycle/siteDuration.py +3 -3
- hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +1 -1
- hestia_earth/models/geospatialDatabase/croppingIntensity.py +4 -4
- hestia_earth/models/geospatialDatabase/longFallowRatio.py +4 -4
- hestia_earth/models/geospatialDatabase/region.py +3 -2
- hestia_earth/models/geospatialDatabase/utils.py +6 -5
- hestia_earth/models/haversineFormula/transport/distance.py +5 -4
- hestia_earth/models/hestia/landCover.py +1 -5
- hestia_earth/models/hestia/landTransformation100YearAverageDuringCycle.py +2 -1
- hestia_earth/models/hestia/landTransformation20YearAverageDuringCycle.py +2 -1
- hestia_earth/models/hestia/seed_emissions.py +1 -1
- hestia_earth/models/impact_assessment/emissions.py +1 -1
- hestia_earth/models/impact_assessment/product/economicValueShare.py +1 -1
- hestia_earth/models/impact_assessment/product/value.py +1 -1
- hestia_earth/models/ipcc2019/animal/fatContent.py +2 -2
- hestia_earth/models/ipcc2019/animal/milkYieldPerAnimal.py +2 -2
- hestia_earth/models/ipcc2019/animal/trueProteinContent.py +2 -2
- hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +7 -2
- hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChange.py +1 -0
- hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChange.py +2 -1
- hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChange.py +2 -1
- hestia_earth/models/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning.py +1 -0
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1.py +8 -8
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2.py +40 -12
- hestia_earth/models/koble2014/cropResidueManagement.py +1 -1
- hestia_earth/models/koble2014/residueBurnt.py +1 -1
- hestia_earth/models/koble2014/residueRemoved.py +1 -1
- hestia_earth/models/koble2014/utils.py +3 -3
- hestia_earth/models/mocking/search-results.json +1179 -1137
- hestia_earth/models/pooreNemecek2018/excretaKgN.py +1 -1
- hestia_earth/models/pooreNemecek2018/freshwaterWithdrawalsDuringCycle.py +1 -1
- hestia_earth/models/pooreNemecek2018/utils.py +6 -3
- hestia_earth/models/schmidt2007/ch4ToAirWasteTreatment.py +1 -3
- hestia_earth/models/schmidt2007/h2SToAirWasteTreatment.py +1 -3
- hestia_earth/models/schmidt2007/n2OToAirWasteTreatmentDirect.py +1 -3
- hestia_earth/models/schmidt2007/nh3ToAirWasteTreatment.py +1 -3
- hestia_earth/models/site/management.py +5 -3
- hestia_earth/models/site/pre_checks/country.py +4 -2
- hestia_earth/models/transformation/input/excreta.py +1 -1
- hestia_earth/models/utils/aggregated.py +12 -15
- hestia_earth/models/utils/blank_node.py +15 -1
- hestia_earth/models/utils/product.py +1 -1
- hestia_earth/models/utils/source.py +2 -1
- hestia_earth/models/utils/term.py +26 -1
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.69.0.dist-info → hestia_earth_models-0.70.0.dist-info}/METADATA +1 -1
- {hestia_earth_models-0.69.0.dist-info → hestia_earth_models-0.70.0.dist-info}/RECORD +75 -75
- tests/models/cycle/input/test_hestiaAggregatedData.py +18 -16
- tests/models/{koble2014 → cycle}/test_aboveGroundCropResidue.py +3 -3
- tests/models/geospatialDatabase/test_region.py +1 -1
- tests/models/geospatialDatabase/test_utils.py +1 -1
- tests/models/haversineFormula/transport/test_distance.py +2 -2
- tests/models/ipcc2019/test_ch4ToAirEntericFermentation.py +11 -0
- tests/models/ipcc2019/test_nonCo2EmissionsToAirNaturalVegetationBurning.py +19 -6
- tests/models/ipcc2019/test_organicCarbonPerHa.py +4 -2
- tests/models/pooreNemecek2018/test_landOccupationDuringCycle.py +3 -0
- tests/models/site/pre_checks/test_country.py +4 -3
- tests/models/test_ecoinventV3.py +2 -2
- tests/models/utils/test_source.py +15 -5
- tests/orchestrator/test_models.py +1 -0
- {hestia_earth_models-0.69.0.dist-info → hestia_earth_models-0.70.0.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.69.0.dist-info → hestia_earth_models-0.70.0.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.69.0.dist-info → hestia_earth_models-0.70.0.dist-info}/top_level.txt +0 -0
@@ -1,12 +1,13 @@
|
|
1
1
|
from functools import reduce
|
2
2
|
from enum import Enum
|
3
3
|
from pydash.objects import merge
|
4
|
-
from hestia_earth.
|
4
|
+
from hestia_earth.schema import TermTermType
|
5
5
|
from hestia_earth.utils.tools import flatten, non_empty_list
|
6
6
|
|
7
7
|
from .log import logger
|
8
8
|
from .utils import CACHE_KEY, cached_value
|
9
9
|
from .utils.site import CACHE_YEARS_KEY
|
10
|
+
from .utils.term import download_term
|
10
11
|
from .site.pre_checks.cache_geospatialDatabase import (
|
11
12
|
list_vectors, list_rasters, cache_site_results, _should_run
|
12
13
|
)
|
@@ -92,7 +93,7 @@ def _should_preload_region_area_size(site: dict): return not has_coordinates(sit
|
|
92
93
|
|
93
94
|
def _preload_regions_area_size(sites: dict):
|
94
95
|
region_ids = set(map(_site_gadm_id, filter(_should_preload_region_area_size, sites)))
|
95
|
-
return {term_id:
|
96
|
+
return {term_id: download_term(term_id, TermTermType.REGION).get('area') for term_id in region_ids}
|
96
97
|
|
97
98
|
|
98
99
|
def _group_sites(sites: dict, check_has_cache: bool = True):
|
@@ -17,12 +17,13 @@ REQUIREMENTS = {
|
|
17
17
|
"term.@id": ["resourceUseEnergyDepletionInputsProduction", "resourceUseEnergyDepletionDuringCycle"],
|
18
18
|
"term.units": "MJ",
|
19
19
|
"value": "> 0",
|
20
|
-
"inputs":
|
20
|
+
"inputs": [
|
21
21
|
{
|
22
22
|
"@type": "Input",
|
23
23
|
"term.name": "non-renewable\" energy terms only,\"",
|
24
24
|
"term.termType": ["fuel", "electricity"]
|
25
25
|
}
|
26
|
+
]
|
26
27
|
}
|
27
28
|
]
|
28
29
|
}
|
@@ -14,10 +14,11 @@ REQUIREMENTS = {
|
|
14
14
|
{
|
15
15
|
"@type": "Indicator", "value": "", "term.termType": "resourceUse",
|
16
16
|
"term.@id": ["resourceUseMineralsAndMetalsInputsProduction", "resourceUseMineralsAndMetalsDuringCycle"],
|
17
|
-
"inputs": {
|
17
|
+
"inputs": [{
|
18
18
|
"@type": "Term",
|
19
19
|
"term.units": "kg",
|
20
|
-
"term.termType": ["material", "soilAmendment", "otherInorganicChemical"]
|
20
|
+
"term.termType": ["material", "soilAmendment", "otherInorganicChemical"]
|
21
|
+
}]
|
21
22
|
}]
|
22
23
|
}
|
23
24
|
}
|
@@ -224,7 +224,7 @@
|
|
224
224
|
},
|
225
225
|
{
|
226
226
|
"key": "products",
|
227
|
-
"model": "
|
227
|
+
"model": "cycle",
|
228
228
|
"value": "aboveGroundCropResidue",
|
229
229
|
"runStrategy": "always",
|
230
230
|
"mergeStrategy": "list",
|
@@ -238,6 +238,40 @@
|
|
238
238
|
"mergeStrategy": "list",
|
239
239
|
"stage": 1
|
240
240
|
},
|
241
|
+
[
|
242
|
+
{
|
243
|
+
"key": "practices",
|
244
|
+
"model": "cycle",
|
245
|
+
"value": "residueBurnt",
|
246
|
+
"runStrategy": "add_blank_node_if_missing",
|
247
|
+
"mergeStrategy": "list",
|
248
|
+
"stage": 1
|
249
|
+
},
|
250
|
+
{
|
251
|
+
"key": "practices",
|
252
|
+
"model": "cycle",
|
253
|
+
"value": "residueIncorporated",
|
254
|
+
"runStrategy": "add_blank_node_if_missing",
|
255
|
+
"mergeStrategy": "list",
|
256
|
+
"stage": 1
|
257
|
+
},
|
258
|
+
{
|
259
|
+
"key": "practices",
|
260
|
+
"model": "cycle",
|
261
|
+
"value": "residueLeftOnField",
|
262
|
+
"runStrategy": "add_blank_node_if_missing",
|
263
|
+
"mergeStrategy": "list",
|
264
|
+
"stage": 1
|
265
|
+
},
|
266
|
+
{
|
267
|
+
"key": "practices",
|
268
|
+
"model": "cycle",
|
269
|
+
"value": "residueRemoved",
|
270
|
+
"runStrategy": "add_blank_node_if_missing",
|
271
|
+
"mergeStrategy": "list",
|
272
|
+
"stage": 1
|
273
|
+
}
|
274
|
+
],
|
241
275
|
{
|
242
276
|
"key": "products",
|
243
277
|
"model": "ipcc2006",
|
@@ -50,9 +50,7 @@ def _get_practice_value(term_ids: list, cycle: dict) -> float:
|
|
50
50
|
return list_sum(values) / 100 if len(values) > 0 else None
|
51
51
|
|
52
52
|
|
53
|
-
def _product(term_id: str, value: float):
|
54
|
-
product = _new_product(term_id, round(value, 2), MODEL)
|
55
|
-
return product
|
53
|
+
def _product(term_id: str, value: float): return _new_product(term_id, round(value, 7))
|
56
54
|
|
57
55
|
|
58
56
|
def _should_run_model(model, cycle: dict, total_value: float):
|
@@ -30,7 +30,7 @@ def _run(practice: dict, product: dict):
|
|
30
30
|
practice_value = list_sum(practice.get('value', []))
|
31
31
|
product_value = list_sum(product.get('value', []))
|
32
32
|
value = product_value / (practice_value / 100)
|
33
|
-
return [_product(round(value,
|
33
|
+
return [_product(round(value, 7))]
|
34
34
|
|
35
35
|
|
36
36
|
def _matching_product_by_practice(term_id: str):
|
@@ -11,11 +11,11 @@ REQUIREMENTS = {
|
|
11
11
|
"endDate": "",
|
12
12
|
"optional": {
|
13
13
|
"startDate": "",
|
14
|
-
"products": {
|
14
|
+
"products": [{
|
15
15
|
"@type": "Product",
|
16
16
|
"primary": "True",
|
17
17
|
"term.termType": "crop"
|
18
|
-
},
|
18
|
+
}],
|
19
19
|
"practices": [{"@type": "Practice", "value": "", "term.@id": "croppingIntensity"}]
|
20
20
|
}
|
21
21
|
}
|
@@ -1,12 +1,11 @@
|
|
1
1
|
from hestia_earth.schema import TermTermType
|
2
|
-
from hestia_earth.utils.api import download_hestia
|
3
2
|
from hestia_earth.utils.model import find_primary_product, linked_node, filter_list_term_type
|
4
3
|
from hestia_earth.utils.tools import non_empty_list
|
5
4
|
|
6
5
|
from hestia_earth.models.log import debugValues, logRequirements, logShouldRun
|
7
6
|
from hestia_earth.models.utils.crop import valid_site_type
|
8
7
|
from hestia_earth.models.utils.blank_node import get_lookup_value
|
9
|
-
from hestia_earth.models.utils.term import get_generic_crop
|
8
|
+
from hestia_earth.models.utils.term import get_generic_crop, download_term
|
10
9
|
from hestia_earth.models.utils.aggregated import (
|
11
10
|
should_link_input_to_impact, link_inputs_to_impact, find_closest_impact, aggregated_end_date
|
12
11
|
)
|
@@ -17,7 +16,7 @@ REQUIREMENTS = {
|
|
17
16
|
"@type": "Input",
|
18
17
|
"value": "",
|
19
18
|
"none": {
|
20
|
-
"impactAssessment": "",
|
19
|
+
"impactAssessment": {"@type": "ImpactAssessment"},
|
21
20
|
"fromCycle": "True",
|
22
21
|
"producedInCycle": "True"
|
23
22
|
},
|
@@ -37,7 +36,7 @@ REQUIREMENTS = {
|
|
37
36
|
"term.@id": "seed",
|
38
37
|
"value": "",
|
39
38
|
"none": {
|
40
|
-
"impactAssessment": ""
|
39
|
+
"impactAssessment": {"@type": "ImpactAssessment"}
|
41
40
|
}
|
42
41
|
}],
|
43
42
|
"products": [{"@type": "Product", "value": "", "primary": "True"}]
|
@@ -58,8 +57,7 @@ MODEL_KEY = 'impactAssessment'
|
|
58
57
|
|
59
58
|
|
60
59
|
def _run_seed(cycle: dict, primary_product: dict, seed_input: dict, product_term_id: str):
|
61
|
-
product =
|
62
|
-
region = seed_input.get('region')
|
60
|
+
product = download_term(product_term_id, TermTermType.SEED)
|
63
61
|
country = seed_input.get('country')
|
64
62
|
# to avoid double counting seed => aggregated impact => seed, we need to get the impact of the previous decade
|
65
63
|
# if the data does not exist, use the aggregated impact of generic crop instead
|
@@ -68,16 +66,16 @@ def _run_seed(cycle: dict, primary_product: dict, seed_input: dict, product_term
|
|
68
66
|
default_product = get_generic_crop()
|
69
67
|
|
70
68
|
impact = (
|
71
|
-
find_closest_impact(cycle, date, product,
|
72
|
-
find_closest_impact(cycle, date, primary_product.get('term', {}),
|
73
|
-
find_closest_impact(cycle, date, default_product,
|
69
|
+
find_closest_impact(cycle, date, product, country, must_queries=match_end_date) or
|
70
|
+
find_closest_impact(cycle, date, primary_product.get('term', {}), country, must_queries=match_end_date) or
|
71
|
+
find_closest_impact(cycle, date, default_product, country)
|
74
72
|
)
|
75
73
|
|
76
74
|
search_by_product_term_id = (product or primary_product or default_product).get('@id')
|
77
|
-
|
75
|
+
search_by_country_id = (country or {}).get('@id') or 'region-world'
|
78
76
|
debugValues(cycle, model=MODEL_ID, term=seed_input.get('term', {}).get('@id'), key=MODEL_KEY,
|
79
77
|
search_by_product_term_id=search_by_product_term_id,
|
80
|
-
|
78
|
+
search_by_country_id=search_by_country_id,
|
81
79
|
search_by_end_date=str(date),
|
82
80
|
impact_assessment_id_found=(impact or {}).get('@id'))
|
83
81
|
|
@@ -95,7 +93,7 @@ def _should_run_seed(cycle: dict):
|
|
95
93
|
seed_inputs = [
|
96
94
|
{
|
97
95
|
'input': seed_input,
|
98
|
-
'product': get_lookup_value(seed_input.get('term', {}), LOOKUPS['seed'], key=MODEL_KEY)
|
96
|
+
'product-id': get_lookup_value(seed_input.get('term', {}), LOOKUPS['seed'], key=MODEL_KEY)
|
99
97
|
}
|
100
98
|
for seed_input in seed_inputs
|
101
99
|
]
|
@@ -104,7 +102,7 @@ def _should_run_seed(cycle: dict):
|
|
104
102
|
|
105
103
|
for seed_input in seed_inputs:
|
106
104
|
term_id = seed_input.get('input').get('term', {}).get('@id')
|
107
|
-
linked_product_id = seed_input.get('product')
|
105
|
+
linked_product_id = seed_input.get('product-id')
|
108
106
|
|
109
107
|
logRequirements(cycle, model=MODEL_ID, term=term_id, key=MODEL_KEY,
|
110
108
|
site_type_valid=site_type_valid,
|
@@ -140,7 +138,7 @@ def run(cycle: dict):
|
|
140
138
|
link_inputs_to_impact(MODEL_ID, cycle, inputs) if should_run else []
|
141
139
|
) + (
|
142
140
|
non_empty_list([
|
143
|
-
_run_seed(cycle, primary_product, seed_input.get('input'), seed_input.get('product'))
|
141
|
+
_run_seed(cycle, primary_product, seed_input.get('input'), seed_input.get('product-id'))
|
144
142
|
for seed_input in seed_inputs
|
145
143
|
]) if should_run_seed else []
|
146
144
|
)
|
@@ -9,14 +9,14 @@ REQUIREMENTS = {
|
|
9
9
|
"Cycle": {
|
10
10
|
"cycleDuration": "> 0",
|
11
11
|
"none": {
|
12
|
-
"otherSites": ""
|
12
|
+
"otherSites": [{"@type": "Site"}]
|
13
13
|
},
|
14
14
|
"optional": {
|
15
|
-
"products": {
|
15
|
+
"products": [{
|
16
16
|
"@type": "Product",
|
17
17
|
"primary": "True",
|
18
18
|
"term.termType": "crop"
|
19
|
-
},
|
19
|
+
}],
|
20
20
|
"startDateDefinition": ""
|
21
21
|
}
|
22
22
|
}
|
@@ -18,7 +18,7 @@ REQUIREMENTS = {
|
|
18
18
|
"ionisingCompoundsToWaterInputsProduction",
|
19
19
|
"ionisingCompoundsToSaltwaterInputsProduction"
|
20
20
|
],
|
21
|
-
"inputs": {"@type": "Term", "term.termType": "waste", "term.units": "kg"}
|
21
|
+
"inputs": [{"@type": "Term", "term.termType": "waste", "term.units": "kg"}]
|
22
22
|
}]
|
23
23
|
}
|
24
24
|
}
|
@@ -14,8 +14,8 @@ REQUIREMENTS = {
|
|
14
14
|
"site": {
|
15
15
|
"@type": "Site",
|
16
16
|
"or": [
|
17
|
-
{"region": {"@type": "Term"}},
|
18
|
-
{"country": {"@type": "Term"}}
|
17
|
+
{"region": {"@type": "Term", "termType": "region"}},
|
18
|
+
{"country": {"@type": "Term", "termType": "region"}}
|
19
19
|
]
|
20
20
|
},
|
21
21
|
"optional": {
|
@@ -23,8 +23,8 @@ REQUIREMENTS = {
|
|
23
23
|
{
|
24
24
|
"@type": "Site",
|
25
25
|
"or": [
|
26
|
-
{"region": {"@type": "Term"}},
|
27
|
-
{"country": {"@type": "Term"}}
|
26
|
+
{"region": {"@type": "Term", "termType": "region"}},
|
27
|
+
{"country": {"@type": "Term", "termType": "region"}}
|
28
28
|
]
|
29
29
|
}
|
30
30
|
]
|
@@ -14,8 +14,8 @@ REQUIREMENTS = {
|
|
14
14
|
"site": {
|
15
15
|
"@type": "Site",
|
16
16
|
"or": [
|
17
|
-
{"region": {"@type": "Term"}},
|
18
|
-
{"country": {"@type": "Term"}}
|
17
|
+
{"region": {"@type": "Term", "termType": "region"}},
|
18
|
+
{"country": {"@type": "Term", "termType": "region"}}
|
19
19
|
]
|
20
20
|
},
|
21
21
|
"optional": {
|
@@ -23,8 +23,8 @@ REQUIREMENTS = {
|
|
23
23
|
{
|
24
24
|
"@type": "Site",
|
25
25
|
"or": [
|
26
|
-
{"region": {"@type": "Term"}},
|
27
|
-
{"country": {"@type": "Term"}}
|
26
|
+
{"region": {"@type": "Term", "termType": "region"}},
|
27
|
+
{"country": {"@type": "Term", "termType": "region"}}
|
28
28
|
]
|
29
29
|
}
|
30
30
|
]
|
@@ -1,8 +1,9 @@
|
|
1
|
-
from hestia_earth.
|
1
|
+
from hestia_earth.schema import TermTermType
|
2
2
|
from hestia_earth.utils.model import linked_node
|
3
3
|
|
4
4
|
from hestia_earth.models.log import debugValues, logRequirements, logShouldRun
|
5
5
|
from .utils import download, has_coordinates
|
6
|
+
from hestia_earth.models.utils.term import download_term
|
6
7
|
from . import MODEL
|
7
8
|
|
8
9
|
REQUIREMENTS = {
|
@@ -30,7 +31,7 @@ def _download_region(site: dict):
|
|
30
31
|
only_coordinates=True
|
31
32
|
)
|
32
33
|
try:
|
33
|
-
return None if gadm_id is None else linked_node(
|
34
|
+
return None if gadm_id is None else linked_node(download_term(f"GADM-{gadm_id}", TermTermType.REGION))
|
34
35
|
except Exception:
|
35
36
|
return None
|
36
37
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import os
|
2
2
|
from hestia_earth.schema import TermTermType
|
3
|
-
from hestia_earth.utils.api import download_hestia
|
4
3
|
from hestia_earth.utils.tools import non_empty_list
|
5
4
|
|
6
5
|
from hestia_earth.models.log import debugValues, logErrorRun, logRequirements
|
7
6
|
from hestia_earth.models.utils.site import cached_value, region_factor, region_level_1_id
|
7
|
+
from hestia_earth.models.utils.term import download_term
|
8
8
|
from . import MODEL
|
9
9
|
|
10
10
|
MAX_AREA_SIZE = int(os.getenv('MAX_AREA_SIZE', '5000'))
|
@@ -97,7 +97,7 @@ def _get_boundary_area_size(boundary: dict):
|
|
97
97
|
|
98
98
|
def _get_region_area_size(site: dict):
|
99
99
|
term = site.get('region', site.get('country'))
|
100
|
-
return term.get('area', (
|
100
|
+
return term.get('area', (download_term(term.get('@id'), TermTermType.REGION) or {}).get('area')) if term else None
|
101
101
|
|
102
102
|
|
103
103
|
def get_area_size(site: dict):
|
@@ -153,9 +153,10 @@ def _get_cached_data(term: str, site: dict, data: dict):
|
|
153
153
|
cache = _cached_value(site, term)
|
154
154
|
cache_sub_key = _cache_sub_key(data)
|
155
155
|
# data can be grouped by year when required
|
156
|
-
value = cache.get(cache_sub_key) if (
|
157
|
-
isinstance(cache, dict)
|
158
|
-
|
156
|
+
value = cache.get(cache_sub_key) if all([
|
157
|
+
isinstance(cache, dict),
|
158
|
+
cache_sub_key
|
159
|
+
]) else cache
|
159
160
|
if value is not None:
|
160
161
|
debugValues(site, model=MODEL, term=term, value_from_cache=value)
|
161
162
|
return value
|
@@ -1,9 +1,10 @@
|
|
1
1
|
from haversine import haversine
|
2
|
-
from hestia_earth.
|
2
|
+
from hestia_earth.schema import TermTermType
|
3
3
|
from hestia_earth.utils.tools import non_empty_list
|
4
4
|
|
5
5
|
from hestia_earth.models.log import logRequirements, logShouldRun, debugValues
|
6
6
|
from hestia_earth.models.utils.method import include_methodModel
|
7
|
+
from hestia_earth.models.utils.term import download_term
|
7
8
|
from .. import MODEL
|
8
9
|
|
9
10
|
REQUIREMENTS = {
|
@@ -55,7 +56,7 @@ def _should_run_transport(cycle: dict, transport: dict):
|
|
55
56
|
def _run_input(cycle: dict, site_country: dict):
|
56
57
|
def exec(input: dict):
|
57
58
|
term_id = input.get('term', {}).get('@id')
|
58
|
-
input_country =
|
59
|
+
input_country = download_term(input.get('country', {}).get('@id'), TermTermType.REGION)
|
59
60
|
distance_kms = haversine(
|
60
61
|
(site_country.get('latitude'), site_country.get('longitude')),
|
61
62
|
(input_country.get('latitude'), input_country.get('longitude'))
|
@@ -74,7 +75,7 @@ def _should_run_input(site_country_id: str):
|
|
74
75
|
def exec(input: dict):
|
75
76
|
input_country = input.get('country', {}) or {}
|
76
77
|
input_country_id = input_country.get('@id')
|
77
|
-
input_country =
|
78
|
+
input_country = download_term(input_country_id, TermTermType.REGION)
|
78
79
|
has_transports = len(input.get('transport', [])) > 0
|
79
80
|
should_run = input_country and all([
|
80
81
|
input_country.get('latitude'), input_country.get('latitude'),
|
@@ -89,7 +90,7 @@ def _should_run(cycle: dict):
|
|
89
90
|
country_id = cycle.get('site', {}).get('country', {}).get('@id')
|
90
91
|
inputs = list(filter(_should_run_input(country_id), cycle.get('inputs', [])))
|
91
92
|
# download full term to get coordinates only if there is anything to run
|
92
|
-
country =
|
93
|
+
country = download_term(country_id, TermTermType.REGION) if len(inputs) > 0 else {}
|
93
94
|
|
94
95
|
# can only run if the site country has centroid coordinates
|
95
96
|
logRequirements(cycle, model=MODEL, term=None, key=MODEL_KEY,
|
@@ -40,7 +40,7 @@ REQUIREMENTS = {
|
|
40
40
|
"permanent pasture",
|
41
41
|
"other natural vegetation"
|
42
42
|
],
|
43
|
-
"country": "",
|
43
|
+
"country": {"@type": "Term", "termType": "region"},
|
44
44
|
"management": [
|
45
45
|
{
|
46
46
|
"@type": "Management",
|
@@ -56,11 +56,7 @@ REQUIREMENTS = {
|
|
56
56
|
}
|
57
57
|
RETURNS = {
|
58
58
|
"Management": [{
|
59
|
-
"@type": "Management",
|
60
59
|
"term.termType": "landCover",
|
61
|
-
"term.@id": [
|
62
|
-
"Forest", "Annual cropland", "Permanent cropland", "Permanent pasture", "Other natural vegetation"
|
63
|
-
],
|
64
60
|
"value": "",
|
65
61
|
"endDate": "",
|
66
62
|
"startDate": ""
|
@@ -2,7 +2,8 @@ from .resourceUse_utils import run_resource_use
|
|
2
2
|
|
3
3
|
REQUIREMENTS = {
|
4
4
|
"ImpactAssessment": {
|
5
|
-
"
|
5
|
+
"site": {
|
6
|
+
"@type": "Site",
|
6
7
|
"management": [{"@type": "Management", "value": ">=0", "term.termType": "landCover", "endDate": ""}]
|
7
8
|
},
|
8
9
|
"emissionsResourceUse": [
|
@@ -2,7 +2,8 @@ from .resourceUse_utils import run_resource_use
|
|
2
2
|
|
3
3
|
REQUIREMENTS = {
|
4
4
|
"ImpactAssessment": {
|
5
|
-
"
|
5
|
+
"site": {
|
6
|
+
"@type": "Site",
|
6
7
|
"management": [{"@type": "Management", "value": ">=0", "term.termType": "landCover", "endDate": ""}]
|
7
8
|
},
|
8
9
|
"emissionsResourceUse": [
|
@@ -4,7 +4,7 @@ from .. import MODEL
|
|
4
4
|
|
5
5
|
REQUIREMENTS = {
|
6
6
|
"ImpactAssessment": {
|
7
|
-
"product": {"@type": "Product", "
|
7
|
+
"product": {"@type": "Product", "none": {"economicValueShare": ""}},
|
8
8
|
"cycle": {
|
9
9
|
"@type": "Cycle",
|
10
10
|
"products": [{"@type": "Product", "economicValueShare": ""}]
|
@@ -4,7 +4,7 @@ from .. import MODEL
|
|
4
4
|
|
5
5
|
REQUIREMENTS = {
|
6
6
|
"ImpactAssessment": {
|
7
|
-
"product": {"@type": "Product", "
|
7
|
+
"product": {"@type": "Product", "none": {"value": ""}},
|
8
8
|
"cycle": {
|
9
9
|
"@type": "Cycle",
|
10
10
|
"products": [{"@type": "Product", "value": ""}]
|
@@ -5,6 +5,7 @@ from hestia_earth.utils.tools import list_sum, safe_parse_float
|
|
5
5
|
|
6
6
|
from hestia_earth.models.log import debugMissingLookup, debugValues, logRequirements, logShouldRun, log_as_table
|
7
7
|
from hestia_earth.models.utils.blank_node import get_total_value_converted_with_min_ratio
|
8
|
+
from hestia_earth.models.utils.term import get_ionophore_terms
|
8
9
|
from hestia_earth.models.utils.input import get_feed_inputs
|
9
10
|
from hestia_earth.models.utils.emission import _new_emission
|
10
11
|
from hestia_earth.models.utils.liveAnimal import get_default_digestibility
|
@@ -48,7 +49,10 @@ REQUIREMENTS = {
|
|
48
49
|
}
|
49
50
|
}]
|
50
51
|
}
|
51
|
-
]
|
52
|
+
],
|
53
|
+
"optional": {
|
54
|
+
"inputs": [{"@type": "Input", "term.@id": ["ionophores", "ionophoreAntibiotics"]}]
|
55
|
+
}
|
52
56
|
}
|
53
57
|
}
|
54
58
|
LOOKUPS = {
|
@@ -192,7 +196,8 @@ def _get_DE_type(lookup, term_id: str, term_type: str):
|
|
192
196
|
|
193
197
|
def _is_ionophore(cycle: dict, total_feed: float):
|
194
198
|
inputs = cycle.get('inputs', [])
|
195
|
-
|
199
|
+
ionophore_terms = get_ionophore_terms()
|
200
|
+
has_input = any([find_term_match(inputs, term_id, None) is not None for term_id in ionophore_terms])
|
196
201
|
maize_input = find_term_match(inputs, 'maizeSteamFlaked')
|
197
202
|
maize_feed = get_total_value_converted_with_min_ratio(MODEL, None, blank_nodes=[maize_input]) if maize_input else 0
|
198
203
|
maize_feed_ratio = maize_feed / total_feed if all([maize_feed, total_feed]) else 0
|
@@ -11,6 +11,7 @@ from . import MODEL
|
|
11
11
|
REQUIREMENTS = {
|
12
12
|
"Cycle": {
|
13
13
|
"site": {
|
14
|
+
"@type": "Site",
|
14
15
|
"measurements": [
|
15
16
|
{
|
16
17
|
"@type": "Measurement",
|
@@ -38,7 +39,7 @@ RETURNS = {
|
|
38
39
|
"statsDefinition": "simulated",
|
39
40
|
"observations": "",
|
40
41
|
"methodTier": "",
|
41
|
-
"depth":
|
42
|
+
"depth": 30
|
42
43
|
}]
|
43
44
|
}
|
44
45
|
TERM_ID = 'co2ToAirBelowGroundBiomassStockChangeLandUseChange,co2ToAirBelowGroundBiomassStockChangeManagementChange'
|
@@ -11,6 +11,7 @@ from . import MODEL
|
|
11
11
|
REQUIREMENTS = {
|
12
12
|
"Cycle": {
|
13
13
|
"site": {
|
14
|
+
"@type": "Site",
|
14
15
|
"measurements": [
|
15
16
|
{
|
16
17
|
"@type": "Measurement",
|
@@ -38,7 +39,7 @@ RETURNS = {
|
|
38
39
|
"statsDefinition": "simulated",
|
39
40
|
"observations": "",
|
40
41
|
"methodTier": "",
|
41
|
-
"depth":
|
42
|
+
"depth": 30
|
42
43
|
}]
|
43
44
|
}
|
44
45
|
TERM_ID = 'co2ToAirSoilOrganicCarbonStockChangeLandUseChange,co2ToAirSoilOrganicCarbonStockChangeManagementChange'
|