hestia-earth-models 0.57.2__py3-none-any.whl → 0.59.0__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 (109) hide show
  1. hestia_earth/models/cycle/aboveGroundCropResidueTotal.py +17 -12
  2. hestia_earth/models/cycle/excretaKgMass.py +4 -5
  3. hestia_earth/models/cycle/excretaKgN.py +4 -5
  4. hestia_earth/models/cycle/excretaKgVs.py +4 -5
  5. hestia_earth/models/cycle/inorganicFertiliser.py +2 -2
  6. hestia_earth/models/cycle/{irrigated.py → irrigatedTypeUnspecified.py} +4 -4
  7. hestia_earth/models/cycle/liveAnimal.py +9 -11
  8. hestia_earth/models/cycle/milkYield.py +154 -0
  9. hestia_earth/models/cycle/residueIncorporated.py +1 -1
  10. hestia_earth/models/cycle/utils.py +6 -0
  11. hestia_earth/models/emepEea2019/nh3ToAirInorganicFertiliser.py +3 -3
  12. hestia_earth/models/faostat2018/seed.py +2 -3
  13. hestia_earth/models/geospatialDatabase/clayContent.py +17 -4
  14. hestia_earth/models/geospatialDatabase/sandContent.py +17 -4
  15. hestia_earth/models/geospatialDatabase/siltContent.py +2 -2
  16. hestia_earth/models/impact_assessment/irrigated.py +0 -3
  17. hestia_earth/models/ipcc2006/co2ToAirOrganicSoilCultivation.py +2 -2
  18. hestia_earth/models/ipcc2006/n2OToAirCropResidueDecompositionIndirect.py +2 -2
  19. hestia_earth/models/ipcc2006/n2OToAirExcretaDirect.py +1 -1
  20. hestia_earth/models/ipcc2006/n2OToAirExcretaIndirect.py +8 -4
  21. hestia_earth/models/ipcc2006/n2OToAirInorganicFertiliserDirect.py +4 -1
  22. hestia_earth/models/ipcc2006/n2OToAirInorganicFertiliserIndirect.py +1 -1
  23. hestia_earth/models/ipcc2006/n2OToAirOrganicFertiliserDirect.py +1 -1
  24. hestia_earth/models/ipcc2006/n2OToAirOrganicFertiliserIndirect.py +1 -1
  25. hestia_earth/models/ipcc2006/utils.py +11 -8
  26. hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +4 -4
  27. hestia_earth/models/ipcc2019/ch4ToAirFloodedRice.py +16 -7
  28. hestia_earth/models/ipcc2019/co2ToAirSoilCarbonStockChangeManagementChange.py +759 -0
  29. hestia_earth/models/ipcc2019/croppingDuration.py +12 -6
  30. hestia_earth/models/ipcc2019/n2OToAirCropResidueDecompositionDirect.py +5 -52
  31. hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserDirect.py +104 -0
  32. hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserIndirect.py +1 -1
  33. hestia_earth/models/ipcc2019/n2OToAirOrganicFertiliserDirect.py +105 -0
  34. hestia_earth/models/ipcc2019/n2OToAirOrganicFertiliserIndirect.py +1 -1
  35. hestia_earth/models/ipcc2019/no3ToGroundwaterCropResidueDecomposition.py +1 -1
  36. hestia_earth/models/ipcc2019/no3ToGroundwaterExcreta.py +1 -1
  37. hestia_earth/models/ipcc2019/no3ToGroundwaterInorganicFertiliser.py +1 -1
  38. hestia_earth/models/ipcc2019/no3ToGroundwaterOrganicFertiliser.py +1 -1
  39. hestia_earth/models/ipcc2019/organicCarbonPerHa.py +1088 -1268
  40. hestia_earth/models/ipcc2019/pastureGrass.py +4 -4
  41. hestia_earth/models/ipcc2019/utils.py +102 -1
  42. hestia_earth/models/koble2014/aboveGroundCropResidue.py +15 -17
  43. hestia_earth/models/koble2014/cropResidueManagement.py +2 -2
  44. hestia_earth/models/koble2014/utils.py +19 -3
  45. hestia_earth/models/linkedImpactAssessment/__init__.py +4 -2
  46. hestia_earth/models/log.py +15 -3
  47. hestia_earth/models/mocking/search-results.json +184 -118
  48. hestia_earth/models/pooreNemecek2018/excretaKgN.py +6 -7
  49. hestia_earth/models/pooreNemecek2018/excretaKgVs.py +7 -6
  50. hestia_earth/models/pooreNemecek2018/no3ToGroundwaterCropResidueDecomposition.py +3 -2
  51. hestia_earth/models/pooreNemecek2018/no3ToGroundwaterExcreta.py +3 -2
  52. hestia_earth/models/pooreNemecek2018/no3ToGroundwaterInorganicFertiliser.py +3 -2
  53. hestia_earth/models/pooreNemecek2018/saplings.py +0 -1
  54. hestia_earth/models/site/management.py +168 -0
  55. hestia_earth/models/site/organicCarbonPerHa.py +251 -89
  56. hestia_earth/models/stehfestBouwman2006/n2OToAirCropResidueDecompositionDirect.py +3 -2
  57. hestia_earth/models/stehfestBouwman2006/n2OToAirExcretaDirect.py +3 -2
  58. hestia_earth/models/stehfestBouwman2006/n2OToAirInorganicFertiliserDirect.py +3 -2
  59. hestia_earth/models/stehfestBouwman2006/n2OToAirOrganicFertiliserDirect.py +3 -2
  60. hestia_earth/models/stehfestBouwman2006/noxToAirCropResidueDecomposition.py +3 -2
  61. hestia_earth/models/stehfestBouwman2006/noxToAirExcreta.py +3 -2
  62. hestia_earth/models/stehfestBouwman2006/noxToAirInorganicFertiliser.py +3 -2
  63. hestia_earth/models/stehfestBouwman2006/noxToAirOrganicFertiliser.py +3 -2
  64. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirCropResidueDecomposition.py +3 -2
  65. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirExcreta.py +3 -2
  66. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirInorganicFertiliser.py +3 -2
  67. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirOrganicFertiliser.py +3 -2
  68. hestia_earth/models/utils/aggregated.py +1 -0
  69. hestia_earth/models/utils/blank_node.py +394 -72
  70. hestia_earth/models/utils/cropResidue.py +13 -0
  71. hestia_earth/models/utils/cycle.py +18 -9
  72. hestia_earth/models/utils/measurement.py +1 -1
  73. hestia_earth/models/utils/property.py +4 -4
  74. hestia_earth/models/utils/term.py +48 -3
  75. hestia_earth/models/version.py +1 -1
  76. {hestia_earth_models-0.57.2.dist-info → hestia_earth_models-0.59.0.dist-info}/METADATA +5 -9
  77. {hestia_earth_models-0.57.2.dist-info → hestia_earth_models-0.59.0.dist-info}/RECORD +109 -97
  78. {hestia_earth_models-0.57.2.dist-info → hestia_earth_models-0.59.0.dist-info}/WHEEL +1 -1
  79. tests/models/cycle/animal/input/test_hestiaAggregatedData.py +2 -14
  80. tests/models/cycle/input/test_hestiaAggregatedData.py +4 -16
  81. tests/models/cycle/test_coldCarcassWeightPerHead.py +1 -1
  82. tests/models/cycle/test_coldDressedCarcassWeightPerHead.py +1 -1
  83. tests/models/cycle/{test_irrigated.py → test_irrigatedTypeUnspecified.py} +1 -1
  84. tests/models/cycle/test_milkYield.py +58 -0
  85. tests/models/cycle/test_readyToCookWeightPerHead.py +1 -1
  86. tests/models/emepEea2019/test_nh3ToAirInorganicFertiliser.py +1 -1
  87. tests/models/geospatialDatabase/test_clayContent.py +9 -3
  88. tests/models/geospatialDatabase/test_sandContent.py +9 -3
  89. tests/models/ipcc2006/test_n2OToAirExcretaDirect.py +7 -2
  90. tests/models/ipcc2006/test_n2OToAirExcretaIndirect.py +1 -1
  91. tests/models/ipcc2006/test_n2OToAirInorganicFertiliserDirect.py +7 -2
  92. tests/models/ipcc2006/test_n2OToAirInorganicFertiliserIndirect.py +7 -2
  93. tests/models/ipcc2006/test_n2OToAirOrganicFertiliserDirect.py +7 -2
  94. tests/models/ipcc2006/test_n2OToAirOrganicFertiliserIndirect.py +7 -2
  95. tests/models/ipcc2019/test_ch4ToAirEntericFermentation.py +1 -1
  96. tests/models/ipcc2019/test_co2ToAirSoilCarbonStockChangeManagementChange.py +228 -0
  97. tests/models/ipcc2019/test_n2OToAirInorganicFertiliserDirect.py +74 -0
  98. tests/models/ipcc2019/test_n2OToAirOrganicFertiliserDirect.py +74 -0
  99. tests/models/ipcc2019/test_organicCarbonPerHa.py +303 -1044
  100. tests/models/koble2014/test_residueBurnt.py +1 -2
  101. tests/models/koble2014/test_residueLeftOnField.py +1 -2
  102. tests/models/koble2014/test_residueRemoved.py +1 -2
  103. tests/models/koble2014/test_utils.py +52 -0
  104. tests/models/site/test_management.py +117 -0
  105. tests/models/site/test_organicCarbonPerHa.py +51 -5
  106. tests/models/utils/test_blank_node.py +230 -34
  107. tests/models/utils/test_term.py +17 -3
  108. {hestia_earth_models-0.57.2.dist-info → hestia_earth_models-0.59.0.dist-info}/LICENSE +0 -0
  109. {hestia_earth_models-0.57.2.dist-info → hestia_earth_models-0.59.0.dist-info}/top_level.txt +0 -0
