hestia-earth-models 0.75.1__py3-none-any.whl → 0.75.3__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 (42) hide show
  1. hestia_earth/models/config/Cycle.json +183 -16
  2. hestia_earth/models/cycle/product/economicValueShare.py +4 -4
  3. hestia_earth/models/emepEea2019/blackCarbonToAirFuelCombustion.py +33 -0
  4. hestia_earth/models/emepEea2019/ch4ToAirFuelCombustion.py +33 -0
  5. hestia_earth/models/emepEea2019/coToAirFuelCombustion.py +33 -0
  6. hestia_earth/models/emepEea2019/nmvocToAirFuelCombustion.py +33 -0
  7. hestia_earth/models/emepEea2019/pm10ToAirFuelCombustion.py +33 -0
  8. hestia_earth/models/emepEea2019/pm25ToAirFuelCombustion.py +33 -0
  9. hestia_earth/models/emepEea2019/tspToAirFuelCombustion.py +33 -0
  10. hestia_earth/models/faostat2018/seed.py +9 -8
  11. hestia_earth/models/geospatialDatabase/histosol.py +31 -11
  12. hestia_earth/models/hestia/aboveGroundCropResidueTotal.py +2 -2
  13. hestia_earth/models/hestia/management.py +5 -4
  14. hestia_earth/models/hestia/soilClassification.py +31 -13
  15. hestia_earth/models/ipcc2019/animal/pastureGrass.py +19 -11
  16. hestia_earth/models/ipcc2019/burning_utils.py +406 -4
  17. hestia_earth/models/ipcc2019/ch4ToAirExcreta.py +26 -8
  18. hestia_earth/models/ipcc2019/ch4ToAirOrganicSoilCultivation.py +8 -11
  19. hestia_earth/models/ipcc2019/co2ToAirOrganicSoilCultivation.py +9 -12
  20. hestia_earth/models/ipcc2019/emissionsToAirOrganicSoilBurning.py +516 -0
  21. hestia_earth/models/ipcc2019/n2OToAirOrganicSoilCultivationDirect.py +10 -13
  22. hestia_earth/models/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning.py +56 -433
  23. hestia_earth/models/ipcc2019/organicSoilCultivation_utils.py +2 -2
  24. hestia_earth/models/ipcc2019/pastureGrass.py +19 -11
  25. hestia_earth/models/ipcc2019/pastureGrass_utils.py +17 -10
  26. hestia_earth/models/linkedImpactAssessment/emissions.py +1 -1
  27. hestia_earth/models/mocking/search-results.json +1 -1
  28. hestia_earth/models/pefcrGuidanceDocument2017/__init__.py +13 -0
  29. hestia_earth/models/pefcrGuidanceDocument2017/pesticideToAirPesticideApplication.py +29 -0
  30. hestia_earth/models/pefcrGuidanceDocument2017/pesticideToSoilPesticideApplication.py +29 -0
  31. hestia_earth/models/pefcrGuidanceDocument2017/pesticideToWaterPesticideApplication.py +29 -0
  32. hestia_earth/models/pefcrGuidanceDocument2017/utils.py +55 -0
  33. hestia_earth/models/pooreNemecek2018/saplingsDepreciatedAmountPerCycle.py +1 -1
  34. hestia_earth/models/utils/blank_node.py +68 -0
  35. hestia_earth/models/utils/impact_assessment.py +3 -0
  36. hestia_earth/models/version.py +1 -1
  37. hestia_earth/orchestrator/strategies/merge/merge_node.py +32 -2
  38. {hestia_earth_models-0.75.1.dist-info → hestia_earth_models-0.75.3.dist-info}/METADATA +1 -1
  39. {hestia_earth_models-0.75.1.dist-info → hestia_earth_models-0.75.3.dist-info}/RECORD +42 -29
  40. {hestia_earth_models-0.75.1.dist-info → hestia_earth_models-0.75.3.dist-info}/WHEEL +0 -0
  41. {hestia_earth_models-0.75.1.dist-info → hestia_earth_models-0.75.3.dist-info}/licenses/LICENSE +0 -0
  42. {hestia_earth_models-0.75.1.dist-info → hestia_earth_models-0.75.3.dist-info}/top_level.txt +0 -0
@@ -10,6 +10,7 @@ from hestia_earth.models.utils.completeness import _is_term_type_complete, _is_t
10
10
  from hestia_earth.models.utils.cycle import get_animals_by_period
11
11
  from . import MODEL
