hestia-earth-models 0.72.2__py3-none-any.whl → 0.73.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.
Files changed (144) hide show
  1. hestia_earth/models/{akagiEtAl2011AndIpcc2006 → akagiEtAl2011}/__init__.py +1 -1
  2. hestia_earth/models/akagiEtAl2011/ch4ToAirCropResidueBurning.py +32 -0
  3. hestia_earth/models/akagiEtAl2011/nh3ToAirCropResidueBurning.py +32 -0
  4. hestia_earth/models/akagiEtAl2011/noxToAirCropResidueBurning.py +32 -0
  5. hestia_earth/models/akagiEtAl2011/pm25ToAirCropResidueBurning.py +32 -0
  6. hestia_earth/models/akagiEtAl2011/so2ToAirCropResidueBurning.py +32 -0
  7. hestia_earth/models/akagiEtAl2011/utils.py +45 -0
  8. hestia_earth/models/aware/scarcityWeightedWaterUse.py +10 -9
  9. hestia_earth/models/cache_sites.py +8 -4
  10. hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsLandTransformation.py +14 -11
  11. hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsTotalLandUseEffects.py +1 -1
  12. hestia_earth/models/chaudharyBrooks2018/utils.py +5 -3
  13. hestia_earth/models/config/Cycle.json +48 -7
  14. hestia_earth/models/config/ImpactAssessment.json +22 -0
  15. hestia_earth/models/cycle/completeness/electricityFuel.py +1 -1
  16. hestia_earth/models/cycle/completeness/freshForage.py +1 -1
  17. hestia_earth/models/cycle/completeness/soilAmendment.py +1 -1
  18. hestia_earth/models/cycle/input/hestiaAggregatedData.py +1 -2
  19. hestia_earth/models/cycle/product/economicValueShare.py +4 -2
  20. hestia_earth/models/cycle/product/price.py +35 -10
  21. hestia_earth/models/cycle/product/revenue.py +5 -2
  22. hestia_earth/models/dammgen2009/noxToAirExcreta.py +14 -18
  23. hestia_earth/models/ecoinventV3/__init__.py +11 -6
  24. hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +1 -1
  25. hestia_earth/models/emepEea2019/utils.py +2 -1
  26. hestia_earth/models/environmentalFootprintV3_1/environmentalFootprintSingleOverallScore.py +1 -1
  27. hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandOccupation.py +11 -11
  28. hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandTransformation.py +14 -11
  29. hestia_earth/models/faostat2018/liveweightPerHead.py +1 -1
  30. hestia_earth/models/faostat2018/product/price.py +2 -2
  31. hestia_earth/models/faostat2018/seed.py +3 -2
  32. hestia_earth/models/faostat2018/utils.py +32 -18
  33. hestia_earth/models/geospatialDatabase/altitude.py +2 -1
  34. hestia_earth/models/geospatialDatabase/drainageClass.py +2 -1
  35. hestia_earth/models/geospatialDatabase/organicCarbonPerKgSoil.py +2 -1
  36. hestia_earth/models/geospatialDatabase/totalNitrogenPerKgSoil.py +2 -1
  37. hestia_earth/models/geospatialDatabase/totalPhosphorusPerKgSoil.py +2 -1
  38. hestia_earth/models/geospatialDatabase/utils.py +7 -5
  39. hestia_earth/models/globalCropWaterModel2008/rootingDepth.py +1 -1
  40. hestia_earth/models/hestia/brackishWater.py +1 -1
  41. hestia_earth/models/hestia/default_emissions.py +105 -0
  42. hestia_earth/models/hestia/default_resourceUse.py +110 -0
  43. hestia_earth/models/hestia/excretaKgMass.py +7 -9
  44. hestia_earth/models/hestia/freshWater.py +1 -1
  45. hestia_earth/models/hestia/inorganicFertiliser.py +12 -12
  46. hestia_earth/models/hestia/landCover.py +7 -5
  47. hestia_earth/models/hestia/landTransformation100YearAverageDuringCycle.py +3 -0
  48. hestia_earth/models/hestia/landTransformation20YearAverageDuringCycle.py +3 -0
  49. hestia_earth/models/hestia/liveAnimal.py +1 -1
  50. hestia_earth/models/hestia/management.py +1 -1
  51. hestia_earth/models/hestia/netPrimaryProduction.py +1 -1
  52. hestia_earth/models/hestia/organicCarbonPerHa.py +2 -2
  53. hestia_earth/models/hestia/salineWater.py +1 -1
  54. hestia_earth/models/hestia/seed_emissions.py +35 -21
  55. hestia_earth/models/hestia/stockingDensityAnimalHousingAverage.py +1 -1
  56. hestia_earth/models/hestia/totalNitrogenPerKgSoil.py +1 -1
  57. hestia_earth/models/hestia/waterSalinity.py +3 -2
  58. hestia_earth/models/ipcc2006/aboveGroundCropResidueRemoved.py +2 -2
  59. hestia_earth/models/ipcc2006/aboveGroundCropResidueTotal.py +10 -6
  60. hestia_earth/models/ipcc2006/belowGroundCropResidue.py +12 -8
  61. hestia_earth/models/ipcc2019/animal/utils.py +1 -1
  62. hestia_earth/models/ipcc2019/belowGroundCropResidue.py +1 -1
  63. hestia_earth/models/ipcc2019/carbonContent.py +1 -1
  64. hestia_earth/models/ipcc2019/ch4ToAirAquacultureSystems.py +18 -10
  65. hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +6 -6
  66. hestia_earth/models/ipcc2019/ch4ToAirExcreta.py +4 -2
  67. hestia_earth/models/ipcc2019/co2ToAirUreaHydrolysis.py +1 -1
  68. hestia_earth/models/ipcc2019/croppingDuration.py +4 -2
  69. hestia_earth/models/ipcc2019/ligninContent.py +1 -1
  70. hestia_earth/models/{akagiEtAl2011AndIpcc2006 → ipcc2019}/n2OToAirCropResidueBurningDirect.py +8 -4
  71. hestia_earth/models/ipcc2019/nitrogenContent.py +1 -1
  72. hestia_earth/models/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning.py +6 -2
  73. hestia_earth/models/ipcc2019/pastureGrass_utils.py +13 -12
  74. hestia_earth/models/ipcc2019/utils.py +6 -2
  75. hestia_earth/models/koble2014/residueBurnt.py +6 -3
  76. hestia_earth/models/koble2014/residueRemoved.py +1 -1
  77. hestia_earth/models/mocking/search-results.json +1614 -1610
  78. hestia_earth/models/pooreNemecek2018/aboveGroundCropResidueTotal.py +1 -1
  79. hestia_earth/models/pooreNemecek2018/belowGroundCropResidue.py +1 -1
  80. hestia_earth/models/pooreNemecek2018/excretaKgVs.py +1 -1
  81. hestia_earth/models/pooreNemecek2018/freshwaterWithdrawalsDuringCycle.py +44 -6
  82. hestia_earth/models/pooreNemecek2018/longFallowDuration.py +1 -1
  83. hestia_earth/models/pooreNemecek2018/nurseryDensity.py +1 -1
  84. hestia_earth/models/pooreNemecek2018/nurseryDuration.py +1 -1
  85. hestia_earth/models/pooreNemecek2018/plantationDensity.py +1 -1
  86. hestia_earth/models/pooreNemecek2018/plantationLifespan.py +1 -1
  87. hestia_earth/models/pooreNemecek2018/plantationProductiveLifespan.py +3 -1
  88. hestia_earth/models/pooreNemecek2018/saplingsDepreciatedAmountPerCycle.py +1 -1
  89. hestia_earth/models/resourceUseNotRelevant/__init__.py +65 -0
  90. hestia_earth/models/schererPfister2015/nErosionSoilFlux.py +5 -3
  91. hestia_earth/models/schererPfister2015/pErosionSoilFlux.py +5 -3
  92. hestia_earth/models/schererPfister2015/utils.py +5 -4
  93. hestia_earth/models/site/grouped_measurement.py +1 -1
  94. hestia_earth/models/stehfestBouwman2006/n2OToAirSoilFlux_utils.py +1 -1
  95. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirSoilFlux_utils.py +3 -3
  96. hestia_earth/models/utils/background_emissions.py +15 -11
  97. hestia_earth/models/utils/blank_node.py +6 -4
  98. hestia_earth/models/utils/crop.py +1 -1
  99. hestia_earth/models/utils/cropResidue.py +16 -0
  100. hestia_earth/models/utils/cycle.py +1 -1
  101. hestia_earth/models/utils/ecoClimateZone.py +2 -2
  102. hestia_earth/models/utils/excretaManagement.py +1 -1
  103. hestia_earth/models/utils/feedipedia.py +3 -3
  104. hestia_earth/models/utils/fertiliser.py +7 -1
  105. hestia_earth/models/utils/impact_assessment.py +29 -14
  106. hestia_earth/models/utils/inorganicFertiliser.py +2 -2
  107. hestia_earth/models/utils/input.py +34 -1
  108. hestia_earth/models/utils/liveAnimal.py +2 -2
  109. hestia_earth/models/utils/lookup.py +6 -2
  110. hestia_earth/models/utils/measurement.py +4 -4
  111. hestia_earth/models/utils/productivity.py +1 -1
  112. hestia_earth/models/utils/property.py +4 -2
  113. hestia_earth/models/utils/site.py +2 -1
  114. hestia_earth/models/version.py +1 -1
  115. {hestia_earth_models-0.72.2.dist-info → hestia_earth_models-0.73.1.dist-info}/METADATA +1 -1
  116. {hestia_earth_models-0.72.2.dist-info → hestia_earth_models-0.73.1.dist-info}/RECORD +138 -127
  117. tests/models/akagiEtAl2011/test_ch4ToAirCropResidueBurning.py +33 -0
  118. tests/models/akagiEtAl2011/test_nh3ToAirCropResidueBurning.py +33 -0
  119. tests/models/{akagiEtAl2011AndIpcc2006 → akagiEtAl2011}/test_noxToAirCropResidueBurning.py +5 -17
  120. tests/models/akagiEtAl2011/test_pm25ToAirCropResidueBurning.py +33 -0
  121. tests/models/akagiEtAl2011/test_so2ToAirCropResidueBurning.py +33 -0
  122. tests/models/akagiEtAl2011/test_utils.py +18 -0
  123. tests/models/cycle/product/test_price.py +1 -11
  124. tests/models/dammgen2009/test_noxToAirExcreta.py +30 -10
  125. tests/models/geospatialDatabase/test_utils.py +2 -1
  126. tests/models/hestia/test_default_emissions.py +25 -0
  127. tests/models/hestia/test_default_resourceUse.py +26 -0
  128. tests/models/hestia/test_landCover.py +2 -2
  129. tests/models/ipcc2019/test_ch4ToAirAquacultureSystems.py +2 -2
  130. tests/models/{akagiEtAl2011AndIpcc2006/test_nh3ToAirCropResidueBurning.py → ipcc2019/test_n2OToAirCropResidueBurningDirect.py} +2 -2
  131. tests/models/pooreNemecek2018/test_freshwaterWithdrawalsDuringCycle.py +12 -0
  132. tests/models/test_resourceUseNotRelevant.py +27 -0
  133. tests/models/{akagiEtAl2011AndIpcc2006/test_utils.py → utils/test_cropResidue.py} +6 -6
  134. tests/models/utils/test_impact_assessment.py +29 -13
  135. hestia_earth/models/akagiEtAl2011AndIpcc2006/ch4ToAirCropResidueBurning.py +0 -57
  136. hestia_earth/models/akagiEtAl2011AndIpcc2006/nh3ToAirCropResidueBurning.py +0 -57
  137. hestia_earth/models/akagiEtAl2011AndIpcc2006/noxToAirCropResidueBurning.py +0 -57
  138. hestia_earth/models/akagiEtAl2011AndIpcc2006/utils.py +0 -15
  139. tests/models/akagiEtAl2011AndIpcc2006/test_ch4ToAirCropResidueBurning.py +0 -45
  140. tests/models/akagiEtAl2011AndIpcc2006/test_n2OToAirCropResidueBurningDirect.py +0 -46
  141. {hestia_earth_models-0.72.2.dist-info → hestia_earth_models-0.73.1.dist-info}/LICENSE +0 -0
  142. {hestia_earth_models-0.72.2.dist-info → hestia_earth_models-0.73.1.dist-info}/WHEEL +0 -0
  143. {hestia_earth_models-0.72.2.dist-info → hestia_earth_models-0.73.1.dist-info}/top_level.txt +0 -0
  144. /tests/models/{akagiEtAl2011AndIpcc2006 → akagiEtAl2011}/__init__.py +0 -0
