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
@@ -0,0 +1,47 @@
1
+ """
2
+ End Date
3
+
4
+ This model sets the [Cycle endDate](https://hestia.earth/schema/Cycle#endDate) based on:
5
+ * if no `cycleDuration` is provided, and the `endDate` is set to month precision (e.g., `2000-01`),
6
+ assumed it ended on the 14th of the month.
7
+ """
8
+ from hestia_earth.utils.date import is_in_months
9
+
10
+ from hestia_earth.models.log import logRequirements, logShouldRun
11
+ from . import MODEL
12
+
13
+ REQUIREMENTS = {
14
+ "Cycle": {
15
+ "endDate": "month precision",
16
+ "none": {
17
+ "cycleDuration": ""
18
+ }
19
+ }
20
+ }
21
+ RETURNS = {
22
+ "The endDate as a string": ""
23
+ }
24
+ MODEL_KEY = 'endDate'
25
+
26
+
27
+ def _run(cycle: dict):
28
+ endDate = cycle.get('endDate')
29
+ return f"{endDate}-14"
30
+
31
+
32
+ def _should_run(cycle: dict):
33
+ has_endDate = cycle.get('endDate') is not None
34
+ has_month_precision = has_endDate and is_in_months(cycle.get('endDate'))
35
+ no_cycleDuration = cycle.get('cycleDuration') is None
36
+
37
+ logRequirements(cycle, model=MODEL, key=MODEL_KEY, by='endDate',
38
+ has_endDate=has_endDate,
39
+ has_month_precision=has_month_precision,
40
+ no_cycleDuration=no_cycleDuration)
41
+
42
+ should_run = all([has_endDate, has_month_precision, no_cycleDuration])
43
+ logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY, by='endDate')
44
+ return should_run
45
+
46
+
47
+ def run(cycle: dict): return _run(cycle) if _should_run(cycle) else None
@@ -0,0 +1,91 @@
1
+ """
2
+ Other Sites Unused Duration
3
+
4
+ This model sets the [Cycle otherSitesUnusedDuration](https://hestia.earth/schema/Cycle#otherSitesUnusedDuration)
5
+ based on the `otherSites`, `otherSitesDuration`, and the `longFallowRatio` practice associated with each.
6
+ """
7
+ from hestia_earth.schema import SiteSiteType
8
+ from hestia_earth.utils.tools import list_sum
9
+
10
+ from hestia_earth.models.log import logRequirements, logShouldRun, log_as_table
11
+ from hestia_earth.models.utils.site import valid_site_type
12
+ from . import MODEL
13
+
14
+ REQUIREMENTS = {
15
+ "Cycle": {
16
+ "otherSites": [{
17
+ "@type": "Site",
18
+ "siteType": ["cropland", "glass and high accessible cover"]
19
+ }],
20
+ "otherSitesDuration": "",
21
+ "practices": [{
22
+ "@type": "Practice",
23
+ "value": "> 0",
24
+ "term.@id": "longFallowRatio",
25
+ "site": {"@type": "Site"}
26
+ }]
27
+ }
28
+ }
29
+ RETURNS = {
30
+ "The otherSitesUnusedDuration as an array of number": ""
31
+ }
32
+ MODEL_KEY = 'otherSitesUnusedDuration'
33
+ VALID_SITE_TYPES = [
34
+ SiteSiteType.CROPLAND.value,
35
+ SiteSiteType.GLASS_OR_HIGH_ACCESSIBLE_COVER.value
36
+ ]
37
+ _PRACTICE_TERM_ID = 'longFallowRatio'
38
+
39
+
40
+ def _run(siteDuration: float, longFallowRatio: float):
41
+ return siteDuration * (longFallowRatio - 1)
42
+
43
+
44
+ def _find_site_practice(practices: list, site_id: str):
45
+ return list_sum(next(
46
+ (p for p in practices if all([
47
+ p.get('term', {}).get('@id') == _PRACTICE_TERM_ID,
48
+ p.get('site') is None or p.get('site', {}).get('@id', p.get('site', {}).get('id')) == site_id
49
+ ])),
50
+ {}
51
+ ).get('value'), None)
52
+
53
+
54
+ def _should_run(cycle: dict):
55
+ otherSitesDuration = cycle.get('otherSitesDuration', [])
56
+ practices = cycle.get('practices', [])
57
+
58
+ site_data = [
59
+ {
60
+ 'site-id': site.get('@id', site.get('id')),
61
+ 'siteType': site.get('siteType'),
62
+ 'valid-site': valid_site_type(site, site_types=VALID_SITE_TYPES),
63
+ 'site-duration': otherSitesDuration[index] if len(otherSitesDuration) > index else None,
64
+ _PRACTICE_TERM_ID: _find_site_practice(practices, site.get('@id'))
65
+ }
66
+ for index, site in enumerate(cycle.get('otherSites', []))
67
+ ]
68
+
69
+ has_valid_sites = any([
70
+ all([
71
+ data.get('valid-site'),
72
+ data.get(_PRACTICE_TERM_ID) is not None,
73
+ (data.get('site-duration') or 0) >= 0
74
+ ]) for data in site_data
75
+ ])
76
+
77
+ logRequirements(cycle, model=MODEL, key=MODEL_KEY,
78
+ has_valid_sites=has_valid_sites,
79
+ site_data=log_as_table(site_data))
80
+
81
+ should_run = all([has_valid_sites])
82
+ logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY)
83
+ return should_run, site_data
84
+
85
+
86
+ def run(cycle: dict):
87
+ should_run, site_data = _should_run(cycle)
88
+ return [
89
+ _run(data.get('site-duration'), data.get(_PRACTICE_TERM_ID)) if data.get('valid-site') else None
90
+ for data in site_data
91
+ ] if should_run else []
@@ -37,6 +37,7 @@ def _run(cycle: dict, longFallowRatio: float):
37
37
 
