hestia-earth-models 0.73.0__py3-none-any.whl → 0.73.1__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 +1 -1
- 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/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 +6 -4
- 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/ch4ToAirAquacultureSystems.py +1 -1
- hestia_earth/models/ipcc2019/n2OToAirCropResidueBurningDirect.py +1 -1
- hestia_earth/models/mocking/search-results.json +1290 -1290
- 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.1.dist-info}/METADATA +1 -1
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.1.dist-info}/RECORD +37 -37
- tests/models/pooreNemecek2018/test_freshwaterWithdrawalsDuringCycle.py +12 -0
- tests/models/utils/test_impact_assessment.py +29 -13
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.1.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.1.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.1.dist-info}/top_level.txt +0 -0
@@ -2,7 +2,7 @@ from hestia_earth.schema import EmissionMethodTier, EmissionStatsDefinition, Ter
|
|
2
2
|
|
3
3
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
4
4
|
from hestia_earth.models.utils.emission import _new_emission
|
5
|
-
from hestia_earth.models.utils.
|
5
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
6
6
|
from hestia_earth.models.utils.cropResidue import get_crop_residue_burnt_value
|
7
7
|
from . import MODEL
|
8
8
|
|
@@ -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
|
@@ -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
|
+
])
|
@@ -101,10 +101,12 @@ def _get_region_area_size(site: dict):
|
|
101
101
|
|
102
102
|
|
103
103
|
def get_area_size(site: dict):
|
104
|
-
return
|
105
|
-
|
106
|
-
|
107
|
-
|
104
|
+
return _cached_value(site, CACHE_AREA_SIZE) or (
|
105
|
+
None if has_coordinates(site) else (
|
106
|
+
# fallback if `boundary` provided but no `boundaryArea` was computed
|
107
|
+
site.get('boundaryArea') or _get_boundary_area_size(site.get('boundary'))
|
108
|
+
) if has_boundary(site) else _get_region_area_size(site)
|
109
|
+
)
|
108
110
|
|
109
111
|
|
110
112
|
def _is_below_max_size(term: str, site: dict) -> bool:
|
@@ -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
|
|
@@ -3,7 +3,7 @@ from hestia_earth.utils.model import filter_list_term_type, find_term_match
|
|
3
3
|
from hestia_earth.utils.tools import non_empty_list, list_sum
|
4
4
|
|
5
5
|
from hestia_earth.models.log import debugValues, logRequirements, logShouldRun
|
6
|
-
from hestia_earth.models.utils import get_kg_term_id, get_kg_N_term_id, get_kg_VS_term_id
|
6
|
+
from hestia_earth.models.utils import get_kg_term_id, get_kg_N_term_id, get_kg_VS_term_id, _filter_list_term_unit
|
7
7
|
from hestia_earth.models.utils.term import download_term
|
8
8
|
from hestia_earth.models.utils.constant import Units
|
9
9
|
from hestia_earth.models.utils.product import _new_product, convert_product_to_unit
|
@@ -31,12 +31,12 @@ RETURNS = {
|
|
31
31
|
MODEL_KEY = 'excretaKgMass'
|
32
32
|
|
33
33
|
UNITS = [
|
34
|
-
Units.KG_N
|
35
|
-
Units.KG_VS
|
34
|
+
Units.KG_N,
|
35
|
+
Units.KG_VS
|
36
36
|
]
|
37
37
|
|
38
38
|
|
39
|
-
def _product(
|
39
|
+
def _product(term_id: str, value: float = None):
|
40
40
|
product = _new_product(term_id, value, MODEL)
|
41
41
|
return product
|
42
42
|
|
@@ -80,17 +80,15 @@ def _run_product(cycle: dict, product_term_id: str):
|
|
80
80
|
# use existing product if exist, else create new one
|
81
81
|
existing_product = find_term_match(cycle.get('products', []), product_term_id)
|
82
82
|
|
83
|
-
return (existing_product | _product(
|
83
|
+
return (existing_product | _product(product_term_id, value)) if value else _product(product_term_id)
|
84
84
|
|
85
85
|
|
86
86
|
def _should_run(cycle: dict):
|
87
87
|
node_type = cycle.get('type', cycle.get('@type'))
|
88
88
|
excreta_products = filter_list_term_type(cycle.get('products', []), TermTermType.EXCRETA)
|
89
89
|
kg_term_ids = list(set([
|
90
|
-
get_kg_term_id(p.get('term', {}).get('@id'))
|
91
|
-
|
92
|
-
p.get('value', [])
|
93
|
-
])
|
90
|
+
get_kg_term_id(p.get('term', {}).get('@id'))
|
91
|
+
for p in _filter_list_term_unit(excreta_products, UNITS)
|
94
92
|
]))
|
95
93
|
gap_fill_term_ids = [
|
96
94
|
term_id for term_id in kg_term_ids if not find_term_match(excreta_products, term_id).get('value', [])
|
@@ -14,7 +14,7 @@ from hestia_earth.models.utils.site import valid_site_type
|
|
14
14
|
from hestia_earth.models.utils.cycle import cycle_end_year
|
15
15
|
from hestia_earth.models.utils.crop import get_crop_grouping_faostat_production, get_landCover_term_id
|
16
16
|
from hestia_earth.models.utils.completeness import _is_term_type_complete
|
17
|
-
from hestia_earth.models.utils.
|
17
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
18
18
|
from hestia_earth.models.utils.lookup import get_region_lookup_value
|
19
19
|
from . import MODEL
|
20
20
|
|
@@ -3,7 +3,7 @@ from hestia_earth.utils.model import filter_list_term_type
|
|
3
3
|
|
4
4
|
from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
|
5
5
|
from hestia_earth.models.utils import weighted_average
|
6
|
-
from hestia_earth.models.utils.
|
6
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
7
7
|
from hestia_earth.models.utils.practice import _new_practice
|
8
8
|
from . import MODEL
|
9
9
|
|
@@ -5,7 +5,7 @@ from hestia_earth.utils.tools import safe_parse_float
|
|
5
5
|
from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
|
6
6
|
from hestia_earth.models.utils.measurement import _new_measurement
|
7
7
|
from hestia_earth.models.utils.site import related_cycles
|
8
|
-
from hestia_earth.models.utils.
|
8
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
9
9
|
from . import MODEL
|
10
10
|
|
11
11
|
REQUIREMENTS = {
|
@@ -3,7 +3,7 @@ from hestia_earth.utils.model import find_term_match
|
|
3
3
|
from hestia_earth.utils.tools import safe_parse_float, non_empty_list
|
4
4
|
|
5
5
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
6
|
-
from hestia_earth.models.utils.
|
6
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
7
7
|
from hestia_earth.models.utils.emission import _new_emission
|
8
8
|
from . import MODEL
|
9
9
|
|
@@ -2,7 +2,7 @@ from hestia_earth.schema import EmissionMethodTier
|
|
2
2
|
|
3
3
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
4
4
|
from hestia_earth.models.utils.emission import _new_emission
|
5
|
-
from hestia_earth.models.utils.
|
5
|
+
from hestia_earth.models.utils.term import get_lookup_value
|
6
6
|
from hestia_earth.models.utils.cropResidue import get_crop_residue_burnt_value
|
7
7
|
from . import MODEL
|
8
8
|
|