hestia-earth-models 0.63.0__py3-none-any.whl → 0.64.1__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 (72) hide show
  1. hestia_earth/models/cycle/endDate.py +47 -0
  2. hestia_earth/models/cycle/otherSitesUnusedDuration.py +91 -0
  3. hestia_earth/models/cycle/siteUnusedDuration.py +2 -1
  4. hestia_earth/models/cycle/startDate.py +38 -10
  5. hestia_earth/models/cycle/startDateDefinition.py +2 -2
  6. hestia_earth/models/cycle/unknownPreSeasonWaterRegime.py +51 -0
  7. hestia_earth/models/ecoinventV3/__init__.py +18 -2
  8. hestia_earth/models/edip2003/__init__.py +13 -0
  9. hestia_earth/models/edip2003/ozoneDepletionPotential.py +34 -0
  10. hestia_earth/models/faostat2018/landTransformationFromCropland100YearAverage.py +1 -1
  11. hestia_earth/models/faostat2018/landTransformationFromCropland20YearAverage.py +1 -1
  12. hestia_earth/models/faostat2018/utils.py +2 -2
  13. hestia_earth/models/geospatialDatabase/clayContent.py +44 -17
  14. hestia_earth/models/geospatialDatabase/organicCarbonPerKgSoil.py +43 -17
  15. hestia_earth/models/geospatialDatabase/sandContent.py +43 -16
  16. hestia_earth/models/geospatialDatabase/siltContent.py +58 -18
  17. hestia_earth/models/geospatialDatabase/soilPh.py +43 -16
  18. hestia_earth/models/geospatialDatabase/totalNitrogenPerKgSoil.py +45 -15
  19. hestia_earth/models/geospatialDatabase/utils.py +11 -5
  20. hestia_earth/models/hyde32/landTransformationFromCropland100YearAverageDuringCycle.py +2 -1
  21. hestia_earth/models/hyde32/landTransformationFromCropland20YearAverageDuringCycle.py +2 -1
  22. hestia_earth/models/hyde32/landTransformationFromForest100YearAverageDuringCycle.py +2 -1
  23. hestia_earth/models/hyde32/landTransformationFromForest20YearAverageDuringCycle.py +2 -1
  24. hestia_earth/models/hyde32/landTransformationFromOtherNaturalVegetation100YearAverageDuringCycle.py +2 -1
  25. hestia_earth/models/hyde32/landTransformationFromOtherNaturalVegetation20YearAverageDuringCycle.py +2 -1
  26. hestia_earth/models/hyde32/landTransformationFromPermanentPasture100YearAverageDuringCycle.py +2 -1
  27. hestia_earth/models/hyde32/landTransformationFromPermanentPasture20YearAverageDuringCycle.py +2 -1
  28. hestia_earth/models/hyde32/utils.py +7 -4
  29. hestia_earth/models/impact_assessment/allocationMethod.py +39 -0
  30. hestia_earth/models/impact_assessment/emissions.py +3 -1
  31. hestia_earth/models/mocking/search-results.json +61 -19
  32. hestia_earth/models/pooreNemecek2018/excretaKgN.py +9 -9
  33. hestia_earth/models/pooreNemecek2018/excretaKgVs.py +6 -8
  34. hestia_earth/models/poschEtAl2008/__init__.py +13 -0
  35. hestia_earth/models/poschEtAl2008/terrestrialAcidificationPotentialAccumulatedExceedance.py +40 -0
  36. hestia_earth/models/site/management.py +15 -1
  37. hestia_earth/models/site/pre_checks/cache_geospatialDatabase.py +23 -16
  38. hestia_earth/models/site/waterDepth.py +0 -3
  39. hestia_earth/models/utils/indicator.py +3 -1
  40. hestia_earth/models/utils/term.py +34 -0
  41. hestia_earth/models/version.py +1 -1
  42. {hestia_earth_models-0.63.0.dist-info → hestia_earth_models-0.64.1.dist-info}/METADATA +3 -3
  43. {hestia_earth_models-0.63.0.dist-info → hestia_earth_models-0.64.1.dist-info}/RECORD +72 -56
  44. tests/models/cycle/test_endDate.py +22 -0
  45. tests/models/cycle/test_otherSitesUnusedDuration.py +54 -0
  46. tests/models/cycle/test_startDate.py +23 -5
  47. tests/models/cycle/test_unknownPreSeasonWaterRegime.py +36 -0
  48. tests/models/edip2003/__init__.py +0 -0
  49. tests/models/edip2003/test_ozoneDepletionPotential.py +46 -0
  50. tests/models/geospatialDatabase/test_clayContent.py +16 -2
  51. tests/models/geospatialDatabase/test_organicCarbonPerKgSoil.py +16 -2
  52. tests/models/geospatialDatabase/test_sandContent.py +16 -2
  53. tests/models/geospatialDatabase/test_siltContent.py +2 -2
  54. tests/models/geospatialDatabase/test_soilPh.py +16 -2
  55. tests/models/geospatialDatabase/test_totalNitrogenPerKgSoil.py +16 -2
  56. tests/models/hyde32/test_landTransformationFromCropland100YearAverageDuringCycle.py +1 -0
  57. tests/models/hyde32/test_landTransformationFromCropland20YearAverageDuringCycle.py +1 -0
  58. tests/models/hyde32/test_landTransformationFromForest100YearAverageDuringCycle.py +1 -0
  59. tests/models/hyde32/test_landTransformationFromForest20YearAverageDuringCycle.py +1 -0
  60. tests/models/hyde32/test_landTransformationFromOtherNaturalVegetation100YearAverageDuringCycle.py +1 -0
  61. tests/models/hyde32/test_landTransformationFromOtherNaturalVegetation20YearAverageDuringCycle.py +1 -0
  62. tests/models/hyde32/test_landTransformationFromPermanentPasture100YearAverageDuringCycle.py +1 -0
  63. tests/models/hyde32/test_landTransformationFromPermanentPasture20YearAverageDuringCycle.py +1 -0
  64. tests/models/impact_assessment/test_allocationMethod.py +48 -0
  65. tests/models/poschEtAl2008/__init__.py +0 -0
  66. tests/models/poschEtAl2008/test_terrestrialAcidificationPotentialAccumulatedExceedance.py +45 -0
  67. tests/models/test_cache_sites.py +10 -4
  68. tests/models/test_ecoinventV3.py +1 -0
  69. tests/models/utils/test_source.py +1 -1
  70. {hestia_earth_models-0.63.0.dist-info → hestia_earth_models-0.64.1.dist-info}/LICENSE +0 -0
  71. {hestia_earth_models-0.63.0.dist-info → hestia_earth_models-0.64.1.dist-info}/WHEEL +0 -0
  72. {hestia_earth_models-0.63.0.dist-info → hestia_earth_models-0.64.1.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
1
- from unittest.mock import patch
1
+ from unittest.mock import patch, call
2
2
  import json
3
3
  from tests.utils import fixtures_path, fake_new_measurement
4
4
 
@@ -32,4 +32,18 @@ def test_run(mock_download, *args):
32
32
  site = json.load(f)
33
33
 
34
34
  run(site)
35
- mock_download.assert_called_once()
35
+ base_params = {'ee_type': 'raster', 'reducer': 'mean'}
36
+ mock_download.assert_has_calls([
37
+ call(TERM_ID, site, base_params | {
38
+ 'collection': 'T_SAND_v2_depth_1', 'depthUpper': 0, 'depthLower': 20
39
+ }),
40
+ call(TERM_ID, site, base_params | {
41
+ 'collection': 'T_SAND_v2_depth_2', 'depthUpper': 20, 'depthLower': 40
42
+ }),
43
+ call(TERM_ID, site, base_params | {
44
+ 'collection': 'T_SAND_v2_depth_3', 'depthUpper': 40, 'depthLower': 60
45
+ }),
46
+ call(TERM_ID, site, base_params | {
47
+ 'collection': 'T_SAND_v2_depth_4', 'depthUpper': 60, 'depthLower': 80
48
+ })
49
+ ])
@@ -17,8 +17,8 @@ def test_should_run():
17
17
 
18
18
  # with measumrents => run
19
19
  site['measurements'] = [
20
- {'term': {'@id': 'clayContent'}, 'value': [10]},
21
- {'term': {'@id': 'sandContent'}, 'value': [20]}
20
+ {'term': {'@id': 'clayContent'}, 'value': [10], 'depthUpper': 0, 'depthLower': 20},
21
+ {'term': {'@id': 'sandContent'}, 'value': [20], 'depthUpper': 0, 'depthLower': 20}
22
22
  ]
23
23
  should_run, *_ = _should_run(site)
24
24
  assert should_run is True
@@ -1,4 +1,4 @@
1
- from unittest.mock import patch
1
+ from unittest.mock import patch, call
2
2
  import json
3
3
  from tests.utils import fixtures_path, fake_new_measurement
4
4
 
@@ -26,4 +26,18 @@ def test_run(mock_download, *args):
26
26
  site = json.load(f)
27
27
 
28
28
  run(site)
29
- mock_download.assert_called_once()
29
+ base_params = {'ee_type': 'raster', 'reducer': 'mean'}
30
+ mock_download.assert_has_calls([
31
+ call(TERM_ID, site, base_params | {
32
+ 'collection': 'T_PH_H2O_v2_depth_1', 'depthUpper': 0, 'depthLower': 20
33
+ }),
34
+ call(TERM_ID, site, base_params | {
35
+ 'collection': 'T_PH_H2O_v2_depth_2', 'depthUpper': 20, 'depthLower': 40
36
+ }),
37
+ call(TERM_ID, site, base_params | {
38
+ 'collection': 'T_PH_H2O_v2_depth_3', 'depthUpper': 40, 'depthLower': 60
39
+ }),
40
+ call(TERM_ID, site, base_params | {
41
+ 'collection': 'T_PH_H2O_v2_depth_4', 'depthUpper': 60, 'depthLower': 80
42
+ })
43
+ ])
@@ -1,4 +1,4 @@
1
- from unittest.mock import patch
1
+ from unittest.mock import patch, call
2
2
  import json
3
3
  from tests.utils import fixtures_path, fake_new_measurement
4
4
 
@@ -26,4 +26,18 @@ def test_run(mock_download, *args):
26
26
  site = json.load(f)
27
27
 
28
28
  run(site)
29
- mock_download.assert_called_once()
29
+ base_params = {'ee_type': 'raster', 'reducer': 'mean'}
30
+ mock_download.assert_has_calls([
31
+ call(TERM_ID, site, base_params | {
32
+ 'collection': 'T_N_v2_depth_1', 'depthUpper': 0, 'depthLower': 20
33
+ }),
34
+ call(TERM_ID, site, base_params | {
35
+ 'collection': 'T_N_v2_depth_2', 'depthUpper': 20, 'depthLower': 40
36
+ }),
37
+ call(TERM_ID, site, base_params | {
38
+ 'collection': 'T_N_v2_depth_3', 'depthUpper': 40, 'depthLower': 60
39
+ }),
40
+ call(TERM_ID, site, base_params | {
41
+ 'collection': 'T_N_v2_depth_4', 'depthUpper': 60, 'depthLower': 80
42
+ })
43
+ ])
@@ -8,6 +8,7 @@ class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
9
9
 
10
10
 
11
+ @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
11
12
  @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
12
13
  def test_run(*args):
13
14
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -8,6 +8,7 @@ class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
9
9
 
10
10
 
11
+ @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
11
12
  @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
12
13
  def test_run(*args):
13
14
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -8,6 +8,7 @@ class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
9
9
 
10
10
 
11
+ @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
11
12
  @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
12
13
  def test_run(*args):
13
14
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -8,6 +8,7 @@ class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
9
9
 
10
10
 
11
+ @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
11
12
  @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
12
13
  def test_run(*args):
13
14
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -10,6 +10,7 @@ class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
10
10
  fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
11
11
 
12
12
 
13
+ @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
13
14
  @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
14
15
  def test_run(*args):
15
16
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -8,6 +8,7 @@ class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
9
9
 
10
10
 
11
+ @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
11
12
  @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
12
13
  def test_run(*args):
13
14
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -8,6 +8,7 @@ class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
9
9
 
10
10
 
11
+ @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
11
12
  @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
12
13
  def test_run(*args):
13
14
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -8,6 +8,7 @@ class_path = f"hestia_earth.models.hyde32.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/hyde32/{TERM_ID}"
9
9
 
10
10
 
11
+ @patch('hestia_earth.models.hyde32.utils.get_land_cover_term_id', return_value='cropland')
11
12
  @patch('hestia_earth.models.hyde32.utils._new_indicator', side_effect=fake_new_indicator)
12
13
  def test_run(*args):
13
14
  with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
@@ -0,0 +1,48 @@
1
+ import json
2
+ import pytest
3
+ from tests.utils import fixtures_path
4
+
5
+ from hestia_earth.models.impact_assessment.allocationMethod import MODEL_KEY, run, _should_run
6
+
7
+ fixtures_folder = f"{fixtures_path}/impact_assessment/{MODEL_KEY}"
8
+
9
+
10
+ @pytest.mark.parametrize(
11
+ 'test_name,impact,expected_should_run',
12
+ [
13
+ (
14
+ 'no updated/modified => no run',
15
+ {},
16
+ False
17
+ ),
18
+ (
19
+ 'updated organic => no run',
20
+ {'updated': ['organic']},
21
+ False
22
+ ),
23
+ (
24
+ 'updated impacts => run',
25
+ {'updated': ['impacts']},
26
+ True
27
+ ),
28
+ (
29
+ 'added emissions => run',
30
+ {'updated': ['emissionsResourceUse']},
31
+ True
32
+ )
33
+ ]
34
+ )
35
+ def test_should_run(test_name, impact, expected_should_run):
36
+ should_run = _should_run(impact)
37
+ assert should_run == expected_should_run, test_name
38
+
39
+
40
+ def test_run():
41
+ with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
42
+ impact = json.load(f)
43
+
44
+ with open(f"{fixtures_folder}/result.txt", encoding='utf-8') as f:
45
+ expected = f.read().strip()
46
+
47
+ result = run(impact)
48
+ assert result == expected
File without changes
@@ -0,0 +1,45 @@
1
+ import json
2
+ from unittest.mock import patch
3
+
4
+ from hestia_earth.models.poschEtAl2008.terrestrialAcidificationPotentialAccumulatedExceedance import MODEL, TERM_ID, run
5
+ from tests.utils import fixtures_path, fake_new_indicator
6
+
7
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
+
10
+
11
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
12
+ def test_run(*args):
13
+ with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
14
+ cycle = json.load(f)
15
+
16
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
17
+ expected = json.load(f)
18
+
19
+ value = run(cycle)
20
+ assert value == expected
21
+
22
+
23
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
24
+ def test_lookup_to_bad_country(*args):
25
+ with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
26
+ cycle = json.load(f)
27
+ cycle['country']['@id'] = "example-land-not-real"
28
+
29
+ value = run(cycle)
30
+ assert value['value'] is None
31
+
32
+
33
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
34
+ def test_lookup_no_term_type(*args):
35
+ """
36
+ We currently do not filter out bad termTypes so this is expected behavior.
37
+ """
38
+ with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
39
+ cycle = json.load(f)
40
+ del cycle['emissionsResourceUse'][0]['term']['termType']
41
+ del cycle['emissionsResourceUse'][1]['term']['termType']
42
+ cycle['emissionsResourceUse'][2]['term']['termType'] = "wrong-type"
43
+
44
+ value = run(cycle)
45
+ assert value['value'] == 0.085
@@ -10,7 +10,7 @@ fixtures_folder = os.path.join(fixtures_path, 'cache_sites')
10
10
  coordinates = [{"latitude": 46.47, "longitude": 2.94}]
11
11
 
12
12
 
13
- @patch(f"{class_path}._run_query", return_value=[10] * 100)
13
+ @patch(f"{class_path}._run_query")
14
14
  def test_run(mock_run_query, *args):
15
15
  with open(f"{fixtures_folder}/data.json", encoding='utf-8') as f:
16
16
  data = json.load(f)
@@ -19,9 +19,9 @@ def test_run(mock_run_query, *args):
19
19
  with open(f"{fixtures_folder}/params.json", encoding='utf-8') as f:
20
20
  params = json.load(f)
21
21
 
22
+ mock_run_query.return_value = [10] * len(params.get('rasters', []) + params.get('vectors', []))
23
+
22
24
  sites = run(data.get('nodes', []), [2019, 2020], include_region=False)
23
- expected = [site | {'_cache': cache} for site in data.get('nodes', [])]
24
- assert sites == expected
25
25
 
26
26
  mock_run_query.assert_has_calls([
27
27
  call({
@@ -36,15 +36,21 @@ def test_run(mock_run_query, *args):
36
36
  })
37
37
  ])
38
38
 
39
+ expected = [site | {'_cache': cache} for site in data.get('nodes', [])]
40
+ assert sites == expected
41
+
39
42
 
40
- @patch(f"{class_path}._run_query", return_value=[10] * 100)
43
+ @patch(f"{class_path}._run_query")
41
44
  def test_run_include_region(mock_run_query, *args):
42
45
  with open(f"{fixtures_folder}/data.json", encoding='utf-8') as f:
43
46
  data = json.load(f)
44
47
  with open(f"{fixtures_folder}/params.json", encoding='utf-8') as f:
45
48
  params = json.load(f)
46
49
 
50
+ mock_run_query.return_value = [10] * len(params.get('rasters', []) + params.get('vectors', []))
51
+
47
52
  run(data.get('nodes', []), [2019, 2020], include_region=True)
53
+
48
54
  mock_run_query.assert_has_calls([
49
55
  call({
50
56
  "ee_type": "raster",
@@ -50,6 +50,7 @@ def test_run(*args):
50
50
  expected = json.load(f)
51
51
 
52
52
  result = run('all', cycle)
53
+ # print(json.dumps(result, indent=2))
53
54
  assert result == expected
54
55
 
55
56
 
@@ -12,7 +12,7 @@ search_results = [{
12
12
 
13
13
 
14
14
  def test_list_sources():
15
- assert len(_list_sources()) == 11
15
+ assert len(_list_sources()) == 10
16
16
 
17
17
 
18
18
  @patch(f"{class_path}.search", return_value=search_results)