hestia-earth-models 0.64.7__py3-none-any.whl → 0.64.9__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 (58) hide show
  1. hestia_earth/models/cycle/animal/milkYield.py +10 -22
  2. hestia_earth/models/cycle/siteArea.py +2 -1
  3. hestia_earth/models/cycle/unknownPreSeasonWaterRegime.py +0 -1
  4. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandOccupation.py +73 -82
  5. hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandTransformation.py +168 -0
  6. hestia_earth/models/environmentalFootprintV3/soilQualityIndexTotalLandUseEffects.py +77 -0
  7. hestia_earth/models/environmentalFootprintV3/utils.py +1 -1
  8. hestia_earth/models/faostat2018/landTransformationFromCropland100YearAverage.py +3 -2
  9. hestia_earth/models/faostat2018/landTransformationFromCropland20YearAverage.py +3 -2
  10. hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +69 -37
  11. hestia_earth/models/hyde32/utils.py +4 -0
  12. hestia_earth/models/ipcc2019/animal/fatContent.py +38 -0
  13. hestia_earth/models/ipcc2019/animal/liveweightGain.py +3 -54
  14. hestia_earth/models/ipcc2019/animal/liveweightPerHead.py +3 -54
  15. hestia_earth/models/ipcc2019/animal/pastureGrass.py +3 -1
  16. hestia_earth/models/ipcc2019/animal/pregnancyRateTotal.py +38 -0
  17. hestia_earth/models/ipcc2019/animal/trueProteinContent.py +38 -0
  18. hestia_earth/models/ipcc2019/animal/utils.py +87 -3
  19. hestia_earth/models/ipcc2019/animal/weightAtMaturity.py +4 -10
  20. hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +191 -0
  21. hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChangeLandUseChange.py +204 -0
  22. hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +255 -35
  23. hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +63 -149
  24. hestia_earth/models/ipcc2019/pastureGrass.py +3 -1
  25. hestia_earth/models/mocking/search-results.json +2026 -26
  26. hestia_earth/models/pooreNemecek2018/landOccupationDuringCycle.py +1 -1
  27. hestia_earth/models/poschEtAl2008/terrestrialAcidificationPotentialAccumulatedExceedance.py +4 -1
  28. hestia_earth/models/poschEtAl2008/terrestrialEutrophicationPotentialAccumulatedExceedance.py +4 -1
  29. hestia_earth/models/site/management.py +3 -5
  30. hestia_earth/models/utils/__init__.py +5 -4
  31. hestia_earth/models/utils/impact_assessment.py +13 -4
  32. hestia_earth/models/utils/input.py +5 -2
  33. hestia_earth/models/utils/site.py +4 -2
  34. hestia_earth/models/version.py +1 -1
  35. {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/METADATA +2 -2
  36. {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/RECORD +58 -44
  37. tests/models/cycle/animal/test_milkYield.py +1 -14
  38. tests/models/environmentalFootprintV3/test_soilQualityIndexLandOccupation.py +97 -66
  39. tests/models/environmentalFootprintV3/test_soilQualityIndexLandTransformation.py +176 -0
  40. tests/models/environmentalFootprintV3/test_soilQualityIndexTotalLandUseEffects.py +55 -0
  41. tests/models/frischknechtEtAl2000/test_ionisingRadiationKbqU235Eq.py +67 -44
  42. tests/models/ipcc2019/animal/test_fatContent.py +22 -0
  43. tests/models/ipcc2019/animal/test_liveweightGain.py +4 -2
  44. tests/models/ipcc2019/animal/test_liveweightPerHead.py +4 -2
  45. tests/models/ipcc2019/animal/test_pregnancyRateTotal.py +22 -0
  46. tests/models/ipcc2019/animal/test_trueProteinContent.py +22 -0
  47. tests/models/ipcc2019/animal/test_weightAtMaturity.py +2 -1
  48. tests/models/ipcc2019/test_co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +83 -0
  49. tests/models/ipcc2019/test_co2ToAirBelowGroundBiomassStockChangeLandUseChange.py +83 -0
  50. tests/models/ipcc2019/test_co2ToAirCarbonStockChange_utils.py +6 -6
  51. tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +5 -4
  52. tests/models/poschEtAl2008/test_terrestrialAcidificationPotentialAccumulatedExceedance.py +30 -17
  53. tests/models/poschEtAl2008/test_terrestrialEutrophicationPotentialAccumulatedExceedance.py +28 -14
  54. tests/models/site/test_management.py +4 -1
  55. tests/models/utils/test_input.py +65 -1
  56. {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/LICENSE +0 -0
  57. {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/WHEEL +0 -0
  58. {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/top_level.txt +0 -0
@@ -1,71 +1,107 @@
1
1
  import json
2
2
  from unittest.mock import patch
3
3
 
4
- from hestia_earth.models.environmentalFootprintV3.soilQualityIndexLandOccupation import MODEL, TERM_ID, run, _should_run
4
+ import pytest
5
+
6
+ from hestia_earth.models.environmentalFootprintV3.soilQualityIndexLandOccupation import MODEL, TERM_ID, run, \
7
+ _should_run
5
8
  from tests.utils import fixtures_path, fake_new_indicator
6
9
 
7
10
  class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
8
11
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
9
12
 
10
-
11
- with open(f"{fixtures_path}/impact_assessment/emissions/impact-assessment.jsonld", encoding='utf-8') as f:
12
- impact = json.load(f)
13
-
14
-
15
- def test_should_run():
16
- with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
17
- cycle = json.load(f)
18
-
19
- # a LandCover type with no CF => no run
20
- cycle['site']['management'] = [{"endDate": "2024-03-31", "@type": "Management",
21
- "term": {"termType": "landCover", "@type": "Term", "@id": "ocean"}}]
22
-
23
- should_run, *args = _should_run({'cycle': cycle})
24
- assert not should_run
25
-
26
- # no management => no run
27
- cycle['site']['management'] = []
28
- should_run, *args = _should_run({'cycle': cycle})
29
- assert not should_run
13
+ crop_land = {"@id": "cropland", "termType": "landCover"}
14
+ sea_land_cover = {"@id": "seaOrOcean", "termType": "landCover"}
15
+ forest = {"@id": "forest", "termType": "landCover"}
16
+
17
+ wrong_indicator = {"term": {"@id": "NOT_landOccupationInputsProduction", "termType": "resourceUse", "units": "m2*year"},
18
+ "value": 0.5, "landCover": crop_land}
19
+
20
+ indicator_no_land_cover = {
21
+ "term": {"@id": "landOccupationInputsProduction", "termType": "resourceUse", "units": "m2*year"},
22
+ "value": 0.5}
23
+
24
+ indicator_no_unit = {"term": {"@id": "landOccupationInputsProduction", "termType": "resourceUse"},
25
+ "value": 0.5, "landCover": crop_land}
26
+
27
+ indicator_wrong_unit = {
28
+ "term": {"@id": "landOccupationInputsProduction", "termType": "resourceUse", "units": "ha*day"}, "value": 0.5,
29
+ "landCover": crop_land}
30
+
31
+ indicator_bad_area_time_value = {
32
+ "term": {"@id": "landOccupationInputsProduction", "termType": "resourceUse", "units": "m2*year"}, "value": 0,
33
+ "landCover": crop_land}
34
+
35
+ inputs_production_indicator_no_cf = {
36
+ "term": {"@id": "landOccupationInputsProduction", "termType": "resourceUse", "units": "m2*year"}, "value": 0.5,
37
+ "landCover": sea_land_cover}
38
+
39
+ good_inputs_production_indicator_cropland = {
40
+ "term": {"@id": "landOccupationInputsProduction", "termType": "resourceUse", "units": "m2*year"}, "value": 0.5,
41
+ "landCover": crop_land}
42
+
43
+ good_inputs_production_indicator_forest = {
44
+ "term": {"@id": "landOccupationInputsProduction", "termType": "resourceUse", "units": "m2*year"}, "value": 0.5,
45
+ "landCover": forest}
46
+
47
+ good_during_cycle_indicator_cropland = {
48
+ "term": {"@id": "landOccupationDuringCycle", "termType": "resourceUse", "units": "m2*year"}, "value": 0.5,
49
+ "landCover": crop_land}
50
+
51
+ good_during_cycle_indicator_forest = {
52
+ "term": {"@id": "landOccupationDuringCycle", "termType": "resourceUse", "units": "m2*year"}, "value": 0.5,
53
+ "landCover": forest}
54
+
55
+
56
+ @pytest.mark.parametrize(
57
+ "resources, expected, num_inputs",
58
+ [
59
+ ([], False, 0),
60
+ ([wrong_indicator], False, 0),
61
+ ([indicator_no_land_cover], False, 0),
62
+ ([indicator_no_unit], False, 0),
63
+ ([indicator_wrong_unit], False, 0),
64
+ ([indicator_bad_area_time_value], False, 0),
65
+ ([inputs_production_indicator_no_cf], True, 0),
66
+ ([good_during_cycle_indicator_cropland], True, 1),
67
+ ([good_during_cycle_indicator_cropland, good_inputs_production_indicator_forest], True, 2),
68
+ ([good_during_cycle_indicator_cropland, inputs_production_indicator_no_cf], True, 1),
69
+ ([good_during_cycle_indicator_cropland, good_during_cycle_indicator_forest,
70
+ good_inputs_production_indicator_forest, good_inputs_production_indicator_cropland], True, 4),
71
+
72
+ ],
73
+ ids=["No emissionsResourceUse => no run",
74
+ "Wrong indicator termid => no run",
75
+ "Indicator no landcover terms => no run",
76
+ "Missing unit => no run",
77
+ "Wrong unit => no run",
78
+ "Bad area*time value => no run",
79
+ "Input with no cf => run, empty input",
80
+ "One good input => run, 1 dict",
81
+ "Two good input => run, 2 dict",
82
+ "One good input and One with no CF => run, 2 dict",
83
+ "Multiple good indicators with same id => run, 4 dict",
84
+ ]
85
+ )
86
+ def test_should_run(resources, expected, num_inputs):
87
+ with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
88
+ impactassessment = json.load(f)
89
+
90
+ impactassessment['emissionsResourceUse'] = resources
91
+
92
+ should_run, resources_with_cf = _should_run(impactassessment)
93
+ assert should_run is expected
94
+ assert len(resources_with_cf) == num_inputs
30
95
 
31
96
 
32
97
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
33
98
  def test_run(*args):
34
- with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
35
- cycle = json.load(f)
99
+ with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
100
+ impact = json.load(f)
36
101
 
37
102
  with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
38
103
  expected = json.load(f)
39
104
 
40
- impact['cycle'] = cycle
41
- value = run(impact)
42
- assert value == expected
43
-
44
-
45
- @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
46
- def test_run_other_sites(*args):
47
- """
48
- This test case contains 2 sites:
49
- One is a crop in france, with value:
50
- CF_METHOD_factor_france_permanent_crops * ( siteArea_france_crop * time_in_years )
51
- = 87.631 * ( 1.0082662E-7 * 1 )
52
- = 8.835537537220001e-06
53
-
54
- And one a forest in italy, with value:
55
- CF_METHOD_factor_italy_forest * ( siteArea_italy_forest * time_in_years )
56
- = 43.198 * ( 1.3573373E-9 * 1 )
57
- = 5.86342566854E-08
58
-
59
- We expect the model to return 8.835537537220001e-06 + 5.86342566854E-08 = 8.894171793905402e-06
60
-
61
- """
62
- with open(f"{fixtures_folder}/otherSites/cycle.jsonld", encoding='utf-8') as f:
63
- cycle = json.load(f)
64
-
65
- with open(f"{fixtures_folder}/otherSites/result.jsonld", encoding='utf-8') as f:
66
- expected = json.load(f)
67
-
68
- impact['cycle'] = cycle
69
105
  value = run(impact)
70
106
  assert value == expected
71
107
 
@@ -75,21 +111,18 @@ def test_run_with_subclass_landcover(*args):
75
111
  """
76
112
  Example data:
77
113
  Country: Italy
78
- Quantity in m^2: 1.3573373E-9
79
- CF METHOD factor: 4.3198E+01
80
- "Charact Result [soil quality index]" result also in result.jsonld : 5.86342566854E-08
81
- siteArea in test file in ha: 1.3573373E-9 / 10 000 = 1.3573373e-13
114
+ Quantity in m2*year: 1
115
+ CF METHOD factor: 50.438
82
116
 
83
117
  landCover field "plantationForest" should map to
84
118
  Name Flow: "forest, intensive Land occupation"
85
119
  """
86
- with open(f"{fixtures_folder}/plantationForest/cycle.jsonld", encoding='utf-8') as f:
87
- cycle = json.load(f)
88
120
 
121
+ with open(f"{fixtures_folder}/plantationForest/impact-assessment.jsonld", encoding='utf-8') as f:
122
+ impact = json.load(f)
89
123
  with open(f"{fixtures_folder}/plantationForest/result.jsonld", encoding='utf-8') as f:
90
124
  expected = json.load(f)
91
125
 
92
- impact['cycle'] = cycle
93
126
  value = run(impact)
94
127
  assert value == expected
95
128
 
@@ -99,13 +132,12 @@ def test_run_with_region_missing_data(*args):
99
132
  """
100
133
  When given valid sub-region or country not in the lookup file should default to 'region-world'
101
134
  """
102
- with open(f"{fixtures_folder}/default-region-world/cycle.jsonld", encoding='utf-8') as f:
103
- cycle = json.load(f)
135
+ with open(f"{fixtures_folder}/default-region-world/impact-assessment.jsonld", encoding='utf-8') as f:
136
+ impact = json.load(f)
104
137
 
105
138
  with open(f"{fixtures_folder}/default-region-world/result.jsonld", encoding='utf-8') as f:
106
139
  expected = json.load(f)
107
140
 
108
- impact['cycle'] = cycle
109
141
  value = run(impact)
110
142
  assert value == expected
111
143
 
@@ -115,14 +147,13 @@ def test_run_with_no_region(*args):
115
147
  """
116
148
  When no location is specified, defaults to region world.
117
149
  """
118
- with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
119
- cycle = json.load(f)
150
+ with open(f"{fixtures_folder}/default-region-world/impact-assessment.jsonld", encoding='utf-8') as f:
151
+ impact = json.load(f)
120
152
 
121
- del cycle['site']['country']
153
+ del impact['country']
122
154
 
123
155
  with open(f"{fixtures_folder}/default-region-world/result.jsonld", encoding='utf-8') as f:
124
156
  expected = json.load(f)
125
157
 
126
- impact['cycle'] = cycle
127
158
  value = run(impact)
128
159
  assert value == expected
@@ -0,0 +1,176 @@
1
+ import json
2
+ from unittest.mock import patch
3
+
4
+ from pytest import mark
5
+
6
+ from hestia_earth.models.environmentalFootprintV3.soilQualityIndexLandTransformation import MODEL, TERM_ID, run, \
7
+ _should_run
8
+ from tests.utils import fixtures_path, fake_new_indicator
9
+
10
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
11
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
12
+
13
+
14
+ def fake_rounded_indicator(value: float):
15
+ indicator = fake_new_indicator(TERM_ID, MODEL)
16
+ indicator['value'] = round(value, 7)
17
+ return indicator
18
+
19
+
20
+ crop_land = {"@id": "cropland", "termType": "landCover"}
21
+ sea_land_cover = {"@id": "seaOrOcean", "termType": "landCover"}
22
+ forest = {"@id": "forest", "termType": "landCover"}
23
+
24
+ wrong_indicator = {"term": {"@id": "NOT_VALID_INDICATOR_ID", "termType": "resourceUse", "units": "m2 / year"},
25
+ "value": 0.5, "landCover": crop_land}
26
+
27
+ indicator_no_land_cover = {
28
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse",
29
+ "units": "m2 / year"},
30
+ "value": 0.5}
31
+
32
+ indicator_no_unit = {
33
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse"},
34
+ "value": 0.5, "landCover": crop_land}
35
+
36
+ indicator_wrong_unit = {
37
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse",
38
+ "units": "ha*day"}, "value": 0.5,
39
+ "landCover": crop_land}
40
+
41
+ indicator_bad_area_value = {
42
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse",
43
+ "units": "m2 / year"}, "value": -10,
44
+ "landCover": crop_land}
45
+
46
+ inputs_production_indicator_from_forest_to_no_cf = {
47
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse",
48
+ "units": "m2 / year"}, "value": 0.5,
49
+ "landCover": sea_land_cover}
50
+
51
+ good_inputs_production_indicator_from_forest_to_cropland = {
52
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse",
53
+ "units": "m2 / year"}, "value": 0.5,
54
+ "landCover": crop_land}
55
+
56
+ good_inputs_production_indicator_from_forest_to_forest = {
57
+ "term": {"@id": "landTransformationFromForest20YearAverageInputsProduction", "termType": "resourceUse",
58
+ "units": "m2 / year"}, "value": 0.5,
59
+ "landCover": forest}
60
+
61
+ good_during_cycle_indicator_from_forest_to_cropland = {
62
+ "term": {"@id": "landTransformationFromForest20YearAverageDuringCycle", "termType": "resourceUse",
63
+ "units": "m2 / year"}, "value": 0.5,
64
+ "landCover": crop_land}
65
+
66
+ good_during_cycle_indicator_from_forest_to_forest = {
67
+ "term": {"@id": "landTransformationFromForest20YearAverageDuringCycle", "termType": "resourceUse",
68
+ "units": "m2 / year"}, "value": 0.5,
69
+ "landCover": forest}
70
+
71
+
72
+ @mark.parametrize(
73
+ "resources, expected, num_inputs",
74
+ [
75
+ ([], True, 0),
76
+ ([wrong_indicator], True, 0),
77
+ ([indicator_no_land_cover], False, 0),
78
+ ([indicator_no_unit], False, 0),
79
+ ([indicator_wrong_unit], False, 0),
80
+ ([indicator_bad_area_value], False, 0),
81
+ ([good_during_cycle_indicator_from_forest_to_cropland], True, 1),
82
+ ([good_during_cycle_indicator_from_forest_to_forest], True, 1),
83
+ ([good_inputs_production_indicator_from_forest_to_cropland], True, 1),
84
+ ([good_inputs_production_indicator_from_forest_to_forest], True, 1),
85
+ ([inputs_production_indicator_from_forest_to_no_cf], True, 0), # todo check
86
+ ([good_inputs_production_indicator_from_forest_to_cropland,
87
+ good_during_cycle_indicator_from_forest_to_cropland], True, 2)
88
+ ],
89
+ ids=["No emissionsResourceUse => run, 0 dict",
90
+ "Wrong indicator termid => run, 0 dict",
91
+ "Indicator no landcover terms => no run",
92
+ "Missing unit => no run",
93
+ "Wrong unit => no run",
94
+ "Bad m2 / year value => no run",
95
+ "One good during cycle transformation => run, 1 dict",
96
+ "One 0 during cycle transformation => run, 1 dict",
97
+ "One good inputs production transformation => run, 1 dict",
98
+ "One 0 inputs production transformation => run, 1 dict",
99
+ "One good from transformation and One with no CF (ocean) => run, 2 dict", # todo
100
+ "Multiple good indicators => run, 2 dict",
101
+ ]
102
+ )
103
+ @patch(f"{class_path}.download_all_land_cover_terms",
104
+ return_value=[{'@id': 'cropland'}, {'@id': 'seaOrOcean'}, {'@id': 'forest'}])
105
+ def test_should_run(mock_download, resources, expected, num_inputs):
106
+ with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
107
+ impact = json.load(f)
108
+
109
+ impact['emissionsResourceUse'] = resources
110
+
111
+ should_run, resources_with_cf = _should_run(impact)
112
+ assert should_run is expected
113
+ assert len(resources_with_cf) == num_inputs
114
+
115
+
116
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
117
+ def test_run(*args):
118
+ with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
119
+ impact = json.load(f)
120
+
121
+ with open(f"{fixtures_folder}/multipleTransformations/result.jsonld", encoding='utf-8') as f:
122
+ expected = json.load(f)
123
+
124
+ value = run(impact)
125
+ assert value == expected
126
+
127
+
128
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
129
+ def test_run_italy(*args):
130
+ with open(f"{fixtures_folder}/Italy/impact-assessment.jsonld", encoding='utf-8') as f:
131
+ impact = json.load(f)
132
+
133
+ with open(f"{fixtures_folder}/Italy/result.jsonld", encoding='utf-8') as f:
134
+ expected = json.load(f)
135
+
136
+ value = run(impact)
137
+ assert value == expected
138
+
139
+
140
+ @mark.parametrize(
141
+ "added_data",
142
+ [
143
+ {"country": {}},
144
+ {"country": {"@id": "region-europe", "@type": "Term", "name": "Europe"}},
145
+ ],
146
+ ids=["No country/region => default to region world",
147
+ "region-europe not in the lookup file => default to region world"]
148
+ )
149
+ @patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
150
+ def test_run_with_country_fallback(mocked_indicator, added_data):
151
+ """
152
+ When given valid sub-region or country not in the lookup file, default to country 'region-world' with value 574.56
153
+ """
154
+
155
+ with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
156
+ impact = json.load(f)
157
+
158
+ impact = impact | added_data
159
+
160
+ value = run(impact)
161
+ assert value['value'] == 574.56
162
+
163
+
164
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
165
+ def test_run_no_transformation(*args):
166
+ """
167
+ Impact assessment with no transformations should return a indicator of 0
168
+ """
169
+ with open(f"{fixtures_folder}/multipleTransformations/impact-assessment.jsonld", encoding='utf-8') as f:
170
+ impact = json.load(f)
171
+
172
+ impact['emissionsResourceUse'] = []
173
+
174
+ value = run(impact)
175
+
176
+ assert value['value'] == 0
@@ -0,0 +1,55 @@
1
+ import json
2
+ from unittest.mock import patch
3
+
4
+ from pytest import mark
5
+
6
+ from hestia_earth.models.environmentalFootprintV3.soilQualityIndexTotalLandUseEffects import MODEL, TERM_ID, run, \
7
+ _should_run
8
+ from tests.utils import fixtures_path, fake_new_indicator
9
+
10
+ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
11
+ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
12
+
13
+ transform_indicator = {'term': {'@id': 'soilQualityIndexLandTransformation'}, 'value': 10}
14
+ occupation_indicator = {'term': {'@id': 'soilQualityIndexLandOccupation'}, 'value': 10}
15
+ missing_value_indicator = {'term': {'@id': 'soilQualityIndexLandOccupation'}}
16
+ bad_value_indicator = {'term': {'@id': 'soilQualityIndexLandOccupation'}, 'value': "42"}
17
+
18
+
19
+ @mark.parametrize(
20
+ "emissions_resource_use, expected, num_expected",
21
+ [
22
+ ([], False, 0),
23
+ ([transform_indicator], False, 1),
24
+ ([transform_indicator, transform_indicator], False, 2),
25
+ ([transform_indicator, missing_value_indicator], False, 2),
26
+ ([transform_indicator, bad_value_indicator], False, 2),
27
+ ([transform_indicator, occupation_indicator], True, 2),
28
+ ([occupation_indicator], False, 1),
29
+ ([occupation_indicator, occupation_indicator, occupation_indicator,
30
+ transform_indicator, transform_indicator], True, 5),
31
+ ],
32
+ ids=["Empty", "missing obligatory occupation", "duplicate entry", "no value in entry", "bad value in entry",
33
+ "correct assessment", "just occupation", "multiple occupations and transformations"]
34
+ )
35
+ def test_should_run(emissions_resource_use, expected, num_expected):
36
+ with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
37
+ impactassessment = json.load(f)
38
+
39
+ impactassessment['emissionsResourceUse'] = emissions_resource_use
40
+
41
+ should_run, indicators = _should_run(impactassessment)
42
+ assert should_run is expected
43
+ assert len(indicators) is num_expected
44
+
45
+
46
+ @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
47
+ def test_run(*args):
48
+ with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
49
+ impactassessment = json.load(f)
50
+
51
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
52
+ expected = json.load(f)
53
+
54
+ value = run(impactassessment)
55
+ assert value == expected
@@ -8,54 +8,77 @@ from hestia_earth.models.frischknechtEtAl2000.ionisingRadiationKbqU235Eq import
8
8
  class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