@@ -3,7 +3,7 @@ from hestia_earth.utils.model import find_term_match
3
3
  from hestia_earth.utils.tools import safe_parse_float, non_empty_list
4
4
 
5
5
  from hestia_earth.models.log import logRequirements, logShouldRun
6
- from hestia_earth.models.utils.blank_node import get_lookup_value
6
+ from hestia_earth.models.utils.term import get_lookup_value
7
7
  from hestia_earth.models.utils.emission import _new_emission
8
8
  from . import MODEL
9
9
 
@@ -63,15 +63,12 @@ def _find_measurement(site: dict):
63
63
  return measurements[0] if measurements else None
64
64
 
65
65
 
66
- def _run(cycle: dict):
66
+ def _run(cycle: dict, factors: list):
67
67
  cycle_duration = cycle.get('cycleDuration')
68
68
  site = cycle.get('site', {})
69
69
  site_area = site.get('area')
70
- water_term = _find_measurement(site).get('term', {})
71
- factor_value = safe_parse_float(get_lookup_value(water_term, LOOKUPS.get('measurement')))
72
- factor_min = safe_parse_float(get_lookup_value(water_term, f"{LOOKUPS.get('measurement')}-min"))
73
- factor_max = safe_parse_float(get_lookup_value(water_term, f"{LOOKUPS.get('measurement')}-max"))
74
70
  ratio = site_area * cycle_duration / 365