@@ -52,7 +52,7 @@ def _should_run(cycle: dict):
52
52
  N_total=N_total,
53
53
  term_type_excreta_complete=term_type_complete)
54
54
 
55
- should_run = all([N_total, term_type_complete])
55
+ should_run = all([N_total is not None, term_type_complete])
56
56
  logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
57
57
  return should_run, N_total
58
58
 
@@ -1,13 +1,15 @@
1
- from hestia_earth.schema import EmissionMethodTier
1
+ from hestia_earth.schema import EmissionMethodTier, TermTermType
2
2
 
3
3
  from hestia_earth.models.log import logRequirements, logShouldRun
4
4
  from hestia_earth.models.utils.constant import Units, get_atomic_conversion
5
+ from hestia_earth.models.utils.completeness import _is_term_type_complete
5
6
  from hestia_earth.models.utils.emission import _new_emission
6
7
  from .utils import get_nh3_no3_nox_to_n, COEFF_NH3NOX_N2O, COEFF_NO3_N2O
7
8
  from . import MODEL
8
9
 
9
10
  REQUIREMENTS = {
10
11
  "Cycle": {
12
+ "completeness.excreta": "True",
11
13
  "emissions": [
12
14
  {"@type": "Emission", "value": "", "term.@id": "no3ToGroundwaterExcreta"},
13
15
  {"@type": "Emission", "value": "", "term.@id": "nh3ToAirExcreta"},
@@ -41,14 +43,16 @@ def _run(no3_n: float, nh3_n: float, nox_n: float):
41
43
 
42
44
 
43
45
  def _should_run(cycle: dict):
44
- nh3_n, no3_n, nox_n = get_nh3_no3_nox_to_n(cycle, NH3_TERM_ID, NO3_TERM_ID, NOX_TERM_ID)
46
+ nh3_n, no3_n, nox_n = get_nh3_no3_nox_to_n(cycle, NH3_TERM_ID, NO3_TERM_ID, NOX_TERM_ID, allow_none=False)
47
+ term_type_complete = _is_term_type_complete(cycle, TermTermType.EXCRETA)
45
48
 
46
49
  logRequirements(cycle, model=MODEL, term=TERM_ID,
47
50
  no3ToGroundwaterExcreta_to_n=no3_n,
48
51
  nh3ToAirExcreta_to_n=nh3_n,
49
- noxToAirExcreta_to_n=nox_n)
52
+ noxToAirExcreta_to_n=nox_n,
53
+ term_type_excreta_complete=term_type_complete)
50
54
 
51
- should_run = all([no3_n, nh3_n, nox_n])
55
+ should_run = all([no3_n is not None, nh3_n is not None, nox_n is not None, term_type_complete])
52
56
  logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
53
57
  return should_run, no3_n, nh3_n, nox_n
54
58
 
@@ -28,6 +28,9 @@ RETURNS = {
28
28
  "methodTier": "tier 1"
29
29
  }]
30
30
  }