9
9
  fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
10
10
 
11
+ hydrogen3_input = {"@id": "hydrogen3", "termType": "waste", "units": "kg"}
12
+ cesium134_input = {"@id": "cesium134", "termType": "waste", "units": "kg"}
13
+ cesium137_input = {"@id": "cesium137", "termType": "waste", "units": "kg"}
14
+ uranium234_input = {"@id": "uranium234", "termType": "waste", "units": "kg"}
15
+ iodine129_input = {"@id": "iodine129", "termType": "waste", "units": "kg"}
16
+ no_cf_input = {"@id": "oilPalmMillEffluentWaste", "termType": "waste", "units": "kg"}
17
+
18
+ wrong_indicator = {"term": {"@id": "co2ToAirSoilOrganicCarbonStockChangeManagementChange", "termType": "emission"},
19
+ "value": 3, "inputs": [hydrogen3_input]}
20
+
21
+ indicator_no_inputs = {"term": {"@id": "ionisingCompoundsToAirInputsProduction", "termType": "emission"},
22
+ "value": 3, "inputs": []}
23
+
24
+ indicator_2_inputs = {"term": {"@id": "ionisingCompoundsToWaterInputsProduction", "termType": "emission"},
25
+ "value": 3, "inputs": [cesium134_input, cesium137_input]}
26
+
27
+ indicator_no_unit = {"term": {"@id": "ionisingCompoundsToAirInputsProduction", "termType": "emission"},
28
+ "value": 3, "inputs": [{"@id": "hydrogen3", "termType": "waste"}]}
29
+
30
+ indicator_wrong_unit = {"term": {"@id": "ionisingCompoundsToAirInputsProduction", "termType": "emission"},
31
+ "value": 3, "inputs": [{"@id": "hydrogen3", "termType": "waste", "units": "not_a_unit"}]}
32
+
33
+ indicator_no_cf_input = {"term": {"@id": "ionisingCompoundsToAirInputsProduction", "termType": "emission"},
34
+ "value": 3, "inputs": [no_cf_input]}
35
+
36
+ indicator_hydrogen3_input = {"term": {"@id": "ionisingCompoundsToAirInputsProduction", "termType": "emission"},
37
+ "value": 3, "inputs": [hydrogen3_input]}
38
+
39
+ indicator_cesium137_input = {"term": {"@id": "ionisingCompoundsToWaterInputsProduction", "termType": "emission"},
40
+ "value": 3, "inputs": [cesium137_input]}
41
+
42
+ indicator_uranium234_input = {"term": {"@id": "ionisingCompoundsToSaltwaterInputsProduction", "termType": "emission"},
43
+ "value": 3, "inputs": [uranium234_input]}
44
+
11
45
 
