hestia-earth-models 0.63.0__py3-none-any.whl → 0.64.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.

Potentially problematic release.


This version of hestia-earth-models might be problematic. Click here for more details.

Files changed (72) hide show
  1. hestia_earth/models/cycle/endDate.py +47 -0
  2. hestia_earth/models/cycle/otherSitesUnusedDuration.py +91 -0
  3. hestia_earth/models/cycle/siteUnusedDuration.py +2 -1
  4. hestia_earth/models/cycle/startDate.py +38 -10
  5. hestia_earth/models/cycle/startDateDefinition.py +2 -2
  6. hestia_earth/models/cycle/unknownPreSeasonWaterRegime.py +51 -0
  7. hestia_earth/models/ecoinventV3/__init__.py +18 -2
  8. hestia_earth/models/edip2003/__init__.py +13 -0
  9. hestia_earth/models/edip2003/ozoneDepletionPotential.py +34 -0
  10. hestia_earth/models/faostat2018/landTransformationFromCropland100YearAverage.py +1 -1
  11. hestia_earth/models/faostat2018/landTransformationFromCropland20YearAverage.py +1 -1
  12. hestia_earth/models/faostat2018/utils.py +2 -2
  13. hestia_earth/models/geospatialDatabase/clayContent.py +44 -17
  14. hestia_earth/models/geospatialDatabase/organicCarbonPerKgSoil.py +43 -17
  15. hestia_earth/models/geospatialDatabase/sandContent.py +43 -16
  16. hestia_earth/models/geospatialDatabase/siltContent.py +58 -18
  17. hestia_earth/models/geospatialDatabase/soilPh.py +43 -16
  18. hestia_earth/models/geospatialDatabase/totalNitrogenPerKgSoil.py +45 -15
  19. hestia_earth/models/geospatialDatabase/utils.py +11 -5
  20. hestia_earth/models/hyde32/landTransformationFromCropland100YearAverageDuringCycle.py +2 -1
  21. hestia_earth/models/hyde32/landTransformationFromCropland20YearAverageDuringCycle.py +2 -1
  22. hestia_earth/models/hyde32/landTransformationFromForest100YearAverageDuringCycle.py +2 -1
  23. hestia_earth/models/hyde32/landTransformationFromForest20YearAverageDuringCycle.py +2 -1
  24. hestia_earth/models/hyde32/landTransformationFromOtherNaturalVegetation100YearAverageDuringCycle.py +2 -1
  25. hestia_earth/models/hyde32/landTransformationFromOtherNaturalVegetation20YearAverageDuringCycle.py +2 -1
  26. hestia_earth/models/hyde32/landTransformationFromPermanentPasture100YearAverageDuringCycle.py +2 -1
  27. hestia_earth/models/hyde32/landTransformationFromPermanentPasture20YearAverageDuringCycle.py +2 -1
  28. hestia_earth/models/hyde32/utils.py +7 -4
  29. hestia_earth/models/impact_assessment/allocationMethod.py +39 -0
  30. hestia_earth/models/impact_assessment/emissions.py +3 -1
  31. hestia_earth/models/mocking/search-results.json +61 -19
  32. hestia_earth/models/pooreNemecek2018/excretaKgN.py +9 -9
  33. hestia_earth/models/pooreNemecek2018/excretaKgVs.py +6 -8
  34. hestia_earth/models/poschEtAl2008/__init__.py +13 -0
  35. hestia_earth/models/poschEtAl2008/terrestrialAcidificationPotentialAccumulatedExceedance.py +40 -0
  36. hestia_earth/models/site/management.py +15 -1
  37. hestia_earth/models/site/pre_checks/cache_geospatialDatabase.py +23 -16
  38. hestia_earth/models/site/waterDepth.py +0 -3
  39. hestia_earth/models/utils/indicator.py +3 -1
  40. hestia_earth/models/utils/term.py +34 -0
  41. hestia_earth/models/version.py +1 -1
  42. {hestia_earth_models-0.63.0.dist-info → hestia_earth_models-0.64.1.dist-info}/METADATA +3 -3
  43. {hestia_earth_models-0.63.0.dist-info → hestia_earth_models-0.64.1.dist-info}/RECORD +72 -56
  44. tests/models/cycle/test_endDate.py +22 -0
  45. tests/models/cycle/test_otherSitesUnusedDuration.py +54 -0
  46. tests/models/cycle/test_startDate.py +23 -5
  47. tests/models/cycle/test_unknownPreSeasonWaterRegime.py +36 -0
  48. tests/models/edip2003/__init__.py +0 -0
  49. tests/models/edip2003/test_ozoneDepletionPotential.py +46 -0
  50. tests/models/geospatialDatabase/test_clayContent.py +16 -2
  51. tests/models/geospatialDatabase/test_organicCarbonPerKgSoil.py +16 -2
  52. tests/models/geospatialDatabase/test_sandContent.py +16 -2
  53. tests/models/geospatialDatabase/test_siltContent.py +2 -2
  54. tests/models/geospatialDatabase/test_soilPh.py +16 -2
  55. tests/models/geospatialDatabase/test_totalNitrogenPerKgSoil.py +16 -2
  56. tests/models/hyde32/test_landTransformationFromCropland100YearAverageDuringCycle.py +1 -0
  57. tests/models/hyde32/test_landTransformationFromCropland20YearAverageDuringCycle.py +1 -0
  58. tests/models/hyde32/test_landTransformationFromForest100YearAverageDuringCycle.py +1 -0
  59. tests/models/hyde32/test_landTransformationFromForest20YearAverageDuringCycle.py +1 -0
  60. tests/models/hyde32/test_landTransformationFromOtherNaturalVegetation100YearAverageDuringCycle.py +1 -0
  61. tests/models/hyde32/test_landTransformationFromOtherNaturalVegetation20YearAverageDuringCycle.py +1 -0
  62. tests/models/hyde32/test_landTransformationFromPermanentPasture100YearAverageDuringCycle.py +1 -0
  63. tests/models/hyde32/test_landTransformationFromPermanentPasture20YearAverageDuringCycle.py +1 -0
  64. tests/models/impact_assessment/test_allocationMethod.py +48 -0
  65. tests/models/poschEtAl2008/__init__.py +0 -0
  66. tests/models/poschEtAl2008/test_terrestrialAcidificationPotentialAccumulatedExceedance.py +45 -0
  67. tests/models/test_cache_sites.py +10 -4
  68. tests/models/test_ecoinventV3.py +1 -0
  69. tests/models/utils/test_source.py +1 -1
  70. {hestia_earth_models-0.63.0.dist-info → hestia_earth_models-0.64.1.dist-info}/LICENSE +0 -0
  71. {hestia_earth_models-0.63.0.dist-info → hestia_earth_models-0.64.1.dist-info}/WHEEL +0 -0
  72. {hestia_earth_models-0.63.0.dist-info → hestia_earth_models-0.64.1.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,5 @@
1
1
  from hestia_earth.schema import MeasurementMethodClassification
2
+ from hestia_earth.utils.tools import non_empty_list
2
3
 
3
4
  from hestia_earth.models.log import logRequirements, logShouldRun
4
5
  from hestia_earth.models.utils.blank_node import has_original_by_ids
@@ -29,37 +30,63 @@ REQUIREMENTS = {
29
30
  RETURNS = {
30
31
  "Measurement": [{
31
32
  "value": "",
32
- "depthUpper": "0",
33
- "depthLower": "30",
33
+ "depthUpper": "",
34
+ "depthLower": "",
34
35
  "methodClassification": "geospatial dataset"
35
36
  }]
36
37
  }
37
38
  TERM_ID = 'sandContent'
38
- EE_PARAMS = {
39
- 'collection': 'T_SAND',
40
- 'ee_type': 'raster',
41
- 'reducer': 'mean'
42
- }
43
- BIBLIO_TITLE = 'Harmonized World Soil Database Version 1.2. Food and Agriculture Organization of the United Nations (FAO).' # noqa: E501
39
+ EE_PARAMS = [
40
+ {
41
+ 'collection': 'T_SAND_v2_depth_1',
42
+ 'ee_type': 'raster',
43
+ 'reducer': 'mean',
44
+ 'depthUpper': 0,
45
+ 'depthLower': 20
46
+ },
47
+ {
48
+ 'collection': 'T_SAND_v2_depth_2',
49
+ 'ee_type': 'raster',
50
+ 'reducer': 'mean',
51
+ 'depthUpper': 20,
52
+ 'depthLower': 40
53
+ },
54
+ {
55
+ 'collection': 'T_SAND_v2_depth_3',
56
+ 'ee_type': 'raster',
57
+ 'reducer': 'mean',
58
+ 'depthUpper': 40,
59
+ 'depthLower': 60
60
+ },
61
+ {
62
+ 'collection': 'T_SAND_v2_depth_4',
63
+ 'ee_type': 'raster',
64
+ 'reducer': 'mean',
65
+ 'depthUpper': 60,
66
+ 'depthLower': 80
67
+ }
68
+ ]
69
+ BIBLIO_TITLE = 'Harmonized World Soil Database Version 2.0.'
44
70
 
45
71
 
46
- def _measurement(site: dict, value: int):
72
+ def _measurement(site: dict, value: int, depthUpper: int, depthLower: int):
47
73
  measurement = _new_measurement(TERM_ID)
48
74
  measurement['value'] = [value]
49
- measurement['depthUpper'] = 0
50
- measurement['depthLower'] = 30
75
+ measurement['depthUpper'] = depthUpper
76
+ measurement['depthLower'] = depthLower
51
77
  measurement['methodClassification'] = MeasurementMethodClassification.GEOSPATIAL_DATASET.value
52
78
  return measurement | get_source(site, BIBLIO_TITLE)
53
79
 
54
80
 
55
- def _download(site: dict):
56
- value = download(TERM_ID, site, EE_PARAMS)
57
- return None if value is None else round(value, 2)
81
+ def _run_depths(site: dict, params: dict):
82
+ value = download(TERM_ID, site, params)
83
+ return None if value is None else (
84
+ _measurement(site, round(value, 2), params.get('depthUpper'), params.get('depthLower'))
85
+ )
58
86
 
59
87
 
60
88
  def _run(site: dict):
61
- value = _download(site)
62
- return [_measurement(site, value)] if value is not None else []
89
+ return non_empty_list([_run_depths(site, params) for params in EE_PARAMS])
63
90
 
64
91
 
65
92
  def _should_run(site: dict):
@@ -1,12 +1,30 @@
1
1
  from hestia_earth.schema import MeasurementMethodClassification
2
+ from hestia_earth.utils.model import find_term_match
3
+ from hestia_earth.utils.tools import non_empty_list, flatten
2
4
 
3
- from hestia_earth.models.log import logRequirements, logShouldRun, log_blank_nodes_id
4
- from hestia_earth.models.utils.measurement import _new_measurement, measurement_value
5
+ from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
6
+ from hestia_earth.models.utils.measurement import _new_measurement, measurement_value, group_measurements_by_depth
5
7
  from hestia_earth.models.utils.source import get_source
6
8
  from . import MODEL, clayContent, sandContent
7
9
 
8
10
  REQUIREMENTS = {
9
11
  "Site": {
12
+ "measurements": [
13
+ {
14
+ "@type": "Measurement",
15
+ "term.@id": "clayContent",
16
+ "value": ">= 0",
17
+ "depthUpper": ">= 0",
18
+ "depthLower": ">= 0"
19
+ },
20
+ {
21
+ "@type": "Measurement",
22
+ "term.@id": "sandContent",
23
+ "value": ">= 0",
24
+ "depthUpper": ">= 0",
25
+ "depthLower": ">= 0"
26
+ }
27
+ ],
10
28
  "or": [
11
29
  {"latitude": "", "longitude": ""},
12
30
  {"boundary": {}},
@@ -17,8 +35,8 @@ REQUIREMENTS = {
17
35
  RETURNS = {
18
36
  "Measurement": [{
19
37
  "value": "",
20
- "depthUpper": "0",
21
- "depthLower": "30",
38
+ "depthUpper": "",
39
+ "depthLower": "",
22
40
  "methodClassification": "geospatial dataset"
23
41
  }]
24
42
  }
@@ -27,39 +45,61 @@ OTHER_TERM_IDS = [
27
45
  clayContent.TERM_ID,
28
46
  sandContent.TERM_ID
29
47
  ]
30
- BIBLIO_TITLE = 'Harmonized World Soil Database Version 1.2. Food and Agriculture Organization of the United Nations (FAO).' # noqa: E501
48
+ BIBLIO_TITLE = 'Harmonized World Soil Database Version 2.0.'
31
49
 
32
50
 
33
- def _measurement(site: dict, value: int):
51
+ def _measurement(site: dict, value: int, depthUpper: int, depthLower: int):
34
52
  measurement = _new_measurement(TERM_ID)
35
53
  measurement['value'] = [value]
36
- measurement['depthUpper'] = 0
37
- measurement['depthLower'] = 30
54
+ measurement['depthUpper'] = depthUpper
55
+ measurement['depthLower'] = depthLower
38
56
  measurement['methodClassification'] = MeasurementMethodClassification.GEOSPATIAL_DATASET.value
39
57
  return measurement | get_source(site, BIBLIO_TITLE)
40
58
 
41
59
 
42
60
  def _run(site: dict, measurements: list):
43
61
  value = 100 - sum([measurement_value(m) for m in measurements])
44
- return [_measurement(site, value)]
62
+ return [_measurement(site, value, measurements[0].get('depthUpper'), measurements[0].get('depthLower'))]
45
63
 
46
64
 
47
65
  def _should_run(site: dict):
48
- measurements = [
49
- m for m in site.get('measurements', [])
50
- if m.get('term', {}).get('@id') in OTHER_TERM_IDS and len(m.get('value', [])) > 0
66
+ grouped_measurements = group_measurements_by_depth(site.get('measurements', []), include_dates=False)
67
+ relevant_measurements = [
68
+ [
69
+ m for m in measurements if all([
70
+ m.get('term', {}).get('@id') in OTHER_TERM_IDS,
71
+ len(m.get('value', [])) > 0,
72
+ m.get('depthUpper', -1) >= 0,
73
+ m.get('depthLower', -1) >= 0
74
+ ])
75
+ ]
76
+ for measurements in grouped_measurements.values()
77
+ ]
78
+ valid_measurements = [
79
+ values for values in relevant_measurements if len(values) == len(OTHER_TERM_IDS)
51
80
  ]
52
- has_all_measurements = len(measurements) == len(OTHER_TERM_IDS)
81
+
82
+ has_valid_measurements = len(valid_measurements) > 0
53
83
 
54
84
  logRequirements(site, model=MODEL, term=TERM_ID,
55
- has_all_measurements=has_all_measurements,
56
- measurement_ids=log_blank_nodes_id(measurements))
85
+ has_valid_measurements=has_valid_measurements,
86
+ measurements=log_as_table([
87
+ {
88
+ 'depths': '-'.join(non_empty_list([
89
+ str(values[0].get('depthUpper', '')),
90
+ str(values[0].get('depthLower', ''))
91
+ ]))
92
+ } | {
93
+ term_id: measurement_value(find_term_match(values, term_id))
94
+ for term_id in OTHER_TERM_IDS
95
+ } for values in valid_measurements
96
+ ]))
57
97
 
58
- should_run = all([has_all_measurements])
98
+ should_run = all([has_valid_measurements])
59
99
  logShouldRun(site, MODEL, TERM_ID, should_run)
60
- return should_run, measurements
100
+ return should_run, valid_measurements
61
101
 
62
102
 
63
103
  def run(site: dict):
64
104
  should_run, measurements = _should_run(site)
65
- return _run(site, measurements) if should_run else []
105
+ return flatten([_run(site, values) for values in measurements]) if should_run else []
@@ -1,4 +1,5 @@
1
1
  from hestia_earth.schema import MeasurementMethodClassification
2
+ from hestia_earth.utils.tools import non_empty_list
2
3
 
3
4
  from hestia_earth.models.log import logRequirements, logShouldRun
4
5
  from hestia_earth.models.utils.measurement import _new_measurement
@@ -18,37 +19,63 @@ REQUIREMENTS = {
18
19
  RETURNS = {
19
20
  "Measurement": [{
20
21
  "value": "",
21
- "depthUpper": "0",
22
- "depthLower": "30",
22
+ "depthUpper": "",
23
+ "depthLower": "",
23
24
  "methodClassification": "geospatial dataset"
24
25
  }]
25
26
  }
26
27
  TERM_ID = 'soilPh'
27
- EE_PARAMS = {
28
- 'collection': 'T_PH_H2O',
29
- 'ee_type': 'raster',
30
- 'reducer': 'mean'
31
- }
32
- BIBLIO_TITLE = 'Harmonized World Soil Database Version 1.2. Food and Agriculture Organization of the United Nations (FAO).' # noqa: E501
28
+ EE_PARAMS = [
29
+ {
30
+ 'collection': 'T_PH_H2O_v2_depth_1',
31
+ 'ee_type': 'raster',
32
+ 'reducer': 'mean',
33
+ 'depthUpper': 0,
34
+ 'depthLower': 20
35
+ },
36
+ {
37
+ 'collection': 'T_PH_H2O_v2_depth_2',
38
+ 'ee_type': 'raster',
39
+ 'reducer': 'mean',
40
+ 'depthUpper': 20,
41
+ 'depthLower': 40
42
+ },
43
+ {
44
+ 'collection': 'T_PH_H2O_v2_depth_3',
45
+ 'ee_type': 'raster',
46
+ 'reducer': 'mean',
47
+ 'depthUpper': 40,
48
+ 'depthLower': 60
49
+ },
50
+ {
51
+ 'collection': 'T_PH_H2O_v2_depth_4',
52
+ 'ee_type': 'raster',
53
+ 'reducer': 'mean',
54
+ 'depthUpper': 60,
55
+ 'depthLower': 80
56
+ }
57
+ ]
58
+ BIBLIO_TITLE = 'Harmonized World Soil Database Version 2.0.'
33
59
 
34
60
 
35
- def _measurement(site: dict, value: float):
61
+ def _measurement(site: dict, value: int, depthUpper: int, depthLower: int):
36
62
  measurement = _new_measurement(TERM_ID)
37
63
  measurement['value'] = [value]
38
- measurement['depthUpper'] = 0
39
- measurement['depthLower'] = 30
64
+ measurement['depthUpper'] = depthUpper
65
+ measurement['depthLower'] = depthLower
40
66
  measurement['methodClassification'] = MeasurementMethodClassification.GEOSPATIAL_DATASET.value
41
67
  return measurement | get_source(site, BIBLIO_TITLE)
42
68
 
43
69
 
44
- def _download(site: dict):
45
- value = download(TERM_ID, site, EE_PARAMS)
46
- return None if value is None else round(value, 7)
70
+ def _run_depths(site: dict, params: dict):
71
+ value = download(TERM_ID, site, params)
72
+ return None if value is None else (
73
+ _measurement(site, round(value, 7), params.get('depthUpper'), params.get('depthLower'))
74
+ )
47
75
 
48
76
 
49
77
  def _run(site: dict):
50
- value = _download(site)
51
- return [] if value is None else [_measurement(site, value)]
78
+ return non_empty_list([_run_depths(site, params) for params in EE_PARAMS])
52
79
 
53
80
 
54
81
  def _should_run(site: dict):
@@ -1,5 +1,5 @@
1
1
  from hestia_earth.schema import MeasurementMethodClassification
2
- from hestia_earth.utils.tools import safe_parse_float
2
+ from hestia_earth.utils.tools import safe_parse_float, non_empty_list
3
3
 
4
4
  from hestia_earth.models.log import logRequirements, logShouldRun
5
5
  from hestia_earth.models.utils.measurement import _new_measurement
@@ -19,33 +19,63 @@ REQUIREMENTS = {
19
19
  RETURNS = {
20
20
  "Measurement": [{
21
21
  "value": "",
22
- "depthUpper": "0",
23
- "depthLower": "50",
22
+ "depthUpper": "",
23
+ "depthLower": "",
24
24
  "methodClassification": "geospatial dataset"
25
25
  }]
26
26
  }
27
27
  TERM_ID = 'totalNitrogenPerKgSoil'
28
- EE_PARAMS = {
29
- 'collection': 'T_N',
30
- 'ee_type': 'raster',
31
- 'reducer': 'mean'
32
- }
33
- BIBLIO_TITLE = 'Harmonized soil property values for broad-scale modelling (WISE30sec) '
34
- 'with estimates of global soil carbon stocks'
28
+ EE_PARAMS = [
29
+ {
30
+ 'collection': 'T_N_v2_depth_1',
31
+ 'ee_type': 'raster',
32
+ 'reducer': 'mean',
33
+ 'depthUpper': 0,
34
+ 'depthLower': 20
35
+ },
36
+ {
37
+ 'collection': 'T_N_v2_depth_2',
38
+ 'ee_type': 'raster',
39
+ 'reducer': 'mean',
40
+ 'depthUpper': 20,
41
+ 'depthLower': 40
42
+ },
43
+ {
44
+ 'collection': 'T_N_v2_depth_3',
45
+ 'ee_type': 'raster',
46
+ 'reducer': 'mean',
47
+ 'depthUpper': 40,
48
+ 'depthLower': 60
49
+ },
50
+ {
51
+ 'collection': 'T_N_v2_depth_4',
52
+ 'ee_type': 'raster',
53
+ 'reducer': 'mean',
54
+ 'depthUpper': 60,
55
+ 'depthLower': 80
56
+ }
57
+ ]
58
+ BIBLIO_TITLE = 'Harmonized World Soil Database Version 2.0.'
35
59
 
36
60
 
37
- def _measurement(site: dict, value: float):
61
+ def _measurement(site: dict, value: int, depthUpper: int, depthLower: int):
38
62
  measurement = _new_measurement(TERM_ID)
39
63
  measurement['value'] = [value]
40
- measurement['depthUpper'] = 0
41
- measurement['depthLower'] = 50
64
+ measurement['depthUpper'] = depthUpper
65
+ measurement['depthLower'] = depthLower
42
66
  measurement['methodClassification'] = MeasurementMethodClassification.GEOSPATIAL_DATASET.value
43
67
  return measurement | get_source(site, BIBLIO_TITLE)
44
68
 
45
69
 
70
+ def _run_depths(site: dict, params: dict):
71
+ value = download(TERM_ID, site, params)
72
+ return None if value is None else (
73
+ _measurement(site, safe_parse_float(value), params.get('depthUpper'), params.get('depthLower'))
74
+ )
75
+
76
+
46
77
  def _run(site: dict):
47
- value = download(TERM_ID, site, EE_PARAMS)
48
- return [_measurement(site, safe_parse_float(value))] if value is not None else []
78
+ return non_empty_list([_run_depths(site, params) for params in EE_PARAMS])
49
79
 
50
80
 
51
81
  def _should_run(site: dict):
@@ -134,13 +134,19 @@ def _parse_run_query(term: str, query: dict):
134
134
  return None
135
135
 
136
136
 
137
+ def _cache_sub_key(collection: dict):
138
+ return '-'.join(non_empty_list([
139
+ str(collection.get('year', '')),
140
+ str(collection.get('start_date', '')),
141
+ str(collection.get('end_date', '')),
142
+ str(collection.get('depthUpper', '')),
143
+ str(collection.get('depthLower', ''))
144
+ ]))
145
+
146
+
137
147
  def _get_cached_data(term: str, site: dict, data: dict):
138
148
  cache = _cached_value(site, term)
139
- cache_sub_key = '-'.join(non_empty_list([
140
- data.get('year'),
141
- data.get('start_date'),
142
- data.get('end_date')
143
- ]))
149
+ cache_sub_key = _cache_sub_key(data)
144
150
  # data can be grouped by year when required
145
151
  value = cache.get(cache_sub_key) if (
146
152
  isinstance(cache, dict) and cache_sub_key in cache and cache is not None
@@ -50,7 +50,8 @@ LOOKUPS = {
50
50
  }
51
51
  RETURNS = {
52
52
  "Indicator": [{
53
- "value": ""
53
+ "value": "",
54
+ "landCover": ""
54
55
  }]
55
56
  }
56
57
  TERM_ID = 'landTransformationFromCropland100YearAverageDuringCycle'
@@ -50,7 +50,8 @@ LOOKUPS = {
50
50
  }
51
51
  RETURNS = {
52
52
  "Indicator": [{
53
- "value": ""
53
+ "value": "",
54
+ "landCover": ""
54
55
  }]
55
56
  }
56
57
  TERM_ID = 'landTransformationFromCropland20YearAverageDuringCycle'
@@ -50,7 +50,8 @@ LOOKUPS = {
50
50
  }
51
51
  RETURNS = {
52
52
  "Indicator": [{
53
- "value": ""
53
+ "value": "",
54
+ "landCover": ""
54
55
  }]
55
56
  }
56
57
  TERM_ID = 'landTransformationFromForest100YearAverageDuringCycle'
@@ -50,7 +50,8 @@ LOOKUPS = {
50
50
  }
51
51
  RETURNS = {
52
52
  "Indicator": [{
53
- "value": ""
53
+ "value": "",
54
+ "landCover": ""
54
55
  }]
55
56
  }
56
57
  TERM_ID = 'landTransformationFromForest20YearAverageDuringCycle'
@@ -50,7 +50,8 @@ LOOKUPS = {
50
50
  }
51
51
  RETURNS = {
52
52
  "Indicator": [{
53
- "value": ""
53
+ "value": "",
54
+ "landCover": ""
54
55
  }]
55
56
  }
56
57
  TERM_ID = 'landTransformationFromOtherNaturalVegetation100YearAverageDuringCycle'
@@ -50,7 +50,8 @@ LOOKUPS = {
50
50
  }
51
51
  RETURNS = {
52
52
  "Indicator": [{
53
- "value": ""
53
+ "value": "",
54
+ "landCover": ""
54
55
  }]
55
56
  }
56
57
  TERM_ID = 'landTransformationFromOtherNaturalVegetation20YearAverageDuringCycle'
@@ -50,7 +50,8 @@ LOOKUPS = {
50
50
  }
51
51
  RETURNS = {
52
52
  "Indicator": [{
53
- "value": ""
53
+ "value": "",
54
+ "landCover": ""
54
55
  }]
55
56
  }
56
57
  TERM_ID = 'landTransformationFromPermanentPasture100YearAverageDuringCycle'
@@ -50,7 +50,8 @@ LOOKUPS = {
50
50
  }
51
51
  RETURNS = {
52
52
  "Indicator": [{
53
- "value": ""
53
+ "value": "",
54
+ "landCover": ""
54
55
  }]
55
56
  }
56
57
  TERM_ID = 'landTransformationFromPermanentPasture20YearAverageDuringCycle'
@@ -6,6 +6,7 @@ from hestia_earth.models.log import debugMissingLookup, debugValues, logRequirem
6
6
  from hestia_earth.models.utils.indicator import _new_indicator
7
7
  from hestia_earth.models.utils.impact_assessment import get_product, get_site, get_region_id
8
8
  from hestia_earth.models.utils.cycle import land_occupation_per_kg
9
+ from hestia_earth.models.utils.site import get_land_cover_term_id
9
10
  from . import MODEL
10
11
 
11
12
 
@@ -28,17 +29,19 @@ def _get_emission_factor(term_id: str, impact_assessment: dict, average_years: s
28
29
  return safe_parse_float(extract_grouped_data_closest_date(value, end_date.year), None) if end_date else None
29
30
 
30
31
 
31
- def _indicator(term_id: str, value: float):
32
- indicator = _new_indicator(term_id, MODEL)
32
+ def _indicator(term_id: str, value: float, land_covert_term_id: str):
33
+ indicator = _new_indicator(term_id, MODEL, land_covert_term_id)
33
34
  indicator['value'] = value
34
35
  return indicator
35
36
 
36
37
 
37
38
  def _run(impact_assessment: dict, term_id: str, land_occupation_m2: float, factor: float):
39
+ land_covert_term_id = get_land_cover_term_id(get_site(impact_assessment).get('siteType'))
38
40
  value = land_occupation_m2 * (factor or 0)
39
41
  debugValues(impact_assessment, model=MODEL, term=term_id,
40
- value=value)
41
- return _indicator(term_id, value)
42
+ value=value,
43
+ land_covert_term_id=land_covert_term_id)
44
+ return _indicator(term_id, value, land_covert_term_id)
42
45
 
43
46
 
44
47
  def _should_run(impact_assessment: dict, term_id: str, from_site_type: SiteSiteType, years: int):
@@ -0,0 +1,39 @@
1
+ """
2
+ Allocation Method
3
+
4
+ If any of the impact `emissionsResourceUse`, `impacts`, or `endpoints`, have been modified by the calculations,
5
+ the `allocationMethod` will be set to `economic`.
6
+ """
7
+ from hestia_earth.schema import ImpactAssessmentAllocationMethod
8
+
9
+ from hestia_earth.models.log import logShouldRun, logRequirements
10
+ from . import MODEL
11
+
12
+ REQUIREMENTS = {
13
+ "ImpactAssessment": {
14
+ "updated": ["emissionsResourceUse", "impacts", "endpoints"],
15
+ "added": ["emissionsResourceUse", "impacts", "endpoints"]
16
+ }
17
+ }
18
+ RETURNS = {
19
+ "`economic` if any indicators were updated or added by the HESTIA models": ""
20
+ }
21
+
22
+ MODEL_KEY = 'allocationMethod'
23
+ _MODIFIED_KEYS = ["emissionsResourceUse", "impacts", "endpoints"]
24
+
25
+
26
+ def _should_run(impact: dict):
27
+ modified = impact.get('updated', []) + impact.get('added', [])
28
+ is_modified_by_hestia = any([key for key in _MODIFIED_KEYS if key in modified])
29
+
30
+ logRequirements(impact, model=MODEL, key=MODEL_KEY,
31
+ is_modified_by_hestia=is_modified_by_hestia)
32
+
33
+ should_run = all([is_modified_by_hestia])
34
+ logShouldRun(impact, MODEL, None, should_run, key=MODEL_KEY)
35
+ return should_run
36
+
37
+
38
+ def run(impact: dict):
39
+ return ImpactAssessmentAllocationMethod.ECONOMIC.value if _should_run(impact) else None
@@ -31,7 +31,8 @@ REQUIREMENTS = {
31
31
  RETURNS = {
32
32
  "Indicator": [{
33
33
  "term": "",
34
- "value": ""
34
+ "value": "",
35
+ "methodTier": ""
35
36
  }]
36
37
  }
37
38
  MODEL_KEY = 'emissions'
@@ -44,6 +45,7 @@ def _indicator(product: dict):
44
45
 
45
46
  indicator = _new_indicator(emission.get('term', {}), emission.get('methodModel'))
46
47
  indicator['value'] = value
48
+ indicator['methodTier'] = emission.get('methodTier')
47
49
 
48
50
  if len(emission.get('inputs', [])):
49
51
  indicator['inputs'] = emission['inputs']