38
38
 
39
39
  def _should_run(cycle: dict):
40
+ site_id = cycle.get('site', {}).get('@id', cycle.get('site', {}).get('id'))
40
41
  site_type_valid = valid_site_type(cycle.get('site'), site_types=VALID_SITE_TYPES)
41
42
 
42
43
  siteDuration = cycle.get('siteDuration', 0)
@@ -45,7 +46,7 @@ def _should_run(cycle: dict):
45
46
  longFallowRatio = list_sum(next((
46
47
  p for p in practices if all([
47
48
  p.get('term', {}).get('@id') == 'longFallowRatio',
48
- p.get('site') is None or p.get('site', {}).get('@id') == cycle.get('site', {}).get('@id')
49
+ p.get('site') is None or p.get('site', {}).get('@id', p.get('site', {}).get('id')) == site_id
49
50
  ])
50
51
  ), {}).get('value'), None)
51
52
 
@@ -1,11 +1,13 @@
1
1
  """
2
2
  Start Date
3
3
 
4
- This model sets the [Cycle startDate](https://hestia.earth/schema/Cycle#startDate) based on the `endDate` and the
5
- `cycleDuration`. This only works when the `endDate` has been provided to a day precision (`2000-01-01`).
4
+ This model sets the [Cycle startDate](https://hestia.earth/schema/Cycle#startDate) based on:
5
+ * the `cycleDuration` and the `endDate` if it has been provided to a day precision (e.g., `2000-01-01`);
6
+ * if no `cycleDuration` is provided, and the `startDate` is set to month precision (e.g., `2000-01`),
7
+ assumed it started on the 15th of the month.
6
8
  """
7
9
  from datetime import timedelta
8
- from hestia_earth.utils.date import is_in_days
10
+ from hestia_earth.utils.date import is_in_days, is_in_months
9
11
  from hestia_earth.utils.tools import safe_parse_date
10
12
 