12
46
  @pytest.mark.parametrize(
13
- 'test_name,impact,expected_should_run',
47
+ "resources, expected, num_inputs",
14
48
  [
15
- (
16
- 'no emissionsResourceUse => no run',
17
- {},
18
- False
19
- ),
20
- (
21
- 'no emissions in the lookups list => no run',
22
- {
23
- 'emissionsResourceUse': [
24
- {
25
- 'term': {'@id': 'co2ToAirInputsProduction'}
26
- }
27
- ]
28
- },
29
- False
30
- ),
31
- (
32
- 'with emissions in the lookup list but no waste inputs => no run',
33
- {
34
- 'emissionsResourceUse': [
35
- {
36
- 'term': {'@id': 'ionisingCompoundsToAirInputsProduction'}
37
- }
38
- ]
39
- },
40
- False
41
- ),
42
- (
43
- 'with emissions in the lookup list and waste inputs => run',
44
- {
45
- 'emissionsResourceUse': [
46
- {
47
- 'term': {'@id': 'ionisingCompoundsToAirInputsProduction'},
48
- 'inputs': [{'termType': 'waste'}]
49
- }
50
- ]
51
- },
52
- True
53
- )
54
- ]
49
+ ([], True, 0),
50
+ ([wrong_indicator], True, 0),
51
+ ([indicator_no_inputs], False, 0),
52
+ ([indicator_2_inputs], False, 0),
53
+ ([indicator_no_unit], False, 0),
54
+ ([indicator_wrong_unit], False, 0),
55
+ ([indicator_no_cf_input], True, 0),
56
+ ([indicator_hydrogen3_input], True, 1),
57
+ ([indicator_cesium137_input], True, 1),
58
+ ([indicator_uranium234_input], True, 1),
59
+ ([indicator_cesium137_input, indicator_no_cf_input], True, 1),
60
+ ],
61
+ ids=["No emissionsResourceUse => run, empty input",
62
+ "Wrong indicator termid => run, empty input",
63
+ "Indicator no inputs => no run",
64
+ "Indicator 2 inputs => no run",
65
+ "Missing unit => no run",
66
+ "Wrong unit => no run",
67
+ "Input with no cf => run, empty input",
68
+ "Good input ionisingCompoundsToAirInputsProduction => run, 1 input",
69
+ "Good input ionisingCompoundsToWaterInputsProduction => run, 1 input",
70
+ "Good input ionisingCompoundsToSaltwaterInputsProduction => run, 1 input",
71
+ "One good input => run, 1 input"]
55
72
  )
