hestia-earth-models 0.59.3__py3-none-any.whl → 0.59.5__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 (39) hide show
  1. hestia_earth/models/cycle/liveAnimal.py +3 -0
  2. hestia_earth/models/cycle/milkYield.py +1 -1
  3. hestia_earth/models/cycle/utils.py +1 -1
  4. hestia_earth/models/geospatialDatabase/potentialEvapotranspirationLongTermAnnualMean.py +2 -2
  5. hestia_earth/models/geospatialDatabase/potentialEvapotranspirationMonthly.py +99 -0
  6. hestia_earth/models/geospatialDatabase/precipitationMonthly.py +100 -0
  7. hestia_earth/models/geospatialDatabase/temperatureAnnual.py +2 -6
  8. hestia_earth/models/geospatialDatabase/temperatureLongTermAnnualMean.py +2 -3
  9. hestia_earth/models/geospatialDatabase/temperatureMonthly.py +98 -0
  10. hestia_earth/models/geospatialDatabase/utils.py +13 -1
  11. hestia_earth/models/ipcc2019/organicCarbonPerHa.py +72 -135
  12. hestia_earth/models/linkedImpactAssessment/__init__.py +78 -43
  13. hestia_earth/models/mocking/search-results.json +8 -47
  14. hestia_earth/models/schmidt2007/n2OToAirWasteTreatmentDirect.py +58 -0
  15. hestia_earth/models/schmidt2007/nh3ToAirWasteTreatment.py +58 -0
  16. hestia_earth/models/site/management.py +106 -13
  17. hestia_earth/models/site/pre_checks/cache_geospatialDatabase.py +27 -7
  18. hestia_earth/models/site/soilMeasurement.py +9 -9
  19. hestia_earth/models/site/utils.py +2 -6
  20. hestia_earth/models/utils/__init__.py +9 -0
  21. hestia_earth/models/utils/blank_node.py +3 -3
  22. hestia_earth/models/utils/site.py +8 -5
  23. hestia_earth/models/utils/term.py +0 -23
  24. hestia_earth/models/version.py +1 -1
  25. {hestia_earth_models-0.59.3.dist-info → hestia_earth_models-0.59.5.dist-info}/METADATA +2 -2
  26. {hestia_earth_models-0.59.3.dist-info → hestia_earth_models-0.59.5.dist-info}/RECORD +39 -29
  27. tests/models/geospatialDatabase/test_potentialEvapotranspirationMonthly.py +20 -0
  28. tests/models/geospatialDatabase/test_precipitationMonthly.py +20 -0
  29. tests/models/geospatialDatabase/test_temperatureMonthly.py +20 -0
  30. tests/models/ipcc2019/test_organicCarbonPerHa.py +8 -39
  31. tests/models/schmidt2007/test_n2OToAirWasteTreatmentDirect.py +45 -0
  32. tests/models/schmidt2007/test_nh3ToAirWasteTreatment.py +45 -0
  33. tests/models/site/test_management.py +37 -16
  34. tests/models/site/test_soilMeasurement.py +40 -21
  35. tests/models/utils/test_site.py +1 -1
  36. tests/models/utils/test_term.py +1 -8
  37. {hestia_earth_models-0.59.3.dist-info → hestia_earth_models-0.59.5.dist-info}/LICENSE +0 -0
  38. {hestia_earth_models-0.59.3.dist-info → hestia_earth_models-0.59.5.dist-info}/WHEEL +0 -0
  39. {hestia_earth_models-0.59.3.dist-info → hestia_earth_models-0.59.5.dist-info}/top_level.txt +0 -0
@@ -1,8 +1,10 @@
1
1
  import json
2
2
  from unittest.mock import patch
3
+
4
+ import pytest
3
5
  from hestia_earth.schema import TermTermType
4
6
 
5
- from hestia_earth.models.site.management import MODEL, MODEL_KEY, run, should_run
7
+ from hestia_earth.models.site.management import MODEL, MODEL_KEY, run, _should_run
6
8
  from tests.utils import fixtures_path
7
9
 
8
10
  CLASS_PATH = f"hestia_earth.models.{MODEL}.{MODEL_KEY}"
@@ -13,18 +15,28 @@ TERM_BY_ID = {
13
15
  }
14
16
 
15
17
 
18
+ def lookup_side_effect(*args, **kwargs):
19
+ # Values taken from real lookups.
20
+ _ = kwargs
21
+ if args[0]["@id"] == "ureaKgN" and args[1] == "nitrogenContent":
22
+ return 45.5
23
+ if args[0]["@id"] == "compostKgMass" and args[1] == "ANIMAL_MANURE":
24
+ return False
25
+ return True
26
+
27
+
16
28
  @patch(f"{CLASS_PATH}.download_hestia", side_effect=lambda id, *args: TERM_BY_ID[id])
