hestia-earth-models 0.74.4__py3-none-any.whl → 0.74.6__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 (66) hide show
  1. hestia_earth/models/cml2001Baseline/abioticResourceDepletionMineralsAndMetals.py +0 -1
  2. hestia_earth/models/config/Cycle.json +15 -0
  3. hestia_earth/models/config/ImpactAssessment.json +9 -1
  4. hestia_earth/models/cycle/animal/input/hestiaAggregatedData.py +3 -3
  5. hestia_earth/models/cycle/completeness/seed.py +1 -1
  6. hestia_earth/models/cycle/input/hestiaAggregatedData.py +25 -16
  7. hestia_earth/models/data/hestiaAggregatedData/__init__.py +73 -0
  8. hestia_earth/models/environmentalFootprintV3_1/scarcityWeightedWaterUse.py +1 -1
  9. hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandOccupation.py +5 -6
  10. hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandTransformation.py +10 -13
  11. hestia_earth/models/fantkeEtAl2016/damageToHumanHealthParticulateMatterFormation.py +1 -1
  12. hestia_earth/models/hestia/default_resourceUse.py +18 -16
  13. hestia_earth/models/hestia/landCover.py +24 -0
  14. hestia_earth/models/hestia/landOccupationDuringCycle.py +80 -51
  15. hestia_earth/models/hestia/landTransformation100YearAverageDuringCycle.py +7 -1
  16. hestia_earth/models/hestia/landTransformation20YearAverageDuringCycle.py +7 -1
  17. hestia_earth/models/hestia/resourceUse_utils.py +58 -119
  18. hestia_earth/models/hestia/waterSalinity.py +57 -12
  19. hestia_earth/models/impact_assessment/post_checks/__init__.py +3 -2
  20. hestia_earth/models/impact_assessment/post_checks/remove_cache_fields.py +9 -0
  21. hestia_earth/models/impact_assessment/pre_checks/cache_emissionsResourceUse.py +21 -0
  22. hestia_earth/models/impact_assessment/pre_checks/cycle.py +5 -0
  23. hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChange.py +6 -64
  24. hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChange.py +9 -87
  25. hestia_earth/models/ipcc2019/co2ToAirBiocharStockChange.py +140 -0
  26. hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +329 -217
  27. hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChange.py +10 -87
  28. hestia_earth/models/mocking/__init__.py +2 -2
  29. hestia_earth/models/mocking/mock_search.py +20 -10
  30. hestia_earth/models/mocking/search-results.json +1 -7679
  31. hestia_earth/models/pooreNemecek2018/landOccupationDuringCycle.py +8 -7
  32. hestia_earth/models/poschEtAl2008/terrestrialAcidificationPotentialAccumulatedExceedance.py +1 -1
  33. hestia_earth/models/poschEtAl2008/terrestrialEutrophicationPotentialAccumulatedExceedance.py +1 -1
  34. hestia_earth/models/preload_requests.py +18 -4
  35. hestia_earth/models/schmidt2007/utils.py +3 -3
  36. hestia_earth/models/utils/__init__.py +4 -1
  37. hestia_earth/models/utils/aggregated.py +21 -68
  38. hestia_earth/models/utils/cycle.py +3 -3
  39. hestia_earth/models/utils/impact_assessment.py +45 -41
  40. hestia_earth/models/utils/indicator.py +1 -3
  41. hestia_earth/models/utils/lookup.py +92 -67
  42. hestia_earth/models/version.py +1 -1
  43. hestia_earth/orchestrator/models/__init__.py +47 -10
  44. hestia_earth/orchestrator/models/transformations.py +3 -1
  45. hestia_earth/orchestrator/strategies/merge/__init__.py +1 -2
  46. hestia_earth/orchestrator/strategies/merge/merge_list.py +31 -8
  47. hestia_earth/orchestrator/utils.py +29 -0
  48. {hestia_earth_models-0.74.4.dist-info → hestia_earth_models-0.74.6.dist-info}/METADATA +2 -3
  49. {hestia_earth_models-0.74.4.dist-info → hestia_earth_models-0.74.6.dist-info}/RECORD +66 -59
  50. tests/models/cycle/animal/input/test_hestiaAggregatedData.py +3 -3
  51. tests/models/cycle/input/test_hestiaAggregatedData.py +9 -18
  52. tests/models/data/__init__.py +0 -0
  53. tests/models/data/test_hestiaAggregatedData.py +32 -0
  54. tests/models/hestia/test_default_emissions.py +8 -1
  55. tests/models/hestia/test_default_resourceUse.py +7 -1
  56. tests/models/hestia/test_landCover.py +32 -1
  57. tests/models/hestia/test_waterSalinity.py +16 -4
  58. tests/models/ipcc2019/test_co2ToAirAboveGroundBiomassStockChange.py +1 -6
  59. tests/models/ipcc2019/test_co2ToAirBelowGroundBiomassStockChange.py +1 -6
  60. tests/models/ipcc2019/test_co2ToAirBiocharStockChange.py +90 -0
  61. tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChange.py +1 -6
  62. tests/models/pooreNemecek2018/test_landOccupationDuringCycle.py +1 -0
  63. tests/orchestrator/strategies/merge/test_merge_list.py +5 -0
  64. {hestia_earth_models-0.74.4.dist-info → hestia_earth_models-0.74.6.dist-info}/LICENSE +0 -0
  65. {hestia_earth_models-0.74.4.dist-info → hestia_earth_models-0.74.6.dist-info}/WHEEL +0 -0
  66. {hestia_earth_models-0.74.4.dist-info → hestia_earth_models-0.74.6.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,6 @@
1
- from hestia_earth.schema import CycleFunctionalUnit, EmissionMethodTier, MeasurementMethodClassification, SiteSiteType
1
+ from hestia_earth.schema import EmissionMethodTier, MeasurementMethodClassification
2
2
 
3
3
  from hestia_earth.models.log import logRequirements, logShouldRun
4
- from hestia_earth.models.utils.blank_node import cumulative_nodes_term_match
5
4
  from hestia_earth.models.utils.emission import _new_emission
6
5
 
7
6
  from .biomass_utils import detect_land_cover_change, get_valid_management_nodes, summarise_land_cover_nodes
@@ -61,13 +60,6 @@ The list of `MeasurementMethodClassification`s that can be used to calculate SOC
61
60
  order from strongest to weakest.
62
61
  """
63
62
 
64
- _SITE_TYPE_SYSTEMS_MAPPING = {
65
- SiteSiteType.GLASS_OR_HIGH_ACCESSIBLE_COVER.value: [
66
- "protectedCroppingSystemSoilBased",
67
- "protectedCroppingSystemSoilAndSubstrateBased"
68
- ]
69
- }
70
-
71
63
 
72
64
  def _emission(
73
65
  *,
@@ -129,12 +121,12 @@ def run(cycle: dict) -> list[dict]:
129
121
  A list of [Emission nodes](https://www.hestia.earth/schema/Emission) containing model results.
130
122
  """
131
123
  should_run_exec = create_should_run_function(
132
- carbon_stock_term_id=_CARBON_STOCK_TERM_ID,
124
+ _CARBON_STOCK_TERM_ID,
125
+ measurements_mandatory=False, # Model can allocate zero emissions to LUC with enough landCover data
126
+ measurement_method_ranking=_MEASUREMENT_METHOD_RANKING,
133
127
  get_valid_management_nodes_func=get_valid_management_nodes,
134
- should_compile_inventory_func=_should_compile_inventory_func,
135
128
  summarise_land_use_func=summarise_land_cover_nodes,
136
129
  detect_land_use_change_func=detect_land_cover_change,
137
- measurement_method_ranking=_MEASUREMENT_METHOD_RANKING
138
130
  )
139
131
 
140
132
  run_exec = create_run_function(
@@ -143,60 +135,10 @@ def run(cycle: dict) -> list[dict]:
143
135
  management_change_emission_term_id=_MG_EMISSION_TERM_ID
144
136
  )
145
137
 
146
- should_run, kwargs, logs = should_run_exec(cycle)
138
+ should_run, cycle_id, inventory, logs = should_run_exec(cycle)
147
139
 
148
140
  for term_id in [_LU_EMISSION_TERM_ID, _MG_EMISSION_TERM_ID]:
149
141
  logRequirements(cycle, model=MODEL, term=term_id, **logs)
150
142
  logShouldRun(cycle, MODEL, term_id, should_run)
151
143
 
152
- return run_exec(**kwargs) if should_run else []
153
-
154
-
155
- def _should_compile_inventory_func(
156
- site: dict, cycles: list[dict], carbon_stock_measurements: list[dict]
157
- ) -> tuple[bool, dict]:
158
- """
159
- Determine whether a site is suitable and has enough data to compile a carbon stock inventory.
160
-
161
- Parameters
162
- ----------
163
- site : dict
164
- A HESTIA (Site node)[https://www.hestia.earth/schema/Site]
165
- cycles : list[dict]
166
- A list of HESTIA (Cycle nodes)[https://www.hestia.earth/schema/Cycle] that are related to the site.
167
- carbon_stock_measurements : list[dict]
168
- A list of HESTIA carbon stock (Measurement nodes)[https://www.hestia.earth/schema/Measurement] that are related
169
- to the site.
170
-
171
- Returns
172
- -------
173
- tuple[bool, dict]
174
- `(should_run, logs)`.
175
- """
176
- site_type = site.get("siteType")
177
- has_soil = site_type not in _SITE_TYPE_SYSTEMS_MAPPING or all(
178
- cumulative_nodes_term_match(
179
- cycle.get("practices", []),
180
- target_term_ids=_SITE_TYPE_SYSTEMS_MAPPING[site_type],
181
- cumulative_threshold=0
182
- ) for cycle in cycles
183
- )
184
-
185
- has_cycles = len(cycles) > 0
186
- has_functional_unit_1_ha = all(cycle.get('functionalUnit') == CycleFunctionalUnit._1_HA.value for cycle in cycles)
187
-
188
- should_run = all([
189
- has_soil,
190
- has_cycles,
191
- has_functional_unit_1_ha
192
- ])
193
-
194
- logs = {
195
- "site_type": site_type,
196
- "has_soil": has_soil,
197
- "carbon_stock_term": _CARBON_STOCK_TERM_ID,
198
- "has_cycles": has_cycles,
199
- "has_functional_unit_1_ha": has_functional_unit_1_ha,
200
- }
201
-
202
- return should_run, logs
144
+ return run_exec(cycle_id, inventory) if should_run else []
@@ -1,7 +1,6 @@
1
- from hestia_earth.schema import CycleFunctionalUnit, EmissionMethodTier, SiteSiteType
1
+ from hestia_earth.schema import EmissionMethodTier
2
2
 
3
3
  from hestia_earth.models.log import logRequirements, logShouldRun
4
- from hestia_earth.models.utils.blank_node import cumulative_nodes_term_match
5
4
  from hestia_earth.models.utils.emission import _new_emission
6
5
 
7
6
  from .biomass_utils import detect_land_cover_change, get_valid_management_nodes, summarise_land_cover_nodes
@@ -19,7 +18,7 @@ REQUIREMENTS = {
19
18
  "dates": "",
20
19
  "depthUpper": "0",
21
20
  "depthLower": "30",
22
- "term.@id": " belowGroundBiomass"
21
+ "term.@id": "belowGroundBiomass"
23
22
  }
24
23
  ]
