hestia-earth-models 0.64.9__py3-none-any.whl → 0.64.11__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 (125) hide show
  1. hestia_earth/models/cml2001Baseline/abioticResourceDepletionFossilFuels.py +175 -0
  2. hestia_earth/models/cml2001Baseline/abioticResourceDepletionMineralsAndMetals.py +136 -0
  3. hestia_earth/models/cml2001Baseline/eutrophicationPotentialExcludingFate.py +2 -2
  4. hestia_earth/models/cml2001Baseline/terrestrialAcidificationPotentialIncludingFateAverageEurope.py +2 -2
  5. hestia_earth/models/cml2001NonBaseline/eutrophicationPotentialIncludingFateAverageEurope.py +2 -2
  6. hestia_earth/models/cml2001NonBaseline/terrestrialAcidificationPotentialExcludingFate.py +2 -2
  7. hestia_earth/models/cycle/completeness/cropResidue.py +15 -10
  8. hestia_earth/models/cycle/completeness/freshForage.py +60 -0
  9. hestia_earth/models/edip2003/ozoneDepletionPotential.py +2 -2
  10. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandTransformation.py +2 -2
  11. hestia_earth/models/fantkeEtAl2016/damageToHumanHealthParticulateMatterFormation.py +7 -17
  12. hestia_earth/models/ipcc2013ExcludingFeedbacks/gwp100.py +2 -2
  13. hestia_earth/models/ipcc2013IncludingFeedbacks/gwp100.py +2 -2
  14. hestia_earth/models/ipcc2019/aboveGroundBiomass.py +31 -243
  15. hestia_earth/models/ipcc2019/belowGroundBiomass.py +529 -0
  16. hestia_earth/models/ipcc2019/biomass_utils.py +406 -0
  17. hestia_earth/models/ipcc2019/{co2ToAirAboveGroundBiomassStockChangeLandUseChange.py → co2ToAirAboveGroundBiomassStockChange.py} +19 -7
  18. hestia_earth/models/ipcc2019/{co2ToAirBelowGroundBiomassStockChangeLandUseChange.py → co2ToAirBelowGroundBiomassStockChange.py} +19 -7
  19. hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +402 -73
  20. hestia_earth/models/ipcc2019/{co2ToAirSoilOrganicCarbonStockChangeManagementChange.py → co2ToAirSoilOrganicCarbonStockChange.py} +20 -8
  21. hestia_earth/models/ipcc2019/organicCarbonPerHa.py +3 -1
  22. hestia_earth/models/ipcc2019/pastureGrass_utils.py +6 -7
  23. hestia_earth/models/ipcc2021/gwp100.py +2 -2
  24. hestia_earth/models/lcImpactAllEffects100Years/damageToFreshwaterEcosystemsClimateChange.py +2 -2
  25. hestia_earth/models/lcImpactAllEffects100Years/damageToFreshwaterEcosystemsFreshwaterEutrophication.py +2 -2
  26. hestia_earth/models/lcImpactAllEffects100Years/damageToFreshwaterEcosystemsWaterStress.py +2 -2
  27. hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthClimateChange.py +2 -2
  28. hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthParticulateMatterFormation.py +2 -2
  29. hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthPhotochemicalOzoneFormation.py +2 -2
  30. hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthStratosphericOzoneDepletion.py +2 -2
  31. hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthWaterStress.py +2 -2
  32. hestia_earth/models/lcImpactAllEffects100Years/damageToMarineEcosystemsMarineEutrophication.py +2 -2
  33. hestia_earth/models/lcImpactAllEffects100Years/damageToTerrestrialEcosystemsClimateChange.py +2 -2
  34. hestia_earth/models/lcImpactAllEffects100Years/damageToTerrestrialEcosystemsPhotochemicalOzoneFormation.py +2 -2
  35. hestia_earth/models/lcImpactAllEffects100Years/damageToTerrestrialEcosystemsTerrestrialAcidification.py +2 -2
  36. hestia_earth/models/lcImpactAllEffectsInfinite/damageToFreshwaterEcosystemsClimateChange.py +2 -2
  37. hestia_earth/models/lcImpactAllEffectsInfinite/damageToFreshwaterEcosystemsFreshwaterEutrophication.py +2 -2
  38. hestia_earth/models/lcImpactAllEffectsInfinite/damageToFreshwaterEcosystemsWaterStress.py +2 -2
  39. hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthClimateChange.py +2 -2
  40. hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthParticulateMatterFormation.py +2 -2
  41. hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthPhotochemicalOzoneFormation.py +2 -2
  42. hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthStratosphericOzoneDepletion.py +2 -2
  43. hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthWaterStress.py +2 -2
  44. hestia_earth/models/lcImpactAllEffectsInfinite/damageToMarineEcosystemsMarineEutrophication.py +2 -2
  45. hestia_earth/models/lcImpactAllEffectsInfinite/damageToTerrestrialEcosystemsClimateChange.py +2 -2
  46. hestia_earth/models/lcImpactAllEffectsInfinite/damageToTerrestrialEcosystemsPhotochemicalOzoneFormation.py +2 -2
  47. hestia_earth/models/lcImpactAllEffectsInfinite/damageToTerrestrialEcosystemsTerrestrialAcidification.py +2 -2
  48. hestia_earth/models/lcImpactCertainEffects100Years/damageToFreshwaterEcosystemsFreshwaterEutrophication.py +2 -2
  49. hestia_earth/models/lcImpactCertainEffects100Years/damageToFreshwaterEcosystemsWaterStress.py +2 -2
  50. hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthClimateChange.py +2 -2
  51. hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthParticulateMatterFormation.py +2 -2
  52. hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthPhotochemicalOzoneFormation.py +2 -2
  53. hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthStratosphericOzoneDepletion.py +2 -2
  54. hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthWaterStress.py +2 -2
  55. hestia_earth/models/lcImpactCertainEffects100Years/damageToMarineEcosystemsMarineEutrophication.py +2 -2
  56. hestia_earth/models/lcImpactCertainEffects100Years/damageToTerrestrialEcosystemsClimateChange.py +2 -2
  57. hestia_earth/models/lcImpactCertainEffects100Years/damageToTerrestrialEcosystemsPhotochemicalOzoneFormation.py +2 -2
  58. hestia_earth/models/lcImpactCertainEffects100Years/damageToTerrestrialEcosystemsTerrestrialAcidification.py +2 -2
  59. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToFreshwaterEcosystemsFreshwaterEutrophication.py +2 -2
  60. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToFreshwaterEcosystemsWaterStress.py +2 -2
  61. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthClimateChange.py +2 -2
  62. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthParticulateMatterFormation.py +2 -2
  63. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthPhotochemicalOzoneFormation.py +2 -2
  64. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthStratosphericOzoneDepletion.py +2 -2
  65. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthWaterStress.py +2 -2
  66. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToMarineEcosystemsMarineEutrophication.py +2 -2
  67. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToTerrestrialEcosystemsClimateChange.py +2 -2
  68. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToTerrestrialEcosystemsPhotochemicalOzoneFormation.py +2 -2
  69. hestia_earth/models/lcImpactCertainEffectsInfinite/damageToTerrestrialEcosystemsTerrestrialAcidification.py +2 -2
  70. hestia_earth/models/mocking/build_mock_search.py +44 -0
  71. hestia_earth/models/mocking/mock_search.py +8 -49
  72. hestia_earth/models/mocking/search-results.json +3055 -558
  73. hestia_earth/models/poschEtAl2008/terrestrialAcidificationPotentialAccumulatedExceedance.py +3 -3
  74. hestia_earth/models/poschEtAl2008/terrestrialEutrophicationPotentialAccumulatedExceedance.py +3 -3
  75. hestia_earth/models/preload_requests.py +1 -1
  76. hestia_earth/models/recipe2016Egalitarian/ecosystemDamageOzoneFormation.py +2 -2
  77. hestia_earth/models/recipe2016Egalitarian/freshwaterEutrophicationPotential.py +2 -2
  78. hestia_earth/models/recipe2016Egalitarian/humanDamageOzoneFormation.py +2 -2
  79. hestia_earth/models/recipe2016Egalitarian/marineEutrophicationPotential.py +2 -2
  80. hestia_earth/models/recipe2016Egalitarian/ozoneDepletionPotential.py +2 -2
  81. hestia_earth/models/recipe2016Egalitarian/terrestrialAcidificationPotential.py +2 -2
  82. hestia_earth/models/recipe2016Hierarchist/ecosystemDamageOzoneFormation.py +2 -2
  83. hestia_earth/models/recipe2016Hierarchist/freshwaterEutrophicationPotential.py +2 -2
  84. hestia_earth/models/recipe2016Hierarchist/humanDamageOzoneFormation.py +2 -2
  85. hestia_earth/models/recipe2016Hierarchist/marineEutrophicationPotential.py +2 -2
  86. hestia_earth/models/recipe2016Hierarchist/ozoneDepletionPotential.py +2 -2
  87. hestia_earth/models/recipe2016Hierarchist/terrestrialAcidificationPotential.py +2 -2
  88. hestia_earth/models/recipe2016Individualist/ecosystemDamageOzoneFormation.py +2 -2
  89. hestia_earth/models/recipe2016Individualist/freshwaterEutrophicationPotential.py +2 -2
  90. hestia_earth/models/recipe2016Individualist/humanDamageOzoneFormation.py +2 -2
  91. hestia_earth/models/recipe2016Individualist/marineEutrophicationPotential.py +2 -2
  92. hestia_earth/models/recipe2016Individualist/ozoneDepletionPotential.py +2 -2
  93. hestia_earth/models/recipe2016Individualist/terrestrialAcidificationPotential.py +2 -2
  94. hestia_earth/models/schmidt2007/utils.py +13 -4
  95. hestia_earth/models/utils/blank_node.py +73 -3
  96. hestia_earth/models/utils/constant.py +8 -1
  97. hestia_earth/models/utils/cycle.py +10 -13
  98. hestia_earth/models/utils/fuel.py +1 -1
  99. hestia_earth/models/utils/impact_assessment.py +49 -24
  100. hestia_earth/models/utils/lookup.py +36 -7
  101. hestia_earth/models/utils/pesticideAI.py +1 -1
  102. hestia_earth/models/utils/property.py +11 -4
  103. hestia_earth/models/utils/term.py +15 -8
  104. hestia_earth/models/version.py +1 -1
  105. {hestia_earth_models-0.64.9.dist-info → hestia_earth_models-0.64.11.dist-info}/METADATA +2 -2
  106. {hestia_earth_models-0.64.9.dist-info → hestia_earth_models-0.64.11.dist-info}/RECORD +123 -114
  107. {hestia_earth_models-0.64.9.dist-info → hestia_earth_models-0.64.11.dist-info}/WHEEL +1 -1
  108. tests/models/cml2001Baseline/test_abioticResourceDepletionFossilFuels.py +196 -0
  109. tests/models/cml2001Baseline/test_abioticResourceDepletionMineralsAndMetals.py +124 -0
  110. tests/models/cycle/completeness/test_freshForage.py +21 -0
  111. tests/models/edip2003/test_ozoneDepletionPotential.py +1 -13
  112. tests/models/environmentalFootprintV3/test_soilQualityIndexLandTransformation.py +1 -2
  113. tests/models/impact_assessment/test_emissions.py +1 -0
  114. tests/models/ipcc2019/test_aboveGroundBiomass.py +27 -63
  115. tests/models/ipcc2019/test_belowGroundBiomass.py +146 -0
  116. tests/models/ipcc2019/test_biomass_utils.py +115 -0
  117. tests/models/ipcc2019/{test_co2ToAirAboveGroundBiomassStockChangeLandUseChange.py → test_co2ToAirAboveGroundBiomassStockChange.py} +5 -5
  118. tests/models/ipcc2019/{test_co2ToAirBelowGroundBiomassStockChangeLandUseChange.py → test_co2ToAirBelowGroundBiomassStockChange.py} +5 -5
  119. tests/models/ipcc2019/{test_co2ToAirSoilOrganicCarbonStockChangeManagementChange.py → test_co2ToAirSoilOrganicCarbonStockChange.py} +5 -5
  120. tests/models/ipcc2021/test_gwp100.py +2 -2
  121. tests/models/utils/test_impact_assessment.py +3 -3
  122. hestia_earth/models/ipcc2019/aboveGroundBiomass_utils.py +0 -180
  123. tests/models/ipcc2019/test_aboveGroundBiomass_utils.py +0 -92
  124. {hestia_earth_models-0.64.9.dist-info → hestia_earth_models-0.64.11.dist-info}/LICENSE +0 -0
  125. {hestia_earth_models-0.64.9.dist-info → hestia_earth_models-0.64.11.dist-info}/top_level.txt +0 -0