17
29
  @patch(f"{CLASS_PATH}.related_cycles")
18
30
  def test_should_run(mock_related_cycles, *args):
19
31
  # no cycles => do not run
20
32
  mock_related_cycles.return_value = []
21
- _should_run, *args = should_run({})
22
- assert _should_run is False
33
+ should_run, *args = _should_run({})
34
+ assert should_run is False
23
35
 
24
36
  # no products => do not run
25
37
  mock_related_cycles.return_value = [{"products": []}]
26
- _should_run, *args = should_run({})
27
- assert _should_run is False
38
+ should_run, *args = _should_run({})
39
+ assert should_run is False
28
40
 
29
41
  # with irrelevant termType => do not run
30
42
  mock_related_cycles.return_value = [
@@ -37,8 +49,8 @@ def test_should_run(mock_related_cycles, *args):
37
49
  "endDate": "2022"
38
50
  }
39
51
  ]
40
- _should_run, *args = should_run({})
41
- assert _should_run is False
52
+ should_run, *args = _should_run({})
53
+ assert should_run is False
42
54
 
43
55
  # products and practices but no relevant terms/termTypes => do not run
44
56
  mock_related_cycles.return_value = [
@@ -53,8 +65,8 @@ def test_should_run(mock_related_cycles, *args):
53
65
  ]
54
66
  }
55
67
  ]
56
- _should_run, *args = should_run({})
57
- assert _should_run is False
68
+ should_run, *args = _should_run({})
69
+ assert should_run is False
58
70
 
59
71
  # # practices with relevant termType => run
60
72
  mock_related_cycles.return_value = [
@@ -67,8 +79,8 @@ def test_should_run(mock_related_cycles, *args):
67
79
  "endDate": "2022"
68
80
  }
69
81
  ]
70
- _should_run, *args = should_run({})
71
- assert _should_run is True
82
+ should_run, *args = _should_run({})
83
+ assert should_run is True
72
84
 
73
85
  # with relevant product => run
74
86
  mock_related_cycles.return_value = [
@@ -89,8 +101,8 @@ def test_should_run(mock_related_cycles, *args):
89
101
  "endDate": "2022"
90
102
  }
91
103
  ]
92
- _should_run, *args = should_run({})
93
- assert _should_run is True
104
+ should_run, *args = _should_run({})
105
+ assert should_run is True
94
106
  assert args[0] == [{
95
107
  'term': TERM_BY_ID['genericCropPlant'],
96
108
  'value': 100,
@@ -100,17 +112,26 @@ def test_should_run(mock_related_cycles, *args):
100
112
  }]
101
113
 
102
114
 
115
+ @pytest.mark.parametrize(
116
+ "test_name,fixture_path",
117
+ [
118
+ ("Example 1", f"{fixtures_folder}/inputs/example1"),
119
+ ("Example 2", f"{fixtures_folder}/inputs/example2"),
120
+ ("Example 3", f"{fixtures_folder}/inputs/example3")
121
+ ]
122
+ )
103
123
  @patch(f"{CLASS_PATH}.download_hestia", side_effect=lambda id, *args: TERM_BY_ID[id])
104
124
  @patch(f"{CLASS_PATH}.related_cycles")
105
- def test_run(mock_related_cycles, *args):
106
- with open(f"{fixtures_folder}/cycles.jsonld", encoding='utf-8') as f:
125
+ @patch(f"{CLASS_PATH}._get_lookup_with_debug", side_effect=lookup_side_effect)
126
+ def test_run(mock_get_lookup_with_debug, mock_related_cycles, mock_download, test_name, fixture_path):
127
+ with open(f"{fixture_path}/cycles.jsonld", encoding='utf-8') as f:
107
128
  cycles = json.load(f)
108
129
  mock_related_cycles.return_value = cycles
109
130
 
110
131
  with open(f"{fixtures_folder}/site.jsonld", encoding='utf-8') as f:
111
132
  site = json.load(f)
112
133
 
113
- with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
134
+ with open(f"{fixture_path}/result.jsonld", encoding='utf-8') as f:
114
135
  expected = json.load(f)
115
136
 
116
137
  result = run(site)
