hestia-earth-models 0.62.4__py3-none-any.whl → 0.62.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 (55) hide show
  1. hestia_earth/models/cycle/croppingIntensity.py +57 -0
  2. hestia_earth/models/cycle/longFallowRatio.py +52 -0
  3. hestia_earth/models/cycle/siteDuration.py +23 -3
  4. hestia_earth/models/cycle/siteUnusedDuration.py +64 -0
  5. hestia_earth/models/emepEea2019/co2ToAirFuelCombustion.py +2 -10
  6. hestia_earth/models/emepEea2019/n2OToAirFuelCombustionDirect.py +2 -10
  7. hestia_earth/models/emepEea2019/nh3ToAirExcreta.py +2 -9
  8. hestia_earth/models/emepEea2019/nh3ToAirInorganicFertiliser.py +2 -9
  9. hestia_earth/models/emepEea2019/noxToAirFuelCombustion.py +2 -10
  10. hestia_earth/models/emepEea2019/pm10ToAirAnimalHousing.py +57 -0
  11. hestia_earth/models/emepEea2019/pm25ToAirAnimalHousing.py +57 -0
  12. hestia_earth/models/emepEea2019/so2ToAirFuelCombustion.py +2 -10
  13. hestia_earth/models/emepEea2019/tspToAirAnimalHousing.py +57 -0
  14. hestia_earth/models/emepEea2019/utils.py +60 -1
  15. hestia_earth/models/geospatialDatabase/croppingIntensity.py +32 -22
  16. hestia_earth/models/geospatialDatabase/longFallowRatio.py +34 -23
  17. hestia_earth/models/ipcc2019/animal/pastureGrass.py +2 -2
  18. hestia_earth/models/ipcc2019/pastureGrass.py +2 -2
  19. hestia_earth/models/ipcc2019/pastureGrass_utils.py +1 -10
  20. hestia_earth/models/mocking/mock_search.py +14 -8
  21. hestia_earth/models/mocking/search-results.json +27 -27
  22. hestia_earth/models/pooreNemecek2018/longFallowPeriod.py +1 -2
  23. hestia_earth/models/pooreNemecek2018/nurseryDensity.py +1 -2
  24. hestia_earth/models/pooreNemecek2018/nurseryDuration.py +1 -2
  25. hestia_earth/models/pooreNemecek2018/plantationDensity.py +1 -2
  26. hestia_earth/models/pooreNemecek2018/plantationLifespan.py +1 -2
  27. hestia_earth/models/pooreNemecek2018/plantationProductiveLifespan.py +1 -2
  28. hestia_earth/models/preload_requests.py +14 -7
  29. hestia_earth/models/site/management.py +7 -5
  30. hestia_earth/models/utils/__init__.py +0 -9
  31. hestia_earth/models/utils/cycle.py +20 -3
  32. hestia_earth/models/utils/product.py +2 -2
  33. hestia_earth/models/version.py +1 -1
  34. {hestia_earth_models-0.62.4.dist-info → hestia_earth_models-0.62.6.dist-info}/METADATA +2 -2
  35. {hestia_earth_models-0.62.4.dist-info → hestia_earth_models-0.62.6.dist-info}/RECORD +55 -43
  36. tests/models/cycle/test_croppingIntensity.py +53 -0
  37. tests/models/cycle/test_longFallowRatio.py +49 -0
  38. tests/models/cycle/test_siteDuration.py +41 -14
  39. tests/models/cycle/test_siteUnusedDuration.py +55 -0
  40. tests/models/emepEea2019/test_co2ToAirFuelCombustion.py +3 -2
  41. tests/models/emepEea2019/test_n2OToAirFuelCombustionDirect.py +3 -2
  42. tests/models/emepEea2019/test_nh3ToAirExcreta.py +2 -1
  43. tests/models/emepEea2019/test_nh3ToAirInorganicFertiliser.py +4 -3
  44. tests/models/emepEea2019/test_noxToAirFuelCombustion.py +3 -2
  45. tests/models/emepEea2019/test_pm10ToAirAnimalHousing.py +21 -0
  46. tests/models/emepEea2019/test_pm25ToAirAnimalHousing.py +21 -0
  47. tests/models/emepEea2019/test_so2ToAirFuelCombustion.py +3 -2
  48. tests/models/emepEea2019/test_tspToAirAnimalHousing.py +21 -0
  49. tests/models/emepEea2019/test_utils.py +198 -1
  50. tests/models/geospatialDatabase/test_croppingIntensity.py +5 -3
  51. tests/models/geospatialDatabase/test_longFallowRatio.py +5 -3
  52. tests/models/site/test_management.py +1 -0
  53. {hestia_earth_models-0.62.4.dist-info → hestia_earth_models-0.62.6.dist-info}/LICENSE +0 -0
  54. {hestia_earth_models-0.62.4.dist-info → hestia_earth_models-0.62.6.dist-info}/WHEEL +0 -0
  55. {hestia_earth_models-0.62.4.dist-info → hestia_earth_models-0.62.6.dist-info}/top_level.txt +0 -0