31
+ LOOKUPS = {
32
+ "crop": "N2ON_FERT"
33
+ }
31
34
  TERM_ID = 'n2OToAirInorganicFertiliserDirect'
32
35
  TIER = EmissionMethodTier.TIER_1.value
33
36
 
@@ -53,7 +56,7 @@ def _should_run(cycle: dict):
53
56
  N_total=N_total,
54
57
  term_type_fertiliser_complete=term_type_complete)
55
58
 
56
- should_run = all([N_total, term_type_complete])
59
+ should_run = all([N_total is not None, term_type_complete])
57
60
  logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
58
61
  return should_run, N_total
59
62
 
@@ -69,7 +69,7 @@ def _should_run(cycle: dict):
69
69
  N_total=N_total,
70
70
  term_type_fertiliser_complete=term_type_complete)
71
71
 
72
- should_run = all([N_total, term_type_complete])
72
+ should_run = all([N_total is not None, term_type_complete])
73
73
  logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
74
74
  return should_run, N_total
75
75
 
@@ -55,7 +55,7 @@ def _should_run(cycle: dict):
55
55
  N_total=N_total,
56
56
  term_type_fertiliser_complete=term_type_complete)
57
57
 
58
- should_run = all([N_total, term_type_complete])
58
+ should_run = all([N_total is not None, term_type_complete])
59
59
  logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
