hestia-earth-models 0.64.7__py3-none-any.whl → 0.64.9__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 (58) hide show
  1. hestia_earth/models/cycle/animal/milkYield.py +10 -22
  2. hestia_earth/models/cycle/siteArea.py +2 -1
  3. hestia_earth/models/cycle/unknownPreSeasonWaterRegime.py +0 -1
  4. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandOccupation.py +73 -82
  5. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandTransformation.py +168 -0
  6. hestia_earth/models/environmentalFootprintV3/soilQualityIndexTotalLandUseEffects.py +77 -0
  7. hestia_earth/models/environmentalFootprintV3/utils.py +1 -1
  8. hestia_earth/models/faostat2018/landTransformationFromCropland100YearAverage.py +3 -2
  9. hestia_earth/models/faostat2018/landTransformationFromCropland20YearAverage.py +3 -2
  10. hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +69 -37
  11. hestia_earth/models/hyde32/utils.py +4 -0
  12. hestia_earth/models/ipcc2019/animal/fatContent.py +38 -0
  13. hestia_earth/models/ipcc2019/animal/liveweightGain.py +3 -54
  14. hestia_earth/models/ipcc2019/animal/liveweightPerHead.py +3 -54
  15. hestia_earth/models/ipcc2019/animal/pastureGrass.py +3 -1
  16. hestia_earth/models/ipcc2019/animal/pregnancyRateTotal.py +38 -0
  17. hestia_earth/models/ipcc2019/animal/trueProteinContent.py +38 -0
  18. hestia_earth/models/ipcc2019/animal/utils.py +87 -3
  19. hestia_earth/models/ipcc2019/animal/weightAtMaturity.py +4 -10
  20. hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +191 -0
  21. hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChangeLandUseChange.py +204 -0
  22. hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +255 -35
  23. hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +63 -149
  24. hestia_earth/models/ipcc2019/pastureGrass.py +3 -1
  25. hestia_earth/models/mocking/search-results.json +2026 -26
  26. hestia_earth/models/pooreNemecek2018/landOccupationDuringCycle.py +1 -1
  27. hestia_earth/models/poschEtAl2008/terrestrialAcidificationPotentialAccumulatedExceedance.py +4 -1
  28. hestia_earth/models/poschEtAl2008/terrestrialEutrophicationPotentialAccumulatedExceedance.py +4 -1
  29. hestia_earth/models/site/management.py +3 -5
  30. hestia_earth/models/utils/__init__.py +5 -4
  31. hestia_earth/models/utils/impact_assessment.py +13 -4
  32. hestia_earth/models/utils/input.py +5 -2
  33. hestia_earth/models/utils/site.py +4 -2
  34. hestia_earth/models/version.py +1 -1
  35. {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/METADATA +2 -2
  36. {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/RECORD +58 -44
  37. tests/models/cycle/animal/test_milkYield.py +1 -14
  38. tests/models/environmentalFootprintV3/test_soilQualityIndexLandOccupation.py +97 -66
  39. tests/models/environmentalFootprintV3/test_soilQualityIndexLandTransformation.py +176 -0
  40. tests/models/environmentalFootprintV3/test_soilQualityIndexTotalLandUseEffects.py +55 -0
  41. tests/models/frischknechtEtAl2000/test_ionisingRadiationKbqU235Eq.py +67 -44
  42. tests/models/ipcc2019/animal/test_fatContent.py +22 -0
  43. tests/models/ipcc2019/animal/test_liveweightGain.py +4 -2
  44. tests/models/ipcc2019/animal/test_liveweightPerHead.py +4 -2
  45. tests/models/ipcc2019/animal/test_pregnancyRateTotal.py +22 -0
  46. tests/models/ipcc2019/animal/test_trueProteinContent.py +22 -0
  47. tests/models/ipcc2019/animal/test_weightAtMaturity.py +2 -1
  48. tests/models/ipcc2019/test_co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +83 -0
  49. tests/models/ipcc2019/test_co2ToAirBelowGroundBiomassStockChangeLandUseChange.py +83 -0
  50. tests/models/ipcc2019/test_co2ToAirCarbonStockChange_utils.py +6 -6
  51. tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +5 -4
  52. tests/models/poschEtAl2008/test_terrestrialAcidificationPotentialAccumulatedExceedance.py +30 -17
  53. tests/models/poschEtAl2008/test_terrestrialEutrophicationPotentialAccumulatedExceedance.py +28 -14
  54. tests/models/site/test_management.py +4 -1
  55. tests/models/utils/test_input.py +65 -1
  56. {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/LICENSE +0 -0
  57. {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/WHEEL +0 -0
  58. {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,191 @@
1
+ from hestia_earth.schema import CycleFunctionalUnit, EmissionMethodTier, MeasurementMethodClassification, SiteSiteType
2
+
3
+ from hestia_earth.models.log import logRequirements, logShouldRun
4
+ from hestia_earth.models.utils.blank_node import cumulative_nodes_term_match
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
+ "measurements": [
14
+ {
15
+ "@type": "Measurement",
16
+ "value": "",
17
+ "dates": "",
18
+ "depthUpper": "0",
19
+ "depthLower": "30",
20
+ "term.@id": "aboveGroundBiomass"
21
+ }
22
+ ]
23
+ },
24
+ "functionalUnit": "1 ha",
25
+ "endDate": "",
26
+ "optional": {
27
+ "startDate": ""
28
+ }
29
+ }
30
+ }
31
+ RETURNS = {
32
+ "Emission": [{
33
+ "value": "",
34
+ "sd": "",
35
+ "min": "",
36
+ "max": "",
37
+ "statsDefinition": "simulated",
38
+ "observations": "",
39
+ "methodTier": ""
40
+ }]
41
+ }
42
+ TERM_ID = 'co2ToAirAboveGroundBiomassStockChangeLandUseChange'
43
+
44
+ _CARBON_STOCK_TERM_ID = 'aboveGroundBiomass'
45
+
46
+ _MEASUREMENT_METHOD_RANKING = [
47
+ MeasurementMethodClassification.ON_SITE_PHYSICAL_MEASUREMENT,
48
+ MeasurementMethodClassification.MODELLED_USING_OTHER_MEASUREMENTS,
49
+ MeasurementMethodClassification.TIER_3_MODEL,
50
+ MeasurementMethodClassification.TIER_2_MODEL,
51
+ MeasurementMethodClassification.TIER_1_MODEL,
52
+ MeasurementMethodClassification.GEOSPATIAL_DATASET
53
+ ]
54
+ """
55
+ The list of `MeasurementMethodClassification`s that can be used to calculate SOC stock change emissions, ranked in
56
+ order from strongest to weakest.
57
+ """
58
+
59
+ _SITE_TYPE_SYSTEMS_MAPPING = {
60
+ SiteSiteType.GLASS_OR_HIGH_ACCESSIBLE_COVER.value: [
61
+ "protectedCroppingSystemSoilBased",
62
+ "protectedCroppingSystemSoilAndSubstrateBased"
63
+ ]
64
+ }
65
+
66
+
67
+ def _emission(
68
+ *,
69
+ value: list[float],
70
+ method_tier: EmissionMethodTier,
71
+ sd: list[float] = None,
72
+ min: list[float] = None,
73
+ max: list[float] = None,
74
+ statsDefinition: str = None,
75
+ observations: list[int] = None
76
+ ) -> dict:
77
+ """
78
+ Create an emission node based on the provided value and method tier.
79
+
80
+ See [Emission schema](https://www.hestia.earth/schema/Emission) for more information.
81
+
82
+ Parameters
83
+ ----------
84
+ value : float
85
+ The emission value (kg CO2 ha-1).
86
+ sd : float
87
+ The standard deviation (kg CO2 ha-1).
88
+ method_tier : EmissionMethodTier
89
+ The emission method tier.
90
+
91
+ Returns
92
+ -------
93
+ dict
94
+ The emission dictionary with keys 'depth', 'value', and 'methodTier'.
95
+ """
96
+ update_dict = {
97
+ "value": value,
98
+ "sd": sd,
99
+ "min": min,
100
+ "max": max,
101
+ "statsDefinition": statsDefinition,
102
+ "observations": observations,
103
+ "methodTier": method_tier.value
104
+ }
105
+ emission = _new_emission(TERM_ID, MODEL) | {
106
+ key: value for key, value in update_dict.items() if value
107
+ }
108
+ return emission
109
+
110
+
111
+ def run(cycle: dict) -> list[dict]:
112
+ """
113
+ Run the `ipcc2019.co2ToAirAboveGroundBiomassStockChangeManagementChange`.
114
+
115
+ Parameters
116
+ ----------
117
+ cycle : dict
118
+ A HESTIA (Cycle node)[https://www.hestia.earth/schema/Cycle].
119
+
120
+ Returns
121
+ -------
122
+ list[dict]
123
+ A list of [Emission nodes](https://www.hestia.earth/schema/Emission) containing model results.
124
+ """
125
+ should_run_exec = create_should_run_function(
126
+ _CARBON_STOCK_TERM_ID,
127
+ _should_compile_inventory_func,
128
+ measurement_method_ranking=_MEASUREMENT_METHOD_RANKING
129
+ )
130
+
131
+ run_exec = create_run_function(_emission)
132
+
133
+ should_run, cycle_id, inventory, logs = should_run_exec(cycle)
134
+
135
+ logRequirements(cycle, model=MODEL, term=TERM_ID, **logs)
136
+ logShouldRun(cycle, MODEL, TERM_ID, should_run)
137
+
138
+ return run_exec(cycle_id, inventory) if should_run else []
139
+
140
+
141
+ def _should_compile_inventory_func(
142
+ site: dict, cycles: list[dict], carbon_stock_measurements: list[dict]
143
+ ) -> tuple[bool, dict]:
144
+ """
145
+ Determine whether a site is suitable and has enough data to compile a carbon stock inventory.
146
+
147
+ Parameters
148
+ ----------
149
+ site : dict
150
+ A HESTIA (Site node)[https://www.hestia.earth/schema/Site]
151
+ cycles : list[dict]
152
+ A list of HESTIA (Cycle nodes)[https://www.hestia.earth/schema/Cycle] that are related to the site.
153
+ carbon_stock_measurements : list[dict]
154
+ A list of HESTIA carbon stock (Measurement nodes)[https://www.hestia.earth/schema/Measurement] that are related
155
+ to the site.
156
+
157
+ Returns
158
+ -------
159
+ tuple[bool, dict]
160
+ `(should_run, logs)`.
161
+ """
162
+ site_type = site.get("siteType")
163
+ has_soil = site_type not in _SITE_TYPE_SYSTEMS_MAPPING or all(
164
+ cumulative_nodes_term_match(
165
+ cycle.get("practices", []),
166
+ target_term_ids=_SITE_TYPE_SYSTEMS_MAPPING[site_type],
167
+ cumulative_threshold=0
168
+ ) for cycle in cycles
169
+ )
170
+
171
+ has_stock_measurements = len(carbon_stock_measurements) > 0
172
+ has_cycles = len(cycles) > 0
173
+ has_functional_unit_1_ha = all(cycle.get('functionalUnit') == CycleFunctionalUnit._1_HA.value for cycle in cycles)
174
+
175
+ should_run = all([
176
+ has_soil,
177
+ has_stock_measurements,
178
+ has_cycles,
179
+ has_functional_unit_1_ha
180
+ ])
181
+
182
+ logs = {
183
+ "site_type": site_type,
184
+ "has_soil": has_soil,
185
+ "carbon_stock_term": _CARBON_STOCK_TERM_ID,
186
+ "has_stock_measurements": has_stock_measurements,
187
+ "has_cycles": has_cycles,
188
+ "has_functional_unit_1_ha": has_functional_unit_1_ha,
189
+ }
190
+
191
+ return should_run, logs
@@ -0,0 +1,204 @@
1
+ from hestia_earth.schema import CycleFunctionalUnit, EmissionMethodTier, SiteSiteType
2
+
3
+ from hestia_earth.models.log import logRequirements, logShouldRun
4
+ from hestia_earth.models.utils.blank_node import cumulative_nodes_term_match
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
+ "measurements": [
14
+ {
15
+ "@type": "Measurement",
16
+ "value": "",
17
+ "dates": "",
18
+ "depthUpper": "0",
19
+ "depthLower": "30",
20
+ "term.@id": " belowGroundBiomass"
21
+ }
22
+ ]
23
+ },
24
+ "functionalUnit": "1 ha",
25
+ "endDate": "",
26
+ "optional": {
27
+ "startDate": ""
28
+ }
29
+ }
30
+ }
31
+ RETURNS = {
32
+ "Emission": [{
33
+ "value": "",
34
+ "sd": "",
35
+ "min": "",
36
+ "max": "",
37
+ "statsDefinition": "simulated",
38
+ "observations": "",
39
+ "methodTier": "",
40
+ "depth": "30"
41
+ }]
42
+ }
43
+ TERM_ID = 'co2ToAirBelowGroundBiomassStockChangeLandUseChange'
44
+
45
+ _DEPTH_UPPER = 0
46
+ _DEPTH_LOWER = 30
47
+
48
+ _CARBON_STOCK_TERM_ID = 'belowGroundBiomass'
49
+
50
+ _SITE_TYPE_SYSTEMS_MAPPING = {
51
+ SiteSiteType.GLASS_OR_HIGH_ACCESSIBLE_COVER.value: [
52
+ "protectedCroppingSystemSoilBased",
53
+ "protectedCroppingSystemSoilAndSubstrateBased"
54
+ ]
55
+ }
56
+
57
+
58
+ def _emission(
59
+ *,
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
+ _should_compile_inventory_func,
120
+ should_run_measurement_func=_should_run_measurement_func
121
+ )
122
+
123
+ run_exec = create_run_function(_emission)
124
+
125
+ should_run, cycle_id, inventory, logs = should_run_exec(cycle)
126
+
127
+ logRequirements(cycle, model=MODEL, term=TERM_ID, **logs)
128
+ logShouldRun(cycle, MODEL, TERM_ID, should_run)
129
+
130
+ return run_exec(cycle_id, inventory) if should_run else []
131
+
132
+
133
+ def _should_run_measurement_func(node: dict) -> bool:
134
+ """
135
+ Validate a [Measurement](https://www.hestia.earth/schema/Measurement) to determine whether it is a valid
136
+ `organicCarbonPerHa` node.
137
+
138
+ Parameters
139
+ ----------
140
+ node : dict
141
+ The node to be validated.
142
+
143
+ Returns
144
+ -------
145
+ bool
146
+ `True` if the node passes all validation criteria, `False` otherwise.
147
+ """
148
+ return all([
149
+ node.get("depthLower") == _DEPTH_LOWER,
150
+ node.get("depthUpper") == _DEPTH_UPPER
151
+ ])
152
+
153
+
154
+ def _should_compile_inventory_func(
155
+ site: dict, cycles: list[dict], carbon_stock_measurements: list[dict]
156
+ ) -> tuple[bool, dict]:
157
+ """
158
+ Determine whether a site is suitable and has enough data to compile a carbon stock inventory.
159
+
160
+ Parameters
161
+ ----------
162
+ site : dict
163
+ A HESTIA (Site node)[https://www.hestia.earth/schema/Site]
164
+ cycles : list[dict]
165
+ A list of HESTIA (Cycle nodes)[https://www.hestia.earth/schema/Cycle] that are related to the site.
166
+ carbon_stock_measurements : list[dict]
167
+ A list of HESTIA carbon stock (Measurement nodes)[https://www.hestia.earth/schema/Measurement] that are related
168
+ to the site.
169
+
170
+ Returns
171
+ -------
172
+ tuple[bool, dict]
173
+ `(should_run, logs)`.
174
+ """
175
+ site_type = site.get("siteType")
176
+ has_soil = site_type not in _SITE_TYPE_SYSTEMS_MAPPING or all(
177
+ cumulative_nodes_term_match(
178
+ cycle.get("practices", []),
179
+ target_term_ids=_SITE_TYPE_SYSTEMS_MAPPING[site_type],
180
+ cumulative_threshold=0
181
+ ) for cycle in cycles
182
+ )
183
+
184
+ has_stock_measurements = len(carbon_stock_measurements) > 0
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_stock_measurements,
191
+ has_cycles,
192
+ has_functional_unit_1_ha
193
+ ])
194
+
195
+ logs = {
196
+ "site_type": site_type,
197
+ "has_soil": has_soil,
198
+ "carbon_stock_term": _CARBON_STOCK_TERM_ID,
199
+ "has_stock_measurements": has_stock_measurements,
200
+ "has_cycles": has_cycles,
201
+ "has_functional_unit_1_ha": has_functional_unit_1_ha,
202
+ }
203
+
204
+ return should_run, logs