@@ -5,6 +5,7 @@ from tests.utils import fixtures_path, fake_new_emission
5
5
  from hestia_earth.models.emepEea2019.nh3ToAirInorganicFertiliser import MODEL, TERM_ID, run, _should_run
6
6
 
7
7
  class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
+ model_utils_path = f"hestia_earth.models.{MODEL}.utils"
8
9
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
10
 
10
11
 
@@ -27,7 +28,7 @@ def test_should_run(mock_measurement, *args):
27
28
  assert should_run is True
28
29
 
29
30
 
30
- @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
31
+ @patch(f"{model_utils_path}._new_emission", side_effect=fake_new_emission)
31
32
  def test_run(*args):
32
33
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
33
34
  cycle = json.load(f)
@@ -39,7 +40,7 @@ def test_run(*args):
39
40
  assert value == expected
40
41
 
41
42
 
42
- @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
43
+ @patch(f"{model_utils_path}._new_emission", side_effect=fake_new_emission)
43
44
  def test_run_with_unspecified(*args):
44
45
  with open(f"{fixtures_folder}/with-unspecified/cycle.jsonld", encoding='utf-8') as f:
45
46
  cycle = json.load(f)
@@ -51,7 +52,7 @@ def test_run_with_unspecified(*args):
51
52
  assert value == expected
52
53
 
53
54
 
54
- @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
55
+ @patch(f"{model_utils_path}._new_emission", side_effect=fake_new_emission)
55
56
  def test_run_complete(*args):
56
57
  with open(f"{fixtures_folder}/is-complete/cycle.jsonld", encoding='utf-8') as f:
57
58
  cycle = json.load(f)
@@ -5,6 +5,7 @@ from tests.utils import fixtures_path, fake_new_emission
5
5
  from hestia_earth.models.emepEea2019.noxToAirFuelCombustion import MODEL, TERM_ID, run, _should_run
6
6
 
7
7
  class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
+ model_utils_path = f"hestia_earth.models.{MODEL}.utils"
8
9
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
10
 
10
11
 
@@ -21,7 +22,7 @@ def test_should_run(mock_get_fuel_values):
21
22
  assert should_run is True
22
23
 
23
24
 
24
- @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
25
+ @patch(f"{model_utils_path}._new_emission", side_effect=fake_new_emission)
25
26
  def test_run(*args):
26
27
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
27
28
  cycle = json.load(f)
@@ -33,7 +34,7 @@ def test_run(*args):
33
34
  assert value == expected
34
35
 
35
36
 
36
- @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
37
+ @patch(f"{model_utils_path}._new_emission", side_effect=fake_new_emission)
37
38
  def test_run_data_complete(*args):
38
39
  with open(f"{fixtures_folder}/no-input-data-complete/cycle.jsonld", encoding='utf-8') as f:
39
40
  cycle = json.load(f)
