hestia-earth-models 0.62.2__py3-none-any.whl → 0.62.4__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 (50) hide show
  1. hestia_earth/models/agribalyse2016/fuelElectricity.py +1 -1
  2. hestia_earth/models/cycle/animal/input/hestiaAggregatedData.py +1 -1
  3. hestia_earth/models/cycle/cycleDuration.py +7 -2
  4. hestia_earth/models/cycle/input/hestiaAggregatedData.py +1 -1
  5. hestia_earth/models/cycle/product/price.py +5 -1
  6. hestia_earth/models/cycle/product/revenue.py +6 -7
  7. hestia_earth/models/ecoinventV3/__init__.py +25 -52
  8. hestia_earth/models/ecoinventV3/utils.py +40 -0
  9. hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py +92 -91
  10. hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +15 -105
  11. hestia_earth/models/faostat2018/liveweightPerHead.py +1 -1
  12. hestia_earth/models/faostat2018/product/price.py +1 -2
  13. hestia_earth/models/geospatialDatabase/croppingIntensity.py +2 -1
  14. hestia_earth/models/geospatialDatabase/utils.py +1 -1
  15. hestia_earth/models/ipcc2019/aboveGroundCropResidueTotal.py +15 -10
  16. hestia_earth/models/ipcc2019/belowGroundCropResidue.py +16 -11
  17. hestia_earth/models/ipcc2019/carbonContent.py +1 -1
  18. hestia_earth/models/ipcc2019/croppingDuration.py +2 -2
  19. hestia_earth/models/ipcc2019/ligninContent.py +1 -1
  20. hestia_earth/models/ipcc2019/nitrogenContent.py +1 -1
  21. hestia_earth/models/ipcc2019/organicCarbonPerHa.py +3 -3
  22. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +5 -5
  23. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +17 -17
  24. hestia_earth/models/koble2014/cropResidueManagement.py +1 -1
  25. hestia_earth/models/linkedImpactAssessment/emissions.py +15 -14
  26. hestia_earth/models/log.py +1 -1
  27. hestia_earth/models/mocking/search-results.json +8 -16
  28. hestia_earth/models/pooreNemecek2018/longFallowPeriod.py +1 -1
  29. hestia_earth/models/preload_requests.py +1 -1
  30. hestia_earth/models/requirements.py +6 -6
  31. hestia_earth/models/site/management.py +38 -35
  32. hestia_earth/models/site/organicCarbonPerHa.py +1 -1
  33. hestia_earth/models/utils/__init__.py +1 -1
  34. hestia_earth/models/utils/blank_node.py +14 -9
  35. hestia_earth/models/utils/cycle.py +12 -12
  36. hestia_earth/models/utils/measurement.py +3 -3
  37. hestia_earth/models/utils/site.py +1 -1
  38. hestia_earth/models/utils/term.py +2 -1
  39. hestia_earth/models/version.py +1 -1
  40. {hestia_earth_models-0.62.2.dist-info → hestia_earth_models-0.62.4.dist-info}/METADATA +12 -12
  41. {hestia_earth_models-0.62.2.dist-info → hestia_earth_models-0.62.4.dist-info}/RECORD +50 -49
  42. {hestia_earth_models-0.62.2.dist-info → hestia_earth_models-0.62.4.dist-info}/WHEEL +1 -1
  43. tests/models/cycle/product/test_revenue.py +0 -3
  44. tests/models/cycle/test_cycleDuration.py +1 -1
  45. tests/models/faostat2018/test_liveweightPerHead.py +9 -0
  46. tests/models/site/test_management.py +31 -12
  47. tests/models/test_ecoinventV3.py +12 -0
  48. tests/models/test_ecoinventV3AndEmberClimate.py +5 -72
  49. {hestia_earth_models-0.62.2.dist-info → hestia_earth_models-0.62.4.dist-info}/LICENSE +0 -0
  50. {hestia_earth_models-0.62.2.dist-info → hestia_earth_models-0.62.4.dist-info}/top_level.txt +0 -0