60
60
  return should_run, N_total
61
61
 
@@ -68,7 +68,7 @@ def _should_run(cycle: dict):
68
68
  N_total=N_total,
69
69
  term_type_fertiliser_complete=term_type_complete)
70
70
 
71
- should_run = all([N_total, term_type_complete])
71
+ should_run = all([N_total is not None, term_type_complete])
72
72
  logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
73
73
  return should_run, N_total
74
74
 
@@ -7,14 +7,17 @@ COEFF_NH3NOX_N2O = 0.01
7
7
  COEFF_NO3_N2O = 0.0075
8
8
 
9
9
 
10
- def get_nh3_no3_nox_to_n(cycle: dict, nh3_term_id: str, no3_term_id: str, nox_term_id: str):
11
- nh3 = find_terms_value(cycle.get('emissions', []), nh3_term_id)
12
- nh3 = nh3 / get_atomic_conversion(Units.KG_NH3, Units.TO_N)
13
- no3 = find_terms_value(cycle.get('emissions', []), no3_term_id)
14
- no3 = no3 / get_atomic_conversion(Units.KG_NO3, Units.TO_N)
15
- nox = find_terms_value(cycle.get('emissions', []), nox_term_id)
16
- nox = nox / get_atomic_conversion(Units.KG_NOX, Units.TO_N)
17
- return nh3, no3, nox
10
+ def get_nh3_no3_nox_to_n(cycle: dict, nh3_term_id: str, no3_term_id: str, nox_term_id: str, allow_none: bool = True):
11
+ default_value = 0 if allow_none else None
12
+
13
+ nh3 = find_terms_value(cycle.get('emissions', []), nh3_term_id, default=default_value)
14
+ nh3 = None if nh3 is None else nh3 / get_atomic_conversion(Units.KG_NH3, Units.TO_N)
15
+ no3 = find_terms_value(cycle.get('emissions', []), no3_term_id, default=default_value)
16
+ no3 = None if no3 is None else no3 / get_atomic_conversion(Units.KG_NO3, Units.TO_N)
17
+ nox = find_terms_value(cycle.get('emissions', []), nox_term_id, default=default_value)
18
+ nox = None if nox is None else nox / get_atomic_conversion(Units.KG_NOX, Units.TO_N)
19
+
20
+ return (nh3, no3, nox)
18
21
 
19
22
 
20
23
  def get_N_N2O_excreta_coeff_from_primary_product(cycle: dict):