71
+ factor_value, factor_min, factor_max = factors
75
72
  return [_emission(ratio * factor_value, ratio * factor_min, ratio * factor_max)]
76
73
 
77
74
 
@@ -80,7 +77,13 @@ def _should_run(cycle: dict):
80
77
  is_relative = cycle.get('functionalUnit') == CycleFunctionalUnit.RELATIVE.value
81
78
  site = cycle.get('site', {})
82
79
  site_area = site.get('area')
83
- has_water_type = _find_measurement(site) is not None
80
+
81
+ water_measurement = _find_measurement(site)
82
+ has_water_type = water_measurement is not None
83
+ water_term = (water_measurement or {}).get('term', {})
84
+ factor_value = safe_parse_float(get_lookup_value(water_term, LOOKUPS.get('measurement')), default=None)
85
+ factor_min = safe_parse_float(get_lookup_value(water_term, f"{LOOKUPS.get('measurement')}-min"), default=None)
86
+ factor_max = safe_parse_float(get_lookup_value(water_term, f"{LOOKUPS.get('measurement')}-max"), default=None)
84
87
 
85
88
  logRequirements(cycle, model=MODEL, term=TERM_ID,
86
89
  cycle_duration=cycle_duration,
@@ -88,9 +91,14 @@ def _should_run(cycle: dict):
88
91
  site_area=site_area,
89
92
  has_water_type=has_water_type)