@@ -15,10 +15,10 @@ condensed into a single node to aid readability.
15
15
  """
16
16
  from functools import reduce
17
17
 
18
- from hestia_earth.schema import SchemaType, TermTermType
18
+ from hestia_earth.schema import SchemaType, TermTermType, SiteSiteType
19
19
  from hestia_earth.utils.api import download_hestia
20
20
  from hestia_earth.utils.model import filter_list_term_type, linked_node
21
- from hestia_earth.utils.tools import safe_parse_float
21
+ from hestia_earth.utils.tools import safe_parse_float, flatten
22
22
  from hestia_earth.utils.blank_node import get_node_value
23
23
 
24
24
  from hestia_earth.models.log import logRequirements, logShouldRun, log_blank_nodes_id
@@ -120,6 +120,9 @@ INPUT_RULES = {
120
120
  )
121
121
  )
122
122
  }
123
+ _SKIP_LAND_COVER_SITE_TYPES = [
124
+ SiteSiteType.CROPLAND.value
125
+ ]
123
126
 
124
127
 
125
128
  def management(data: dict):
@@ -134,12 +137,11 @@ def _extract_node_value(node: dict) -> dict:
134
137
  def _include(value: dict, keys: list) -> dict: return {k: v for k, v in value.items() if k in keys}
135
138
 
136
139
 
137
- def _default_dates(cycle: dict, values: list) -> list:
138
- """Only uses the dates from the cycle if they are missing from the item."""
140
+ def _default_dates(cycle: dict, values: list):
139
141
  return [(_include(cycle, ["startDate", "endDate"]) | v) for v in values]
140
142
 
141
143
 
142
- def _overwrite_dates(cycle: dict, values: list) -> list:
144
+ def _dates_from_current_cycle(cycle: dict, values: list) -> list:
143
145
  """Always uses the dates from the cycle."""
144
146
  return [v | _include(cycle, ["startDate", "endDate"]) for v in values]
145
147
 
@@ -156,14 +158,14 @@ def _get_landCover_term_id(product: dict) -> str:
156
158
 
157
159
 
158
160
  def _get_relevant_items(
159
- cycles: list[dict], item_name: str, relevant_terms: list, date_fill: callable = _default_dates
160
- ) -> list[tuple]:
161
+ cycles: list[dict], item_name: str, relevant_terms: list, date_fill: callable = _default_dates
162
+ ) -> list:
161
163
  """
162
- Get items (optionally in tuples with site_type) from the list of cycles with any of the relevant terms.
164
+ Get items from the list of cycles with any of the relevant terms.
163
165
  Also adds dates if missing.
