hestia-earth-models 0.62.0__py3-none-any.whl → 0.62.2__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 (68) hide show
  1. hestia_earth/models/blonkConsultants2016/utils.py +3 -2
  2. hestia_earth/models/cycle/coldCarcassWeightPerHead.py +4 -2
  3. hestia_earth/models/cycle/coldDressedCarcassWeightPerHead.py +2 -2
  4. hestia_earth/models/cycle/concentrateFeed.py +3 -3
  5. hestia_earth/models/cycle/feedConversionRatio/feedConversionRatioNitrogen.py +2 -1
  6. hestia_earth/models/cycle/post_checks/__init__.py +3 -2
  7. hestia_earth/models/cycle/post_checks/otherSites.py +40 -0
  8. hestia_earth/models/cycle/pre_checks/__init__.py +2 -1
  9. hestia_earth/models/cycle/pre_checks/otherSites.py +42 -0
  10. hestia_earth/models/cycle/pre_checks/site.py +1 -1
  11. hestia_earth/models/cycle/readyToCookWeightPerHead.py +2 -2
  12. hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +1 -1
  13. hestia_earth/models/emepEea2019/utils.py +4 -3
  14. hestia_earth/models/geospatialDatabase/heavyWinterPrecipitation.py +1 -1
  15. hestia_earth/models/ipcc2019/animal/pastureGrass.py +53 -43
  16. hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +30 -4
  17. hestia_earth/models/ipcc2019/n2OToAirExcretaDirect.py +6 -2
  18. hestia_earth/models/ipcc2019/n2OToAirExcretaIndirect.py +1 -1
  19. hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserDirect.py +1 -1
  20. hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserIndirect.py +1 -1
  21. hestia_earth/models/ipcc2019/n2OToAirOrganicFertiliserIndirect.py +1 -1
  22. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +4 -2
  23. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +210 -40
  24. hestia_earth/models/ipcc2019/organicCarbonPerHa_utils.py +2 -6
  25. hestia_earth/models/ipcc2019/pastureGrass.py +44 -42
  26. hestia_earth/models/ipcc2019/pastureGrass_utils.py +46 -92
  27. hestia_earth/models/mocking/search-results.json +378 -234
  28. hestia_earth/models/schererPfister2015/utils.py +2 -2
  29. hestia_earth/models/site/brackishWater.py +1 -1
  30. hestia_earth/models/site/flowingWater.py +1 -1
  31. hestia_earth/models/site/freshWater.py +1 -1
  32. hestia_earth/models/site/management.py +79 -38
  33. hestia_earth/models/site/pre_checks/cache_sources.py +9 -13
  34. hestia_earth/models/site/salineWater.py +1 -1
  35. hestia_earth/models/stehfestBouwman2006/n2OToAirCropResidueDecompositionDirect.py +12 -2
  36. hestia_earth/models/stehfestBouwman2006/n2OToAirExcretaDirect.py +12 -2
  37. hestia_earth/models/stehfestBouwman2006/n2OToAirInorganicFertiliserDirect.py +11 -1
  38. hestia_earth/models/stehfestBouwman2006/n2OToAirOrganicFertiliserDirect.py +11 -1
  39. hestia_earth/models/stehfestBouwman2006/noxToAirCropResidueDecomposition.py +12 -2
  40. hestia_earth/models/stehfestBouwman2006/noxToAirExcreta.py +12 -2
  41. hestia_earth/models/stehfestBouwman2006/noxToAirInorganicFertiliser.py +11 -1
  42. hestia_earth/models/stehfestBouwman2006/noxToAirOrganicFertiliser.py +11 -1
  43. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirCropResidueDecomposition.py +12 -2
  44. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirExcreta.py +12 -2
  45. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirInorganicFertiliser.py +11 -1
  46. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirOrganicFertiliser.py +11 -1
  47. hestia_earth/models/utils/blank_node.py +144 -110
  48. hestia_earth/models/utils/constant.py +2 -0
  49. hestia_earth/models/utils/lookup.py +19 -6
  50. hestia_earth/models/utils/property.py +6 -6
  51. hestia_earth/models/utils/site.py +7 -0
  52. hestia_earth/models/utils/source.py +1 -1
  53. hestia_earth/models/utils/term.py +21 -1
  54. hestia_earth/models/version.py +1 -1
  55. {hestia_earth_models-0.62.0.dist-info → hestia_earth_models-0.62.2.dist-info}/METADATA +2 -2
  56. {hestia_earth_models-0.62.0.dist-info → hestia_earth_models-0.62.2.dist-info}/RECORD +68 -63
  57. tests/models/cycle/post_checks/test_otherSites.py +15 -0
  58. tests/models/cycle/pre_checks/test_otherSites.py +21 -0
  59. tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +5 -3
  60. tests/models/ipcc2019/test_organicCarbonPerHa.py +10 -20
  61. tests/models/ipcc2019/test_organicCarbonPerHa_tier_2_utils.py +0 -8
  62. tests/models/site/pre_checks/test_cache_sources.py +6 -10
  63. tests/models/site/test_management.py +192 -4
  64. tests/models/utils/test_blank_node.py +0 -281
  65. tests/models/utils/test_lookup.py +10 -0
  66. {hestia_earth_models-0.62.0.dist-info → hestia_earth_models-0.62.2.dist-info}/LICENSE +0 -0
  67. {hestia_earth_models-0.62.0.dist-info → hestia_earth_models-0.62.2.dist-info}/WHEEL +0 -0
  68. {hestia_earth_models-0.62.0.dist-info → hestia_earth_models-0.62.2.dist-info}/top_level.txt +0 -0