90
93
 
91
- should_run = all([cycle_duration, is_relative, site_area, has_water_type])
94
+ should_run = all([
95
+ cycle_duration, is_relative, site_area, has_water_type,
96
+ factor_value is not None, factor_min is not None, factor_max is not None
97
+ ])
92
98
  logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
93
- return should_run
99
+ return should_run, [factor_value, factor_min, factor_max]
94
100
 
95
101
 
96
- def run(cycle: dict): return _run(cycle) if _should_run(cycle) else []
102
+ def run(cycle: dict):
103
+ should_run, factors = _should_run(cycle)
104
+ return _run(cycle, factors) if should_run else []
@@ -172,7 +172,7 @@ def _extract_groupped_data(value: str, DE: float, NDF: float, ionophore: bool, m
172
172
  debugValues({}, model=MODEL, term=TERM_ID,
173
173
  value_key=value_key)
174
174
 
175
- return safe_parse_float(extract_grouped_data(value, value_key), None)
175
+ return safe_parse_float(extract_grouped_data(value, value_key), default=None)
176
176
 
177
177
 
178
178
  def _get_lookup_value(lookup, term: dict, lookup_col: str, DE: float, NDF: float, ionophore: bool, milk_yield: float):
@@ -215,9 +215,9 @@ def _get_default_values(lookup, term: dict):
215
215
  min = get_table_value(lookup, 'termid', term_id, column_name(LOOKUPS['liveAnimal'][4])) if term_id else None
216
216
  max = get_table_value(lookup, 'termid', term_id, column_name(LOOKUPS['liveAnimal'][5])) if term_id else None
217
217
  return {
218
- 'value': safe_parse_float(value, None),
219
- 'min': safe_parse_float(min, None),
220
- 'max': safe_parse_float(max, None)
218
+ 'value': safe_parse_float(value, default=None),
219
+ 'min': safe_parse_float(min, default=None),
220
+ 'max': safe_parse_float(max, default=None)
221
221
  }
222
222
 
223
223
 
@@ -257,10 +257,10 @@ def _should_run(cycle: dict):
257
257
 
258
258
  enteric_factor = safe_parse_float(_get_lookup_value(
259
259
  lookup, term, LOOKUPS['liveAnimal'][1], DE or DE_default, NDF, ionophore, milk_yield
260
- ), None)
260
+ ), default=None)
261
261
  enteric_sd = safe_parse_float(_get_lookup_value(
262
262
  lookup, term, LOOKUPS['liveAnimal'][2], DE or DE_default, NDF, ionophore, milk_yield
263
- ), None)
263
+ ), default=None)
264
264
 