@@ -14,7 +14,7 @@ from . import MODEL
14
14
  REQUIREMENTS = {
15
15
  "Cycle": {
16
16
  "completeness.animalFeed": "True",
17
- "completeness.grazedForage": "True",
17
+ "completeness.freshForage": "True",
18
18
  "or": [
19
19
  {
20
20
  "animals": [{
@@ -207,7 +207,7 @@ def _get_default_values(lookup, term: dict):
207
207
 
208
208
  def _should_run(cycle: dict):
209
209
  is_animalFeed_complete = cycle.get('completeness', {}).get('animalFeed', False) is True
210
- is_grazedForage_complete = cycle.get('completeness', {}).get('grazedForage', False) is True
210
+ is_freshForage_complete = cycle.get('completeness', {}).get('freshForage', False) is True
211
211
 
212
212
  primary_product = find_primary_product(cycle) or {}
213
213
  term = primary_product.get('term', {})
@@ -252,11 +252,11 @@ def _should_run(cycle: dict):
252
252
 
253
253
  logRequirements(cycle, model=MODEL, term=TERM_ID,
254
254
  term_type_animalFeed_complete=is_animalFeed_complete,
255
- term_type_grazedForage_complete=is_grazedForage_complete,
255
+ term_type_freshForage_complete=is_freshForage_complete,
256
256
  total_feed_in_MJ=total_feed)
257
257
 
258
258
  should_run = all([
259
- is_animalFeed_complete, is_grazedForage_complete, total_feed,
259
+ is_animalFeed_complete, is_freshForage_complete, total_feed,
260
260
  enteric_factor or default_values[0]
261
261
  ])
262
262
  logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
@@ -21,17 +21,24 @@ REQUIREMENTS = {
21
21
  "products": [{"@type": "Product", "value": "", "term.@id": "aboveGroundCropResidueIncorporated"}],
22
22
  "practices": [
23
23
  {"@type": "Practice", "value": "", "term.termType": "cropResidueManagement"},
24
+ {"@type": "Practice", "value": "", "term.termType": "landUseManagement"},
24
25
  {"@type": "Practice", "value": "", "term.termType": "waterRegime"}
25
26
  ]
26
27
  }
27
28
  }
28
29
  }
29
30
  LOOKUPS = {
31
+ "landUseManagement": [
32
+ "IPCC_2019_CH4_rice_SFw", "IPCC_2019_CH4_rice_SFw-min", "IPCC_2019_CH4_rice_SFw-max",
33
+ "IPCC_2019_CH4_rice_SFw-sd",
34
+ "IPCC_2019_CH4_rice_SFp", "IPCC_2019_CH4_rice_SFp-min", "IPCC_2019_CH4_rice_SFp-max",
35
+ "IPCC_2019_CH4_rice_SFp-sd"
36
+ ],
30
37
  "waterRegime": [
31
- "IPCC_2019_CH4_rice_SFw", "IPCC_2019_CH4_rice_SFw_min", "IPCC_2019_CH4_rice_SFw_max",
32
- "IPCC_2019_CH4_rice_SFw_sd",
33
- "IPCC_2019_CH4_rice_SFp", "IPCC_2019_CH4_rice_SFp_min", "IPCC_2019_CH4_rice_SFp_max",
34
- "IPCC_2019_CH4_rice_SFp_sd"
38
+ "IPCC_2019_CH4_rice_SFw", "IPCC_2019_CH4_rice_SFw-min", "IPCC_2019_CH4_rice_SFw-max",
39
+ "IPCC_2019_CH4_rice_SFw-sd",
40
+ "IPCC_2019_CH4_rice_SFp", "IPCC_2019_CH4_rice_SFp-min", "IPCC_2019_CH4_rice_SFp-max",
41
+ "IPCC_2019_CH4_rice_SFp-sd"
35
42
  ],
36
43
  "organicFertiliser": ["IPCC_2019_CH4_rice_CFOA_kg_fresh_weight", "IPCC_2019_CH4_rice_CFOA_kg_dry_weight"],
37
44
  "region-ch4ef-IPCC2019": ["CH4_ef", "CH4_ef_min", "CH4_ef_max", "CH4_ef_sd"]
@@ -66,7 +73,7 @@ def _get_CH4_ef(country: str, suffix: str = ''):
66
73
  return safe_parse_float(get_table_value(lookup, 'termid', country, column_name('CH4_ef' + suffix)))
67
74
 
68
75
 
69
- def _get_waterRegime_lookup(term: dict, col: str):
76
+ def _get_practice_lookup(term: dict, col: str):
70
77
  return safe_parse_float(get_lookup_value(term, col, model=MODEL, term=TERM_ID))
71
78
 
72
79
 
@@ -99,7 +106,7 @@ def _calculate_SFo(cycle: dict, suffix: str = ''):
99
106
 
100
107
  def _calculate_SF_average(practices: list, factor: str):
101
108
  values = [
102
- (_get_waterRegime_lookup(p.get('term', {}), factor), list_sum(p.get('value', []), None)) for p in practices
109
+ (_get_practice_lookup(p.get('term', {}), factor), list_sum(p.get('value', []), None)) for p in practices
103
110
  ]
104
111
  # sum only values that are numbers
105
112
  return list_sum([factor * percent / 100 for factor, percent in values if percent is not None])
@@ -124,7 +131,9 @@ def _get_croppingDuration(croppingDuration: dict, key: str = 'value'):
124
131
 
125
132
 
126
133
  def _run(cycle: dict, croppingDuration: dict, country: str):
127
- practices = filter_list_term_type(cycle.get('practices', []), TermTermType.WATERREGIME)
134
+ practices = filter_list_term_type(cycle.get('practices', []), [
135
+ TermTermType.WATERREGIME, TermTermType.LANDUSEMANAGEMENT
136
+ ])
128
137
 
129
138
  value = _calculate_factor(cycle, country, practices) * _get_croppingDuration(croppingDuration)
130
139
  min = _calculate_factor(cycle, country, practices, '_min') * _get_croppingDuration(croppingDuration, 'min')