@@ -79,12 +79,12 @@ def test_harmonise_measurements(measurements_list, returns_dict, expected_value)
79
79
  (
80
80
  "missing dates => run",
81
81
  {
82
- "measurements":
83
- [
82
+ "measurements": [
84
83
  {
85
84
  "term": {"@id": "clayContent"},
86
85
  "depthUpper": 0,
87
- "depthLower": 20
86
+ "depthLower": 20,
87
+ "value": [0]
88
88
  }
89
89
  ]
90
90
  },
@@ -93,29 +93,43 @@ def test_harmonise_measurements(measurements_list, returns_dict, expected_value)
93
93
  (
94
94
  "no depthUpper => no run",
95
95
  {
96
- "measurements":
97
- [
98
- {
99
- "term": {"@id": "clayContent"},
100
- "dates": ["2022-01-02"],
101
- "depthLower": 20
102
- }
103
- ]
96
+ "measurements": [
97
+ {
98
+ "term": {"@id": "clayContent"},
99
+ "dates": ["2022-01-02"],
100
+ "depthLower": 20,
101
+ "value": [0]
102
+ }
103
+ ]
104
+ },
105
+ False
106
+ ),
107
+ (
108
+ "missing value => not run",
109
+ {
110
+ "measurements": [
111
+ {
112
+ "term": {"@id": "clayContent"},
113
+ "dates": ["2022-01-02"],
114
+ "depthUpper": 0,
115
+ "depthLower": 20
116
+ }
117
+ ]
104
118
  },
105
119
  False
106
120
  ),
107
121
  (
108
122
  "all fields => run",
109
123
  {
110
- "measurements":
111
- [
112
- {
113
- "term": {"@id": "clayContent"},
114
- "dates": ["2022-01-02"],
115
- "depthUpper": 0,
116
- "depthLower": 20
117
- }
118
- ]
124
+ "measurements": [
125
+ {
126
+ "term": {"@id": "clayContent"},
127
+ "dates": ["2022-01-02"],
128
+ "depthUpper": 0,
129
+ "depthLower": 20,
130
+ "value": [0]
131
+ }
132
+ ]
119
133
  },
120
134
  True
121
135
  )
@@ -141,7 +155,12 @@ def lookup_side_effect(*args, **kwargs):
141
155
  @pytest.mark.parametrize(
142
156
  "test_name",
143
157
  [
144
- "missingDepth", "simpleSoilPh", "clayContent", "missingDepth", "nonUniqueMeasurements", "arrays"
158
+ "missing-depth",
159
+ "missing-value",
160
+ "simple-soilPh",
161
+ "clayContent",
162
+ "non-unique-measurements",
163
+ "arrays"
145
164
  ]
146
165
  )
147
166
  @patch(f"{class_path}._new_measurement", side_effect=fake_new_measurement)
@@ -19,7 +19,7 @@ def test_region_level_1_id():
19
19
 
20
20
 
21
21
  @patch(f"{class_path}.find_related", return_value=[CYCLE])
22
- @patch(f"{class_path}.download_hestia", return_value=CYCLE)
22
+ @patch(f"{class_path}._load_calculated_node", return_value=CYCLE)
23
23
  def test_related_cycles(*args):
24
24
  assert related_cycles('id') == [CYCLE]
25
25
 
@@ -4,7 +4,7 @@ from hestia_earth.models.utils.term import (
4
4
  get_liquid_fuel_terms, get_irrigation_terms, get_urea_terms, get_excreta_N_terms, get_excreta_VS_terms,
5
5
  get_generic_crop, get_rice_paddy_terms, get_tillage_terms, get_crop_residue_terms, get_cover_crop_property_terms,
6
6
  get_crop_residue_incorporated_or_left_on_field_terms, get_irrigated_terms, get_residue_removed_or_burnt_terms,
7
- get_upland_rice_land_cover_terms, get_upland_rice_crop_terms, get_long_fallow_land_cover_terms
7
+ get_upland_rice_land_cover_terms, get_upland_rice_crop_terms
8
8
  )
9
9
 
10
10
  class_path = 'hestia_earth.models.utils.term'
@@ -113,10 +113,3 @@ def test_get_upland_rice_crop_terms(mock_find_node):
113
113
  id = 'term-id'
114
114
  mock_find_node.return_value = [{'@id': id}]
115
115
  assert get_upland_rice_crop_terms() == [id]
116
-
117
-
118
- @patch(f"{class_path}.search")
119
- def test_get_long_fallow_land_cover_terms(mock_find_node):
120
- id = 'term-id'
121
- mock_find_node.return_value = [{'@id': id}]
122
- assert get_long_fallow_land_cover_terms() == [id]