265
265
  default_values = _get_default_values(lookup, term)
266
266
 
@@ -89,7 +89,8 @@ def _get_excreta_b0(country: dict, input: dict):
89
89
  data_values = get_region_lookup_value(lookup_name, country.get('@id'), term_id, model=MODEL, term=TERM_ID)
90
90
  return safe_parse_float(
91
91
  extract_grouped_data(data_values, productivity_key.value) or
92
- extract_grouped_data(data_values, PRODUCTIVITY.HIGH.value) # defaults to high if low is not found
92
+ extract_grouped_data(data_values, PRODUCTIVITY.HIGH.value), # defaults to high if low is not found
93
+ default=None
93
94
  )
94
95
 
95
96
 
@@ -100,7 +101,8 @@ def _get_excretaManagement_MCF_from_lookup(term_id: str, ecoClimateZone: int, du
100
101
  debugMissingLookup(lookup_name, 'termid', term_id, ecoClimateZone, data_values, model=MODEL, term=TERM_ID)
101
102
  return safe_parse_float(
102
103
  extract_grouped_data(data_values, duration_key.value)
103
- or extract_grouped_data(data_values, DEFAULT_DURATION.value) # defaults to 12 months if no duration specified
104
+ or extract_grouped_data(data_values, DEFAULT_DURATION.value), # defaults to 12 months if no duration specified
105
+ default=None
104
106
  ) if data_values else 0
105
107
 
106
108
 
@@ -38,7 +38,7 @@ def _emission(value: float):
38
38
 
39
39
 
40
40
  def _urea_emission_factor(term_id: str):
41
- return safe_parse_float(get_term_lookup(term_id, LOOKUPS['inorganicFertiliser'][2]), None)
41
+ return safe_parse_float(get_term_lookup(term_id, LOOKUPS['inorganicFertiliser'][2]), default=None)
42
42
 
43
43
 
44
44
  def _run(urea_values: list):
@@ -54,7 +54,9 @@ def _practice(value: float, min: float, max: float, sd: float):
54
54
 
55
55
 
56
56
  def _get_value(country: str, col: str):
57
- return safe_parse_float(get_region_lookup_value(LOOKUP_TABLE, country, col, model=MODEL, term=TERM_ID))
57
+ return safe_parse_float(
58
+ get_region_lookup_value(LOOKUP_TABLE, country, col, model=MODEL, term=TERM_ID), default=None
59
+ )
58
60
 
59
61
 
60
62
  def _run(country: str):
@@ -67,7 +69,7 @@ def _run(country: str):
67
69
 
68
70
  def _should_run(cycle: dict):
69
71
  country = cycle.get('site', {}).get('country', {}).get('@id')
70
- croppingDuration = _get_value(country, LOOKUP_COL_PREFIX)
72
+ croppingDuration = _get_value(country, LOOKUP_COL_PREFIX) or 0
71
73
 
72
74
  cycleDuration = cycle.get('cycleDuration', 0)
73
75
  flooded_rice = has_flooded_rice(cycle.get('products', []))
@@ -67,7 +67,7 @@ def _crop_residue_lookup_col(term):
67
67
 
68
68
 
69
69
  def _get_lookup_value(term: dict, column: str):
70
- return safe_parse_float(get_lookup_value(term, column, model=MODEL, term=TERM_ID), None)
70
+ return safe_parse_float(get_lookup_value(term, column, model=MODEL, term=TERM_ID), default=None)
71
71
 
72
72
 
73
73
  # Single crop
@@ -2,7 +2,8 @@ from hestia_earth.schema import EmissionMethodTier
2
2
 
3
3
  from hestia_earth.models.log import logRequirements, logShouldRun
4
4
  from hestia_earth.models.utils.emission import _new_emission
5
- from .utils import _get_crop_residue_burnt_value
5
+ from hestia_earth.models.utils.term import get_lookup_value
6
+ from hestia_earth.models.utils.cropResidue import get_crop_residue_burnt_value
6
7
  from . import MODEL
7
8
 
8
9
  REQUIREMENTS = {
@@ -23,9 +24,11 @@ RETURNS = {
23
24
  "methodTier": "tier 1"
24
25
  }]
25
26
  }