25
24
  },
@@ -52,13 +51,6 @@ _DEPTH_LOWER = 30
52
51
 
53
52
  _CARBON_STOCK_TERM_ID = 'belowGroundBiomass'
54
53
 
55
- _SITE_TYPE_SYSTEMS_MAPPING = {
56
- SiteSiteType.GLASS_OR_HIGH_ACCESSIBLE_COVER.value: [
57
- "protectedCroppingSystemSoilBased",
58
- "protectedCroppingSystemSoilAndSubstrateBased"
59
- ]
60
- }
61
-
62
54
 
63
55
  def _emission(
64
56
  *,
@@ -121,12 +113,13 @@ def run(cycle: dict) -> list[dict]:
121
113
  A list of [Emission nodes](https://www.hestia.earth/schema/Emission) containing model results.
122
114
  """
123
115
  should_run_exec = create_should_run_function(
124
- carbon_stock_term_id=_CARBON_STOCK_TERM_ID,
116
+ _CARBON_STOCK_TERM_ID,
117
+ depth_upper=_DEPTH_UPPER,
118
+ depth_lower=_DEPTH_LOWER,
119
+ measurements_mandatory=False, # Model can allocate zero emissions to LUC with enough landCover data
125
120
  get_valid_management_nodes_func=get_valid_management_nodes,
126
- should_compile_inventory_func=_should_compile_inventory_func,
127
121
  summarise_land_use_func=summarise_land_cover_nodes,
128
- detect_land_use_change_func=detect_land_cover_change,
129
- should_run_measurement_func=_should_run_measurement_func
122
+ detect_land_use_change_func=detect_land_cover_change
130
123
  )
131
124
 
132
125
  run_exec = create_run_function(
@@ -135,81 +128,10 @@ def run(cycle: dict) -> list[dict]:
135
128
  management_change_emission_term_id=_MG_EMISSION_TERM_ID
136
129
  )
137
130
 
138
- should_run, kwargs, logs = should_run_exec(cycle)
131
+ should_run, cycle_id, inventory, logs = should_run_exec(cycle)
139
132
 
140
133
  for term_id in [_LU_EMISSION_TERM_ID, _MG_EMISSION_TERM_ID]:
141
134
  logRequirements(cycle, model=MODEL, term=term_id, **logs)
142
135
  logShouldRun(cycle, MODEL, term_id, should_run)
143
136
 
144
- return run_exec(**kwargs) if should_run else []
145
-
146
-
147
- def _should_run_measurement_func(node: dict) -> bool:
148
- """
149
- Validate a [Measurement](https://www.hestia.earth/schema/Measurement) to determine whether it is a valid
150
- `organicCarbonPerHa` node.
151
-
152
- Parameters
153
- ----------
154
- node : dict
155
- The node to be validated.
156
-
157
- Returns
158
- -------
159
- bool
160
- `True` if the node passes all validation criteria, `False` otherwise.
161
- """
162
- return all([
163
- node.get("depthLower") == _DEPTH_LOWER,
164
- node.get("depthUpper") == _DEPTH_UPPER
165
- ])
166
-
167
-
168
- def _should_compile_inventory_func(
169
- site: dict, cycles: list[dict], carbon_stock_measurements: list[dict]
170
- ) -> tuple[bool, dict]:
171
- """
172
- Determine whether a site is suitable and has enough data to compile a carbon stock inventory.
173
-
174
- Parameters
175
- ----------
176
- site : dict
177
- A HESTIA (Site node)[https://www.hestia.earth/schema/Site]
178
- cycles : list[dict]
179
- A list of HESTIA (Cycle nodes)[https://www.hestia.earth/schema/Cycle] that are related to the site.
180
- carbon_stock_measurements : list[dict]
181
- A list of HESTIA carbon stock (Measurement nodes)[https://www.hestia.earth/schema/Measurement] that are related
182
- to the site.
183
-
184
- Returns
185
- -------
186
- tuple[bool, dict]
187
- `(should_run, logs)`.
188
- """
189
- site_type = site.get("siteType")
190
- has_soil = site_type not in _SITE_TYPE_SYSTEMS_MAPPING or all(
191
- cumulative_nodes_term_match(
192
- cycle.get("practices", []),
193
- target_term_ids=_SITE_TYPE_SYSTEMS_MAPPING[site_type],
194
- cumulative_threshold=0
195
- ) for cycle in cycles
196
- )
197
-
198
- has_cycles = len(cycles) > 0
199
- has_functional_unit_1_ha = all(cycle.get('functionalUnit') == CycleFunctionalUnit._1_HA.value for cycle in cycles)
200
-
201
- should_run = all([
202
- has_soil,
203
- has_cycles,
204
- has_functional_unit_1_ha
205
- ])
206
-
207
- logs = {
208
- "site_type": site_type,
209
- "has_soil": has_soil,
210
- "carbon_stock_term": _CARBON_STOCK_TERM_ID,
211
- "has_cycles": has_cycles,
212
- "has_functional_unit_1_ha": has_functional_unit_1_ha,
213
- }
214
-
215
- return should_run, logs
137
+ return run_exec(cycle_id, inventory) if should_run else []
@@ -0,0 +1,140 @@
1
+ from hestia_earth.schema import EmissionMethodTier
2
+ from hestia_earth.utils.date import YEAR
3
+
4
+ from hestia_earth.models.log import logRequirements, logShouldRun
5
+ from hestia_earth.models.utils.emission import _new_emission
6
+
7
+ from .co2ToAirCarbonStockChange_utils import create_run_function, create_should_run_function
8
+ from . import MODEL
9
+
10
+ REQUIREMENTS = {
11
+ "Cycle": {
12
+ "site": {
13
+ "@type": "Site",
14
+ "measurements": [
15
+ {
16
+ "@type": "Measurement",
17
+ "value": "",
18
+ "dates": "",
19
+ "depthUpper": "0",
20
+ "depthLower": "30",
21
+ "term.@id": "biocharOrganicCarbonPerHa"
22
+ }
23
+ ]
24
+ },
25
+ "functionalUnit": "1 ha",
26
+ "endDate": "",
27
+ "optional": {
28
+ "startDate": ""
29
+ }
30
+ }
31
+ }
32
+ RETURNS = {
33
+ "Emission": [{
34
+ "value": "",
35
+ "sd": "",
36
+ "min": "",
37
+ "max": "",
38
+ "statsDefinition": "simulated",
39
+ "observations": "",
40
+ "methodTier": "",
41
+ "depth": 30
42
+ }]
43
+ }
44
+ TERM_ID = 'co2ToAirBiocharStockChange'
45
+
46
+ _DEPTH_UPPER = 0
47
+ _DEPTH_LOWER = 30
48
+
49
+ _CARBON_STOCK_TERM_ID = 'biocharOrganicCarbonPerHa'
50
+
51
+ _TRANSITION_PERIOD_YEARS = 100
52
+ _TRANSITION_PERIOD_DAYS = _TRANSITION_PERIOD_YEARS * YEAR
53
+
54
+ _EXCLUDE_FROM_LOGS = ["land_use_inventory"] # not required for model
55
+
56
+
57
+ def _emission(
58
+ *,
59
+ term_id: str,
60
+ value: list[float],
61
+ method_tier: EmissionMethodTier,
62
+ sd: list[float] = None,
63
+ min: list[float] = None,
64
+ max: list[float] = None,
65
+ statsDefinition: str = None,
66
+ observations: list[int] = None
67
+ ) -> dict:
68
+ """
69
+ Create an emission node based on the provided value and method tier.
70
+
71
+ See [Emission schema](https://www.hestia.earth/schema/Emission) for more information.
72
+
73
+ Parameters
74
+ ----------
75
+ value : float
76
+ The emission value (kg CO2 ha-1).
77
+ sd : float
78
+ The standard deviation (kg CO2 ha-1).
79
+ method_tier : EmissionMethodTier
80
+ The emission method tier.
81
+
82
+ Returns
83
+ -------
84
+ dict
85
+ The emission dictionary with keys 'depth', 'value', and 'methodTier'.
86
+ """
87
+ update_dict = {
88
+ "value": value,
89
+ "sd": sd,
90
+ "min": min,
91
+ "max": max,
92
+ "statsDefinition": statsDefinition,
93
+ "observations": observations,
94
+ "methodTier": method_tier.value,
95
+ "depth": _DEPTH_LOWER
96
+ }
97
+ emission = _new_emission(term_id, MODEL) | {
98
+ key: value for key, value in update_dict.items() if value
99
+ }
100
+ return emission
101
+
102
+
103
+ def run(cycle: dict) -> list[dict]:
104
+ """
105
+ Run the `ipcc2019.co2ToAirBelowGroundBiomassStockChangeManagementChange`.
106
+
107
+ Parameters
108
+ ----------
109
+ cycle : dict
110
+ A HESTIA (Cycle node)[https://www.hestia.earth/schema/Cycle].
111
+
112
+ Returns
113
+ -------
114
+ list[dict]
115
+ A list of [Emission nodes](https://www.hestia.earth/schema/Emission) containing model results.
116
+ """
117
+ should_run_exec = create_should_run_function(
118
+ _CARBON_STOCK_TERM_ID,
119
+ depth_upper=_DEPTH_UPPER,
120
+ depth_lower=_DEPTH_LOWER,
121
+ transition_period=_TRANSITION_PERIOD_DAYS
122
+ )
123
+
124
+ run_exec = create_run_function(
125
+ new_emission_func=_emission,
126
+ land_use_change_emission_term_id=None, # All emissions allocated to management change
127
+ management_change_emission_term_id=TERM_ID
128
+ )
129
+
130
+ should_run, cycle_id, inventory, logs = should_run_exec(cycle)
131
+
132
+ logRequirements(
133
+ cycle,
134
+ model=MODEL,
135
+ term=TERM_ID,
136
+ **{k: v for k, v in logs.items() if k not in _EXCLUDE_FROM_LOGS}
137
+ )
138
+ logShouldRun(cycle, MODEL, TERM_ID, should_run)
139
+
140
+ return run_exec(cycle_id, inventory) if should_run else []