12
12
  from .pastureGrass_utils import (
13
+ has_cycle_inputs_feed,
13
14
  practice_input_id,
14
15
  should_run_practice,
15
16
  calculate_meanDE,
@@ -56,7 +57,11 @@ REQUIREMENTS = {
56
57
  "properties": [{
57
58
  "@type": "Property",
58
59
  "value": "",
59
- "term.@id": ["neutralDetergentFibreContent", "energyContentHigherHeatingValue"]
60
+ "term.@id": [
61
+ "neutralDetergentFibreContent",
62
+ "energyContentHigherHeatingValue",
63
+ "energyDigestibilityRuminants"
64
+ ]
60
65
  }]
61
66
  }
62
67
  }],
@@ -175,6 +180,7 @@ def _run_practice(cycle: dict, meanDE: float, meanECHHV: float, REM: float, REG:
175
180
  GE = (
176
181
  calculate_GE(animal_values, REM, REG, NEwool, NEm_feed, NEg_feed) / (meanDE/100)
177
182
  ) if meanDE else 0
183
+ has_positive_GE_value = GE >= 0
178
184
 
179
185
  def run(practice: dict):
180
186
  key = practice.get('key', {})
@@ -206,11 +212,12 @@ def _run_practice(cycle: dict, meanDE: float, meanECHHV: float, REM: float, REG:
206
212
  logRequirements(cycle, model=MODEL, term=input_term_id, model_key=MODEL_KEY,
207
213
  feed_logs=log_as_table(log_feed),
208
214
  has_positive_feed_values=has_positive_feed_values,
215
+ has_positive_GE_value=has_positive_GE_value,
209
216
  animal_logs=logs,
210
217
  animal_lookups=animal_lookups,
211
218
  animal_properties=animal_properties)
212
219
 
213
- should_run = all([has_positive_feed_values])
220
+ should_run = all([has_positive_feed_values, has_positive_GE_value])
214
221
  logShouldRun(cycle, MODEL, input_term_id, should_run, model_key=MODEL_KEY)
215
222
 
216
223
  return _input(input_term_id, value) if should_run else None
@@ -225,10 +232,8 @@ def _should_run(cycle: dict, practices: dict):
225
232
  freshForage_incomplete = _is_term_type_incomplete(cycle, 'freshForage')
226
233
  all_animals_have_value = all([a.get('value', 0) > 0 for a in cycle.get('animals', [])])
227
234
 
228
- has_cycle_inputs_feed = any([i.get('isAnimalFeed', False) for i in cycle.get('inputs', [])])
229
-
230
- meanDE = calculate_meanDE(practices)
231
- meanECHHV = calculate_meanECHHV(practices)
235
+ meanDE = calculate_meanDE(cycle, practices)
236
+ meanECHHV = calculate_meanECHHV(cycle, practices)
232
237
  REM = calculate_REM(meanDE)
233
238
  REG = calculate_REG(meanDE)
234
239
 
@@ -239,7 +244,6 @@ def _should_run(cycle: dict, practices: dict):
239
244
  animalFeed_complete,
240
245
  animalPopulation_complete,
241
246
  freshForage_incomplete,
242
- has_cycle_inputs_feed,
243
247
  all_animals_have_value,
244
248
  has_practice_termType_system,
245
249
  has_practice_pastureGrass_with_landCover_key,
@@ -252,12 +256,11 @@ def _should_run(cycle: dict, practices: dict):
252
256
  term_type_animalFeed_complete=animalFeed_complete,
253
257
  term_type_animalPopulation_complete=animalPopulation_complete,
254
258
  term_type_freshForage_incomplete=freshForage_incomplete,
255
- has_cycle_inputs_feed=has_cycle_inputs_feed,
256
259
  all_animals_have_value=all_animals_have_value,
257
260
  has_practice_termType_system=has_practice_termType_system,
258
261
  has_practice_pastureGrass_with_landCover_key=has_practice_pastureGrass_with_landCover_key,
259
- grass_MeanDE=calculate_meanDE(practices, term=term_id),
260
- grass_MeanECHHV=calculate_meanECHHV(practices, term=term_id),
262
+ grass_MeanDE=calculate_meanDE(cycle, practices, term=term_id),
263
+ grass_MeanECHHV=calculate_meanECHHV(cycle, practices, term=term_id),
261
264
  grass_REM=REM,
262
265
  grass_REG=REG)
263
266
 
@@ -266,9 +269,14 @@ def _should_run(cycle: dict, practices: dict):
266
269
  return should_run, meanDE, meanECHHV, REM, REG, systems
267
270
 
268
271
 
269
- def run(cycle: dict):
272
+ def _run(cycle: dict):
270
273
  practices = list(filter(should_run_practice(cycle), cycle.get('practices', [])))
271
274
  should_run, meanDE, meanECHHV, REM, REG, systems = _should_run(cycle, practices)
272
275
  return non_empty_list(
273
276
  map(_run_practice(cycle, meanDE, meanECHHV, REM, REG, systems), practices)
274
277
  ) if should_run else []
278
+
279
+
280
+ def run(cycle: dict):
281
+ # determines if this model or animal model should run
282
+ return _run(cycle) if has_cycle_inputs_feed(cycle) else []
@@ -2,12 +2,13 @@ from hestia_earth.schema import TermTermType
2
2
  from hestia_earth.utils.api import download_hestia
3
3
  from hestia_earth.utils.lookup import download_lookup, get_table_value, extract_grouped_data
4
4
  from hestia_earth.utils.tools import list_sum, safe_parse_float
5
+ from hestia_earth.utils.model import find_term_match
5
6
 
6
7
  from hestia_earth.models.log import debugValues
7
8
  from hestia_earth.models.utils import weighted_average
8
9
  from hestia_earth.models.utils.input import get_feed_inputs
9
10
  from hestia_earth.models.utils.term import get_lookup_value
10
- from hestia_earth.models.utils.property import get_node_property, get_node_property_value, node_property_lookup_value
11
+ from hestia_earth.models.utils.property import get_node_property, get_node_property_value
11
12
  from .utils import get_milkYield_practice
12
13
  from . import MODEL
13
14
 
@@ -17,6 +18,9 @@ KEY_TERM_TYPES = [
17
18
  ]
18
19
 
19
20
 
21
+ def has_cycle_inputs_feed(cycle: dict): return any([i.get('isAnimalFeed', False) for i in cycle.get('inputs', [])])
22
+
23
+
20
24
  def practice_input_id(practice: dict):
21
25
  return get_lookup_value(practice.get('key', {}), 'grazedPastureGrassInputId', model=MODEL, model_key=MODEL_KEY)
22
26
 
@@ -217,13 +221,16 @@ def _calculate_NEg(cycle: dict, animal: dict) -> float:
217
221
  return _NEg_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal)
