hestia-earth-models 0.70.5__py3-none-any.whl → 0.71.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.
Files changed (35) hide show
  1. hestia_earth/models/cache_nodes.py +157 -0
  2. hestia_earth/models/cache_sites.py +1 -1
  3. hestia_earth/models/config/Cycle.json +0 -30
  4. hestia_earth/models/data/ecoinventV3/__init__.py +7 -5
  5. hestia_earth/models/ecoinventV3/__init__.py +8 -1
  6. hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py +1 -0
  7. hestia_earth/models/emepEea2019/co2ToAirFuelCombustion.py +20 -15
  8. hestia_earth/models/emepEea2019/n2OToAirFuelCombustionDirect.py +21 -16
  9. hestia_earth/models/emepEea2019/noxToAirFuelCombustion.py +20 -15
  10. hestia_earth/models/emepEea2019/so2ToAirFuelCombustion.py +20 -15
  11. hestia_earth/models/emepEea2019/utils.py +73 -25
  12. hestia_earth/models/hestia/aboveGroundCropResidue.py +3 -3
  13. hestia_earth/models/hestia/management.py +12 -7
  14. hestia_earth/models/hestia/seed_emissions.py +25 -21
  15. hestia_earth/models/mocking/search-results.json +1506 -1502
  16. hestia_earth/models/utils/background_emissions.py +24 -0
  17. hestia_earth/models/utils/blank_node.py +4 -1
  18. hestia_earth/models/utils/pesticideAI.py +1 -1
  19. hestia_earth/models/version.py +1 -1
  20. {hestia_earth_models-0.70.5.dist-info → hestia_earth_models-0.71.0.dist-info}/METADATA +2 -2
  21. {hestia_earth_models-0.70.5.dist-info → hestia_earth_models-0.71.0.dist-info}/RECORD +31 -33
  22. tests/models/emepEea2019/test_co2ToAirFuelCombustion.py +1 -14
  23. tests/models/emepEea2019/test_n2OToAirFuelCombustionDirect.py +1 -14
  24. tests/models/emepEea2019/test_noxToAirFuelCombustion.py +1 -14
  25. tests/models/emepEea2019/test_so2ToAirFuelCombustion.py +1 -14
  26. tests/models/emepEea2019/test_utils.py +1 -49
  27. tests/models/hestia/test_management.py +2 -1
  28. tests/models/test_cache_nodes.py +31 -0
  29. hestia_earth/models/ipcc2006/co2ToAirOrganicSoilCultivation.py +0 -100
  30. hestia_earth/models/ipcc2006/n2OToAirOrganicSoilCultivationDirect.py +0 -99
  31. tests/models/ipcc2006/test_co2ToAirOrganicSoilCultivation.py +0 -49
  32. tests/models/ipcc2006/test_n2OToAirOrganicSoilCultivationDirect.py +0 -32
  33. {hestia_earth_models-0.70.5.dist-info → hestia_earth_models-0.71.0.dist-info}/LICENSE +0 -0
  34. {hestia_earth_models-0.70.5.dist-info → hestia_earth_models-0.71.0.dist-info}/WHEEL +0 -0
  35. {hestia_earth_models-0.70.5.dist-info → hestia_earth_models-0.71.0.dist-info}/top_level.txt +0 -0
@@ -135,9 +135,9 @@ def management(data: dict):
135
135
  return node
136
136
 
137
137
 
138
- def _get_cycle_duration(cycle: dict, land_cover_id: str):
138
+ def _get_cycle_duration(cycle: dict, land_cover_id: str = None):
139
139
  cycle_duration = cycle.get('cycleDuration')