164
166
  """
165
167
  return [
166
- (item, cycle.get("site", {}).get("siteType", ""))
168
+ item
167
169
  for cycle in cycles
168
170
  for item in date_fill(cycle=cycle, values=filter_list_term_type(cycle.get(item_name, []), relevant_terms))
169
171
  ]
@@ -213,24 +215,25 @@ def _get_relevant_inputs(cycles: list[dict]) -> list:
213
215
  return relevant_inputs
214
216
 
215
217
 
216
- def _should_run_all_products(cycles):
218
+ def _should_run_all_products(cycles: list, site_type: str):
217
219
  products_land_cover = [
218
220
  _extract_node_value(
219
221
  _include(
220
222
  value=product,
221
223
  keys=["term", "value", "startDate", "endDate", "properties"]
222
224
  )
223
- ) for product, _ in _get_relevant_items(
225
+ ) for product in _get_relevant_items(
224
226
  cycles=cycles,
225
227
  item_name="products",
226
228
  relevant_terms=[TermTermType.LANDCOVER]
227
229
  )
228
- ]
230
+ ] if site_type else []
231
+
229
232
  products_crop_forage = _get_relevant_items(
230
233
  cycles=cycles,
231
234
  item_name="products",
232
235
  relevant_terms=[TermTermType.CROP, TermTermType.FORAGE],
233
- date_fill=_overwrite_dates
236
+ date_fill=_dates_from_current_cycle
234
237
  )
235
238
  products_crop_forage = [
236
239
  _copy_item_if_exists(
@@ -241,32 +244,32 @@ def _should_run_all_products(cycles):
241
244
  "value": 100
242
245
  }
243
246
  )
244
- for product in list(filter(_get_landCover_term_id, [i[0] for i in products_crop_forage]))
245
- ]
246
- products_animal_with_site_type = _get_relevant_items(
247
- cycles=cycles,
248
- item_name="products",
249
- relevant_terms=[TermTermType.LIVEANIMAL, TermTermType.ANIMALPRODUCT]
250
- )
251
- products_animal = [
252
- _copy_item_if_exists(
253
- source=product,
254
- keys=["startDate", "endDate", "properties"],
255
- dest={
256
- "term": linked_node(download_hestia(get_landCover_term_id_from_site_type(site_type))),
257
- "value": 100
258
- }
259
- )
260
- for product, site_type in products_animal_with_site_type if product
261
- ]
262
-
263
- return products_animal, products_crop_forage, products_land_cover
247
+ for product in list(filter(_get_landCover_term_id, [i for i in products_crop_forage]))
248
+ ] if site_type else []
249
+ dates = sorted(list(set(
250
+ flatten([[cycle.get('startDate'), cycle.get('endDate')] for cycle in cycles])
251
+ ))) if site_type not in _SKIP_LAND_COVER_SITE_TYPES else []
252
+ site_type_term = download_hestia(get_landCover_term_id_from_site_type(site_type)) if all([
253
+ len(dates) >= 2,
254
+ site_type
255
+ ]) else None
256
+ products_site_type = [{
257
+ "term": linked_node(site_type_term),
258
+ "value": 100,
259
+ "startDate": dates[0],
260
+ "endDate": dates[-1]
261
+ }] if site_type_term else []
262
+
263
+ return products_site_type, products_crop_forage, products_land_cover
264
264
 
265
265
 
266
266
  def _should_run(site: dict):
267
267
  cycles = related_cycles(site)
268
268
 
269
- products_animal, products_crop_forage, products_land_cover = _should_run_all_products(cycles)
269
+ products_animal, products_crop_forage, products_land_cover = _should_run_all_products(
270
+ cycles=cycles,
271
+ site_type=site.get("siteType", "")
272
+ )
270
273
  all_products = products_land_cover + products_crop_forage + products_animal
271
274
  all_products = condense_nodes(all_products)
272
275
 
@@ -276,7 +279,7 @@ def _should_run(site: dict):
276
279
  value=practice,
277
280
  keys=["term", "value", "startDate", "endDate"]
278
281
  )
279
- ) for practice, _ in _get_relevant_items(
282
+ ) for practice in _get_relevant_items(
280
283
  cycles=cycles,
281
284
  item_name="practices",
282
285
  relevant_terms=[
@@ -278,7 +278,7 @@ def _rescale_soc_value(
278
278
  """
279
279
  Rescale an SOC measurement value from a source depth interval to a target depth interval.
280
280
 
281
- Depths are converted from centimetres (Hestia schema) to metres for use in `cdf` function.
281
+ Depths are converted from centimetres (HESTIA schema) to metres for use in `cdf` function.
282
282
 
283
283
  Parameters
284
284
  ----------
@@ -61,7 +61,7 @@ def _filter_list_term_unit(values: list, unit: Any):
61
61
 
62
62
  def is_from_model(node: dict) -> bool:
63
63
  """
64
- Check if the Blank Node came from one of the Hestia Models.
64
+ Check if the Blank Node came from one of the HESTIA Models.
65
65
 
66
66
  Parameters
67
67
  ----------
@@ -267,12 +267,17 @@ def get_total_value_converted_with_min_ratio(
267
267
  total_value_with_property = list_sum([value for term_id, value, prop_value in values if prop_value])
268
268
  total_value_ratio = total_value_with_property / total_value if total_value > 0 else 0
269
269
 
270
- debugValues(node, model=model, term=term, property_id=prop_id,
271
- total_value=total_value,
272
- total_value_with_property=total_value_with_property,
273
- total_value_ratio=total_value_ratio,
274
- min_value_ratio=min_ratio,
275
- conversion_details=value_logs)
270
+ logs = {
271
+ f"{prop_id}-term-id": prop_id,
272
+ f"{prop_id}-total-value": total_value,
273
+ f"{prop_id}-total-value-with-property": total_value_with_property,
274
+ f"{prop_id}-total-value-with-ratio": total_value_ratio,
275
+ f"{prop_id}-min-value-ratio": min_ratio,
276
+ f"{prop_id}-values": value_logs
277
+ }
278
+
279
+ debugValues(node, model=model, term=term,
280
+ **logs)
276
281
 
277
282
  return list_sum([
278
283
  value * prop_value for term_id, value, prop_value in values if all([value, prop_value])
@@ -612,7 +617,7 @@ def cumulative_nodes_lookup_match(
612
617
 
613
618
  class DatestrFormat(Enum):
614
619
  """
615
- Enum representing ISO date formats permitted by Hestia.
620
+ Enum representing ISO date formats permitted by HESTIA.
616
621
 
617
622
  See: https://en.wikipedia.org/wiki/ISO_8601
618
623
  """
@@ -677,7 +682,7 @@ def _check_datestr_format(datestr: str, format: DatestrFormat) -> bool:
677
682
 
678
683
  def _get_datestr_format(datestr: str, default: Optional[Any] = None) -> Union[DatestrFormat, Any, None]:
679
684
  """
680
- Check a datestr against each ISO format permitted by the Hestia schema and
685
+ Check a datestr against each ISO format permitted by the HESTIA schema and
681
686
  return the matching format.
682
687
  """
683
688
  return next(
@@ -1170,7 +1175,7 @@ def group_nodes_by_last_date(nodes: list) -> dict[str, list[dict]]:
1170
1175
  Parameters
1171
1176
  ----------
1172
1177
  nodes : list[dict]
1173
- A list of Hestia format nodes.
1178
+ A list of HESTIA format nodes.
1174
1179
 
1175
1180
  Return
1176
1181
  ------
@@ -22,7 +22,7 @@ def unique_currencies(cycle: dict) -> list:
22
22
  Parameters
23
23
  ----------
24
24
  cycle : dict
25
- The `Cycle` as defined in the Hestia Schema.
25
+ The `Cycle` as defined in the HESTIA Schema.
26
26
 
27
27
  Returns
28
28
  -------
@@ -41,7 +41,7 @@ def default_currency(cycle: dict) -> str:
41
41
  Parameters
42
42
  ----------
43
43
  cycle : dict
44
- The `Cycle` as defined in the Hestia Schema.
44
+ The `Cycle` as defined in the HESTIA Schema.
45
45
 
46
46
  Returns
47
47
  -------
@@ -59,7 +59,7 @@ def get_crop_residue_decomposition_N_total(cycle: dict) -> float:
59
59
  Parameters
60
60
  ----------
61
61
  cycle : dict
62
- The `Cycle` as defined in the Hestia Schema.
62
+ The `Cycle` as defined in the HESTIA Schema.
63
63
 
64
64
  Returns
65
65
  -------
@@ -87,7 +87,7 @@ def get_excreta_N_total(cycle: dict) -> float:
87
87
  Parameters
88
88
  ----------
89
89
  cycle : dict
90
- The `Cycle` as defined in the Hestia Schema.
90
+ The `Cycle` as defined in the HESTIA Schema.
91
91
 
92
92
  Returns
93
93
  -------
@@ -115,7 +115,7 @@ def get_organic_fertiliser_N_total(cycle: dict) -> float:
115
115
  Parameters
116
116
  ----------
117
117
  cycle : dict
118
- The `Cycle` as defined in the Hestia Schema.
118
+ The `Cycle` as defined in the HESTIA Schema.
119
119
 
120
120
  Returns
121
121
  -------
@@ -141,7 +141,7 @@ def get_organic_fertiliser_P_total(cycle: dict) -> float:
141
141
  Parameters
142
142
  ----------
143
143
  cycle : dict
144
- The `Cycle` as defined in the Hestia Schema.
144
+ The `Cycle` as defined in the HESTIA Schema.
145
145
 
146
146
  Returns
147
147
  -------
@@ -165,7 +165,7 @@ def get_inorganic_fertiliser_N_total(cycle: dict) -> float:
165
165
  Parameters
166
166
  ----------
167
167
  cycle : dict
168
- The `Cycle` as defined in the Hestia Schema.
168
+ The `Cycle` as defined in the HESTIA Schema.
169
169
 
170
170
  Returns
171
171
  -------
@@ -189,7 +189,7 @@ def get_inorganic_fertiliser_P_total(cycle: dict) -> float:
189
189
  Parameters
190
190
  ----------
191
191
  cycle : dict
192
- The `Cycle` as defined in the Hestia Schema.
192
+ The `Cycle` as defined in the HESTIA Schema.
193
193
 
194
194
  Returns
195
195
  -------
@@ -260,7 +260,7 @@ def land_occupation_per_ha(model: str, term_id: str, cycle: dict):
260
260
  term_id : str
261
261
  The name of the term running this function. For debugging purpose only.
262
262
  cycle : dict
263
- The `Cycle` as defined in the Hestia Schema.
263
+ The `Cycle` as defined in the HESTIA Schema.
264
264
 
265
265
  Returns
266
266
  -------
@@ -302,9 +302,9 @@ def land_occupation_per_kg(model: str, term_id: str, cycle: dict, site: dict, pr
302
302
  term_id : str
303
303
  The name of the term running this function. For debugging purpose only.
304
304
  cycle : dict
305
- The `Cycle` as defined in the Hestia Schema.
305
+ The `Cycle` as defined in the HESTIA Schema.
306
306
  site : dict
307
- The `Site` as defined in the Hestia Schema.
307
+ The `Site` as defined in the HESTIA Schema.
308
308
  primary_product : dict
309
309
  The primary `Product` of the `Cycle`.
310
310
 
@@ -447,7 +447,7 @@ def check_cycle_site_ids_identical(cycles: list[dict]) -> bool:
447
447
  Parameters
448
448
  ----------
449
449
  cycles : list[dict]
450
- A list of Hestia `Cycle` nodes, see: https://www.hestia.earth/schema/Cycle.
450
+ A list of HESTIA `Cycle` nodes, see: https://www.hestia.earth/schema/Cycle.
451
451
 
452
452
  Returns
453
453
  -------
@@ -111,7 +111,7 @@ def group_measurement_values_by_year(
111
111
  Parameters
112
112
  ----------
113
113
  measurement : dict
114
- A Hestia `Measurement` node, see: https://www.hestia.earth/schema/Measurement.
114
+ A HESTIA `Measurement` node, see: https://www.hestia.earth/schema/Measurement.
115
115
  inner_key: Any | None
116
116
  An optional inner dictionary key for the outputted annualised groups (can be used to merge annualised
117
117
  dictionaries together), default value: `None`.
@@ -165,9 +165,9 @@ def most_relevant_measurement_value_by_depth_and_date(
165
165
  Parameters
166
166
  ----------
167
167
  measurements list[dict]
168
- A list of Hestia `Measurement` nodes, see: https://www.hestia.earth/schema/Measurement.
168
+ A list of HESTIA `Measurement` nodes, see: https://www.hestia.earth/schema/Measurement.
169
169
  term_id : str
170
- The `@id` of a Hestia `Term`. Example: `"sandContent"`
170
+ The `@id` of a HESTIA `Term`. Example: `"sandContent"`
171
171
  date : str
172
172
  The target date in ISO 8601 string format (`"YYYY-MM-DD"`), see: https://en.wikipedia.org/wiki/ISO_8601.
173
173
  depth_upper : int
@@ -126,4 +126,4 @@ def region_factor(model: str, region_id: str, term_id: str, termType: TermTermTy
126
126
  def get_land_cover_term_id(site_type: str):
127
127
  land_cover_terms = get_land_cover_siteTypes()
128
128
  term = next((term for term in land_cover_terms if term["name"].lower() == site_type.lower()), {})
129
- return term.get('@id')
129
+ return term.get("@id", "")
@@ -615,7 +615,7 @@ def get_electricity_grid_mix_terms():
615
615
  list
616
616
  List of matching `Term` as dict.
617
617
  """
