hestia-earth-models 0.62.6__py3-none-any.whl → 0.64.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 (59) hide show
  1. hestia_earth/models/cycle/longFallowRatio.py +9 -9
  2. hestia_earth/models/cycle/unknownPreSeasonWaterRegime.py +51 -0
  3. hestia_earth/models/ecoinventV3/__init__.py +18 -2
  4. hestia_earth/models/faostat2018/landTransformationFromCropland100YearAverage.py +1 -1
  5. hestia_earth/models/faostat2018/landTransformationFromCropland20YearAverage.py +1 -1
  6. hestia_earth/models/faostat2018/utils.py +2 -2
  7. hestia_earth/models/geospatialDatabase/clayContent.py +44 -17
  8. hestia_earth/models/geospatialDatabase/organicCarbonPerKgSoil.py +43 -17
  9. hestia_earth/models/geospatialDatabase/sandContent.py +43 -16
  10. hestia_earth/models/geospatialDatabase/siltContent.py +58 -18
  11. hestia_earth/models/geospatialDatabase/soilPh.py +43 -16
  12. hestia_earth/models/geospatialDatabase/totalNitrogenPerKgSoil.py +45 -15
  13. hestia_earth/models/geospatialDatabase/utils.py +11 -5
  14. hestia_earth/models/hyde32/landTransformationFromCropland100YearAverageDuringCycle.py +2 -1
  15. hestia_earth/models/hyde32/landTransformationFromCropland20YearAverageDuringCycle.py +2 -1
  16. hestia_earth/models/hyde32/landTransformationFromForest100YearAverageDuringCycle.py +2 -1
  17. hestia_earth/models/hyde32/landTransformationFromForest20YearAverageDuringCycle.py +2 -1
  18. hestia_earth/models/hyde32/landTransformationFromOtherNaturalVegetation100YearAverageDuringCycle.py +2 -1
  19. hestia_earth/models/hyde32/landTransformationFromOtherNaturalVegetation20YearAverageDuringCycle.py +2 -1
  20. hestia_earth/models/hyde32/landTransformationFromPermanentPasture100YearAverageDuringCycle.py +2 -1
  21. hestia_earth/models/hyde32/landTransformationFromPermanentPasture20YearAverageDuringCycle.py +2 -1
  22. hestia_earth/models/hyde32/utils.py +7 -4
  23. hestia_earth/models/impact_assessment/allocationMethod.py +39 -0
  24. hestia_earth/models/impact_assessment/emissions.py +3 -1
  25. hestia_earth/models/mocking/search-results.json +60 -18
  26. hestia_earth/models/pooreNemecek2018/{longFallowPeriod.py → longFallowDuration.py} +2 -2
  27. hestia_earth/models/pooreNemecek2018/rotationDuration.py +5 -5
  28. hestia_earth/models/site/management.py +15 -1
  29. hestia_earth/models/site/pre_checks/cache_geospatialDatabase.py +23 -16
  30. hestia_earth/models/utils/cycle.py +2 -2
  31. hestia_earth/models/utils/indicator.py +3 -1
  32. hestia_earth/models/utils/term.py +34 -0
  33. hestia_earth/models/version.py +1 -1
  34. {hestia_earth_models-0.62.6.dist-info → hestia_earth_models-0.64.0.dist-info}/METADATA +2 -2
  35. {hestia_earth_models-0.62.6.dist-info → hestia_earth_models-0.64.0.dist-info}/RECORD +59 -55
  36. tests/models/cycle/test_longFallowRatio.py +5 -5
  37. tests/models/cycle/test_unknownPreSeasonWaterRegime.py +36 -0
  38. tests/models/geospatialDatabase/test_clayContent.py +16 -2
  39. tests/models/geospatialDatabase/test_organicCarbonPerKgSoil.py +16 -2
  40. tests/models/geospatialDatabase/test_sandContent.py +16 -2
  41. tests/models/geospatialDatabase/test_siltContent.py +2 -2
  42. tests/models/geospatialDatabase/test_soilPh.py +16 -2
  43. tests/models/geospatialDatabase/test_totalNitrogenPerKgSoil.py +16 -2
  44. tests/models/hyde32/test_landTransformationFromCropland100YearAverageDuringCycle.py +1 -0
  45. tests/models/hyde32/test_landTransformationFromCropland20YearAverageDuringCycle.py +1 -0
  46. tests/models/hyde32/test_landTransformationFromForest100YearAverageDuringCycle.py +1 -0
  47. tests/models/hyde32/test_landTransformationFromForest20YearAverageDuringCycle.py +1 -0
  48. tests/models/hyde32/test_landTransformationFromOtherNaturalVegetation100YearAverageDuringCycle.py +1 -0
  49. tests/models/hyde32/test_landTransformationFromOtherNaturalVegetation20YearAverageDuringCycle.py +1 -0
  50. tests/models/hyde32/test_landTransformationFromPermanentPasture100YearAverageDuringCycle.py +1 -0
  51. tests/models/hyde32/test_landTransformationFromPermanentPasture20YearAverageDuringCycle.py +1 -0
  52. tests/models/impact_assessment/test_allocationMethod.py +48 -0
  53. tests/models/pooreNemecek2018/{test_longFallowPeriod.py → test_longFallowDuration.py} +1 -1
  54. tests/models/test_cache_sites.py +10 -4
  55. tests/models/test_ecoinventV3.py +1 -0
  56. tests/models/utils/test_source.py +1 -1
  57. {hestia_earth_models-0.62.6.dist-info → hestia_earth_models-0.64.0.dist-info}/LICENSE +0 -0
  58. {hestia_earth_models-0.62.6.dist-info → hestia_earth_models-0.64.0.dist-info}/WHEEL +0 -0
  59. {hestia_earth_models-0.62.6.dist-info → hestia_earth_models-0.64.0.dist-info}/top_level.txt +0 -0
@@ -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
@@ -2,7 +2,7 @@ from unittest.mock import patch
2
2
  import json
3
3
  from tests.utils import fixtures_path, fake_new_practice
4
4
 
5
- from hestia_earth.models.pooreNemecek2018.longFallowPeriod import MODEL, TERM_ID, run
5
+ from hestia_earth.models.pooreNemecek2018.longFallowDuration import MODEL, TERM_ID, run
6
6
 
7
7
  class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
8
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
@@ -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)