140
- lookup_value = None if cycle_duration else safe_parse_float(get_table_value(
140
+ lookup_value = None if cycle_duration or not land_cover_id else safe_parse_float(get_table_value(
141
141
  download_lookup("crop.csv"),
142
142
  column_name('landCoverTermId'),
143
143
  land_cover_id,
@@ -157,7 +157,7 @@ def _gap_filled_date_obj(date_str: str, mode: str = DatestrGapfillMode.END) -> d
157
157
  )
158
158
 
159
159
 
160
- def _gap_filled_start_date(land_cover_id: str, end_date: str, cycle: dict) -> dict:
160
+ def _gap_filled_start_date(cycle: dict, end_date: str, land_cover_id: str = None) -> dict:
161
161
  """If possible, gap-fill the startDate based on the endDate - cycleDuration"""
162
162
  cycle_duration = _get_cycle_duration(cycle, land_cover_id)
163
163
  return {
@@ -216,9 +216,9 @@ def _get_relevant_items(cycle: dict, item_name: str, term_types: List[TermTermTy
216
216
  _include_with_date_gap_fill(cycle, ["startDate", "endDate"]) |
217
217
  _include(
218
218
  _gap_filled_start_date(
219
- land_cover_id=get_landCover_term_id(item.get('term', {})),
219
+ cycle=cycle,
220
220
  end_date=item.get("endDate") if "endDate" in item else cycle.get("endDate", ""),
221
- cycle=cycle
221
+ land_cover_id=get_landCover_term_id(item.get('term', {})),
222
222
  ) if "startDate" not in item else {},
223
223
  "startDate"
224
224
  ) |
@@ -255,12 +255,17 @@ def _run_from_siteType(site: dict, cycle: dict):
255
255
  site_type = site.get('siteType')
256
256
  site_type_id = get_landCover_term_id_from_site_type(site_type) if site_type not in _SKIP_LAND_COVER_SITE_TYPES \
257
257
  else None
258
+ start_date = cycle.get('startDate') or _gap_filled_start_date(
259
+ cycle=cycle,
260
+ end_date=cycle.get('endDate'),
261
+ land_cover_id=site_type_id
262
+ ).get('startDate')
258
263
 
259
- should_run = all([site_type_id])
264
+ should_run = all([site_type_id, start_date])
260
265
  return [{
261
266
  'id': site_type_id,
262
267
  'value': 100,
263
- 'startDate': cycle.get('startDate'),
268
+ 'startDate': start_date,
264
269
  'endDate': cycle.get('endDate')
265
270
  }] if should_run else []
266
271
 
@@ -98,6 +98,23 @@ def _run(cycle: dict, economicValueShare: float, total_yield: float, seed_input:
98
98
  ]
99
99
 
100
100
 
101
+ def _map_group_emissions(group_id: str, required_emission_term_ids: list, emission_ids: list):
102
+ lookup = download_lookup('emission.csv')
103
+ emissions = list(filter(
104
+ lambda id: id in required_emission_term_ids,
105
+ find_term_ids_by(lookup, column_name('inputProductionGroupId'), group_id)
106
+ ))
107
+ included_emissions = list(filter(lambda v: v in emission_ids, emissions))
108
+ missing_emissions = list(filter(lambda v: v not in emission_ids, emissions))
109
+ return {
110
+ 'id': group_id,
111
+ 'total-emissions': len(emissions),
112
+ 'included-emissions': len(included_emissions),
113
+ 'missing-emissions': '-'.join(missing_emissions),
114
+ 'is-valid': len(emissions) == len(included_emissions)
115
+ }
116
+
117
+
101
118
  def _filter_emissions(cycle: dict):
102
119
  required_emission_term_ids = cycle_emissions_in_system_boundary(cycle)
103
120
 
@@ -117,31 +134,12 @@ def _filter_emissions(cycle: dict):
117
134
  group_ids = set([v.get('group-id') for v in emissions if v.get('group-id')])
118
135
 
119
136
  # for each group, get the list of all required emissions
120
- lookup = download_lookup('emission.csv')
121
137
  emissions_per_group = [
122
- {
123
- 'id': group_id,
124
- 'emissions': list(filter(
125
- lambda id: id in required_emission_term_ids,
126
- find_term_ids_by(lookup, column_name('inputProductionGroupId'), group_id)
127
- ))
128
- }
138
+ _map_group_emissions(group_id, required_emission_term_ids, emission_ids)
129
139
  for group_id in group_ids
130
140
  ]
131
- emissions_per_group = [
132
- {
133
- 'id': group.get('id'),
134
- 'total-emissions': len(group.get('emissions', [])),
135
- 'included-emissions': len(list(filter(lambda v: v in emission_ids, group.get('emissions', [])))),
136
- 'missing-emissions': '-'.join(list(filter(lambda v: v not in emission_ids, group.get('emissions', []))))
137
- }
138
- for group in emissions_per_group
139
- ]
140
141
  # only keep groups that have all emissions present in the Cycle
141
- valid_groups = list(filter(
142
- lambda group: group.get('total-emissions') == group.get('included-emissions'),
143
- emissions_per_group
144
- ))
142
+ valid_groups = list(filter(lambda group: group.get('is-valid'), emissions_per_group))
145
143
  valid_group_ids = set([v.get('id') for v in valid_groups])
146
144
 
147
145
  # finally, only return emissions which groups are valid
@@ -273,6 +271,12 @@ def _should_run(cycle: dict):
273
271
 
274
272
  logShouldRun(cycle, MODEL, term_id, should_run, methodTier=TIER, model_key=MODEL_KEY)
275
273
 
274
+ # log missing emissions to show in the logs
275
+ for group in emissions_per_group:
276
+ if not group.get('is-valid'):
277
+ logShouldRun(cycle, MODEL, term_id, False,
278
+ methodTier=TIER, model_key=MODEL_KEY, emission_id=group.get('id'))
279
+
276
280
  return should_run, total_economicValueShare, total_yield, grouped_seed_inputs, grouped_emissions
277
281
 
278
282