56
- def test_should_run(test_name, impact, expected_should_run):
57
- should_run, *args = _should_run(impact)
58
- assert should_run == expected_should_run, test_name
73
+ def test_should_run(resources, expected, num_inputs):
74
+ with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
75
+ impactassessment = json.load(f)
76
+
77
+ impactassessment['emissionsResourceUse'] = resources
78
+
79
+ should_run, resources_with_cf = _should_run(impactassessment)
80
+ assert should_run is expected
81
+ assert len(resources_with_cf) == num_inputs
59
82
 
60
83
 
61
84
  @patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
@@ -0,0 +1,22 @@
1
+ from unittest.mock import patch
2
+ import json
3
+ from tests.utils import fixtures_path, fake_new_property
4
+
5
+ from hestia_earth.models.ipcc2019 import MODEL
6
+ from hestia_earth.models.ipcc2019.animal.fatContent import TERM_ID, run
7
+
8
+ utils_path = '.'.join(['hestia_earth', 'models', MODEL, 'animal', 'utils'])
9
+ class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
10
+ fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
11
+
12
+
13
+ @patch(f"{utils_path}._new_property", side_effect=fake_new_property)
14
+ def test_run(*args):
15
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
16
+ cycle = json.load(f)
17
+
18
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
19
+ expected = json.load(f)
20
+
21
+ value = run(cycle)
22
+ assert value == expected
@@ -2,13 +2,15 @@ from unittest.mock import patch
2
2
  import json