@@ -32,15 +32,11 @@ def _get_activityCoefficient(cycle: dict, animal: dict, system: dict) -> float:
32
32
  lookup = download_lookup('system-liveAnimal-activityCoefficient-ipcc2019.csv')
33
33
  activityCoefficient = safe_parse_float(get_table_value(lookup, 'termid', system_id, column_name(term_id)), 0)
34
34
 
35
- debugValues(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
36
- activityCoefficient=activityCoefficient)
37
-
38
35
  return activityCoefficient
39
36
 
40
37
 
41
38
  def _calculate_NEm(cycle: dict, animal: dict) -> float:
42
39
  term = animal.get('term', {})
43
- term_id = term.get('@id')
44
40
 
45
41
  mjDayKgCfiNetEnergyMaintenance = safe_parse_float(
46
42
  get_lookup_value(term, 'mjDayKgCfiNetEnergyMaintenanceIpcc2019', model=MODEL, model_key=MODEL_KEY), 0
@@ -50,32 +46,18 @@ def _calculate_NEm(cycle: dict, animal: dict) -> float:
50
46
  cycleDuration = cycle.get('cycleDuration', 365)
51
47
  NEm = mjDayKgCfiNetEnergyMaintenance * pow(liveweightPerHead, 0.75) * animal_value * cycleDuration
52
48
 
53
- debugValues(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
54
- mjDayKgCfiNetEnergyMaintenance=mjDayKgCfiNetEnergyMaintenance,
55
- liveweightPerHead=liveweightPerHead,
56
- NEm=NEm)
57
-
58
49
  return NEm
59
50
 
60
51
 
61
52
  def _calculate_NEa_cattleAndBuffalo(cycle: dict, animal: dict, system: dict, NEm: float) -> float:
62
- term = animal.get('term', {})
63
- term_id = term.get('@id')
64
-
65
53
  activityCoefficient = _get_activityCoefficient(cycle, animal, system)
66
54
 
67
55
  NEa = activityCoefficient * NEm
68
56
 
69
- debugValues(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
70
- NEa=NEa)
71
-
72
57
  return NEa
73
58
 
74
59
 
75
60
  def _calculate_NEa_sheepAndGoat(cycle: dict, animal: dict, system: dict, _NEm: float) -> float:
76
- term = animal.get('term', {})
77
- term_id = term.get('@id')
78
-
79
61
  activityCoefficient = _get_activityCoefficient(cycle, animal, system)
80
62
 
81
63
  liveweightPerHead = get_node_property(animal, 'liveweightPerHead', False).get('value', 0)
@@ -83,10 +65,6 @@ def _calculate_NEa_sheepAndGoat(cycle: dict, animal: dict, system: dict, _NEm: f
83
65
  cycleDuration = cycle.get('cycleDuration', 365)
84
66
  NEa = activityCoefficient * liveweightPerHead * animal_value * cycleDuration
85
67
 
86
- debugValues(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
87
- liveweightPerHead=liveweightPerHead,
88
- NEa=NEa)
89
-
90
68
  return NEa
91
69
 
92
70
 
@@ -102,9 +80,6 @@ def _calculate_NEa(cycle: dict, animal: dict, system: dict, NEm: float) -> float
102
80
 
103
81
 
104
82
  def _calculate_NEl_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
105
- term = animal.get('term', {})
106
- term_id = term.get('@id')
107
-
108
83
  milkYieldPractice = get_milkYield_practice(animal)
109
84
  milkYield = list_sum(milkYieldPractice.get('value', []))
110
85
  fatContent = get_node_property(milkYieldPractice, 'fatContent').get('value', 0)
@@ -112,18 +87,10 @@ def _calculate_NEl_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
112
87
  cycleDuration = cycle.get('cycleDuration', 365)
113
88
  NEl = milkYield * (1.47 + (0.4 * fatContent)) * animal_value * cycleDuration
114
89
 
115
- debugValues(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
116
- milkYield=milkYield,
117
- fatContent=fatContent,
118
- NEl=NEl)
119
-
120
90
  return NEl
121
91
 
122
92
 
123
93
  def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict) -> float:
124
- term = animal.get('term', {})
125
- term_id = term.get('@id')
126
-
127
94
  milkYieldPractice = get_milkYield_practice(animal)
128
95
  milkYield = list_sum(milkYieldPractice.get('value', []))
129
96
  EV_milk = safe_parse_float(
@@ -131,8 +98,9 @@ def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict) -> float:
131
98
  0
132
99
  )
