hestia-earth-models 0.61.7__py3-none-any.whl → 0.62.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.

Potentially problematic release.


This version of hestia-earth-models might be problematic. Click here for more details.

Files changed (51) hide show
  1. hestia_earth/models/cycle/completeness/electricityFuel.py +60 -0
  2. hestia_earth/models/cycle/product/economicValueShare.py +47 -31
  3. hestia_earth/models/emepEea2019/nh3ToAirInorganicFertiliser.py +44 -59
  4. hestia_earth/models/geospatialDatabase/histosol.py +4 -0
  5. hestia_earth/models/ipcc2006/co2ToAirOrganicSoilCultivation.py +4 -2
  6. hestia_earth/models/ipcc2006/n2OToAirOrganicSoilCultivationDirect.py +1 -1
  7. hestia_earth/models/ipcc2019/aboveGroundCropResidueTotal.py +1 -1
  8. hestia_earth/models/ipcc2019/animal/pastureGrass.py +30 -24
  9. hestia_earth/models/ipcc2019/belowGroundCropResidue.py +1 -1
  10. hestia_earth/models/ipcc2019/ch4ToAirExcreta.py +1 -1
  11. hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +511 -458
  12. hestia_earth/models/ipcc2019/co2ToAirUreaHydrolysis.py +5 -1
  13. hestia_earth/models/ipcc2019/organicCarbonPerHa.py +116 -3882
  14. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1_utils.py +2060 -0
  15. hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2_utils.py +1630 -0
  16. hestia_earth/models/ipcc2019/organicCarbonPerHa_utils.py +324 -0
  17. hestia_earth/models/ipcc2019/pastureGrass.py +37 -19
  18. hestia_earth/models/ipcc2019/pastureGrass_utils.py +4 -21
  19. hestia_earth/models/mocking/search-results.json +293 -289
  20. hestia_earth/models/site/organicCarbonPerHa.py +58 -44
  21. hestia_earth/models/site/soilMeasurement.py +18 -13
  22. hestia_earth/models/utils/__init__.py +28 -0
  23. hestia_earth/models/utils/array_builders.py +578 -0
  24. hestia_earth/models/utils/blank_node.py +55 -39
  25. hestia_earth/models/utils/descriptive_stats.py +285 -0
  26. hestia_earth/models/utils/emission.py +73 -2
  27. hestia_earth/models/utils/inorganicFertiliser.py +2 -2
  28. hestia_earth/models/utils/measurement.py +118 -4
  29. hestia_earth/models/version.py +1 -1
  30. {hestia_earth_models-0.61.7.dist-info → hestia_earth_models-0.62.0.dist-info}/METADATA +2 -2
  31. {hestia_earth_models-0.61.7.dist-info → hestia_earth_models-0.62.0.dist-info}/RECORD +51 -39
  32. tests/models/cycle/completeness/test_electricityFuel.py +21 -0
  33. tests/models/cycle/product/test_economicValueShare.py +8 -0
  34. tests/models/emepEea2019/test_nh3ToAirInorganicFertiliser.py +2 -2
  35. tests/models/ipcc2019/animal/test_pastureGrass.py +2 -2
  36. tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +55 -165
  37. tests/models/ipcc2019/test_organicCarbonPerHa.py +219 -460
  38. tests/models/ipcc2019/test_organicCarbonPerHa_tier_1_utils.py +471 -0
  39. tests/models/ipcc2019/test_organicCarbonPerHa_tier_2_utils.py +208 -0
  40. tests/models/ipcc2019/test_organicCarbonPerHa_utils.py +75 -0
  41. tests/models/ipcc2019/test_pastureGrass.py +0 -16
  42. tests/models/site/test_organicCarbonPerHa.py +3 -12
  43. tests/models/site/test_soilMeasurement.py +3 -18
  44. tests/models/utils/test_array_builders.py +253 -0
  45. tests/models/utils/test_blank_node.py +154 -15
  46. tests/models/utils/test_descriptive_stats.py +134 -0
  47. tests/models/utils/test_emission.py +51 -1
  48. tests/models/utils/test_measurement.py +54 -2
  49. {hestia_earth_models-0.61.7.dist-info → hestia_earth_models-0.62.0.dist-info}/LICENSE +0 -0
  50. {hestia_earth_models-0.61.7.dist-info → hestia_earth_models-0.62.0.dist-info}/WHEEL +0 -0
  51. {hestia_earth_models-0.61.7.dist-info → hestia_earth_models-0.62.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,134 @@
1
+ from numpy import array, inf
2
+ from numpy.testing import assert_almost_equal
3
+ from pytest import mark
4
+
5
+ from hestia_earth.schema import MeasurementStatsDefinition
6
+
7
+ from hestia_earth.models.utils.descriptive_stats import (
8
+ _calc_confidence_level, calc_confidence_level_monte_carlo, calc_descriptive_stats, calc_precision_monte_carlo,
9
+ calc_required_iterations_monte_carlo, calc_z_critical
10
+ )
11
+
12
+ # confidence_level, n_sided, z_critical
13
+ CONFIDENCE_INTERVAL_PARAMS = [
14
+ # 1 sided
15
+ (0, 1, -inf),
16
+ (50, 1, 0),
17
+ (80, 1, 0.8416),
18
+ (90, 1, 1.2816),
19
+ (95, 1, 1.6449),
20
+ (99, 1, 2.3263),
21
+ (100, 1, inf),
22
+ # 2 sided
23
+ (0, 2, 0),
24
+ (50, 2, 0.6745),
25
+ (80, 2, 1.2816),
26
+ (90, 2, 1.6449),
27
+ (95, 2, 1.9600),
28
+ (99, 2, 2.5758),
29
+ (100, 2, inf)
30
+ ]
31
+
32
+
33
+ @mark.parametrize(
34
+ "confidence_level, n_sided, z_critical",
35
+ CONFIDENCE_INTERVAL_PARAMS,
36
+ ids=[f"z={z}, n={n}" for _, n, z in CONFIDENCE_INTERVAL_PARAMS]
37
+ )
38
+ def test_calc_confidence_level(confidence_level, n_sided, z_critical):
39
+ result = _calc_confidence_level(z_critical, n_sided=n_sided)
40
+ assert_almost_equal(result, confidence_level, decimal=2)
41
+
42
+
43
+ @mark.parametrize(
44
+ "confidence_level, n_sided, z_critical",
45
+ CONFIDENCE_INTERVAL_PARAMS,
46
+ ids=[f"conf={conf}, n={n}" for conf, n, _ in CONFIDENCE_INTERVAL_PARAMS]
47
+ )
48
+ def test_calc_z_critical(confidence_level, n_sided, z_critical):
49
+ result = calc_z_critical(confidence_level, n_sided=n_sided)
50
+ assert_almost_equal(result, z_critical, decimal=4)
51
+
52
+
53
+ # confidence_level, n_iterations, precision, sd
54
+ MONTE_CARLO_PARAMS = [
55
+ (95, 80767, 0.01, 1.45),
56
+ (95, 1110, 0.01, 0.17),
57
+ (99, 1917, 0.01, 0.17),
58
+ (50, 102, 100.18, 1500)
59
+ ]
60
+
61
+
62
+ @mark.parametrize(
63
+ "confidence_level, n_iterations, precision, sd",
64
+ MONTE_CARLO_PARAMS,
65
+ ids=[f"n={n}, prec={prec}, sd={sd}" for _, n, prec, sd in MONTE_CARLO_PARAMS]
66
+ )
67
+ def test_calc_confidence_level_monte_carlo(confidence_level, n_iterations, precision, sd):
68
+ result = calc_confidence_level_monte_carlo(n_iterations, precision, sd,)
69
+ assert_almost_equal(result, confidence_level, decimal=2)
70
+
71
+
72
+ @mark.parametrize(
73
+ "confidence_level, n_iterations, precision, sd",
74
+ MONTE_CARLO_PARAMS,
75
+ ids=[f"conf={conf}, prec={prec}, sd={sd}" for conf, _, prec, sd in MONTE_CARLO_PARAMS]
76
+ )
77
+ def test_calc_required_iterations_monte_carlo(confidence_level, n_iterations, precision, sd):
78
+ result = calc_required_iterations_monte_carlo(confidence_level, precision, sd)
79
+ assert result == n_iterations
80
+
81
+
82
+ @mark.parametrize(
83
+ "confidence_level, n_iterations, precision, sd",
84
+ MONTE_CARLO_PARAMS,
85
+ ids=[f"conf={conf}, n={n}, sd={sd}" for conf, n, _, sd in MONTE_CARLO_PARAMS]
86
+ )
87
+ def test_calc_precision_monte_carlo(confidence_level, n_iterations, precision, sd):
88
+ result = calc_precision_monte_carlo(confidence_level, n_iterations, sd)
89
+ assert_almost_equal(result, precision, decimal=2)
90
+
91
+
92
+ EXPECTED_FLATTENED = {
93
+ "value": [5],
94
+ "sd": [2.581989],
95
+ "min": [1],
96
+ "max": [9],
97
+ "statsDefinition": "simulated",
98
+ "observations": [9]
99
+ }
100
+
101
+ EXPECTED_COLUMNWISE = {
102
+ "value": [4, 5, 6],
103
+ "sd": [2.44949, 2.44949, 2.44949],
104
+ "min": [1, 2, 3],
105
+ "max": [7, 8, 9],
106
+ "statsDefinition": "simulated",
107
+ "observations": [3, 3, 3]
108
+ }
109
+
110
+ EXPECTED_ROWWISE = {
111
+ "value": [2, 5, 8],
112
+ "sd": [0.816497, 0.816497, 0.816497],
113
+ "min": [1, 4, 7],
114
+ "max": [3, 6, 9],
115
+ "statsDefinition": "simulated",
116
+ "observations": [3, 3, 3]
117
+ }
118
+
119
+
120
+ @mark.parametrize(
121
+ "axis, expected",
122
+ [(None, EXPECTED_FLATTENED), (0, EXPECTED_COLUMNWISE), (1, EXPECTED_ROWWISE)],
123
+ ids=["flattened", "columnwise", "rowwise"]
124
+ )
125
+ @mark.parametrize("stats_definition", [MeasurementStatsDefinition.SIMULATED, "simulated"], ids=["Enum", "str"])
126
+ def test_calc_descriptive_stats(stats_definition, axis, expected):
127
+ ARR = array([
128
+ [1, 2, 3],
129
+ [4, 5, 6],
130
+ [7, 8, 9]
131
+ ])
132
+
133
+ result = calc_descriptive_stats(ARR, stats_definition, axis=axis)
134
+ assert result == expected
@@ -1,7 +1,10 @@
1
+ from pytest import mark
1
2
  from unittest.mock import patch
2
3
 
4
+ from hestia_earth.schema import EmissionMethodTier
5
+
3
6
  from tests.utils import TERM
4
- from hestia_earth.models.utils.emission import _new_emission, is_in_system_boundary
7
+ from hestia_earth.models.utils.emission import _new_emission, is_in_system_boundary, min_emission_method_tier
5
8
 
6
9
  class_path = 'hestia_earth.models.utils.emission'
7
10
 
@@ -27,3 +30,50 @@ def test_new_emission(*args):
27
30
  def test_is_in_system_boundary():
28
31
  assert is_in_system_boundary('ch4ToAirCropResidueBurning') is True
29
32
  assert is_in_system_boundary('codToWaterInputsProduction') is False
33
+
34
+
35
+ @mark.parametrize(
36
+ "input, expected",
37
+ [
38
+ (
39
+ (
40
+ EmissionMethodTier.TIER_1,
41
+ EmissionMethodTier.TIER_2,
42
+ EmissionMethodTier.TIER_3
43
+ ),
44
+ EmissionMethodTier.TIER_1
45
+ ),
46
+ (
47
+ [
48
+ EmissionMethodTier.TIER_1,
49
+ EmissionMethodTier.TIER_2,
50
+ EmissionMethodTier.TIER_3
51
+ ],
52
+ EmissionMethodTier.TIER_1
53
+ ),
54
+ (
55
+ [], EmissionMethodTier.NOT_RELEVANT
56
+ ),
57
+ (
58
+ (
59
+ EmissionMethodTier.TIER_1.value,
60
+ EmissionMethodTier.TIER_2.value,
61
+ EmissionMethodTier.TIER_3.value
62
+ ),
63
+ EmissionMethodTier.TIER_1
64
+ ),
65
+ (
66
+ [
67
+ EmissionMethodTier.TIER_1.value,
68
+ EmissionMethodTier.TIER_2.value,
69
+ EmissionMethodTier.TIER_3.value
70
+ ],
71
+ EmissionMethodTier.TIER_1
72
+ ),
73
+
74
+ ],
75
+ ids=["Enum", "list[Enum]", "None", "str", "list[str]"]
76
+ )
77
+ def test_min_emission_method_tier(input, expected):
78
+ result = min_emission_method_tier(input)
79
+ assert result == expected
@@ -1,9 +1,14 @@
1
- from unittest.mock import patch
2
1
  import json
2
+ from pytest import mark
3
+ from unittest.mock import patch
4
+
5
+ from hestia_earth.schema import MeasurementMethodClassification
6
+
3
7
  from tests.utils import fixtures_path, TERM
4
8
 
5
9
  from hestia_earth.models.utils.measurement import (
6
- _new_measurement, most_relevant_measurement_value, _most_recent_measurements, _shallowest_measurement
10
+ _new_measurement, most_relevant_measurement_value, _most_recent_measurements, _shallowest_measurement,
11
+ min_measurement_method_classification
7
12
  )
8
13
 
9
14
  class_path = 'hestia_earth.models.utils.measurement'
@@ -83,3 +88,50 @@ def test_shallowest_measurement():
83
88
  expected = json.load(f)
84
89
 
85
90
  assert _shallowest_measurement(measurements) == expected
91
+
92
+
93
+ @mark.parametrize(
94
+ "input, expected",
95
+ [
96
+ (
97
+ (
98
+ MeasurementMethodClassification.ON_SITE_PHYSICAL_MEASUREMENT,
99
+ MeasurementMethodClassification.TIER_2_MODEL,
100
+ MeasurementMethodClassification.TIER_1_MODEL
101
+ ),
102
+ MeasurementMethodClassification.TIER_1_MODEL
103
+ ),
104
+ (
105
+ [
106
+ MeasurementMethodClassification.ON_SITE_PHYSICAL_MEASUREMENT,
107
+ MeasurementMethodClassification.TIER_2_MODEL,
108
+ MeasurementMethodClassification.TIER_1_MODEL
109
+ ],
110
+ MeasurementMethodClassification.TIER_1_MODEL
111
+ ),
112
+ (
113
+ [], MeasurementMethodClassification.UNSOURCED_ASSUMPTION
114
+ ),
115
+ (
116
+ (
117
+ MeasurementMethodClassification.ON_SITE_PHYSICAL_MEASUREMENT.value,
118
+ MeasurementMethodClassification.TIER_2_MODEL.value,
119
+ MeasurementMethodClassification.TIER_1_MODEL.value
120
+ ),
121
+ MeasurementMethodClassification.TIER_1_MODEL
122
+ ),
123
+ (
124
+ [
125
+ MeasurementMethodClassification.ON_SITE_PHYSICAL_MEASUREMENT.value,
126
+ MeasurementMethodClassification.TIER_2_MODEL.value,
127
+ MeasurementMethodClassification.TIER_1_MODEL.value
128
+ ],
129
+ MeasurementMethodClassification.TIER_1_MODEL
130
+ ),
131
+
132
+ ],
133
+ ids=["Enum", "list[Enum]", "None", "str", "list[str]"]
134
+ )
135
+ def test_min_measurement_method_classification(input, expected):
136
+ result = min_measurement_method_classification(input)
137
+ assert result == expected