@@ -0,0 +1,21 @@
1
+ from unittest.mock import patch
2
+ import json
3
+
4
+ from tests.utils import fixtures_path, fake_new_emission
5
+ from hestia_earth.models.emepEea2019.pm10ToAirAnimalHousing import MODEL, TERM_ID, run
6
+
7
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
+ model_utils_path = f"hestia_earth.models.{MODEL}.utils"
9
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
+
11
+
12
+ @patch(f"{model_utils_path}._new_emission", side_effect=fake_new_emission)
13
+ def test_run(*args):
14
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
15
+ cycle = json.load(f)
16
+
17
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
+ expected = json.load(f)
19
+
20
+ value = run(cycle)
21
+ assert value == expected
@@ -0,0 +1,21 @@
1
+ from unittest.mock import patch
2
+ import json
3
+
4
+ from tests.utils import fixtures_path, fake_new_emission
5
+ from hestia_earth.models.emepEea2019.pm25ToAirAnimalHousing import MODEL, TERM_ID, run
6
+
7
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
+ model_utils_path = f"hestia_earth.models.{MODEL}.utils"
9
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
+
11
+
12
+ @patch(f"{model_utils_path}._new_emission", side_effect=fake_new_emission)
13
+ def test_run(*args):
14
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
15
+ cycle = json.load(f)
16
+
17
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
+ expected = json.load(f)
19
+
20
+ value = run(cycle)
21
+ assert value == expected
@@ -5,6 +5,7 @@ from tests.utils import fixtures_path, fake_new_emission
5
5
  from hestia_earth.models.emepEea2019.so2ToAirFuelCombustion import MODEL, TERM_ID, run, _should_run
6
6
 
7
7
  class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
+ model_utils_path = f"hestia_earth.models.{MODEL}.utils"
8
9
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
10
 
10
11
 
@@ -21,7 +22,7 @@ def test_should_run(mock_get_fuel_values):
21
22
  assert should_run is True
22
23
 
23
24
 
24
- @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
25
+ @patch(f"{model_utils_path}._new_emission", side_effect=fake_new_emission)
25
26
  def test_run(*args):
26
27
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
27
28
  cycle = json.load(f)
@@ -33,7 +34,7 @@ def test_run(*args):
33
34
  assert value == expected
34
35
 
35
36
 
36
- @patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
37
+ @patch(f"{model_utils_path}._new_emission", side_effect=fake_new_emission)
37
38
  def test_run_data_complete(*args):
38
39
  with open(f"{fixtures_folder}/no-input-data-complete/cycle.jsonld", encoding='utf-8') as f:
39
40
  cycle = json.load(f)
@@ -0,0 +1,21 @@
1
+ from unittest.mock import patch
2
+ import json
3
+
4
+ from tests.utils import fixtures_path, fake_new_emission
5
+ from hestia_earth.models.emepEea2019.tspToAirAnimalHousing import MODEL, TERM_ID, run
6
+
7
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
+ model_utils_path = f"hestia_earth.models.{MODEL}.utils"
9
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
+
11
+
12
+ @patch(f"{model_utils_path}._new_emission", side_effect=fake_new_emission)
13
+ def test_run(*args):
14
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
15
+ cycle = json.load(f)
16
+
17
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
18
+ expected = json.load(f)
19
+
20
+ value = run(cycle)
21
+ assert value == expected
@@ -1,6 +1,8 @@
1
1
  from unittest.mock import patch
2
2
 
3
- from hestia_earth.models.emepEea2019.utils import get_fuel_values
3
+ import pytest
4
+
5
+ from hestia_earth.models.emepEea2019.utils import get_fuel_values, should_run_animal, _duration_in_housing
4
6
 
5
7
  class_path = 'hestia_earth.models.emepEea2019.utils'
6
8
  TERMS = [
@@ -53,3 +55,198 @@ def test_get_fuel_values(*args):
53
55
  }
54
56
  result = get_fuel_values('co2ToAirFuelCombustion', cycle, 'co2ToAirFuelCombustionEmepEea2019')
55
57
  assert result == [317.0, 632.0, 475.5, 158.5]