618
- return search({
618
+ terms = search({
619
619
  "bool": {
620
620
  "must": [
621
621
  {"match": {"@type": SchemaType.TERM.value}},
@@ -625,6 +625,7 @@ def get_electricity_grid_mix_terms():
625
625
  ],
626
626
  }
627
627
  }, limit=LIMIT, fields=['@type', '@id', 'name', 'termType', 'units'])
628
+ return list(map(lambda n: n["@id"], terms))
628
629
 
629
630
 
630
631
  def get_land_cover_siteTypes():
@@ -1 +1 @@
1
- VERSION = '0.62.2'
1
+ VERSION = '0.62.4'
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hestia-earth-models
3
- Version: 0.62.2
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.).
3
+ Version: 0.62.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
- Author: Hestia Team
6
+ Author: HESTIA Team
7
7
  Author-email: guillaumeroyer.mail@gmail.com
8
8
  License: GPL
9
9
  Platform: UNKNOWN
@@ -11,25 +11,25 @@ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
11
11
  Classifier: Programming Language :: Python :: 3.6
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: hestia-earth.schema ==29.*
15
- Requires-Dist: hestia-earth.utils >=0.13.2
16
- Requires-Dist: python-dateutil >=2.8.1
17
- Requires-Dist: CurrencyConverter ==0.16.8
18
- Requires-Dist: haversine >=2.7.0
14
+ Requires-Dist: hestia-earth.schema==29.*
15
+ Requires-Dist: hestia-earth.utils>=0.13.2
16
+ Requires-Dist: python-dateutil>=2.8.1
17
+ Requires-Dist: CurrencyConverter==0.16.8
18
+ Requires-Dist: haversine>=2.7.0
19
19
  Requires-Dist: pydash
20
20
  Provides-Extra: spatial
21
- Requires-Dist: hestia-earth.earth-engine >=0.4.7 ; extra == 'spatial'
21
+ Requires-Dist: hestia-earth.earth-engine>=0.4.7; extra == "spatial"
22
22
 
23
- # Hestia Engine Models
23
+ # HESTIA Engine Models
24
24
 
25
25
  [![Pipeline Status](https://gitlab.com/hestia-earth/hestia-engine-models/badges/master/pipeline.svg)](https://gitlab.com/hestia-earth/hestia-engine-models/commits/master)
26
26
  [![Coverage Report](https://gitlab.com/hestia-earth/hestia-engine-models/badges/master/coverage.svg)](https://gitlab.com/hestia-earth/hestia-engine-models/commits/master)
27
27
 
28
- Hestia's set of models for running calculations or retrieving data using external datasets and internal lookups.
28
+ HESTIA's set of models for running calculations or retrieving data using external datasets and internal lookups.
29
29
 
30
30
  ## Documentation
31
31
 
32
- Documentation for every model can be found in the [Hestia API Documentation](https://hestia.earth/docs/#hestia-calculation-models).
32
+ Documentation for every model can be found in the [HESTIA API Documentation](https://hestia.earth/docs/#hestia-calculation-models).
33
33
 
34
34
  ## Install
35
35