hestia-earth-models 0.59.5__py3-none-any.whl → 0.59.6__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 (37) hide show
  1. hestia_earth/models/cycle/animal/milkYield.py +86 -0
  2. hestia_earth/models/cycle/endDate.py +50 -0
  3. hestia_earth/models/cycle/inorganicFertiliser.py +3 -2
  4. hestia_earth/models/cycle/milkYield.py +8 -3
  5. hestia_earth/models/cycle/pre_checks/__init__.py +1 -2
  6. hestia_earth/models/cycle/startDate.py +42 -0
  7. hestia_earth/models/faostat2018/liveweightPerHead.py +77 -41
  8. hestia_earth/models/faostat2018/product/price.py +30 -55
  9. hestia_earth/models/faostat2018/utils.py +10 -2
  10. hestia_earth/models/haversineFormula/transport/distance.py +6 -3
  11. hestia_earth/models/ipcc2006/n2OToAirInorganicFertiliserIndirect.py +1 -1
  12. hestia_earth/models/ipcc2019/organicCarbonPerHa.py +19 -4
  13. hestia_earth/models/ipcc2019/pastureGrass.py +2 -1
  14. hestia_earth/models/linkedImpactAssessment/__init__.py +3 -3
  15. hestia_earth/models/mocking/search-results.json +244 -232
  16. hestia_earth/models/schmidt2007/h2SToAirWasteTreatment.py +58 -0
  17. hestia_earth/models/site/management.py +3 -1
  18. hestia_earth/models/utils/__init__.py +4 -1
  19. hestia_earth/models/utils/animalProduct.py +6 -4
  20. hestia_earth/models/utils/blank_node.py +3 -2
  21. hestia_earth/models/utils/product.py +9 -1
  22. hestia_earth/models/version.py +1 -1
  23. {hestia_earth_models-0.59.5.dist-info → hestia_earth_models-0.59.6.dist-info}/METADATA +1 -1
  24. {hestia_earth_models-0.59.5.dist-info → hestia_earth_models-0.59.6.dist-info}/RECORD +35 -29
  25. tests/models/cycle/animal/test_milkYield.py +43 -0
  26. tests/models/cycle/test_endDate.py +24 -0
  27. tests/models/cycle/test_startDate.py +22 -0
  28. tests/models/faostat2018/product/test_price.py +25 -45
  29. tests/models/faostat2018/test_liveweightPerHead.py +106 -42
  30. tests/models/ipcc2019/test_organicCarbonPerHa.py +8 -0
  31. tests/models/schmidt2007/test_h2SToAirWasteTreatment.py +45 -0
  32. tests/models/utils/test_blank_node.py +71 -3
  33. hestia_earth/models/cycle/pre_checks/startDate.py +0 -52
  34. tests/models/cycle/pre_checks/test_startDate.py +0 -44
  35. {hestia_earth_models-0.59.5.dist-info → hestia_earth_models-0.59.6.dist-info}/LICENSE +0 -0
  36. {hestia_earth_models-0.59.5.dist-info → hestia_earth_models-0.59.6.dist-info}/WHEEL +0 -0
  37. {hestia_earth_models-0.59.5.dist-info → hestia_earth_models-0.59.6.dist-info}/top_level.txt +0 -0
@@ -2,7 +2,13 @@
2
2
  The IPCC model for estimating soil organic carbon stock changes in the 0 - 30cm depth interval due to management