3
3
  from tests.utils import fixtures_path, fake_new_property
4
4
 
5
- from hestia_earth.models.ipcc2019.animal.liveweightGain import MODEL, TERM_ID, run
5
+ from hestia_earth.models.ipcc2019 import MODEL
6
+ from hestia_earth.models.ipcc2019.animal.liveweightGain import TERM_ID, run
6
7
 
8
+ utils_path = '.'.join(['hestia_earth', 'models', MODEL, 'animal', 'utils'])
7
9
  class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
8
10
  fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
9
11
 
10
12
 
11
- @patch(f"{class_path}._new_property", side_effect=fake_new_property)
13
+ @patch(f"{utils_path}._new_property", side_effect=fake_new_property)
12
14
  def test_run(*args):
13
15
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
14
16
  cycle = json.load(f)
@@ -2,13 +2,15 @@ from unittest.mock import patch
2
2
  import json
3
3
  from tests.utils import fixtures_path, fake_new_property
4
4
 
5
- from hestia_earth.models.ipcc2019.animal.liveweightPerHead import MODEL, TERM_ID, run
5
+ from hestia_earth.models.ipcc2019 import MODEL
6
+ from hestia_earth.models.ipcc2019.animal.liveweightPerHead import TERM_ID, run
6
7
 
8
+ utils_path = '.'.join(['hestia_earth', 'models', MODEL, 'animal', 'utils'])
7
9
  class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
8
10
  fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
9
11
 
10
12
 
11
- @patch(f"{class_path}._new_property", side_effect=fake_new_property)
13
+ @patch(f"{utils_path}._new_property", side_effect=fake_new_property)
12
14
  def test_run(*args):
13
15
  with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
14
16
  cycle = json.load(f)
@@ -0,0 +1,22 @@
1
+ from unittest.mock import patch
2
+ import json
3
+ from tests.utils import fixtures_path, fake_new_property
4
+
5
+ from hestia_earth.models.ipcc2019 import MODEL
6
+ from hestia_earth.models.ipcc2019.animal.pregnancyRateTotal import TERM_ID, run
7
+
8
+ utils_path = '.'.join(['hestia_earth', 'models', MODEL, 'animal', 'utils'])
9
+ class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
10
+ fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
11
+
12
+
13
+ @patch(f"{utils_path}._new_property", side_effect=fake_new_property)
14
+ def test_run(*args):
15
+ with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
16
+ cycle = json.load(f)
17
+
18
+ with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
19
+ expected = json.load(f)
20
+
21
+ value = run(cycle)
22
+ assert value == expected