hestia-earth-models 0.65.9__py3-none-any.whl → 0.65.11__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.
Files changed (45) hide show
  1. hestia_earth/models/cml2001Baseline/abioticResourceDepletionFossilFuels.py +3 -5
  2. hestia_earth/models/cml2001Baseline/abioticResourceDepletionMineralsAndMetals.py +1 -1
  3. hestia_earth/models/config/Cycle.json +9 -9
  4. hestia_earth/models/config/Site.json +18 -0
  5. hestia_earth/models/config/__init__.py +6 -0
  6. hestia_earth/models/cycle/materialAndSubstrate.py +1 -1
  7. hestia_earth/models/cycle/milkYield.py +9 -6
  8. hestia_earth/models/cycle/product/economicValueShare.py +8 -4
  9. hestia_earth/models/cycle/product/revenue.py +11 -7
  10. hestia_earth/models/faostat2018/product/price.py +1 -1
  11. hestia_earth/models/geospatialDatabase/utils.py +22 -17
  12. hestia_earth/models/hestia/landCover.py +15 -5
  13. hestia_earth/models/hestia/resourceUse_utils.py +24 -12
  14. hestia_earth/models/hestia/utils.py +1 -2
  15. hestia_earth/models/ipcc2019/animal/pastureGrass.py +1 -1
  16. hestia_earth/models/ipcc2019/pastureGrass.py +1 -1
  17. hestia_earth/models/mocking/search-results.json +914 -914
  18. hestia_earth/models/pooreNemecek2018/freshwaterWithdrawalsDuringCycle.py +0 -1
  19. hestia_earth/models/pooreNemecek2018/landOccupationDuringCycle.py +13 -10
  20. hestia_earth/models/site/defaultMethodClassification.py +35 -0
  21. hestia_earth/models/site/defaultMethodClassificationDescription.py +39 -0
  22. hestia_earth/models/site/management.py +30 -19
  23. hestia_earth/models/utils/blank_node.py +1 -1
  24. hestia_earth/models/utils/crop.py +1 -1
  25. hestia_earth/models/utils/cycle.py +3 -3
  26. hestia_earth/models/utils/impact_assessment.py +5 -3
  27. hestia_earth/models/version.py +1 -1
  28. {hestia_earth_models-0.65.9.dist-info → hestia_earth_models-0.65.11.dist-info}/METADATA +2 -2
  29. {hestia_earth_models-0.65.9.dist-info → hestia_earth_models-0.65.11.dist-info}/RECORD +45 -41
  30. tests/models/cml2001Baseline/test_abioticResourceDepletionFossilFuels.py +2 -16
  31. tests/models/cml2001Baseline/test_abioticResourceDepletionMineralsAndMetals.py +2 -16
  32. tests/models/edip2003/test_ozoneDepletionPotential.py +0 -13
  33. tests/models/hestia/test_landCover.py +2 -1
  34. tests/models/hestia/test_landTransformation20YearAverageDuringCycle.py +2 -1
  35. tests/models/ipcc2021/test_gwp100.py +0 -9
  36. tests/models/pooreNemecek2018/test_landOccupationDuringCycle.py +1 -3
  37. tests/models/poschEtAl2008/test_terrestrialAcidificationPotentialAccumulatedExceedance.py +0 -14
  38. tests/models/poschEtAl2008/test_terrestrialEutrophicationPotentialAccumulatedExceedance.py +0 -14
  39. tests/models/site/test_defaultMethodClassification.py +18 -0
  40. tests/models/site/test_defaultMethodClassificationDescription.py +18 -0
  41. tests/models/test_config.py +11 -2
  42. tests/models/utils/test_crop.py +14 -2
  43. {hestia_earth_models-0.65.9.dist-info → hestia_earth_models-0.65.11.dist-info}/LICENSE +0 -0
  44. {hestia_earth_models-0.65.9.dist-info → hestia_earth_models-0.65.11.dist-info}/WHEEL +0 -0
  45. {hestia_earth_models-0.65.9.dist-info → hestia_earth_models-0.65.11.dist-info}/top_level.txt +0 -0