58
+
59
+
60
+ @pytest.mark.parametrize(
61
+ "test_name,cycle,expected_duration",
62
+ [
63
+ (
64
+ "no sites => 0",
65
+ {"completeness": {"@type": "Completeness", "animalPopulation": False}},
66
+ 0
67
+ ),
68
+ (
69
+ "site and other sites have wrong type => 0",
70
+ {
71
+ "site": {"@type": "Site", "siteType": "permanent pasture"},
72
+ "siteDuration": 15,
73
+ "otherSites": [
74
+ {"@type": "Site", "siteType": "pond"},
75
+ {"@type": "Site", "siteType": "pond"},
76
+ {"@type": "Site", "siteType": "pond"},
77
+ ],
78
+ "otherSitesDuration": [20, 21, 22],
79
+ },
80
+ 0
81
+ ),
82
+ (
83
+ "only second other site is animal housing => 12",
84
+ {
85
+ "site": {"@type": "Site", "siteType": "pond"},
86
+ "siteDuration": 20,
87
+ "otherSites": [
88
+ {"@type": "Site", "siteType": "pond"},
89
+ {"@type": "Site", "siteType": "animal housing"},
90
+ {"@type": "Site", "siteType": "pond"},
91
+ ],
92
+ "otherSitesDuration": [11, 12, 13],
93
+ },
94
+ 12
95
+ ),
96
+ (
97
+ "only site is animal housing => 20",
98
+ {
99
+ "site": {"@type": "Site", "siteType": "animal housing"},
100
+ "otherSites": [
101
+ {"@type": "Site", "siteType": "forest"},
102
+ {"@type": "Site", "siteType": "forest"},
103
+ {"@type": "Site", "siteType": "forest"},
104
+ ],
105
+ "siteDuration": 20,
106
+ "otherSitesDuration": [12, 13, 14],
107
+ },
108
+ 20
109
+ ),
110
+ (
111
+ "site and otherSites are animal housing, sum all values => 59",
112
+ {
113
+ "site": {"@type": "Site", "siteType": "animal housing"},
114
+ "otherSites": [
115
+ {"@type": "Site", "siteType": "animal housing"},
116
+ {"@type": "Site", "siteType": "animal housing"},
117
+ {"@type": "Site", "siteType": "animal housing"},
118
+ ],
119
+ "siteDuration": 20,
120
+ "otherSitesDuration": [12, 13, 14],
121
+ },
122
+ 59
123
+ )
124
+
125
+ ]
126
+ )
127
+ def test_duration_in_housing(test_name, cycle, expected_duration):
128
+ assert _duration_in_housing(cycle) == expected_duration
129
+
130
+
131
+ @pytest.mark.parametrize(
132
+ "test_name,cycle,expected_should_run",
133
+ [
134
+ (
135
+ "not complete => no run",
136
+ {"completeness": {"@type": "Completeness", "animalPopulation": False}},
137
+ False
138
+ ),
139
+ (
140
+ "no site or other sites => no run",
141
+ {"completeness": {"@type": "Completeness", "animalPopulation": True}},
142
+ False
143
+ ),
144
+ (
145
+ "no site or other sites with 'animal housing' type => no run",
146
+ {
147
+ "completeness": {"@type": "Completeness", "animalPopulation": True},
148
+ "site": {"@type": "Site", "siteType": "permanent pasture"},
149
+ "otherSites": [{"@type": "Site", "siteType": "pond"}]
150
+ },
151
+ False
152
+ ),
153
+ (
154
+ "no site or other sites with 'animal housing' type and duration => no run",
155
+ {
156
+ "completeness": {"@type": "Completeness", "animalPopulation": True},
157
+ "site": {"@type": "Site", "siteType": "animal housing"},
158
+ "otherSites": [{"@type": "Site", "siteType": "pond"}],
159
+ "siteDuration": ""
160
+ },
161
+ False
162
+ ),
163
+ (
164
+ "no animal values => no run",
165
+ {
166
+ "completeness": {"@type": "Completeness", "animalPopulation": True},
167
+ "site": {"@type": "Site", "siteType": "animal housing"},
168
+ "otherSites": [{"@type": "Site", "siteType": "pond"}],
169
+ "siteDuration": 150,
170
+ "animals": [
171
+ {"value": ""}
172
+ ]
173
+ },
174
+ False
175
+ ),
176
+ (
177
+ "animal values reference period is not 'average' => no run",
178
+ {
179
+ "completeness": {"@type": "Completeness", "animalPopulation": True},
180
+ "site": {"@type": "Site", "siteType": "animal housing"},
181
+ "otherSites": [{"@type": "Site", "siteType": "pond"}],
182
+ "siteDuration": 150,
183
+ "animals": [
184
+ {
185
+ "@type": "Animal",
186
+ "value": 1
187
+ },
188
+ {
189
+ "@type": "Animal",
190
+ "value": 2,
191
+ "referencePeriod": ""
192
+ },
193
+ {
194
+ "@type": "Animal",
195
+ "value": 3,
196
+ "referencePeriod": "start of Cycle"
197
+ },
198
+ ]
199
+ },
200
+ False
201
+ ),
202
+ (
203
+ "missing otherSitesDuration => no run",
204
+ {
205
+ "completeness": {"@type": "Completeness", "animalPopulation": True},
206
+ "site": {"@type": "Site", "siteType": "animal housing"},
207
+ "otherSites": [{"@type": "Site", "siteType": "pond"}],
208
+ "siteDuration": 150,
209
+ "animals": [
210
+ {
211
+ "@type": "Animal",
212
+ "value": 2,
213
+ "referencePeriod": ""
214
+ },
215
+ {
216
+ "@type": "Animal",
217
+ "value": 3,
218
+ "referencePeriod": "average"
219
+ },
220
+ ]
221
+ },
222
+ False
223
+ ),
224
+ (
225
+ "all requirements met with otherSites => run",
226
+ {
227
+ "completeness": {"@type": "Completeness", "animalPopulation": True},
228
+ "site": {"@type": "Site", "siteType": "pond"},
229
+ "siteDuration": "",
230
+ "otherSites": [{"@type": "Site", "siteType": "animal housing"}],
231
+ "otherSitesDuration": [200],
232
+ "animals": [
233
+ {
234
+ "@type": "Animal",
235
+ "value": 2,
236
+ "referencePeriod": ""
237
+ },
238
+ {
239
+ "@type": "Animal",
240
+ "value": 3,
241
+ "referencePeriod": "average"
242
+ },
243
+ ]
244
+ },
245
+ True
246
+ ),
247
+
248
+ ]
249
+ )
250
+ def test_should_run_animal(test_name, cycle, expected_should_run):
251
+ should_run, *args = should_run_animal(cycle, 'model', 'term', 'tier')
252
+ assert should_run == expected_should_run, test_name
@@ -9,14 +9,16 @@ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
9
 