133
100
  default_fatContent = safe_parse_float(
134
- get_lookup_value(milkYieldPractice.get('term', {}),
135
- 'defaultFatContentEvMilkIpcc2019', model=MODEL, model_key=MODEL_KEY),
101
+ get_lookup_value(
102
+ milkYieldPractice.get('term', {}), 'defaultFatContentEvMilkIpcc2019', model=MODEL, model_key=MODEL_KEY
103
+ ),
136
104
  7
137
105
  )
138
106
  fatContent = get_node_property(milkYieldPractice, 'fatContent').get('value', 0)
@@ -140,11 +108,6 @@ def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict) -> float:
140
108
  cycleDuration = cycle.get('cycleDuration', 365)
141
109
  NEl = milkYield * (EV_milk * fatContent/default_fatContent) * animal_value * cycleDuration
142
110
 
143
- debugValues(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
144
- milkYield=milkYield,
145
- EV_milk=EV_milk,
146
- NEl=NEl)
147
-
148
111
  return NEl
149
112
 
150
113
 
@@ -160,16 +123,9 @@ def _calculate_NEl(cycle: dict, animal: dict) -> float:
160
123
 
161
124
 
162
125
  def _calculate_NEwork(cycle: dict, animal: dict, NEm: float) -> float:
163
- term = animal.get('term', {})
164
- term_id = term.get('@id')
165
-
166
126
  hoursWorkedPerDay = get_node_property(animal, 'hoursWorkedPerDay').get('value', 0)
167
127
  NEwork = 0.1 * NEm * hoursWorkedPerDay
168
128
 
169
- debugValues(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
170
- hoursWorkedPerDay=hoursWorkedPerDay,
171
- NEwork=NEwork)
172
-
173
129
  return NEwork
174
130
 
175
131
 
@@ -194,24 +150,15 @@ def _get_pregnancy_ratio(animal: dict) -> float:
194
150
 
195
151
 
196
152
  def _calculate_NEp(cycle: dict, animal: dict, NEm: float) -> float:
197
- term = animal.get('term', {})
198
- term_id = term.get('@id')
199
-
200
153
  ratioCPregnancyNetEnergyPregnancy = _get_pregnancy_ratio(animal)
201
154
  pregnancyRateTotal = get_node_property(animal, 'pregnancyRateTotal').get('value', 0)
202
155
  NEp = ratioCPregnancyNetEnergyPregnancy * pregnancyRateTotal/100 * NEm
203
156
 
204
- debugValues(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
205
- ratioCPregnancyNetEnergyPregnancy=ratioCPregnancyNetEnergyPregnancy,
206
- pregnancyRateTotal=pregnancyRateTotal,
207
- NEp=NEp)
208
-
209
157
  return NEp
210
158
 
211
159
 
212
160
  def _calculate_NEg_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
213
161
  term = animal.get('term', {})
214
- term_id = term.get('@id')
215
162
 
216
163
  ratioCNetEnergyGrowthCattleBuffalo = safe_parse_float(
217
164
  get_lookup_value(term, 'ratioCNetEnergyGrowthCattleBuffaloIpcc2019', model=MODEL, model_key=MODEL_KEY), 0
@@ -228,22 +175,14 @@ def _calculate_NEg_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
228
175
  ratioCNetEnergyGrowthCattleBuffalo * weightAtMaturity > 0
229
176
  ]) else 0
230
177
 
231
- debugValues(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
232
- ratioCNetEnergyGrowthCattleBuffalo=ratioCNetEnergyGrowthCattleBuffalo,
233
- liveweightPerHead=liveweightPerHead,
234
- weightAtMaturity=weightAtMaturity,
235
- liveweightGain=liveweightGain,
236
- NEg=NEg)
237
-
238
178
  return NEg
239
179
 
240
180
 
241
181
  def _calculate_NEg_sheepAndGoat(cycle: dict, animal: dict) -> float:
242
182
  term = animal.get('term', {})
243
- term_id = term.get('@id')
244
183
 
245
184
  MjKgABNetEnergyGrowthSheepGoats = get_lookup_value(
246
- term, 'MjKgABNetEnergyGrowthSheepGoatsIpcc2019', model=MODEL, model_key=MODEL_KEY)
185
+ term, 'mjKgABNetEnergyGrowthSheepGoatsIpcc2019', model=MODEL, model_key=MODEL_KEY)
247
186
  MjKg_a = safe_parse_float(extract_grouped_data(MjKgABNetEnergyGrowthSheepGoats, 'a'), 0)
248
187
  MjKg_b = safe_parse_float(extract_grouped_data(MjKgABNetEnergyGrowthSheepGoats, 'b'), 0)
249
188
  BWi = get_node_property(animal, 'weightAtWeaning').get('value', 0)
@@ -253,13 +192,6 @@ def _calculate_NEg_sheepAndGoat(cycle: dict, animal: dict) -> float:
253
192
  cycleDuration = cycle.get('cycleDuration', 365)
254
193
  NEg = (BWf - BWi) * (MjKg_a + 0.5 * MjKg_b * (BWi + BWf)) / 365 * animal_value * cycleDuration
255
194
 
256
- debugValues(cycle, model=MODEL, term=term_id, model_key=MODEL_KEY,
257
- MjKg_a=MjKg_a,
258
- MjKg_b=MjKg_b,
259
- BWi=BWi,
260
- BWf=BWf,
261
- NEg=NEg)
262
-
263
195
  return NEg
264
196
 
265
197
 
@@ -271,16 +203,17 @@ _NEg_BY_GROUPING = {
271
203
 
272
204
  def _calculate_NEg(cycle: dict, animal: dict) -> float:
273
205
  grouping = _get_grouping(animal)
274
- return _NEg_BY_GROUPING.get(grouping, lambda *args: None)(cycle, animal)
206
+ return _NEg_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal)
275
207
 
276
208
 
277
- def _pastureGrass_key_property_value(practice: dict, column: dict):
278
- term_id = practice_input_id(practice)
279
- term = download_hestia(term_id)
280
- term_type = term.get('termType')
281
- value = list_sum(practice.get('value', [0]))
282
- lookup_value = node_property_lookup_value(MODEL, {'@id': term_id, 'termType': term_type}, column, default=0)
283
- return (lookup_value, value)
209
+ def _pastureGrass_key_property_value(column: dict, **log_args):
210
+ def get_value(practice: dict):
211
+ term_id = practice_input_id(practice)
212
+ term = download_hestia(term_id)
213
+ value = list_sum(practice.get('value', [0]))
214
+ lookup_value = node_property_lookup_value(MODEL, term, column, default=0, **log_args)
215
+ return (lookup_value, value)
216
+ return get_value
284
217
 
285
218
 
286
219
  def calculate_REM(energy: float = 0) -> float:
@@ -291,14 +224,14 @@ def calculate_REG(energy: float = 0) -> float:
291
224
  return 1.164 - (5.16/1000 * energy) + (1.308/100000 * pow(energy, 2)) - (37.4/energy) if energy > 0 else 0
292
225
 
293
226
 
294
- def _calculate_feed_meanDE(node: dict, input: dict) -> float:
227
+ def _calculate_feed_meanDE(log_node: dict, input: dict) -> float:
295
228
  term_id = input.get('term', {}).get('@id')
296
229
 
297
230
  energyContent = get_node_property_value(MODEL, input, 'energyContentHigherHeatingValue')
298
231
  energyDigestibility = get_node_property_value(MODEL, input, 'energyDigestibilityRuminants')
299
232
  meanDE = energyContent * energyDigestibility if all([energyContent, energyDigestibility]) else 0
300
233
 
301
- debugValues(node, model=MODEL, term=term_id, model_key=MODEL_KEY,
234
+ debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
302
235
  energyContent=energyContent,
303
236
  energyDigestibility=energyDigestibility,
304
237
  meanDE=meanDE)
@@ -306,26 +239,26 @@ def _calculate_feed_meanDE(node: dict, input: dict) -> float:
306
239
  return meanDE
307
240
 
308
241
 
309
- def _calculate_NEfeed_m(node: dict, input: dict, meanDE: float) -> float:
242
+ def _calculate_NEfeed_m(log_node: dict, input: dict, meanDE: float) -> float:
310
243
  term_id = input.get('term', {}).get('@id')
311
244
 
312
245
  energyDigestibility = get_node_property_value(MODEL, input, 'energyDigestibilityRuminants', default=0)
313
246
  REm = calculate_REM(energyDigestibility * 100)
314
247
 
315
- debugValues(node, model=MODEL, term=term_id, model_key=MODEL_KEY,
248
+ debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
316
249
  REm=REm)
317
250
 
318
251
  input_value = list_sum(input.get('value'))
319
252
  return meanDE * REm * input_value
320
253
 
321
254
 
322
- def _calculate_NEfeed_g(node: dict, input: dict, meanDE: float) -> float:
255
+ def _calculate_NEfeed_g(log_node: dict, input: dict, meanDE: float) -> float:
323
256
  term_id = input.get('term', {}).get('@id')
324
257
 
325
258
  energyDigestibility = get_node_property_value(MODEL, input, 'energyDigestibilityRuminants', default=0)
326
259
  REg = calculate_REG(energyDigestibility * 100)
327
260
 
328
- debugValues(node, model=MODEL, term=term_id, model_key=MODEL_KEY,
261
+ debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
329
262
  REg=REg)
330
263
 
331
264
  input_value = list_sum(input.get('value'))
@@ -346,7 +279,7 @@ def calculate_NEfeed(node: dict) -> tuple:
346
279
  return (NEfeed_m, NEfeed_g)
347
280
 
348
281
 
349
- def get_animal_values(cycle: dict, animal: dict, system: dict):
282
+ def get_animal_values(cycle: dict, animal: dict, system: dict) -> dict:
350
283
  NEm = _calculate_NEm(cycle, animal)
351
284
  NEa = _calculate_NEa(cycle, animal, system, NEm)
352
285
  NEl = _calculate_NEl(cycle, animal)
@@ -354,19 +287,40 @@ def get_animal_values(cycle: dict, animal: dict, system: dict):
354
287
  NEp = _calculate_NEp(cycle, animal, NEm)
355
288
  NEg = _calculate_NEg(cycle, animal)
356
289
 
357
- return (NEm, NEa, NEl, NEwork, NEp, NEg)
290
+ return {
291
+ 'NEm': NEm,
292
+ 'NEa': NEa,
293
+ 'NEl': NEl,
294
+ 'NEwork': NEwork,
295
+ 'NEp': NEp,
296
+ 'NEg': NEg
297
+ }
298
+
299
+
300
+ def _sum_values(values: list, key: str): return list_sum([v.get(key) for v in values])
301
+
302
+
303
+ def calculate_GE(values: list, REM: float, REG: float, NEwool: float, NEm_feed: float, NEg_feed: float) -> float:
304
+ NEm = _sum_values(values, 'NEm')
305
+ NEa = _sum_values(values, 'NEa')
306
+ NEl = _sum_values(values, 'NEl')
307
+ NEwork = _sum_values(values, 'NEwork')
308
+ NEp = _sum_values(values, 'NEp')
309
+ NEg = _sum_values(values, 'NEg')
310
+
311
+ return ((NEm + NEa + NEl + NEwork + NEp - NEm_feed)/REM + (NEg + NEwool - NEg_feed)/REG) if all([REM, REG]) else 0
358
312
 
359
313
 
360
- def calculate_meanECHHV(practices: list) -> float:
361
- values = list(map(lambda p: _pastureGrass_key_property_value(p, 'energyContentHigherHeatingValue'), practices))
314
+ def calculate_meanECHHV(practices: list, **log_args) -> float:
315
+ values = list(map(_pastureGrass_key_property_value('energyContentHigherHeatingValue', **log_args), practices))
362
316
  total_weight = sum([weight/100 for _value, weight in values])
363
317
  return sum([
364
318
  (value * weight/100 if all([value, weight]) else 0) for value, weight in values
365
319
  ]) / total_weight if total_weight > 0 else 0
366
320
 
367
321
 
368
- def calculate_meanDE(practices: list) -> float:
369
- values = list(map(lambda p: _pastureGrass_key_property_value(p, 'energyDigestibilityRuminants'), practices))
322
+ def calculate_meanDE(practices: list, **log_args) -> float:
323
+ values = list(map(_pastureGrass_key_property_value('energyDigestibilityRuminants', **log_args), practices))
370
324
  total_weight = sum([weight/100 for _value, weight in values])
371
325
  meanDE = sum([
372
326
  (value * weight/100 if all([value, weight]) else 0) for value, weight in values