@@ -120,8 +120,8 @@ bad_fuel_indicator_no_property_lookup = {
120
120
  @mark.parametrize(
121
121
  "resources, expected, num_inputs",
122
122
  [
123
- ([], True, 0),
124
- ([wrong_indicator], True, 0),
123
+ ([], False, 0),
124
+ ([wrong_indicator], False, 0),
125
125
  ([indicator_no_inputs], False, 0),
126
126
  ([indicator_2_inputs], False, 2),
127
127
  ([indicator_no_unit], False, 0),
@@ -167,20 +167,6 @@ def test_run(*args):
167
167
  assert value == expected
168
168
 
169
169
 
170
- @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
171
- def test_run_no_emissions(*args):
172
- """
173
- Impact assessment with no emissions should return a indicator of 0
174
- """
175
- with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
176
- impactassessment = json.load(f)
177
-
178
- del impactassessment['emissionsResourceUse']
179
-
180
- value = run(impactassessment)
181
- assert value['value'] == 0
182
-
183
-
184
170
  def test_download_all_non_renewable_terms(*args):
185
171
  """
186
172
  make sure download_all_non_renewable_terms() only returns terms we want
@@ -71,8 +71,8 @@ indicator_tellurium = {
71
71
  @mark.parametrize(
72
72
  "resources, expected, num_inputs",
73
73
  [
74
- ([], True, 0),
75
- ([wrong_indicator], True, 0),
74
+ ([], False, 0),
75
+ ([wrong_indicator], False, 0),
76
76
  ([indicator_no_inputs], False, 0),
77
77
  ([indicator_2_inputs], False, 0),
78
78
  ([indicator_no_unit], False, 0),
@@ -108,17 +108,3 @@ def test_run(*args):
108
108
 
109
109
  value = run(impactassessment)
110
110
  assert value == expected
111
-
112
-
113
- @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
114
- def test_run_no_emissions(*args):
115
- """
116
- Impact assessment with no emissions should return a indicator of 0
117
- """
118
- with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
119
- impactassessment = json.load(f)
120
-
121
- del impactassessment['emissionsResourceUse']
122
-
123
- value = run(impactassessment)
124
- assert value['value'] == 0
@@ -19,16 +19,3 @@ def test_run(*args):
19
19
 
20
20
  value = run(impactassessment)
21
21
  assert value == expected
22
-
23
-
24
- @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
25
- def test_run_empty_input(*args):
26
- """
27
- Test with impact-assessment.jsonld that does NOT contain any "emissionsResourceUse".
28
- """
29
-
30
- with open(f"{fixtures_path}/impact_assessment/emissions/impact-assessment.jsonld", encoding='utf-8') as f:
31
- impactassessment = json.load(f)
32
-
33
- result = run(impactassessment)
34
- assert result['value'] == 0
@@ -197,7 +197,8 @@ def test_get_sums_of_crop_expansion():
197
197
  "gbr_example",
198
198
  "malaysia",
199
199
  "prior_landCover",
200
- "nigeria_cassava"
200
+ "nigeria_cassava",
201
+ "cover_crops",
201
202
  ]
202
203
  )
203
204
  @patch(f"{CLASS_PATH}._new_management", side_effect=fake_new_management)
@@ -14,7 +14,8 @@ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
14
14
  @pytest.mark.parametrize(
15
15
  "subfolder",
16
16
  [
17
- "maize_brazil"
17
+ "maize_brazil",
18
+ "orange_iran"
18
19
  ]
19
20
  )
20
21
  @patch("hestia_earth.models.hestia.resourceUse_utils._new_indicator", side_effect=fake_new_indicator)
@@ -8,15 +8,6 @@ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
9
 
10
10
 
11
- def test_run_no_emissions():
12
- with open(f"{fixtures_path}/impact_assessment/emissions/impact-assessment.jsonld", encoding='utf-8') as f:
13
- impact = json.load(f)
14
-
15
- impact['emissionsResourceUse'] = []
16
- indicator = run(impact)
17
- assert indicator.get('value') == 0
18
-
19
-
20
11
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
21
12
  def test_run(*args):
22
13
  with open(f"{fixtures_path}/impact_assessment/emissions/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -9,7 +9,7 @@ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
9
9
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
10
 
11
11
 
12
- @patch(f"{class_path}.get_land_cover_term_id", return_value='cropland')
12
+ @patch(f"{class_path}.get_landCover_term_id", return_value='cropland')
13
13
  @patch(f"{class_path}.land_occupation_per_kg", return_value=None)
14
14
  def test_should_run(mock_land_occupation, *args):
15
15
  # with a cycle and functionalUnit = 1 ha => no run
@@ -23,7 +23,6 @@ def test_should_run(mock_land_occupation, *args):
23
23
  assert should_run is True
24
24
 
25
25
 
26
- @patch(f"{class_path}.get_land_cover_term_id", return_value='cropland')
27
26
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
28
27
  def test_run(*args):
29
28
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -36,7 +35,6 @@ def test_run(*args):
36
35
  assert value == expected
37
36
 
38
37
 
39
- @patch(f"{class_path}.get_land_cover_term_id", return_value='cropland')
40
38
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
41
39
  def test_run_with_plantation(*args):
42
40
  with open(f"{fixtures_folder}/with-orchard-crop/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -42,17 +42,3 @@ def test_lookup_to_bad_country(*args):
42
42
 
43
43
  value = run(impactassessment)
44
44
  assert value == expected
45
-
46
-
47
- @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
48
- def test_run_no_emissions(*args):
49
- """
50
- Impact assessment with no emissions should return a indicator of 0
51
- """
52
- with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
53
- impactassessment = json.load(f)
54
-
55
- del impactassessment['emissionsResourceUse']
56
-
57
- value = run(impactassessment)
58
- assert value['value'] == 0
@@ -42,17 +42,3 @@ def test_lookup_to_bad_country(*args):
42
42
 
43
43
  value = run(impactassessment)
44
44
  assert value == expected
45
-
46
-
47
- @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
48
- def test_run_no_emissions(*args):
49
- """
50
- Impact assessment with no emissions should return a indicator of 0
51
- """
52
- with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
53
- impactassessment = json.load(f)
54
-
55
- del impactassessment['emissionsResourceUse']
56
-
57
- value = run(impactassessment)
58
- assert value['value'] == 0
@@ -0,0 +1,18 @@
1
+ import json
2
+ from tests.utils import fixtures_path
3
+
4
+ from hestia_earth.models.site.defaultMethodClassification import MODEL, MODEL_KEY, run
5
+
6
+ class_path = f"hestia_earth.models.{MODEL}.{MODEL_KEY}"
7
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{MODEL_KEY}"
8
+
9
+
10
+ def test_run():
11
+ with open(f"{fixtures_folder}/site.jsonld", encoding='utf-8') as f:
12
+ site = json.load(f)
13
+
14
+ with open(f"{fixtures_folder}/result.txt", encoding='utf-8') as f:
15
+ expected = f.read().strip()
16
+
17
+ result = run(site)
18
+ assert result == expected
@@ -0,0 +1,18 @@
1
+ import json
2
+ from tests.utils import fixtures_path
3
+
4
+ from hestia_earth.models.site.defaultMethodClassificationDescription import MODEL, MODEL_KEY, run
5
+
6
+ class_path = f"hestia_earth.models.{MODEL}.{MODEL_KEY}"
7
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{MODEL_KEY}"
8
+
9
+
10
+ def test_run():
11
+ with open(f"{fixtures_folder}/site.jsonld", encoding='utf-8') as f:
12
+ site = json.load(f)
13
+
14
+ with open(f"{fixtures_folder}/result.txt", encoding='utf-8') as f:
15
+ expected = f.read().strip()
16
+
17
+ result = run(site)
18
+ assert result == expected
@@ -3,7 +3,8 @@ import importlib
3
3
  from hestia_earth.utils.tools import flatten
4
4
 
5
5
  from hestia_earth.models.config import (
6
- load_config, config_max_stage, _is_aggregated_model, _remove_aggregated, load_run_config, load_trigger_config
6
+ load_config, config_max_stage, _is_aggregated_model, _remove_aggregated, load_run_config, load_trigger_config,
7
+ get_max_stage
7
8
  )
8
9
 
9
10
 
@@ -107,9 +108,17 @@ def _get_models_paths(node_type: str):
107
108
  'node_type',
108
109
  ['Cycle', 'Site', 'ImpactAssessment']
109
110
  )
110
- def test_load_config_cycle(node_type):
111
+ def test_load_config_cycle(node_type: str):
111
112
  paths = _get_models_paths(node_type)
112
113
 
113
114
  for path in paths:
114
115
  run = importlib.import_module(path).run
115
116
  assert run is not None, path
117
+
118
+
119
+ @pytest.mark.parametrize(
120
+ 'node_type, max_stage',
121
+ [('Cycle', 2), ('Site', 2), ('ImpactAssessment', 1)]
122
+ )
123
+ def test_get_max_stage(node_type: str, max_stage: int):
124
+ assert get_max_stage(node_type) == max_stage, node_type
@@ -1,6 +1,7 @@
1
- from hestia_earth.schema import SiteSiteType
1
+ import pytest
2
+ from hestia_earth.schema import SiteSiteType, TermTermType
2
3
 
3
- from hestia_earth.models.utils.crop import valid_site_type
4
+ from hestia_earth.models.utils.crop import valid_site_type, get_landCover_term_id
4
5
 
5
6
  class_path = 'hestia_earth.models.utils.crop'
6
7
 
@@ -13,3 +14,14 @@ def test_valid_site_type():
13
14
  cycle['site']['siteType'] = SiteSiteType.PERMANENT_PASTURE.value
14
15
  assert not valid_site_type(cycle)
15
16
  assert not valid_site_type(site, True) is True
17
+
18
+
19
+ @pytest.mark.parametrize(
20
+ 'term,expected',
21
+ [
22
+ ({'termType': TermTermType.CROP.value, '@id': 'wheatGrain'}, 'wheatPlant'),
23
+ ({'termType': TermTermType.SEED.value, '@id': 'saplings'}, None),
24
+ ]
25
+ )
26
+ def test_get_landCover_term_id(term: dict, expected: str):
27
+ assert get_landCover_term_id(term) == expected, term.get('@id')