27
+ LOOKUPS = {
28
+ "emission": ["ipcc2019CropResidueBurningFactor"]
29
+ }
26
30
  TERM_ID = 'n2OToAirCropResidueBurningDirect'
27
31
  TIER = EmissionMethodTier.TIER_1.value
28
- DRY_MATTER_FACTOR_TO_N2O = 0.07/1000
29
32
 
30
33
 
31
34
  def _emission(value: float):
@@ -37,11 +40,12 @@ def _emission(value: float):
37
40
 
38
41
  def _run(product_value: list):
39
42
  value = sum(product_value)
40
- return [_emission(value * DRY_MATTER_FACTOR_TO_N2O)]
43
+ factor = get_lookup_value({'termType': 'emission', '@id': TERM_ID}, LOOKUPS['emission'][0])
44
+ return [_emission(value * factor)]
41
45
 
42
46
 
43
47
  def _should_run(cycle: dict):
44
- crop_residue_burnt_value = _get_crop_residue_burnt_value(cycle)
48
+ crop_residue_burnt_value = get_crop_residue_burnt_value(cycle)
45
49
  has_crop_residue_burnt = len(crop_residue_burnt_value) > 0
46
50
 
47
51
  logRequirements(cycle, model=MODEL, term=TERM_ID,
@@ -67,7 +67,7 @@ def _crop_residue_lookup_col(term):
67
67
 
68
68
 
69
69
  def _get_lookup_value(term: dict, column: str):
70
- return safe_parse_float(get_lookup_value(term, column, model=MODEL, term=TERM_ID), None)
70
+ return safe_parse_float(get_lookup_value(term, column, model=MODEL, term=TERM_ID), default=None)
71
71
 
72
72
 
73
73
  # Single crop
@@ -314,7 +314,9 @@ def _get_fuel_factor(fuel_category: _FuelCategory) -> dict:
314
314
  debugMissingLookup(LOOKUP_FILENAME, "FuelCategory", row, target, data.get(target), model=MODEL, term=term_id)
315
315
 
316
316
  return (
317
- {k: parsed for k, v in data.items() if (parsed := safe_parse_float(v, None)) is not None} # remove missing
317
+ {
318
+ k: parsed for k, v in data.items() if (parsed := safe_parse_float(v, default=None)) is not None
319
+ } # remove missing
318
320
  or _DEFAULT_FACTOR # if parsed dict empty, return default
319
321
  )
320
322
 
@@ -343,7 +345,9 @@ def _get_emission_factor(term_id: _EmissionTermId, emission_category: _EmissionC
343
345
  )
344
346
 
345
347
  return (
346
- {k: parsed for k, v in data.items() if (parsed := safe_parse_float(v, None)) is not None} # remove missing
348
+ {
349
+ k: parsed for k, v in data.items() if (parsed := safe_parse_float(v, default=None)) is not None
350
+ } # remove missing
347
351
  or _DEFAULT_FACTOR # if parsed dict empty, return default
348
352
  )
349
353
 
@@ -34,7 +34,7 @@ def _get_activityCoefficient(animal: dict, systems: list) -> float:
34
34
  values = [(
35
35
  safe_parse_float(
36
36
  get_table_value(lookup, 'termid', system.get('term', {}).get('@id'), column_name(term_id)),
37
- 0
37
+ default=0
38
38
  ),
39
39
  list_sum(system.get('value', [0]))
40
40
  ) for system in systems]
@@ -46,7 +46,7 @@ def _calculate_NEm(cycle: dict, animal: dict) -> float:
46
46
  term = animal.get('term', {})
47
47
 
48
48
  mjDayKgCfiNetEnergyMaintenance = safe_parse_float(
49
- get_lookup_value(term, 'mjDayKgCfiNetEnergyMaintenanceIpcc2019', model=MODEL, model_key=MODEL_KEY), 0
49
+ get_lookup_value(term, 'mjDayKgCfiNetEnergyMaintenanceIpcc2019', model=MODEL, model_key=MODEL_KEY), default=0
50
50
  )
51
51
  liveweightPerHead = get_node_property(animal, 'liveweightPerHead', False).get('value', 0)
52
52
  animal_value = animal.get('value', 0)
@@ -102,13 +102,13 @@ def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict) -> float:
102
102
  milkYield = list_sum(milkYieldPractice.get('value', []))