218
222
 
219
223
 
220
- def _pastureGrass_key_property_value(column: dict, **log_args):
224
+ def _pastureGrass_key_property_value(node: dict, property_id: dict, **log_args):
221
225
  def get_value(practice: dict):
222
226
  term_id = practice_input_id(practice)
223
- term = download_hestia(term_id)
224
- value = list_sum(practice.get('value', [0]))
225
- lookup_value = node_property_lookup_value(MODEL, term_id, term.get('termType'), column, default=0, **log_args)
226
- return (lookup_value, value)
227
+ # try to find the input with the same id, as it can contain the properties
228
+ input = find_term_match(node.get('inputs', []), term_id) or {
229
+ 'term': download_hestia(term_id)
230
+ }
231
+ property_value = get_node_property_value(MODEL, input, property_id, default=0, **log_args)
232
+ practice_value = list_sum(practice.get('value', [0]))
233
+ return (property_value, practice_value)
227
234
  return get_value
228
235
 
229
236
 
@@ -337,16 +344,16 @@ def calculate_GE(values: list, REM: float, REG: float, NEwool: float, NEm_feed:
337
344
  return ((REM_factor - NEm_feed_corrected)/REM + (REG_factor - NEg_feed_corrected)/REG) if all([REM, REG]) else 0
338
345
 
339
346
 
340
- def calculate_meanECHHV(practices: list, **log_args) -> float:
341
- values = list(map(_pastureGrass_key_property_value('energyContentHigherHeatingValue', **log_args), practices))
347
+ def calculate_meanECHHV(node: dict, practices: list, **log_args) -> float:
348
+ values = list(map(_pastureGrass_key_property_value(node, 'energyContentHigherHeatingValue', **log_args), practices))
342
349
  total_weight = sum([weight/100 for _value, weight in values])
343
350
  return sum([
344
351
  (value * weight/100 if all([value, weight]) else 0) for value, weight in values
345
352
  ]) / total_weight if total_weight > 0 else 0
346
353
 
347
354
 
348
- def calculate_meanDE(practices: list, **log_args) -> float:
349
- values = list(map(_pastureGrass_key_property_value('energyDigestibilityRuminants', **log_args), practices))
355
+ def calculate_meanDE(node: dict, practices: list, **log_args) -> float:
356
+ values = list(map(_pastureGrass_key_property_value(node, 'energyDigestibilityRuminants', **log_args), practices))
350
357
  total_weight = sum([weight/100 for _value, weight in values])
351
358
  meanDE = sum([
352
359
  (value * weight/100 if all([value, weight]) else 0) for value, weight in values
@@ -53,7 +53,7 @@ _GROUP_BY_KEYS = ['term', 'key', 'operation', 'animal']
53
53
 
54
54
 
55
55
  def _emission(model: str, term_id: str, value: float, input: dict, animal={}, extra={}):
56
- emission = _new_emission(term=term_id, model=MODEL, value=value)
56
+ emission = _new_emission(term=term_id, model=model, value=value)
57
57
  emission['methodTier'] = TIER
58
58
  emission['inputs'] = [input]
59
59
  if animal: