hestia-earth-models 0.62.1__py3-none-any.whl → 0.62.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 (56) hide show
  1. hestia_earth/models/agribalyse2016/fuelElectricity.py +1 -1
  2. hestia_earth/models/cycle/animal/input/hestiaAggregatedData.py +1 -1
  3. hestia_earth/models/cycle/coldCarcassWeightPerHead.py +4 -2
  4. hestia_earth/models/cycle/coldDressedCarcassWeightPerHead.py +2 -2
  5. hestia_earth/models/cycle/concentrateFeed.py +3 -3
  6. hestia_earth/models/cycle/cycleDuration.py +7 -2
  7. hestia_earth/models/cycle/feedConversionRatio/feedConversionRatioNitrogen.py +2 -1
  8. hestia_earth/models/cycle/input/hestiaAggregatedData.py +1 -1
  9. hestia_earth/models/cycle/product/price.py +5 -1
  10. hestia_earth/models/cycle/product/revenue.py +6 -7
  11. hestia_earth/models/cycle/readyToCookWeightPerHead.py +2 -2
  12. hestia_earth/models/ecoinventV3/__init__.py +25 -52
  13. hestia_earth/models/ecoinventV3/utils.py +40 -0
  14. hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py +92 -91
  15. hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +15 -105
  16. hestia_earth/models/faostat2018/product/price.py +1 -2
  17. hestia_earth/models/geospatialDatabase/croppingIntensity.py +2 -1
  18. hestia_earth/models/geospatialDatabase/utils.py +1 -1
  19. hestia_earth/models/ipcc2019/aboveGroundCropResidueTotal.py +15 -10
  20. hestia_earth/models/ipcc2019/animal/pastureGrass.py +50 -40
  21. hestia_earth/models/ipcc2019/belowGroundCropResidue.py +16 -11
  22. hestia_earth/models/ipcc2019/carbonContent.py +1 -1
  23. hestia_earth/models/ipcc2019/croppingDuration.py +2 -2
  24. hestia_earth/models/ipcc2019/ligninContent.py +1 -1
  25. hestia_earth/models/ipcc2019/nitrogenContent.py +1 -1
  26. hestia_earth/models/ipcc2019/organicCarbonPerHa.py +3 -3
  27. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +5 -5
  28. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +217 -48
  29. hestia_earth/models/ipcc2019/organicCarbonPerHa_utils.py +2 -6
  30. hestia_earth/models/ipcc2019/pastureGrass.py +43 -41
  31. hestia_earth/models/ipcc2019/pastureGrass_utils.py +63 -109
  32. hestia_earth/models/koble2014/cropResidueManagement.py +1 -1
  33. hestia_earth/models/linkedImpactAssessment/emissions.py +15 -14
  34. hestia_earth/models/mocking/search-results.json +249 -257
  35. hestia_earth/models/pooreNemecek2018/longFallowPeriod.py +1 -1
  36. hestia_earth/models/preload_requests.py +1 -1
  37. hestia_earth/models/requirements.py +6 -6
  38. hestia_earth/models/site/organicCarbonPerHa.py +1 -1
  39. hestia_earth/models/utils/__init__.py +1 -1
  40. hestia_earth/models/utils/blank_node.py +52 -9
  41. hestia_earth/models/utils/cycle.py +12 -12
  42. hestia_earth/models/utils/measurement.py +3 -3
  43. hestia_earth/models/utils/property.py +6 -6
  44. hestia_earth/models/utils/term.py +2 -1
  45. hestia_earth/models/version.py +1 -1
  46. {hestia_earth_models-0.62.1.dist-info → hestia_earth_models-0.62.3.dist-info}/METADATA +12 -12
  47. {hestia_earth_models-0.62.1.dist-info → hestia_earth_models-0.62.3.dist-info}/RECORD +56 -55
  48. {hestia_earth_models-0.62.1.dist-info → hestia_earth_models-0.62.3.dist-info}/WHEEL +1 -1
  49. tests/models/cycle/product/test_revenue.py +0 -3
  50. tests/models/cycle/test_cycleDuration.py +1 -1
  51. tests/models/ipcc2019/test_organicCarbonPerHa.py +9 -20
  52. tests/models/ipcc2019/test_organicCarbonPerHa_tier_2_utils.py +0 -8
  53. tests/models/test_ecoinventV3.py +12 -0
  54. tests/models/test_ecoinventV3AndEmberClimate.py +5 -72
  55. {hestia_earth_models-0.62.1.dist-info → hestia_earth_models-0.62.3.dist-info}/LICENSE +0 -0
  56. {hestia_earth_models-0.62.1.dist-info → hestia_earth_models-0.62.3.dist-info}/top_level.txt +0 -0
@@ -25,22 +25,18 @@ def _get_grouping(animal: dict) -> str:
25
25
  return get_lookup_value(term, 'ipcc2019AnimalTypeGrouping', model=MODEL, model_key=MODEL_KEY)
26
26
 
27
27
 
28
- def _get_activityCoefficient(cycle: dict, animal: dict, system: dict, log_node: dict) -> float:
28
+ def _get_activityCoefficient(cycle: dict, animal: dict, system: dict) -> float:
29
29
  term = animal.get('term', {})
30
30
  term_id = term.get('@id')
31
31
  system_id = system.get('term', {}).get('@id')
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(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
36
- activityCoefficient=activityCoefficient)
37
-
38
35
  return activityCoefficient
39
36
 
40
37
 
41
- def _calculate_NEm(cycle: dict, animal: dict, log_node: dict) -> float:
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,43 +46,25 @@ def _calculate_NEm(cycle: dict, animal: dict, log_node: dict) -> float:
50
46
  cycleDuration = cycle.get('cycleDuration', 365)
51
47
  NEm = mjDayKgCfiNetEnergyMaintenance * pow(liveweightPerHead, 0.75) * animal_value * cycleDuration
52
48
 
53
- debugValues(log_node, 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
- def _calculate_NEa_cattleAndBuffalo(cycle: dict, animal: dict, system: dict, NEm: float, log_node: dict) -> float:
62
- term = animal.get('term', {})
63
- term_id = term.get('@id')
64
-
65
- activityCoefficient = _get_activityCoefficient(cycle, animal, system, log_node)
52
+ def _calculate_NEa_cattleAndBuffalo(cycle: dict, animal: dict, system: dict, NEm: float) -> float:
53
+ activityCoefficient = _get_activityCoefficient(cycle, animal, system)
66
54
 
67
55
  NEa = activityCoefficient * NEm
68
56
 
69
- debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
70
- NEa=NEa)
71
-
72
57
  return NEa
73
58
 
74
59
 
75
- def _calculate_NEa_sheepAndGoat(cycle: dict, animal: dict, system: dict, _NEm: float, log_node: dict) -> float:
76
- term = animal.get('term', {})
77
- term_id = term.get('@id')
78
-
79
- activityCoefficient = _get_activityCoefficient(cycle, animal, system, log_node)
60
+ def _calculate_NEa_sheepAndGoat(cycle: dict, animal: dict, system: dict, _NEm: float) -> float:
61
+ activityCoefficient = _get_activityCoefficient(cycle, animal, system)
80
62
 
81
63
  liveweightPerHead = get_node_property(animal, 'liveweightPerHead', False).get('value', 0)
82
64
  animal_value = animal.get('value', 0)
83
65
  cycleDuration = cycle.get('cycleDuration', 365)
84
66
  NEa = activityCoefficient * liveweightPerHead * animal_value * cycleDuration
85
67
 
86
- debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
87
- liveweightPerHead=liveweightPerHead,
88
- NEa=NEa)
89
-
90
68
  return NEa
91
69
 
92
70
 
@@ -96,15 +74,12 @@ _NEa_BY_GROUPING = {
96
74
  }
97
75
 
98
76
 
99
- def _calculate_NEa(cycle: dict, animal: dict, system: dict, NEm: float, log_node: dict) -> float:
77
+ def _calculate_NEa(cycle: dict, animal: dict, system: dict, NEm: float) -> float:
100
78
  grouping = _get_grouping(animal)
101
- return _NEa_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal, system, NEm, log_node)
79
+ return _NEa_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal, system, NEm)
102
80
 
103
81
 
104
- def _calculate_NEl_cattleAndBuffalo(cycle: dict, animal: dict, log_node: dict) -> float:
105
- term = animal.get('term', {})
106
- term_id = term.get('@id')
107
-
82
+ def _calculate_NEl_cattleAndBuffalo(cycle: dict, animal: dict) -> float:
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, log_node: dict) -
112
87
  cycleDuration = cycle.get('cycleDuration', 365)
113
88
  NEl = milkYield * (1.47 + (0.4 * fatContent)) * animal_value * cycleDuration
114
89
 
115
- debugValues(log_node, 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
- def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict, log_node: dict) -> float:
124
- term = animal.get('term', {})
125
- term_id = term.get('@id')
126
-
93
+ def _calculate_NEl_sheepAndGoat(cycle: dict, animal: dict) -> float:
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, log_node: dict) -> fl
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, log_node: dict) -> fl
140
108
  cycleDuration = cycle.get('cycleDuration', 365)
141
109
  NEl = milkYield * (EV_milk * fatContent/default_fatContent) * animal_value * cycleDuration
142
110
 
143
- debugValues(log_node, 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
 
@@ -154,22 +117,15 @@ _NEl_BY_GROUPING = {
154
117
  }
155
118
 
156
119
 
157
- def _calculate_NEl(cycle: dict, animal: dict, log_node: dict) -> float:
120
+ def _calculate_NEl(cycle: dict, animal: dict) -> float:
158
121
  grouping = _get_grouping(animal)
159
- return _NEl_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal, log_node)
160
-
122
+ return _NEl_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal)
161
123
 
162
- def _calculate_NEwork(cycle: dict, animal: dict, NEm: float, log_node: dict) -> float:
163
- term = animal.get('term', {})
164
- term_id = term.get('@id')
165
124
 
125
+ def _calculate_NEwork(cycle: dict, animal: dict, NEm: float) -> float:
166
126
  hoursWorkedPerDay = get_node_property(animal, 'hoursWorkedPerDay').get('value', 0)
167
127
  NEwork = 0.1 * NEm * hoursWorkedPerDay
168
128
 
169
- debugValues(log_node, model=MODEL, term=term_id, model_key=MODEL_KEY,
170
- hoursWorkedPerDay=hoursWorkedPerDay,
171
- NEwork=NEwork)
172
-
173
129
  return NEwork
174
130
 
175
131
 
@@ -193,25 +149,16 @@ def _get_pregnancy_ratio(animal: dict) -> float:
193
149
  return _get_pregnancy_ratio_per_birth(animal, value) if ';' in value else safe_parse_float(value, 0)
194
150
 
195
151
 
196
- def _calculate_NEp(cycle: dict, animal: dict, NEm: float, log_node: dict) -> float:
197
- term = animal.get('term', {})
198
- term_id = term.get('@id')
199
-
152
+ def _calculate_NEp(cycle: dict, animal: dict, NEm: float) -> float:
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(log_node, 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
- def _calculate_NEg_cattleAndBuffalo(cycle: dict, animal: dict, log_node: dict) -> float:
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, log_node: dict) -
228
175
  ratioCNetEnergyGrowthCattleBuffalo * weightAtMaturity > 0
229
176
  ]) else 0
230
177
 
231
- debugValues(log_node, 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
- def _calculate_NEg_sheepAndGoat(cycle: dict, animal: dict, log_node: dict) -> float:
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, log_node: dict) -> fl
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(log_node, 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
 
@@ -269,18 +201,19 @@ _NEg_BY_GROUPING = {
269
201
  }
270
202
 
271
203
 
272
- def _calculate_NEg(cycle: dict, animal: dict, log_node: dict) -> float:
204
+ def _calculate_NEg(cycle: dict, animal: dict) -> float:
273
205
  grouping = _get_grouping(animal)
274
- return _NEg_BY_GROUPING.get(grouping, lambda *args: 0)(cycle, animal, log_node)
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:
@@ -346,27 +279,48 @@ 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, log_node: dict):
350
- NEm = _calculate_NEm(cycle, animal, log_node=log_node)
351
- NEa = _calculate_NEa(cycle, animal, system, NEm, log_node=log_node)
352
- NEl = _calculate_NEl(cycle, animal, log_node=log_node)
353
- NEwork = _calculate_NEwork(cycle, animal, NEm, log_node=log_node)
354
- NEp = _calculate_NEp(cycle, animal, NEm, log_node=log_node)
355
- NEg = _calculate_NEg(cycle, animal, log_node=log_node)
282
+ def get_animal_values(cycle: dict, animal: dict, system: dict) -> dict:
283
+ NEm = _calculate_NEm(cycle, animal)
284
+ NEa = _calculate_NEa(cycle, animal, system, NEm)
285
+ NEl = _calculate_NEl(cycle, animal)
286
+ NEwork = _calculate_NEwork(cycle, animal, NEm)
287
+ NEp = _calculate_NEp(cycle, animal, NEm)
288
+ NEg = _calculate_NEg(cycle, animal)
289
+
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')
356
310
 
357
- return (NEm, NEa, NEl, NEwork, NEp, NEg)
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
@@ -2,7 +2,7 @@
2
2
  Residue
3
3
 
4
4
  Re-scale all [crop residue management](https://hestia.earth/glossary?termType=cropResidueManagement) Practices
5
- to make sure they all add up to 100%. Note: only practices added by Hestia will be recalculated.
5
+ to make sure they all add up to 100%. Note: only practices added by HESTIA will be recalculated.
6
6
  """
7
7
  from hestia_earth.schema import TermTermType
8
8
  from hestia_earth.utils.model import filter_list_term_type
@@ -8,7 +8,7 @@ from hestia_earth.schema import EmissionMethodTier
8
8
  from hestia_earth.utils.lookup import download_lookup, get_table_value, column_name
9
9
  from hestia_earth.utils.tools import flatten, list_sum
10
10
 
11
- from hestia_earth.models.log import debugValues, logRequirements, logShouldRun, log_as_table
11
+ from hestia_earth.models.log import logShouldRun, debugValues, log_as_table
12
12
  from hestia_earth.models.utils.emission import _new_emission
13
13
  from hestia_earth.models.utils.input import load_impacts
14
14
  from hestia_earth.models.utils.blank_node import group_by_keys
@@ -65,25 +65,29 @@ def _emission(model: str, term_id: str, value: float, input: dict, operation={},
65
65
  return emission
66
66
 
67
67
 
68
- def _run_emission(cycle: dict, term_id: str, data: dict):
68
+ def _run_emission(cycle: dict, emission_term_id: str, data: dict):
69
69
  def run_input(values: dict):
70
70
  value = values.get('value', 0)
71
- term = values.get('term', {})
71
+ input_term = values.get('term', {})
72
+ input_term_id = input_term.get('@id')
72
73
  operation = values.get('operation', {})
73
74
  animal = values.get('animal', {})
74
75
  is_aggregated = any(values.get('aggregated', []))
75
76
  model = MODEL_AGGREGATED if is_aggregated else MODEL
76
77
 
77
- details = values.get('details', {})
78
- logRequirements(cycle, model=model, term=term_id, key=MODEL_KEY,
79
- values=log_as_table([{'impact-assessment-id': key} | value for key, value in details.items()]))
78
+ logShouldRun(cycle, model, input_term_id, True, methodTier=TIER)
80
79
 
81
- logShouldRun(cycle, model, term_id, True, methodTier=TIER, key=MODEL_KEY,
82
- input=term.get('@id'),
83
- operation=operation.get('@id'),
84
- animal=animal.get('@id'))
80
+ # log run on each emission so we know it did run
81
+ details = values.get('details', {})
82
+ debugValues(cycle, model=model, term=emission_term_id,
83
+ value=value,
84
+ coefficient=1,
85
+ details=log_as_table([{'impact-assessment-id': key} | value for key, value in details.items()]),
86
+ input=input_term_id,
87
+ operation=operation.get('@id'),
88
+ animal=animal.get('@id'))
85
89
 
86
- return _emission(model, term_id, value, input=term, operation=operation, animal=animal)
90
+ return _emission(model, emission_term_id, value, input=input_term, operation=operation, animal=animal)
87
91
 
88
92
  return list(map(run_input, data.values()))
89
93
 
@@ -158,9 +162,6 @@ def run(cycle: dict):
158
162
  inputs = reduce(group_by_keys(['term', 'operation', 'animal']), inputs, {})
159
163
  inputs = {key: list(map(_group_input_emissions, value)) for key, value in inputs.items()}
160
164
 
161
- debugValues(cycle, model=MODEL, key=MODEL_KEY,
162
- nb_inputs=len(inputs))
163
-
164
165
  # finally group everything by emission so we can log inputs together
165
166
  # emissions = {'co2ToAirInputsProduct': {'group-id':{'term':{},'value':10,'details':{}}}}
166
167
  emissions = reduce(_group_inputs, inputs.items(), {})