103
103
  EV_milk = safe_parse_float(
104
104
  get_lookup_value(milkYieldPractice.get('term', {}), 'mjKgEvMilkIpcc2019', model=MODEL, model_key=MODEL_KEY),
105
- 0
105
+ default=0
106
106
  )
107
107
  default_fatContent = safe_parse_float(
108
108
  get_lookup_value(
109
109
  milkYieldPractice.get('term', {}), 'defaultFatContentEvMilkIpcc2019', model=MODEL, model_key=MODEL_KEY
110
110
  ),
111
- 7
111
+ default=7
112
112
  )
113
113
  fatContent = get_node_property(milkYieldPractice, 'fatContent').get('value', 0)
114
114
  animal_value = animal.get('value', 0)
@@ -138,9 +138,9 @@ def _calculate_NEwork(cycle: dict, animal: dict, NEm: float) -> float:
138
138
 
139
139
  def _get_pregnancy_ratio_per_birth(animal: dict, value: str) -> float:
140
140
  animalsPerBirth = get_node_property(animal, 'animalsPerBirth').get('value', 3)
141
- single = safe_parse_float(extract_grouped_data(value, 'singleBirth'), 0)
142
- double = safe_parse_float(extract_grouped_data(value, 'doubleBirth'), 0)
143
- tripple = safe_parse_float(extract_grouped_data(value, 'tripleBirthOrMore'))
141
+ single = safe_parse_float(extract_grouped_data(value, 'singleBirth'), default=0)
142
+ double = safe_parse_float(extract_grouped_data(value, 'doubleBirth'), default=0)
143
+ tripple = safe_parse_float(extract_grouped_data(value, 'tripleBirthOrMore'), default=0)
144
144
  return (
145
145
  single if animalsPerBirth <= 1 else
146
146
  ((animalsPerBirth-1)/2)*single * (1-((animalsPerBirth-1)/2)*double) if 1 < animalsPerBirth < 2 else
@@ -153,7 +153,7 @@ def _get_pregnancy_ratio_per_birth(animal: dict, value: str) -> float:
153
153
  def _get_pregnancy_ratio(animal: dict) -> float:
154
154
  term = animal.get('term', {})
155
155
  value = get_lookup_value(term, 'ratioCPregnancyNetEnergyPregnancyIpcc2019', model=MODEL, model_key=MODEL_KEY)
156
- return _get_pregnancy_ratio_per_birth(animal, value) if ';' in value else safe_parse_float(value, 0)
156
+ return _get_pregnancy_ratio_per_birth(animal, value) if ';' in value else safe_parse_float(value, default=0)
157
157
 
158
158
 
159
159
  def _calculate_NEp(cycle: dict, animal: dict, NEm: float) -> float:
@@ -168,7 +168,8 @@ def _calculate_NEg_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
168
168
  term = animal.get('term', {})
169
169
 
170
170
  ratioCNetEnergyGrowthCattleBuffalo = safe_parse_float(
171
- get_lookup_value(term, 'ratioCNetEnergyGrowthCattleBuffaloIpcc2019', model=MODEL, model_key=MODEL_KEY), 0
171
+ get_lookup_value(term, 'ratioCNetEnergyGrowthCattleBuffaloIpcc2019', model=MODEL, model_key=MODEL_KEY),
172
+ default=0
172
173
  )
173
174
  liveweightPerHead = get_node_property(animal, 'liveweightPerHead').get('value', 0)
174
175
  weightAtMaturity = get_node_property(animal, 'weightAtMaturity').get('value', 0)
@@ -190,8 +191,8 @@ def _calculate_NEg_sheepAndGoat(cycle: dict, animal: dict) -> float:
190
191
 
191
192
  MjKgABNetEnergyGrowthSheepGoats = get_lookup_value(
192
193
  term, 'mjKgABNetEnergyGrowthSheepGoatsIpcc2019', model=MODEL, model_key=MODEL_KEY)
193
- MjKg_a = safe_parse_float(extract_grouped_data(MjKgABNetEnergyGrowthSheepGoats, 'a'), 0)
194
- MjKg_b = safe_parse_float(extract_grouped_data(MjKgABNetEnergyGrowthSheepGoats, 'b'), 0)
194
+ MjKg_a = safe_parse_float(extract_grouped_data(MjKgABNetEnergyGrowthSheepGoats, 'a'), default=0)
195
+ MjKg_b = safe_parse_float(extract_grouped_data(MjKgABNetEnergyGrowthSheepGoats, 'b'), default=0)
195
196
  BWi = get_node_property(animal, 'weightAtWeaning').get('value', 0)
196
197
  BWf = get_node_property(animal, 'weightAtOneYear').get('value', 0) or \
197
198
  get_node_property(animal, 'weightAtSlaughter').get('value', 0)
@@ -352,7 +353,7 @@ def calculate_meanDE(practices: list, **log_args) -> float:
352
353
 
353
354
 
354
355
  def product_wool_energy(product: dict):
355
- return safe_parse_float(get_lookup_value(product.get('term', {}), 'mjKgEvWoolNetEnergyWoolIpcc2019'), 24)
356
+ return safe_parse_float(get_lookup_value(product.get('term', {}), 'mjKgEvWoolNetEnergyWoolIpcc2019'), default=24)
356
357
 
357
358
 
358
359
  def should_run_practice(cycle: dict):
@@ -53,7 +53,9 @@ def get_FracNH3NOx_N2O(cycle: dict, term_id: str):
53
53
 
54
54
 
55
55
  def get_yield_dm(term_id: str, term: dict):
56
- return safe_parse_float(get_lookup_value(term, 'IPCC_2019_Ratio_AGRes_YieldDM', model=MODEL, term=term_id), None)
56
+ return safe_parse_float(
57
+ get_lookup_value(term, 'IPCC_2019_Ratio_AGRes_YieldDM', model=MODEL, term=term_id), default=None
58
+ )
57
59
 
58
60
 
59
61
  def get_milkYield_practice(node: dict):
@@ -146,7 +148,9 @@ EF5_FACTORS = {
146
148
 
147
149
 
148
150
  def _get_waterRegime_lookup(model_term_id: str, practice: dict, col: str):
149
- return safe_parse_float(get_lookup_value(practice.get('term', {}), col, model=MODEL, term=model_term_id), None)
151
+ return safe_parse_float(
152
+ get_lookup_value(practice.get('term', {}), col, model=MODEL, term=model_term_id), default=None
153
+ )
150
154
 
151
155
 
152
156
  def _is_wet(ecoClimateZone: str = None):
@@ -31,15 +31,18 @@ LOOKUP_NAME = 'region-crop-cropGroupingResidue-burnt.csv'
31
31
  def _get_default_percent(cycle: dict, term: dict, country_id: str):
32
32
  crop_grouping = get_lookup_value(term, LOOKUPS['crop'][0], model=MODEL, term=TERM_ID)
33
33
  percent = safe_parse_float(
34
- get_region_lookup_value(LOOKUP_NAME, country_id, crop_grouping, model=MODEL, term=TERM_ID), None
34
+ get_region_lookup_value(LOOKUP_NAME, country_id, crop_grouping, model=MODEL, term=TERM_ID), default=None
35
35
  ) if crop_grouping else None
36
- comb_factor = safe_parse_float(get_lookup_value(term, LOOKUPS['crop'][1]))
36
+ comb_factor = safe_parse_float(get_lookup_value(term, LOOKUPS['crop'][1]), default=None)
37
37
  logRequirements(cycle, model=MODEL, term=TERM_ID,
38
38
  crop_grouping=crop_grouping,
39
39
  country_id=country_id,
40
40
  percent=percent,
41
41
  comb_factor=comb_factor)
42
- return percent if comb_factor is None or percent is None else percent * comb_factor
42
+ return percent if any([
43
+ comb_factor is None,
44
+ percent is None
45
+ ]) else percent * comb_factor
43
46
 
44
47
 
45
48
  def _run(cycle: dict, remaining_value: float, primary_product: dict, country_id: str):
@@ -37,7 +37,7 @@ def _get_default_percent(cycle: dict, term: dict, country_id: str):
37
37
  crop_grouping=crop_grouping,
38
38
  country_id=country_id,
39
39
  percent=percent)
40
- return safe_parse_float(percent, None)
40
+ return safe_parse_float(percent, default=None)
41
41
 
42
42
 
43
43
  def _run(cycle: dict, remaining_value: float, primary_product: dict, country_id: str):