11
13
  from hestia_earth.models.log import logRequirements, logShouldRun
@@ -13,8 +15,11 @@ from . import MODEL
13
15
 
14
16
  REQUIREMENTS = {
15
17
  "Cycle": {
16
- "endDate": "to day precision",
17
- "cycleDuration": ""
18
+ "optional": {
19
+ "startDate": "month precision",
20
+ "endDate": "day precision",
21
+ "cycleDuration": ""
22
+ }
18
23
  }
19
24
  }
20
25
  RETURNS = {
@@ -23,25 +28,48 @@ RETURNS = {
23
28
  MODEL_KEY = 'startDate'
24
29
 
25
30
 
26
- def _run(cycle: dict):
31
+ def _run_by_cycleDuration(cycle: dict):
27
32
  endDate = safe_parse_date(cycle.get('endDate'))
28
33
  cycleDuration = cycle.get('cycleDuration')
29
34
  return (endDate - timedelta(days=cycleDuration)).strftime('%Y-%m-%d')
30
35
 
31
36
 
32
- def _should_run(cycle: dict):
37
+ def _should_run_by_cycleDuration(cycle: dict):
33
38
  has_endDate = cycle.get('endDate') is not None
34
39
  has_day_precision = has_endDate and is_in_days(cycle.get('endDate'))
35
40
  has_cycleDuration = cycle.get('cycleDuration') is not None
36
41
 
37
- logRequirements(cycle, model=MODEL, key=MODEL_KEY,
42
+ logRequirements(cycle, model=MODEL, key=MODEL_KEY, by='cycleDuration',
38
43
  has_endDate=has_endDate,
39
44
  has_day_precision=has_day_precision,
40
45
  has_cycleDuration=has_cycleDuration)
41
46
 
42
47
  should_run = all([has_endDate, has_day_precision, has_cycleDuration])
43
- logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY)
48
+ logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY, by='cycleDuration')
44
49
  return should_run
45
50
 
46
51
 
47
- def run(cycle: dict): return _run(cycle) if _should_run(cycle) else None
52
+ def _run_by_startDate(cycle: dict):
53
+ startDate = cycle.get('startDate')
54
+ return f"{startDate}-15"
55
+
56
+
57
+ def _should_run_by_startDate(cycle: dict):
58
+ has_startDate = cycle.get('startDate') is not None
59
+ has_month_precision = has_startDate and is_in_months(cycle.get('startDate'))
60
+ no_cycleDuration = cycle.get('cycleDuration') is None
61
+
62
+ logRequirements(cycle, model=MODEL, key=MODEL_KEY, by='startDate',
63
+ has_startDate=has_startDate,
64
+ has_month_precision=has_month_precision,
65
+ no_cycleDuration=no_cycleDuration)
66
+
67
+ should_run = all([has_startDate, has_month_precision, no_cycleDuration])
68
+ logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY, by='startDate')
69
+ return should_run
70
+
71
+
72
+ def run(cycle: dict):
73
+ return _run_by_cycleDuration(cycle) if _should_run_by_cycleDuration(cycle) else (
74
+ _run_by_startDate(cycle) if _should_run_by_startDate(cycle) else None
75
+ )
@@ -14,11 +14,11 @@ from . import MODEL
14
14
  REQUIREMENTS = {
15
15
  "Cycle": {
16
16
  "cycleDuration": "",
17
- "products": {
17
+ "products": [{
18
18
  "@type": "Product",
19
19
  "primary": "True",
20
20
  "term.termType": "crop"
21
- },
21
+ }],
22
22
  "optional": {
23
23
  "endDate": ""
24
24
  }
@@ -0,0 +1,51 @@
1
+ from hestia_earth.models.log import logRequirements, logShouldRun
2
+ from hestia_earth.models.utils.term import get_flooded_pre_season_terms
3
+ from hestia_earth.models.utils.practice import _new_practice
4
+ from . import MODEL
5
+
6
+ REQUIREMENTS = {
7
+ "Cycle": {
8
+ "none": {
9
+ "practices": [{
10
+ "@type": "Practice",
11
+ "term.termType": "landUseManagement",
12
+ "term.@id": [
13
+ "nonFloodedPreSeasonLessThan180Days",
14
+ "nonFloodedPreSeasonMoreThan180Days",
15
+ "nonFloodedPreSeasonMoreThan365Days",
16
+ "floodedPreSeasonMoreThan30Days"
17
+ ]
18
+ }]
19
+ }
20
+ }
21
+ }
22
+ RETURNS = {
23
+ "Practice": [{
24
+ "value": "100"
25
+ }]
26
+ }
27
+ TERM_ID = 'unknownPreSeasonWaterRegime'
28
+
29
+
30
+ def _practice():
31
+ practice = _new_practice(TERM_ID)
32
+ practice['value'] = [100]
33
+ return practice
34
+
35
+
36
+ def _should_run(cycle: dict):
37
+ practices = cycle.get('practices', [])
38
+ flooded_terms = get_flooded_pre_season_terms()
39
+ print(flooded_terms)
40
+ existing_practice = next((p for p in practices if p.get('term', {}).get('@id') in flooded_terms), None)
41
+
42
+ logRequirements(cycle, model=MODEL, term=TERM_ID,
43
+ existing_practice=existing_practice)
44
+
45
+ should_run = all([not existing_practice])
46
+ logShouldRun(cycle, MODEL, TERM_ID, should_run)
47
+ return should_run
48
+
49
+
50
+ def run(cycle: dict):
51
+ return [_practice()] if _should_run(cycle) else []
@@ -19,6 +19,7 @@ from hestia_earth.utils.tools import flatten, list_sum
19
19
 
20
20
  from hestia_earth.models.log import debugValues, logShouldRun, logRequirements
21
21
  from hestia_earth.models.data.ecoinventV3 import ecoinventV3_emissions
22
+ from hestia_earth.models.utils import is_from_model
22
23
  from hestia_earth.models.utils.emission import _new_emission
23
24
  from hestia_earth.models.utils.blank_node import group_by_keys
24
25
  from hestia_earth.models.utils.pesticideAI import get_pesticides_from_inputs
@@ -109,18 +110,33 @@ def _add_emission(cycle: dict, input: dict):
109
110
 
110
111
 
111
112
  def _run_input(cycle: dict):
113
+ emissions = cycle.get('emissions', [])
114
+
112
115
  def run(inputs: list):
113
116
  input = inputs[0]
114
117
  input_term_id = input.get('term', {}).get('@id')
118
+ operation_term_id = input.get('operation', {}).get('@id')
119
+ animal_term_id = input.get('animal', {}).get('@id')
115
120
  input_value = list_sum(flatten(input.get('value', []) for input in inputs))
116
121
  mappings = get_input_mappings(MODEL, cycle, input)
117
122
  has_mappings = len(mappings) > 0
123
+ # skip input that has background emissions we have already gap-filled (model run before)
124
+ has_no_gap_filled_background_emissions = not any([
125
+ is_from_model(e)
126
+ for e in emissions
127
+ if all([
128
+ any([i.get('@id') == input_term_id for i in e.get('inputs', [])]),
129
+ e.get('operation', {}).get('@id') == operation_term_id,
130
+ e.get('animal', {}).get('@id') == animal_term_id
131
+ ])
132
+ ])
118
133
 
119
134
  logRequirements(cycle, model=MODEL, term=input_term_id,
120
135
  has_ecoinvent_mappings=has_mappings,
121
- ecoinvent_mappings=';'.join([v[0] for v in mappings]))
136
+ ecoinvent_mappings=';'.join([v[0] for v in mappings]),
137
+ has_no_gap_filled_background_emissions=has_no_gap_filled_background_emissions)
122
138
 
123
- should_run = all([has_mappings])
139
+ should_run = all([has_mappings, has_no_gap_filled_background_emissions])
124
140
  logShouldRun(cycle, MODEL, input_term_id, should_run, methodTier=TIER)
125
141
  grouped_emissions = reduce(_add_emission(cycle, input), mappings, {}) if should_run else {}
126
142
  return [
@@ -0,0 +1,13 @@
1
+ from os.path import dirname, abspath
2
+ import sys
3
+ from importlib import import_module
4
+
5
+ from hestia_earth.models.utils.blank_node import run_if_required
6
+
7
+ CURRENT_DIR = dirname(abspath(__file__)) + '/'
8
+ sys.path.append(CURRENT_DIR)
9
+ MODEL = 'edip2003'
10
+ PKG = '.'.join(['hestia_earth', 'models', MODEL])
11
+
12
+
13
+ def run(model: str, data): return run_if_required(MODEL, model, data, import_module(f".{model}", package=PKG))
@@ -0,0 +1,34 @@
1
+ from hestia_earth.models.log import logRequirements, logShouldRun
2
+ from hestia_earth.models.utils.indicator import _new_indicator
3
+ from hestia_earth.models.utils.impact_assessment import impact_lookup_value
4
+ from . import MODEL
5
+
6
+ REQUIREMENTS = {
7
+ "ImpactAssessment": {
8
+ "emissionsResourceUse": [{"@type": "Indicator", "value": "", "term.termType": "emission"}]
9
+ }
10
+ }
11
+ LOOKUPS = {
12
+ "emission": "ozoneDepletionPotential"
13
+ }
14
+ RETURNS = {
15
+ "Indicator": [{
16
+ "value": ""
17
+ }]
18
+ }
19
+
20
+ TERM_ID = 'ozoneDepletionPotential'
21
+
22
+
23
+ def _indicator(value: float):
24
+ indicator = _new_indicator(TERM_ID, MODEL)
25
+ indicator['value'] = value
26
+ return indicator
27
+
28
+
29
+ def run(impact_assessment: dict):
30
+ value = impact_lookup_value(MODEL, TERM_ID, impact_assessment, LOOKUPS['emission'])
31
+ logRequirements(impact_assessment, model=MODEL, term=TERM_ID,
32
+ value=value)
33
+ logShouldRun(impact_assessment, MODEL, TERM_ID, True)
34
+ return _indicator(value)
@@ -16,7 +16,7 @@ REQUIREMENTS = {
16
16
  }
17
17
  }
18
18
  LOOKUPS = {
19
- "region-faostatCroplandArea": ""
19
+ "region-faostatArea": ""
20
20
  }
21
21
  RETURNS = {
22
22
  "Indicator": [{
@@ -16,7 +16,7 @@ REQUIREMENTS = {
16
16
  }
17
17
  }
18
18
  LOOKUPS = {
19
- "region-faostatCroplandArea": ""
19
+ "region-faostatArea": ""
20
20
  }
21
21
  RETURNS = {
22
22
  "Indicator": [{
@@ -62,14 +62,14 @@ def _cropland_split_delta(table_value: str, start_year: int, end_year: int):
62
62
 
63
63
 
64
64
  def get_cropland_ratio(country: str, start_year: int, end_year: int):
65
- lookup = download_lookup('region-faostatCroplandArea.csv')
65
+ lookup = download_lookup('region-faostatArea.csv')
66
66
  total_delta = _cropland_split_delta(
67
67
  get_table_value(lookup, 'termid', country, column_name('Cropland')), start_year, end_year
68
68
  )
69
69
 
70
70
  # get both values and only return result if we have both
71
71
  permanent_delta = _cropland_split_delta(
72
- get_table_value(lookup, 'termid', country, column_name('Land under permanent crops')), start_year, end_year
72
+ get_table_value(lookup, 'termid', country, column_name('Permanent crops')), start_year, end_year
73
73
  )
74
74
  temporary_delta = _cropland_split_delta(
75
75
  get_table_value(lookup, 'termid', country, column_name('Arable land')), start_year, end_year
@@ -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 = 'clayContent'
38
- EE_PARAMS = {
39
- 'collection': 'T_CLAY',
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_CLAY_v2_depth_1',
42
+ 'ee_type': 'raster',
43
+ 'reducer': 'mean',
44
+ 'depthUpper': 0,
45
+ 'depthLower': 20
46
+ },
47
+ {
48
+ 'collection': 'T_CLAY_v2_depth_2',
49
+ 'ee_type': 'raster',
50
+ 'reducer': 'mean',
51
+ 'depthUpper': 20,
52
+ 'depthLower': 40
53
+ },
54
+ {
55
+ 'collection': 'T_CLAY_v2_depth_3',
56
+ 'ee_type': 'raster',
57
+ 'reducer': 'mean',
58
+ 'depthUpper': 40,
59
+ 'depthLower': 60
60
+ },
61
+ {
62
+ 'collection': 'T_CLAY_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):
47
- measurement = _new_measurement(TERM_ID, None)
72
+ def _measurement(site: dict, value: int, depthUpper: int, depthLower: int):
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,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,37 +19,63 @@ REQUIREMENTS = {
19
19
  RETURNS = {
20
20
  "Measurement": [{
21
21
  "value": "",
22
- "depthUpper": "0",
23
- "depthLower": "30",
22
+ "depthUpper": "",
23
+ "depthLower": "",
24
24
  "methodClassification": "geospatial dataset"
25
25
  }]
26
26
  }
27
27
  TERM_ID = 'organicCarbonPerKgSoil'
28
- EE_PARAMS = {
29
- 'collection': 'T_OC',
30
- 'ee_type': 'raster',
31
- 'reducer': 'mean'
32
- }
33
- 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_OC_v2_depth_1',
31
+ 'ee_type': 'raster',
32
+ 'reducer': 'mean',
33
+ 'depthUpper': 0,
34
+ 'depthLower': 20
35
+ },
36
+ {
37
+ 'collection': 'T_OC_v2_depth_2',
38
+ 'ee_type': 'raster',
39
+ 'reducer': 'mean',
40
+ 'depthUpper': 20,
41
+ 'depthLower': 40
42
+ },
43
+ {
44
+ 'collection': 'T_OC_v2_depth_3',
45
+ 'ee_type': 'raster',
46
+ 'reducer': 'mean',
47
+ 'depthUpper': 40,
48
+ 'depthLower': 60
49
+ },
50
+ {
51
+ 'collection': 'T_OC_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.'
34
59
 
35
60
 
36
- def _measurement(site: dict, value: float):
61
+ def _measurement(site: dict, value: int, depthUpper: int, depthLower: int):
37
62
  measurement = _new_measurement(TERM_ID)
38
63
  measurement['value'] = [value]
39
- measurement['depthUpper'] = 0
40
- measurement['depthLower'] = 30
64
+ measurement['depthUpper'] = depthUpper
65
+ measurement['depthLower'] = depthLower
41
66
  measurement['methodClassification'] = MeasurementMethodClassification.GEOSPATIAL_DATASET.value
42
67
  return measurement | get_source(site, BIBLIO_TITLE)
43
68
 
44
69
 
45
- def _download(site: dict):
46
- value = download(TERM_ID, site, EE_PARAMS)
47
- return safe_parse_float(value) * 10 if value is not None else None
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) * 10, params.get('depthUpper'), params.get('depthLower'))
74
+ )
48
75
 
49
76
 
50
77
  def _run(site: dict):
51
- value = _download(site)
52
- return [_measurement(site, value)] if value is not None else []
78
+ return non_empty_list([_run_depths(site, params) for params in EE_PARAMS])
53
79
 
54
80
 
55
81
  def _should_run(site: dict):