hestia-earth-models 0.73.0__py3-none-any.whl → 0.73.2__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/akagiEtAl2011/utils.py +4 -2
- hestia_earth/models/aware/scarcityWeightedWaterUse.py +8 -7
- hestia_earth/models/cache_sites.py +8 -4
- hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsLandTransformation.py +14 -11
- hestia_earth/models/chaudharyBrooks2018/utils.py +4 -2
- hestia_earth/models/config/Cycle.json +35 -37
- hestia_earth/models/config/Site.json +26 -24
- hestia_earth/models/cycle/completeness/electricityFuel.py +1 -1
- hestia_earth/models/cycle/completeness/freshForage.py +1 -1
- hestia_earth/models/cycle/input/hestiaAggregatedData.py +1 -2
- hestia_earth/models/cycle/product/economicValueShare.py +1 -1
- hestia_earth/models/environmentalFootprintV3_1/environmentalFootprintSingleOverallScore.py +1 -1
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandOccupation.py +11 -11
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandTransformation.py +14 -11
- hestia_earth/models/faostat2018/utils.py +26 -13
- hestia_earth/models/geospatialDatabase/utils.py +13 -10
- hestia_earth/models/hestia/aboveGroundCropResidue.py +6 -5
- hestia_earth/models/hestia/cropResidueManagement.py +3 -2
- hestia_earth/models/hestia/default_emissions.py +1 -1
- hestia_earth/models/hestia/default_resourceUse.py +1 -1
- hestia_earth/models/hestia/excretaKgMass.py +7 -9
- hestia_earth/models/hestia/seed_emissions.py +1 -1
- hestia_earth/models/hestia/stockingDensityAnimalHousingAverage.py +1 -1
- hestia_earth/models/hestia/waterSalinity.py +1 -1
- hestia_earth/models/ipcc2019/aboveGroundBiomass.py +2 -4
- hestia_earth/models/ipcc2019/belowGroundBiomass.py +2 -4
- hestia_earth/models/ipcc2019/biomass_utils.py +1 -1
- hestia_earth/models/ipcc2019/ch4ToAirAquacultureSystems.py +1 -1
- hestia_earth/models/ipcc2019/ch4ToAirOrganicSoilCultivation.py +3 -4
- hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +2 -4
- hestia_earth/models/ipcc2019/co2ToAirOrganicSoilCultivation.py +2 -3
- hestia_earth/models/ipcc2019/n2OToAirCropResidueBurningDirect.py +1 -1
- hestia_earth/models/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning.py +2 -3
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1.py +2 -3
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2.py +3 -4
- hestia_earth/models/ipcc2019/organicCarbonPerHa_utils.py +2 -3
- hestia_earth/models/mocking/search-results.json +1582 -1582
- hestia_earth/models/pooreNemecek2018/freshwaterWithdrawalsDuringCycle.py +43 -5
- hestia_earth/models/site/grouped_measurement.py +1 -1
- hestia_earth/models/utils/background_emissions.py +1 -1
- hestia_earth/models/utils/impact_assessment.py +29 -14
- hestia_earth/models/utils/lookup.py +5 -1
- hestia_earth/models/utils/measurement.py +0 -1
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.2.dist-info}/METADATA +3 -2
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.2.dist-info}/RECORD +54 -59
- tests/models/geospatialDatabase/test_utils.py +12 -1
- tests/models/ipcc2019/test_organicCarbonPerHa_tier_2.py +1 -1
- tests/models/pooreNemecek2018/test_freshwaterWithdrawalsDuringCycle.py +12 -0
- tests/models/utils/test_array_builders.py +1 -1
- tests/models/utils/test_impact_assessment.py +29 -13
- hestia_earth/models/utils/array_builders.py +0 -590
- hestia_earth/models/utils/descriptive_stats.py +0 -49
- hestia_earth/models/utils/stats.py +0 -429
- tests/models/utils/test_descriptive_stats.py +0 -50
- tests/models/utils/test_stats.py +0 -186
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.2.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.2.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.2.dist-info}/top_level.txt +0 -0
@@ -1,8 +1,9 @@
|
|
1
1
|
from hestia_earth.schema import EmissionMethodTier, EmissionStatsDefinition, TermTermType
|
2
2
|
|
3
3
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
4
|
+
from hestia_earth.models.utils import multiply_values
|
4
5
|
from hestia_earth.models.utils.emission import _new_emission
|
5
|
-
from hestia_earth.models.utils.
|
6
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
6
7
|
from hestia_earth.models.utils.cropResidue import get_crop_residue_burnt_value
|
7
8
|
from . import MODEL
|
8
9
|
|
@@ -25,7 +26,8 @@ def _run(term_id: str, product_value: list):
|
|
25
26
|
term = {'termType': TermTermType.EMISSION.value, '@id': term_id}
|
26
27
|
factor = get_lookup_value(term, LOOKUP_NAME)
|
27
28
|
factor_sd = get_lookup_value(term, LOOKUP_NAME + '-sd')
|
28
|
-
|
29
|
+
emission_value = multiply_values([value, factor])
|
30
|
+
return [] if emission_value is None else [_emission(term_id, emission_value, multiply_values([value, factor_sd]))]
|
29
31
|
|
30
32
|
|
31
33
|
def _should_run(term_id: str, cycle: dict):
|
@@ -1,4 +1,5 @@
|
|
1
1
|
from hestia_earth.schema import SiteSiteType
|
2
|
+
from hestia_earth.utils.model import find_term_match
|
2
3
|
from hestia_earth.utils.lookup import download_lookup, _get_single_table_value, column_name
|
3
4
|
from hestia_earth.utils.tools import safe_parse_float
|
4
5
|
|
@@ -6,7 +7,7 @@ from hestia_earth.models.log import logRequirements, debugMissingLookup, logShou
|
|
6
7
|
from hestia_earth.models.utils import sum_values, multiply_values
|
7
8
|
from hestia_earth.models.utils.indicator import _new_indicator
|
8
9
|
from hestia_earth.models.utils.impact_assessment import (
|
9
|
-
convert_value_from_cycle,
|
10
|
+
convert_value_from_cycle, get_product, get_site, get_region_id
|
10
11
|
)
|
11
12
|
from hestia_earth.models.utils.input import sum_input_impacts
|
12
13
|
from hestia_earth.models.utils.lookup import get_region_lookup_value
|
@@ -64,8 +65,8 @@ def _get_factor_from_basinId(site: dict, aware_id: str):
|
|
64
65
|
return safe_parse_float(value, default=None)
|
65
66
|
|
66
67
|
|
67
|
-
def _get_factor_from_region(impact_assessment: dict, site: dict):
|
68
|
-
region_id = get_region_id(impact_assessment)
|
68
|
+
def _get_factor_from_region(impact_assessment: dict, fresh_water: dict, site: dict):
|
69
|
+
region_id = get_region_id(impact_assessment, fresh_water)
|
69
70
|
site_type = site.get('siteType')
|
70
71
|
lookup_name = 'region-aware-factors.csv'
|
71
72
|
lookup_suffix = 'unspecified' if not site_type else ('irri' if site_type in IRRIGATED_SITE_TYPES else 'non_irri')
|
@@ -77,23 +78,23 @@ def _get_factor_from_region(impact_assessment: dict, site: dict):
|
|
77
78
|
def run(impact_assessment: dict):
|
78
79
|
cycle = impact_assessment.get('cycle', {})
|
79
80
|
product = get_product(impact_assessment)
|
80
|
-
fresh_water =
|
81
|
+
fresh_water = find_term_match(impact_assessment.get('emissionsResourceUse', []), 'freshwaterWithdrawalsDuringCycle')
|
81
82
|
site = get_site(impact_assessment)
|
82
83
|
aware_id = site.get(AWARE_KEY)
|
83
84
|
factor = (
|
84
85
|
_get_factor_from_basinId(site, aware_id) if aware_id else None
|
85
|
-
) or _get_factor_from_region(impact_assessment, site)
|
86
|
+
) or _get_factor_from_region(impact_assessment, fresh_water, site)
|
86
87
|
inputs_value = convert_value_from_cycle(
|
87
88
|
impact_assessment, product, sum_input_impacts(cycle.get('inputs', []), TERM_ID), model=MODEL, term_id=TERM_ID
|
88
89
|
)
|
89
90
|
|
90
91
|
value = sum_values([
|
91
|
-
multiply_values([fresh_water, factor]),
|
92
|
+
multiply_values([fresh_water.get('value'), factor]),
|
92
93
|
inputs_value
|
93
94
|
])
|
94
95
|
|
95
96
|
logRequirements(impact_assessment, model=MODEL, term=TERM_ID,
|
96
|
-
fresh_water=fresh_water,
|
97
|
+
fresh_water=fresh_water.get('value'),
|
97
98
|
aware_id=aware_id,
|
98
99
|
factor=factor,
|
99
100
|
inputs_value=inputs_value)
|
@@ -132,10 +132,14 @@ def _run(sites: list, years: list = [], years_only: bool = False):
|
|
132
132
|
rasters = list_rasters(years=years, years_only=years_only)
|
133
133
|
vectors = [] if years_only else list_vectors(sites)
|
134
134
|
filtered_data, sites_no_run = _group_sites(sites, not years_only)
|
135
|
-
return flatten(
|
136
|
-
|
137
|
-
|
138
|
-
|
135
|
+
return flatten(
|
136
|
+
[
|
137
|
+
_run_values(filtered_data.get(param_type), param_type, rasters, vectors, years)
|
138
|
+
for param_type in [e for e in ParamType] if len(filtered_data.get(param_type)) > 0
|
139
|
+
] + (
|
140
|
+
_run_values(sites_no_run, years=years) if sites_no_run else []
|
141
|
+
)
|
142
|
+
)
|
139
143
|
|
140
144
|
|
141
145
|
def _run_by_years(sites: list, years: list, batch_size: int):
|
@@ -1,8 +1,10 @@
|
|
1
|
+
from hestia_earth.utils.model import find_term_match
|
2
|
+
|
1
3
|
from hestia_earth.models.log import debugValues, logRequirements, logShouldRun
|
2
4
|
from hestia_earth.models.utils import sum_values, multiply_values
|
3
5
|
from hestia_earth.models.utils.indicator import _new_indicator
|
4
6
|
from hestia_earth.models.utils.impact_assessment import (
|
5
|
-
convert_value_from_cycle,
|
7
|
+
convert_value_from_cycle, get_product, get_site
|
6
8
|
)
|
7
9
|
from hestia_earth.models.utils.input import sum_input_impacts
|
8
10
|
from .utils import get_region_factor
|
@@ -56,26 +58,27 @@ def _indicator(value: float):
|
|
56
58
|
return indicator
|
57
59
|
|
58
60
|
|
59
|
-
def _value(impact_assessment: dict, term_id: str):
|
60
|
-
value = emission_value(impact_assessment, term_id)
|
61
|
-
debugValues(impact_assessment, model=MODEL, term=TERM_ID, node=term_id, value=value, coefficient=1)
|
62
|
-
return value
|
63
|
-
|
64
|
-
|
65
61
|
def _run(impact_assessment: dict):
|
66
62
|
cycle = impact_assessment.get('cycle', {})
|
67
63
|
product = get_product(impact_assessment)
|
68
|
-
landTransformation =
|
69
|
-
|
64
|
+
landTransformation = find_term_match(impact_assessment.get('emissionsResourceUse', []), _TRANSFORMATION_TERM_ID)
|
65
|
+
debugValues(impact_assessment, model=MODEL, term=TERM_ID,
|
66
|
+
node=_TRANSFORMATION_TERM_ID,
|
67
|
+
value=landTransformation.get('value'),
|
68
|
+
coefficient=1)
|
69
|
+
|
70
|
+
region_factor = get_region_factor(
|
71
|
+
TERM_ID, impact_assessment, _LOOKUP_SUFFIX, 'medium_intensity', blank_node=landTransformation
|
72
|
+
)
|
70
73
|
inputs_value = convert_value_from_cycle(
|
71
74
|
impact_assessment, product, sum_input_impacts(cycle.get('inputs', []), TERM_ID), model=MODEL, term_id=TERM_ID
|
72
75
|
)
|
73
76
|
logRequirements(impact_assessment, model=MODEL, term=TERM_ID,
|
74
|
-
landTransformation=landTransformation,
|
77
|
+
landTransformation=landTransformation.get('value'),
|
75
78
|
region_factor=region_factor,
|
76
79
|
inputs_value=inputs_value)
|
77
80
|
value = sum_values([
|
78
|
-
multiply_values([landTransformation, region_factor]),
|
81
|
+
multiply_values([landTransformation.get('value'), region_factor]),
|
79
82
|
inputs_value
|
80
83
|
])
|
81
84
|
return _indicator(value) if value is not None else None
|
@@ -13,10 +13,12 @@ def _lookup_value(term_id: str, lookup_name: str, col_match: str, col_val: str,
|
|
13
13
|
return value
|
14
14
|
|
15
15
|
|
16
|
-
def get_region_factor(
|
16
|
+
def get_region_factor(
|
17
|
+
term_id: str, impact_assessment: dict, lookup_suffix: str, group_key: str = None, blank_node: dict = None
|
18
|
+
):
|
17
19
|
site = get_site(impact_assessment)
|
18
20
|
ecoregion = site.get('ecoregion')
|
19
|
-
country_id = get_country_id(impact_assessment)
|
21
|
+
country_id = get_country_id(impact_assessment, blank_node=blank_node)
|
20
22
|
site_type = site.get('siteType')
|
21
23
|
|
22
24
|
lookup_prefix = 'ecoregion' if ecoregion else 'region' if country_id else None
|
@@ -27,17 +27,9 @@
|
|
27
27
|
"stage": 1
|
28
28
|
},
|
29
29
|
{
|
30
|
-
"key": "
|
31
|
-
"model": "
|
32
|
-
"value": "
|
33
|
-
"runStrategy": "add_blank_node_if_missing",
|
34
|
-
"mergeStrategy": "list",
|
35
|
-
"stage": 1
|
36
|
-
},
|
37
|
-
{
|
38
|
-
"key": "practices",
|
39
|
-
"model": "geospatialDatabase",
|
40
|
-
"value": "croppingIntensity",
|
30
|
+
"key": "inputs",
|
31
|
+
"model": "faostat2018",
|
32
|
+
"value": "seed",
|
41
33
|
"runStrategy": "add_blank_node_if_missing",
|
42
34
|
"mergeStrategy": "list",
|
43
35
|
"stage": 1
|
@@ -100,6 +92,22 @@
|
|
100
92
|
"stage": 1
|
101
93
|
}
|
102
94
|
],
|
95
|
+
{
|
96
|
+
"key": "practices",
|
97
|
+
"model": "hestia",
|
98
|
+
"value": "croppingIntensity",
|
99
|
+
"runStrategy": "add_blank_node_if_missing",
|
100
|
+
"mergeStrategy": "list",
|
101
|
+
"stage": 1
|
102
|
+
},
|
103
|
+
{
|
104
|
+
"key": "practices",
|
105
|
+
"model": "geospatialDatabase",
|
106
|
+
"value": "croppingIntensity",
|
107
|
+
"runStrategy": "add_blank_node_if_missing",
|
108
|
+
"mergeStrategy": "list",
|
109
|
+
"stage": 1
|
110
|
+
},
|
103
111
|
[
|
104
112
|
{
|
105
113
|
"key": "practices",
|
@@ -321,14 +329,6 @@
|
|
321
329
|
"stage": 1
|
322
330
|
},
|
323
331
|
[
|
324
|
-
{
|
325
|
-
"key": "practices",
|
326
|
-
"model": "hestia",
|
327
|
-
"value": "longFallowRatio",
|
328
|
-
"runStrategy": "add_blank_node_if_missing",
|
329
|
-
"mergeStrategy": "list",
|
330
|
-
"stage": 1
|
331
|
-
},
|
332
332
|
{
|
333
333
|
"key": "practices",
|
334
334
|
"model": "hestia",
|
@@ -467,24 +467,22 @@
|
|
467
467
|
"stage": 1
|
468
468
|
}
|
469
469
|
],
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
}
|
487
|
-
],
|
470
|
+
{
|
471
|
+
"key": "practices",
|
472
|
+
"model": "hestia",
|
473
|
+
"value": "longFallowRatio",
|
474
|
+
"runStrategy": "add_blank_node_if_missing",
|
475
|
+
"mergeStrategy": "list",
|
476
|
+
"stage": 1
|
477
|
+
},
|
478
|
+
{
|
479
|
+
"key": "inputs",
|
480
|
+
"model": "pooreNemecek2018",
|
481
|
+
"value": "saplingsDepreciatedAmountPerCycle",
|
482
|
+
"runStrategy": "add_blank_node_if_missing",
|
483
|
+
"mergeStrategy": "list",
|
484
|
+
"stage": 1
|
485
|
+
},
|
488
486
|
{
|
489
487
|
"key": "completeness",
|
490
488
|
"model": "cycle",
|
@@ -65,30 +65,6 @@
|
|
65
65
|
"mergeStrategy": "list",
|
66
66
|
"stage": 1
|
67
67
|
},
|
68
|
-
{
|
69
|
-
"key": "measurements",
|
70
|
-
"model": "hestia",
|
71
|
-
"value": "brackishWater",
|
72
|
-
"runStrategy": "add_blank_node_if_missing",
|
73
|
-
"mergeStrategy": "list",
|
74
|
-
"stage": 1
|
75
|
-
},
|
76
|
-
{
|
77
|
-
"key": "measurements",
|
78
|
-
"model": "hestia",
|
79
|
-
"value": "freshWater",
|
80
|
-
"runStrategy": "add_blank_node_if_missing",
|
81
|
-
"mergeStrategy": "list",
|
82
|
-
"stage": 1
|
83
|
-
},
|
84
|
-
{
|
85
|
-
"key": "measurements",
|
86
|
-
"model": "hestia",
|
87
|
-
"value": "salineWater",
|
88
|
-
"runStrategy": "add_blank_node_if_missing",
|
89
|
-
"mergeStrategy": "list",
|
90
|
-
"stage": 1
|
91
|
-
},
|
92
68
|
{
|
93
69
|
"key": "measurements",
|
94
70
|
"model": "hestia",
|
@@ -470,6 +446,32 @@
|
|
470
446
|
"stage": 2
|
471
447
|
}
|
472
448
|
],
|
449
|
+
[
|
450
|
+
{
|
451
|
+
"key": "measurements",
|
452
|
+
"model": "hestia",
|
453
|
+
"value": "brackishWater",
|
454
|
+
"runStrategy": "add_blank_node_if_missing",
|
455
|
+
"mergeStrategy": "list",
|
456
|
+
"stage": 1
|
457
|
+
},
|
458
|
+
{
|
459
|
+
"key": "measurements",
|
460
|
+
"model": "hestia",
|
461
|
+
"value": "freshWater",
|
462
|
+
"runStrategy": "add_blank_node_if_missing",
|
463
|
+
"mergeStrategy": "list",
|
464
|
+
"stage": 1
|
465
|
+
},
|
466
|
+
{
|
467
|
+
"key": "measurements",
|
468
|
+
"model": "hestia",
|
469
|
+
"value": "salineWater",
|
470
|
+
"runStrategy": "add_blank_node_if_missing",
|
471
|
+
"mergeStrategy": "list",
|
472
|
+
"stage": 1
|
473
|
+
}
|
474
|
+
],
|
473
475
|
[
|
474
476
|
{
|
475
477
|
"key": "defaultMethodClassification",
|
@@ -2,7 +2,7 @@ from hestia_earth.schema import TermTermType
|
|
2
2
|
from hestia_earth.utils.model import filter_list_term_type
|
3
3
|
|
4
4
|
from hestia_earth.models.log import logRequirements, log_as_table
|
5
|
-
from hestia_earth.models.utils.
|
5
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
6
6
|
from hestia_earth.models.utils.completeness import _is_term_type_complete
|
7
7
|
from . import MODEL
|
8
8
|
|
@@ -4,7 +4,7 @@ from hestia_earth.utils.tools import list_sum
|
|
4
4
|
|
5
5
|
from hestia_earth.models.log import logRequirements
|
6
6
|
from hestia_earth.models.utils import is_from_model
|
7
|
-
from hestia_earth.models.utils.
|
7
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
8
8
|
from . import MODEL
|
9
9
|
|
10
10
|
REQUIREMENTS = {
|
@@ -4,8 +4,7 @@ from hestia_earth.utils.tools import non_empty_list
|
|
4
4
|
|
5
5
|
from hestia_earth.models.log import debugValues, logRequirements, logShouldRun
|
6
6
|
from hestia_earth.models.utils.crop import valid_site_type
|
7
|
-
from hestia_earth.models.utils.
|
8
|
-
from hestia_earth.models.utils.term import get_generic_crop, download_term
|
7
|
+
from hestia_earth.models.utils.term import get_lookup_value, get_generic_crop, download_term
|
9
8
|
from hestia_earth.models.utils.aggregated import (
|
10
9
|
should_link_input_to_impact, link_inputs_to_impact, find_closest_impact, aggregated_end_date
|
11
10
|
)
|
@@ -2,7 +2,7 @@ from hestia_earth.utils.model import find_term_match
|
|
2
2
|
from hestia_earth.utils.tools import list_sum
|
3
3
|
|
4
4
|
from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
|
5
|
-
from hestia_earth.models.utils.
|
5
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
6
6
|
from hestia_earth.models.utils.cycle import unique_currencies
|
7
7
|
from .utils import lookup_share
|
8
8
|
from .. import MODEL
|
@@ -4,7 +4,7 @@ from hestia_earth.utils.tools import list_sum
|
|
4
4
|
from typing import List, Optional, Tuple
|
5
5
|
|
6
6
|
from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table, debugValues
|
7
|
-
from hestia_earth.models.utils.
|
7
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
8
8
|
from hestia_earth.models.utils.indicator import _new_indicator
|
9
9
|
from hestia_earth.models.utils.lookup import _node_value
|
10
10
|
from . import MODEL
|
@@ -60,17 +60,17 @@ def _should_run(impact_assessment: dict) -> Tuple[bool, list]:
|
|
60
60
|
]
|
61
61
|
|
62
62
|
found_land_occupation_indicators = [{
|
63
|
-
'area-by-year': _node_value(
|
64
|
-
'area-unit':
|
65
|
-
'land-cover-id':
|
66
|
-
'country-id': get_country_id(impact_assessment),
|
67
|
-
'area-by-year-is-valid': _node_value(
|
68
|
-
|
69
|
-
'area-unit-is-valid':
|
70
|
-
'used-country': fallback_country(get_country_id(impact_assessment), [LOOKUP]),
|
71
|
-
'pef-grouping': get_pef_grouping(
|
72
|
-
|
73
|
-
} for
|
63
|
+
'area-by-year': _node_value(indicator),
|
64
|
+
'area-unit': indicator.get('term', {}).get("units"),
|
65
|
+
'land-cover-id': indicator.get('landCover', {}).get("@id"),
|
66
|
+
'country-id': get_country_id(impact_assessment, blank_node=indicator),
|
67
|
+
'area-by-year-is-valid': _node_value(indicator) is not None and _node_value(
|
68
|
+
indicator) > 0,
|
69
|
+
'area-unit-is-valid': indicator.get('term', {}).get("units") == "m2*year",
|
70
|
+
'used-country': fallback_country(get_country_id(impact_assessment, blank_node=indicator), [LOOKUP]),
|
71
|
+
'pef-grouping': get_pef_grouping(indicator.get('landCover', {}).get("@id"))
|
72
|
+
|
73
|
+
} for indicator in land_occupation_indicators]
|
74
74
|
|
75
75
|
found_indicators_with_coefficient = [
|
76
76
|
indicator | {
|
@@ -92,21 +92,24 @@ def _should_run(impact_assessment: dict) -> Tuple[bool, list]:
|
|
92
92
|
|
93
93
|
found_transformations = [
|
94
94
|
{
|
95
|
-
'value': _node_value(
|
96
|
-
'land-cover-id-from':
|
97
|
-
'land-cover-id-to':
|
98
|
-
'indicator-id':
|
95
|
+
'value': _node_value(indicator),
|
96
|
+
'land-cover-id-from': indicator.get('previousLandCover', {}).get("@id"),
|
97
|
+
'land-cover-id-to': indicator.get('landCover', {}).get("@id"),
|
98
|
+
'indicator-id': indicator.get('term', {}).get('@id', ''),
|
99
99
|
'good-land-cover-term': all([
|
100
|
-
bool(
|
101
|
-
bool(
|
100
|
+
bool(indicator.get('landCover')),
|
101
|
+
bool(indicator.get('previousLandCover'))
|
102
102
|
]),
|
103
|
-
'country-id': get_country_id(impact_assessment),
|
103
|
+
'country-id': get_country_id(impact_assessment, blank_node=indicator),
|
104
104
|
'value-is-valid': (
|
105
|
-
_node_value(
|
106
|
-
_node_value(
|
105
|
+
_node_value(indicator) is not None and
|
106
|
+
_node_value(indicator) >= 0
|
107
107
|
),
|
108
|
-
'lookup-country': fallback_country(
|
109
|
-
|
108
|
+
'lookup-country': fallback_country(
|
109
|
+
get_country_id(impact_assessment, blank_node=indicator),
|
110
|
+
[from_lookup_file, to_lookup_file]
|
111
|
+
),
|
112
|
+
} for indicator in resource_uses
|
110
113
|
]
|
111
114
|
|
112
115
|
found_transformations_with_coefficient = [
|
@@ -1,9 +1,9 @@
|
|
1
1
|
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
|
-
from hestia_earth.utils.tools import safe_parse_float, flatten
|
4
|
+
from hestia_earth.utils.tools import safe_parse_float, flatten, non_empty_list
|
5
5
|
|
6
|
-
from hestia_earth.models.log import logger, debugMissingLookup, logRequirements, logShouldRun, debugValues
|
6
|
+
from hestia_earth.models.log import logger, debugMissingLookup, logRequirements, logShouldRun, debugValues, log_as_table
|
7
7
|
from hestia_earth.models.utils.animalProduct import (
|
8
8
|
FAO_LOOKUP_COLUMN, FAO_EQUIVALENT_LOOKUP_COLUMN, get_animalProduct_lookup_value
|
9
9
|
)
|
@@ -152,24 +152,37 @@ def should_run_landTransformationFromCropland(term_id: str, impact: dict):
|
|
152
152
|
return should_run, indicators
|
153
153
|
|
154
154
|
|
155
|
+
def _map_indicator_value(impact: dict, start_year: int, end_year: int):
|
156
|
+
def mapper(indicator: dict):
|
157
|
+
country_id = get_country_id(impact, blank_node=indicator)
|
158
|
+
total, permanent, temporary = get_cropland_ratio(country_id, start_year, end_year)
|
159
|
+
return {
|
160
|
+
'landCover-id': indicator.get('landCover', {}).get('@id'),
|
161
|
+
'value': indicator.get('value'),
|
162
|
+
'country-id': country_id,
|
163
|
+
'diff-total-area': total,
|
164
|
+
'diff-temporary-area': temporary,
|
165
|
+
'diff-permanent-area': permanent
|
166
|
+
} if total is not None else None
|
167
|
+
return mapper
|
168
|
+
|
169
|
+
|
155
170
|
def run_landTransformationFromCropland(term_id: str, impact: dict, indicators: list, years: int):
|
156
|
-
country_id = get_country_id(impact)
|
157
171
|
end_year = impact_end_year(impact)
|
158
|
-
|
172
|
+
|
173
|
+
values = non_empty_list(map(_map_indicator_value(impact, end_year - years, end_year), indicators))
|
159
174
|
|
160
175
|
debugValues(impact, model=MODEL, term_id=term_id,
|
161
|
-
|
162
|
-
diff_permanent_area=permanent,
|
163
|
-
diff_total_area=total)
|
176
|
+
indicators_used=log_as_table(values))
|
164
177
|
|
165
178
|
return flatten([
|
166
179
|
[
|
167
|
-
_new_indicator(term_id, MODEL,
|
168
|
-
'value':
|
180
|
+
_new_indicator(term_id, MODEL, value.get('landCover-id'), 'annualCropland') | {
|
181
|
+
'value': value.get('value') * value.get('diff-temporary-area') / value.get('diff-total-area')
|
169
182
|
},
|
170
|
-
_new_indicator(term_id, MODEL,
|
171
|
-
'value':
|
183
|
+
_new_indicator(term_id, MODEL, value.get('landCover-id'), 'permanentCropland') | {
|
184
|
+
'value': value.get('value') * value.get('diff-permanent-area') / value.get('diff-total-area')
|
172
185
|
}
|
173
186
|
]
|
174
|
-
for
|
175
|
-
])
|
187
|
+
for value in values
|
188
|
+
])
|
@@ -1,4 +1,6 @@
|
|
1
1
|
import os
|
2
|
+
from area import area
|
3
|
+
from functools import reduce
|
2
4
|
from hestia_earth.schema import TermTermType
|
3
5
|
from hestia_earth.utils.tools import non_empty_list
|
4
6
|
|
@@ -85,12 +87,11 @@ def geospatial_data(site: dict, only_coordinates=False):
|
|
85
87
|
|
86
88
|
def _get_boundary_area_size(boundary: dict):
|
87
89
|
try:
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
return get_size_km2(boundary)
|
90
|
+
return (
|
91
|
+
(area(boundary.get('geometry')) / 1_000_000) if 'geometry' in boundary else
|
92
|
+
reduce(lambda p, c: p + _get_boundary_area_size(c), boundary.get('features'), 0) if 'features' in boundary
|
93
|
+
else area(boundary) / 1_000_000
|
94
|
+
)
|
94
95
|
except Exception:
|
95
96
|
return None
|
96
97
|
|
@@ -101,10 +102,12 @@ def _get_region_area_size(site: dict):
|
|
101
102
|
|
102
103
|
|
103
104
|
def get_area_size(site: dict):
|
104
|
-
return
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
return _cached_value(site, CACHE_AREA_SIZE) or (
|
106
|
+
None if has_coordinates(site) else (
|
107
|
+
# fallback if `boundary` provided but no `boundaryArea` was computed
|
108
|
+
site.get('boundaryArea') or _get_boundary_area_size(site.get('boundary'))
|
109
|
+
) if has_boundary(site) else _get_region_area_size(site)
|
110
|
+
)
|
108
111
|
|
109
112
|
|
110
113
|
def _is_below_max_size(term: str, site: dict) -> bool:
|
@@ -28,6 +28,7 @@ RETURNS = {
|
|
28
28
|
"value": ""
|
29
29
|
}]
|
30
30
|
}
|
31
|
+
MODEL_KEY = 'aboveGroundCropResidue'
|
31
32
|
TERM_ID = 'aboveGroundCropResidueLeftOnField,aboveGroundCropResidueBurnt,aboveGroundCropResidueIncorporated,aboveGroundCropResidueRemoved' # noqa: E501
|
32
33
|
TOTAL_TERM_ID = 'aboveGroundCropResidueTotal'
|
33
34
|
REMAINING_MODEL = PRODUCT_ID_TO_PRACTICES_ID[-1]['product']
|
@@ -59,7 +60,7 @@ def _should_run_model(model, cycle: dict, total_value: float):
|
|
59
60
|
practice_value = _get_practice_value(model.get('practices'), cycle)
|
60
61
|
has_product = find_term_match(cycle.get('products', []), term_id, None) is not None
|
61
62
|
|
62
|
-
logRequirements(cycle, model=MODEL, term=term_id,
|
63
|
+
logRequirements(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
63
64
|
practice_value=practice_value,
|
64
65
|
has_product=has_product)
|
65
66
|
|
@@ -70,7 +71,7 @@ def _should_run_model(model, cycle: dict, total_value: float):
|
|
70
71
|
]),
|
71
72
|
not has_product
|
72
73
|
])
|
73
|
-
logShouldRun(cycle, MODEL, term_id, should_run)
|
74
|
+
logShouldRun(cycle, MODEL, term_id, should_run, model_key=MODEL_KEY)
|
74
75
|
return should_run, practice_value
|
75
76
|
|
76
77
|
|
@@ -104,7 +105,7 @@ def _run(cycle: dict, total_values: list):
|
|
104
105
|
for model in models:
|
105
106
|
term_id = model.get('product')
|
106
107
|
value = _run_model(model, cycle, total_value)
|
107
|
-
debugValues(cycle, model=MODEL, term=term_id,
|
108
|
+
debugValues(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
108
109
|
total_above_ground_crop_residue=total_value,
|
109
110
|
remaining_crop_residue_value=remaining_value,
|
110
111
|
allocated_value=value)
|
@@ -132,13 +133,13 @@ def _should_run_product(cycle: dict, total_values: list, term_id: str):
|
|
132
133
|
find_term_match(cycle.get('practices', []), term_id).get('value', []) == [0] for term_id in practice_term_ids
|
133
134
|
])
|
134
135
|
|
135
|
-
logRequirements(cycle, model=MODEL, term=term_id,
|
136
|
+
logRequirements(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
136
137
|
term_type_cropResidue_incomplete=term_type_incomplete,
|
137
138
|
has_aboveGroundCropResidueTotal=has_aboveGroundCropResidueTotal,
|
138
139
|
practice_term_ids=';'.join(practice_term_ids),
|
139
140
|
practice_value_is_0=is_value_0)
|
140
141
|
should_run = all([has_aboveGroundCropResidueTotal or is_value_0, term_type_incomplete])
|
141
|
-
logShouldRun(cycle, MODEL, term_id, should_run)
|
142
|
+
logShouldRun(cycle, MODEL, term_id, should_run, model_key=MODEL_KEY)
|
142
143
|
return should_run
|
143
144
|
|
144
145
|
|
@@ -20,6 +20,7 @@ RETURNS = {
|
|
20
20
|
"term.termType": "cropResidueManagement"
|
21
21
|
}]
|
22
22
|
}
|
23
|
+
MODEL_KEY = 'cropResidueManagement'
|
23
24
|
PRACTICE_IDS = [
|
24
25
|
residueBurnt.TERM_ID,
|
25
26
|
residueIncorporated.TERM_ID,
|
@@ -50,10 +51,10 @@ def _should_run(cycle: dict):
|
|
50
51
|
should_run = all([99.5 <= sum_practices <= 100.5])
|
51
52
|
|
52
53
|
for term_id in missing_practices:
|
53
|
-
logRequirements(cycle, model=MODEL, term=term_id,
|
54
|
+
logRequirements(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
|
54
55
|
sum_crop_residue_management=sum_practices)
|
55
56
|
|
56
|
-
logShouldRun(cycle, MODEL, term_id, should_run)
|
57
|
+
logShouldRun(cycle, MODEL, term_id, should_run, model_key=MODEL_KEY)
|
57
58
|
|
58
59
|
return should_run, missing_practices
|
59
60
|
|
@@ -6,7 +6,7 @@ from hestia_earth.models.log import logRequirements, logShouldRun
|
|
6
6
|
from hestia_earth.models.utils import _omit
|
7
7
|
from hestia_earth.models.utils.emission import _new_emission
|
8
8
|
from hestia_earth.models.utils.background_emissions import no_gap_filled_background_emissions
|
9
|
-
from hestia_earth.models.utils.
|
9
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
10
10
|
from hestia_earth.models.utils.input import unique_background_inputs
|
11
11
|
from . import MODEL
|
12
12
|
|
@@ -6,7 +6,7 @@ from hestia_earth.models.log import logRequirements, logShouldRun
|
|
6
6
|
from hestia_earth.models.utils import _omit
|
7
7
|
from hestia_earth.models.utils.indicator import _new_indicator
|
8
8
|
from hestia_earth.models.utils.background_emissions import no_gap_filled_background_emissions
|
9
|
-
from hestia_earth.models.utils.
|
9
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
10
10
|
from hestia_earth.models.utils.input import unique_background_inputs
|
11
11
|
from . import MODEL
|
12
12
|
|