@@ -1,13 +1,13 @@
1
1
  from typing import Optional
2
-
2
+ from hestia_earth.schema import TermTermType
3
3
  from hestia_earth.utils.lookup import download_lookup
4
- from hestia_earth.utils.model import find_term_match
4
+ from hestia_earth.utils.model import find_term_match, filter_list_term_type
5
5
  from hestia_earth.utils.tools import list_sum, safe_parse_date
6
6
 
7
- from .lookup import factor_value, _term_factor_value, _aware_factor_value, fallback_country
7
+ from hestia_earth.models.log import logRequirements, debugValues, log_as_table
8
+ from .lookup import all_factor_value, _term_factor_value, _aware_factor_value, fallback_country
8
9
  from .product import find_by_product
9
10
  from .site import region_level_1_id
10
- from ..log import logRequirements
11
11
 
12
12
 
13
13
  def impact_end_year(impact_assessment: dict) -> int:
@@ -88,8 +88,9 @@ def get_country_id(impact_assessment: dict) -> str:
88
88
  return impact_assessment.get('country', get_site(impact_assessment).get('country', {})).get('@id')
89
89
 
90
90
 
91
- def impact_lookup_value(model: str, term_id: str, impact: dict, lookup_col: str,
92
- grouped_key: Optional[str] = None) -> float:
91
+ def impact_emission_lookup_value(
92
+ model: str, term_id: str, impact: dict, lookup_col: str, grouped_key: Optional[str] = None
93
+ ) -> float:
93
94
  """
94
95
  Calculate the value of the impact based on lookup factors and emissions value.
95
96
 
@@ -105,20 +106,31 @@ def impact_lookup_value(model: str, term_id: str, impact: dict, lookup_col: str,
105
106
  The lookup column to fetch the factors from.
106
107
  grouped_key : str
107
108
  key of grouped data to extract in a lookup table
109
+
108
110
  Returns
109
111
  -------
110
112
  int
111
113
  The impact total value.
112
114
  """
113
- nodes = impact.get('emissionsResourceUse', [])
114
-
115
- factors = list(map(factor_value(model, term_id, 'emission.csv', lookup_col, grouped_key), nodes))
116
- values = [value for value in factors if value is not None]
117
- return list_sum(values) if len(values) > 0 else None
118
-
119
-
120
- def impact_country_value(model: str, term_id: str, impact: dict, lookup: str, group_key: str = None,
121
- country_fallback: bool = False, default_no_emissions=None) -> float:
115
+ return all_factor_value(
116
+ model=model,
117
+ term_id=term_id,
118
+ node=impact,
119
+ lookup_name='emission.csv',
120
+ lookup_col=lookup_col,
121
+ blank_nodes=filter_list_term_type(impact.get('emissionsResourceUse', []), TermTermType.EMISSION),
122
+ grouped_key=grouped_key
123
+ )
124
+
125
+
126
+ def impact_country_value(
127
+ model: str,
128
+ term_id: str,
129
+ impact: dict,
130
+ lookup: str,
131
+ group_key: str = None,
132
+ country_fallback: bool = False,
133
+ ) -> float:
122
134
  """
123
135
  Calculate the value of the impact based on lookup factors and `site.country.@id`.
124
136
 
@@ -137,21 +149,29 @@ def impact_country_value(model: str, term_id: str, impact: dict, lookup: str, gr
137
149
  country_fallback : bool
138
150
  Optional: if True fallback to default `region-world` country_id if country_id in `ImpactAssessment` not found in
139
151
  lookup file containing factors.
140
- default_no_emissions :
141
- Optional: if set, will return this value if no contributing terms found in emissionsResourceUse
142
152
 
143
153
  Returns
144
154
  -------
145
155
  int
146
156
  The impact total value.
147
157
  """
148
- nodes = impact.get('emissionsResourceUse', [])
158
+ term_type = TermTermType.RESOURCEUSE.value if 'resourceUse' in lookup else TermTermType.EMISSION.value
159
+ nodes = filter_list_term_type(impact.get('emissionsResourceUse', []), term_type)
160
+
149
161
  country_id = get_country_id(impact)
150
162
  country_id = fallback_country(country_id, [download_lookup(lookup)]) if country_fallback else country_id
151
163
 
152
- factors = list(map(_term_factor_value(model, term_id, lookup, country_id, group_key), nodes))
153
- values = [value for value in factors if value is not None]
154
- return list_sum(values) if len(values) > 0 else default_no_emissions
164
+ values = list(map(_term_factor_value(model, term_id, lookup, country_id, group_key), nodes))
165
+ debugValues(impact, model=model, term=term_id,
166
+ values_used=log_as_table(values))
167
+
168
+ all_with_factors = all([v.get('coefficient') is not None for v in values if v.get('value') is not None])
169
+ values = [float((v.get('value') or 0) * (v.get('coefficient') or 0)) for v in values]
170
+
171
+ # fail if some factors are missing
172
+ return None if not all_with_factors else (
173
+ list_sum(values) if len(values) > 0 else 0
174
+ )
155
175
 