3
3
  changes. This model combines the Tier 1 & Tier 2 methodologies. It first tries to run Tier 2 (only on croplands
4
4
  remaining croplands). If Tier 2 cannot run, it will try to run Tier 1 (for croplands remaining croplands and for
5
- grasslands remaining grasslands). Source:
5
+ grasslands remaining grasslands).
6
+
7
+ More information on this model, including data requirements **and** recommendations, tier methodologies, and examples,
8
+ can be found in the
9
+ [Hestia SOC wiki](https://gitlab.com/hestia-earth/hestia-engine-models/-/wikis/Soil-organic-carbon-modelling).
10
+
11
+ Source:
6
12
  [IPCC 2019, Vol. 4, Chapter 10](https://www.ipcc-nggip.iges.or.jp/public/2019rf/pdf/4_Volume4/19R_V4_Ch05_Cropland.pdf).
7
13
  """
8
14
  from enum import Enum
@@ -846,7 +852,7 @@ def _calc_water_factor(
846
852
  float
847
853
  The water effect on decomposition for a given month, dimensionless, between `0.2129` and `1.5`.
848
854
  """
849
- mappet = min(1.25, precipitation / pet)
855
+ mappet = min(1.25, precipitation / pet) if pet else 1.25
850
856
  return 0.775 if is_irrigated else 0.2129 + (water_factor_slope * (mappet)) - (0.2413 * pow(mappet, 2))
851
857
 
852
858
 
@@ -937,7 +943,8 @@ def _calc_average_nitrogen_content_of_organic_carbon_sources(
937
943
  weighted_values = [
938
944
  c.mass * (c.nitrogen_content if c.nitrogen_content else default_nitrogen_content) for c in carbon_sources
939
945
  ]
940
- return sum(weighted_values) / total_weight if total_weight > 0 else default_nitrogen_content
946
+ should_run = total_weight > 0
947
+ return sum(weighted_values) / total_weight if should_run else 0
941
948
 
942
949
 
943
950
  def _calc_average_lignin_content_of_organic_carbon_sources(
@@ -963,7 +970,8 @@ def _calc_average_lignin_content_of_organic_carbon_sources(
963
970
  weighted_values = [
964
971
  c.mass * (c.lignin_content if c.lignin_content else default_lignin_content) for c in carbon_sources
965
972
  ]
966
- return sum(weighted_values) / total_weight if total_weight > 0 else default_lignin_content
973
+ should_run = total_weight > 0
974
+ return sum(weighted_values) / total_weight if should_run else 0
967
975
 
968
976
 
969
977
  # --- TIER 2 FUNCTIONS: ACTIVE SUB-POOL SOC STOCK ---
@@ -3724,9 +3732,16 @@ def _should_run_inventory_year_tier_2(group: dict) -> bool:
3724
3732
  }
3725
3733
  )
3726
3734
 
3735
+ carbon_input_data_complete = all([
3736
+ group.get(_InventoryKey.CARBON_INPUT, 0) > 0,
3737
+ group.get(_InventoryKey.N_CONTENT, 0) > 0,
3738
+ group.get(_InventoryKey.LIGNIN_CONTENT, 0) > 0,
3739
+ ])
3740
+
3727
3741
  return all([
3728
3742
  not group.get(_InventoryKey.IS_PADDY_RICE),
3729
3743
  monthly_data_complete,
3744
+ carbon_input_data_complete,
3730
3745
  all(key in group.keys() for key in REQUIRED_KEYS_TIER_2),
3731
3746
  ])
3732
3747
 
@@ -497,7 +497,8 @@ def _sum_values(values): return sum([value for term_id, value in values])
497
497
  def _calculate_GE(cycle: dict, meanDE: float, system: dict):
498
498
  animals = [
499
499
  a for a in cycle.get('animals', []) if all([
500
- a.get('value') and a.get('referencePeriod') == AnimalReferencePeriod.AVERAGE.value
500
+ a.get('value'),
501
+ a.get('referencePeriod') == AnimalReferencePeriod.AVERAGE.value
501
502
  ])
502
503
  ]
503
504
 
@@ -75,7 +75,7 @@ def _run_emission(cycle: dict, term_id: str, data: dict):
75
75
 
76
76
  details = values.get('details', {})
77
77
  logRequirements(cycle, model=model, term=term_id,
78
- values=log_as_table([{'impact_assessment_id': key} | value for key, value in details.items()]))
78
+ values=log_as_table([{'impact-assessment-id': key} | value for key, value in details.items()]))
79
79
 
80
80
  logShouldRun(cycle, model, term_id, True, methodTier=TIER,
81
81
  input=term.get('@id'),
@@ -138,8 +138,8 @@ def _group_inputs(group: dict, values: tuple):
138
138
  grouped_inputs['value'] = grouped_inputs['value'] + (emission_value * input_value)
139
139
  # for logging
140
140
  grouped_inputs['details'][input.get('impactAssessment', {}).get('@id')] = {
141
- 'emission_value': emission_value,
142
- 'input_value': input_value
141
+ 'emission-value': emission_value,
142
+ 'input-value': input_value
143
143
  }
144
144
  group[emission_term_id][input_group_key] = grouped_inputs
145
145
  return group