10
10
 
11
11
  @patch(f"{class_path}.is_plantation")
12
- def test_should_run(mock_is_plantation):
12
+ def test_should_run(mock_is_plantation, *args):
13
13
  cycle = {'@type': 'Cycle'}
14
14
 
15
15
  mock_is_plantation.return_value = False
16
- assert _should_run(cycle) is True
16
+ should_run = _should_run(cycle)
17
+ assert should_run is True
17
18
 
18
19
  mock_is_plantation.return_value = True
19
- assert not _should_run(cycle)
20
+ should_run = _should_run(cycle)
21
+ assert not should_run
20
22
 
21
23
 
22
24
  @patch(f"{class_path}._new_practice", side_effect=fake_new_practice)
@@ -9,14 +9,16 @@ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
9
 
10
10
 
11
11
  @patch(f"{class_path}.is_plantation")
12
- def test_should_run(mock_is_plantation):
12
+ def test_should_run(mock_is_plantation, *args):
13
13
  cycle = {'@type': 'Cycle'}
14
14
 
15
15
  mock_is_plantation.return_value = False
16
- assert _should_run(cycle) is True
16
+ should_run = _should_run(cycle)
17
+ assert should_run is True
17
18
 
18
19
  mock_is_plantation.return_value = True
19
- assert not _should_run(cycle)
20
+ should_run = _should_run(cycle)
21
+ assert not should_run
20
22
 
21
23
 
22
24
  @patch(f"{class_path}._new_practice", side_effect=fake_new_practice)
@@ -297,6 +297,7 @@ def test_should_run(mock_related_cycles, *args):
297
297
  @pytest.mark.parametrize(
298
298
  "test_name,fixture_path",
299
299
  [
300
+ ("Products and practices", f"{fixtures_folder}"),
300
301
  ("Example 1", f"{fixtures_folder}/inputs/example1"),
301
302
  ("Example 2", f"{fixtures_folder}/inputs/example2"),
302
303
  ("Example 3", f"{fixtures_folder}/inputs/example3"),