156
176
 
157
177
  def impact_aware_value(model: str, term_id: str, impact: dict, lookup: str, group_key: str = None) -> float:
@@ -210,9 +230,14 @@ def impact_endpoint_value(model: str, term_id: str, impact: dict, lookup_col: st
210
230
  i.get('methodModel').get('@id') == model or
211
231
  not i.get('methodModel').get('@id').startswith(model[0:6]) # allow other non-related models to be accounted for
212
232
  )]
213
- factors = list(map(factor_value(model, term_id, 'characterisedIndicator.csv', lookup_col), nodes))
214
- values = [value for value in factors if value is not None]
215
- return list_sum(values) if len(values) > 0 else None
233
+ return all_factor_value(
234
+ model=model,
235
+ term_id=term_id,
236
+ node=impact,
237
+ lookup_name='characterisedIndicator.csv',
238
+ lookup_col=lookup_col,
239
+ blank_nodes=nodes
240
+ )
216
241
 
217
242
 
218
243
  def emission_value(impact_assessment: dict, term_id: str):
@@ -6,7 +6,7 @@ from hestia_earth.utils.lookup import (
6
6
  )
7
7
  from hestia_earth.utils.tools import list_sum, safe_parse_float, non_empty_list
8
8
 
9
- from ..log import debugValues
9
+ from ..log import debugValues, log_as_table, debugMissingLookup
10
10
 
11
11
 
12
12
  def _node_value(node):
@@ -14,7 +14,7 @@ def _node_value(node):
14
14
  return list_sum(value) if isinstance(value, list) else value
15
15
 
16
16
 
17
- def factor_value(model: str, term_id: str, lookup_name: str, lookup_col: str, grouped_key: Optional[str] = None):
17
+ def _factor_value(model: str, term_id: str, lookup_name: str, lookup_col: str, grouped_key: Optional[str] = None):
18
18
  lookup = download_lookup(lookup_name)
19
19
 
20
20
  def get_value(data: dict):
@@ -33,11 +33,41 @@ def factor_value(model: str, term_id: str, lookup_name: str, lookup_col: str, gr
33
33
  operation=data.get('operation', {}).get('@id'),
34
34
  value=value,
35
35
  coefficient=coefficient)
36
- return value * coefficient
37
- return None
36
+ return {'id': node_term_id, 'value': value, 'coefficient': coefficient}
38
37
  return get_value
39
38
 
40
39
 
40
+ def all_factor_value(
41
+ model: str,
42
+ term_id: str,
43
+ node: dict,
44
+ lookup_name: str,
45
+ lookup_col: str,
46
+ blank_nodes: List[dict],
47
+ grouped_key: Optional[str] = None,
48
+ default_no_values=0
49
+ ):
50
+ values = list(map(_factor_value(model, term_id, lookup_name, lookup_col, grouped_key), blank_nodes))
51
+
52
+ missing_values = set([v.get('id') for v in values if v.get('value') is not None and v.get('coefficient') is None])
53
+ all_with_factors = all([v.get('coefficient') is not None for v in values if v.get('value') is not None])
54
+
55
+ for term_id in missing_values:
56
+ debugMissingLookup(lookup_name, 'termid', term_id, lookup_col, None)
57
+
58
+ debugValues(node, model=model, term=term_id,
59
+ all_with_factors=all_with_factors,
60
+ missing_lookup_factor=';'.join(missing_values),
61
+ values_used=log_as_table(values))
62
+
63
+ values = [float((v.get('value') or 0) * (v.get('coefficient') or 0)) for v in values]
64
+
65
+ # fail if some factors are missing
66
+ return None if not all_with_factors else (
67
+ list_sum(values) if len(values) > 0 else default_no_values
68
+ )
69
+
70
+
41
71
  def _term_factor_value(model: str, term_id: str, lookup_name: str, lookup_term_id: str, group_key: str = None):
42
72
  lookup = download_lookup(lookup_name, False) # avoid saving in memory as there could be many different files used
43
73
 
@@ -45,11 +75,10 @@ def _term_factor_value(model: str, term_id: str, lookup_name: str, lookup_term_i
45
75
  node_term_id = data.get('term', {}).get('@id')
46
76
  value = _node_value(data)
47
77
  coefficient = get_table_value(lookup, 'termid', lookup_term_id, column_name(node_term_id))
48
- coefficient = safe_parse_float(extract_grouped_data(coefficient, group_key)) if group_key else coefficient
78
+ coefficient = safe_parse_float(extract_grouped_data(coefficient, group_key) if group_key else coefficient)
49
79
  if value is not None and coefficient is not None:
50
80
  debugValues(data, model=model, term=term_id, node=node_term_id, value=value, coefficient=coefficient)
51
- return value * coefficient
52
- return None
81
+ return {'id': node_term_id, 'value': value, 'coefficient': coefficient}
53
82
  return get_value
54
83
 
55
84
 
@@ -22,7 +22,7 @@ def impact_lookup_value(model: str, term_id: str, impact_assessment: dict, looku
22
22
  get_pesticides_from_inputs(cycle)
23
23
  has_pesticides_inputs = len(pesticides) > 0
24
24
  pesticides_total_value = convert_value_from_cycle(
25
- product, cycle_lookup_value(model, term_id, pesticides, lookup_col, False), model=model, term_id=term_id
25
+ product, cycle_lookup_value(model, term_id, cycle, pesticides, lookup_col), model=model, term_id=term_id
26
26
  ) if has_pesticides_inputs else None
27
27
 
28
28
  logRequirements(impact_assessment, model=model, term=term_id,
@@ -1,12 +1,16 @@
1
+ from functools import cache
2
+
1
3
  from hestia_earth.schema import SchemaType, TermTermType
2
4
  from hestia_earth.utils.api import download_hestia
3
- from hestia_earth.utils.model import find_term_match, linked_node
4
5
  from hestia_earth.utils.lookup import download_lookup, extract_grouped_data, get_table_value, column_name
6
+ from hestia_earth.utils.model import find_term_match, linked_node
5
7
  from hestia_earth.utils.tools import list_sum, safe_parse_float
6
8
 
7
- from ..log import debugMissingLookup
8
9
  from . import _term_id, _include_methodModel
9
10
  from .term import get_lookup_value
11
+ from ..log import debugMissingLookup
12
+
13
+ download_hestia_cached = cache(download_hestia)
10
14
 
11
15
 
12
16
  def _new_property(term, model=None):
@@ -26,7 +30,7 @@ def get_property_lookup_value(model: str, term_id: str, column: str):
26
30
  return get_lookup_value(term, column, model=model, term=term_id)
27
31
 
28
32
 
29
- def find_term_property(term, property: str, default=None) -> dict:
33
+ def find_term_property(term, property: str, default=None, keep_in_memory=False) -> dict:
30
34
  """
31
35
  Get the property by `@id` linked to the `Term` in the glossary.
32
36
 
@@ -38,15 +42,18 @@ def find_term_property(term, property: str, default=None) -> dict:
38
42
  The `term.@id` of the property. Example: `nitrogenContent`.
39
43
  default : Any
40
44
  The default value if the property is not found. Defaults to `None`.
45
+ keep_in_memory: bool
46
+ Should we cache results from download_hestia(). Default False
41
47
 
42
48
  Returns
43
49
  -------
44
50
  dict
45
51
  The property if found, `default` otherwise.
46
52
  """
53
+ download_func = download_hestia_cached if keep_in_memory else download_hestia
47
54
  props = term.get('defaultProperties', []) if isinstance(term, dict) else []
48
55
  term_id = _term_id(term)
49
- props = (download_hestia(term_id) or {}).get('defaultProperties', []) if len(props) == 0 and term_id else props
56
+ props = (download_func(term_id) or {}).get('defaultProperties', []) if len(props) == 0 and term_id else props
50
57
  return find_term_match(props, property, default)
51
58
 
52
59
 
@@ -673,8 +673,8 @@ def get_land_cover_siteTypes():
673
673
  return search({
674
674
  "bool": {
675
675
  "must": [
676
- {"match": {"@type": "Term"}},
677
- {"match": {"termType": "landCover"}}
676
+ {"match": {"@type": SchemaType.TERM.value}},
677
+ {"match": {"termType": TermTermType.LANDCOVER.value}}
678
678
  ],
679
679
  "should": [{"match": {"name": siteType.value}} for siteType in SiteSiteType],
680
680
  "minimum_should_match": 1
@@ -682,13 +682,20 @@ def get_land_cover_siteTypes():
682
682
  }, limit=LIMIT)
683
683
 
684
684
 
685
- def download_all_land_cover_terms():
686
- result = search({
685
+ def get_land_cover_terms():
686
+ """
687
+ Find all `Land Cover` terms from the Glossary: https://hestia.earth/glossary?termType=landCover
688
+
689
+ Returns
690
+ -------
691
+ List of landCover terms with associated siteTypes.
692
+ """
693
+ terms = search({
687
694
  "bool": {
688
695
  "must": [
689
- {"match": {"@type": "Term"}},
690
- {"match": {"termType": "landCover"}}
696
+ {"match": {"@type": SchemaType.TERM.value}},
697
+ {"match": {"termType": TermTermType.LANDCOVER.value}}
691
698
  ]
692
699
  },
693
- }, fields=['@id', 'nameNormalized', 'subClassOf'], limit=10000)
694
- return result
700
+ }, limit=LIMIT, fields=['@id'])
701
+ return list(map(lambda n: n["@id"], terms))
@@ -1 +1 @@
1
- VERSION = '0.64.9'
1
+ VERSION = '0.64.11'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hestia-earth-models
3
- Version: 0.64.9
3
+ Version: 0.64.11
4
4
  Summary: HESTIA's set of modules for filling gaps in the activity data using external datasets (e.g. populating soil properties with a geospatial dataset using provided coordinates) and internal lookups (e.g. populating machinery use from fuel use). Includes rules for when gaps should be filled versus not (e.g. never gap fill yield, gap fill crop residue if yield provided etc.).
5
5
  Home-page: https://gitlab.com/hestia-earth/hestia-engine-models
6
6
  Author: HESTIA Team
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3.6
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: hestia-earth.schema==30.*
15
- Requires-Dist: hestia-earth.utils>=0.13.5
15
+ Requires-Dist: hestia-earth.utils>=0.13.10
16
16
  Requires-Dist: python-dateutil>=2.8.1
17
17
  Requires-Dist: CurrencyConverter==0.16.8
18
18
  Requires-Dist: haversine>=2.7.0