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.
- hestia_earth/models/cycle/animal/milkYield.py +10 -22
- hestia_earth/models/cycle/siteArea.py +2 -1
- hestia_earth/models/cycle/unknownPreSeasonWaterRegime.py +0 -1
- hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandOccupation.py +73 -82
- hestia_earth/models/environmentalFootprintV3/soilQualityIndexLandTransformation.py +168 -0
- hestia_earth/models/environmentalFootprintV3/soilQualityIndexTotalLandUseEffects.py +77 -0
- hestia_earth/models/environmentalFootprintV3/utils.py +1 -1
- hestia_earth/models/faostat2018/landTransformationFromCropland100YearAverage.py +3 -2
- hestia_earth/models/faostat2018/landTransformationFromCropland20YearAverage.py +3 -2
- hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +69 -37
- hestia_earth/models/hyde32/utils.py +4 -0
- hestia_earth/models/ipcc2019/animal/fatContent.py +38 -0
- hestia_earth/models/ipcc2019/animal/liveweightGain.py +3 -54
- hestia_earth/models/ipcc2019/animal/liveweightPerHead.py +3 -54
- hestia_earth/models/ipcc2019/animal/pastureGrass.py +3 -1
- hestia_earth/models/ipcc2019/animal/pregnancyRateTotal.py +38 -0
- hestia_earth/models/ipcc2019/animal/trueProteinContent.py +38 -0
- hestia_earth/models/ipcc2019/animal/utils.py +87 -3
- hestia_earth/models/ipcc2019/animal/weightAtMaturity.py +4 -10
- hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +191 -0
- hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChangeLandUseChange.py +204 -0
- hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +255 -35
- hestia_earth/models/ipcc2019/co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +63 -149
- hestia_earth/models/ipcc2019/pastureGrass.py +3 -1
- hestia_earth/models/mocking/search-results.json +2026 -26
- hestia_earth/models/pooreNemecek2018/landOccupationDuringCycle.py +1 -1
- hestia_earth/models/poschEtAl2008/terrestrialAcidificationPotentialAccumulatedExceedance.py +4 -1
- hestia_earth/models/poschEtAl2008/terrestrialEutrophicationPotentialAccumulatedExceedance.py +4 -1
- hestia_earth/models/site/management.py +3 -5
- hestia_earth/models/utils/__init__.py +5 -4
- hestia_earth/models/utils/impact_assessment.py +13 -4
- hestia_earth/models/utils/input.py +5 -2
- hestia_earth/models/utils/site.py +4 -2
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/METADATA +2 -2
- {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/RECORD +58 -44
- tests/models/cycle/animal/test_milkYield.py +1 -14
- tests/models/environmentalFootprintV3/test_soilQualityIndexLandOccupation.py +97 -66
- tests/models/environmentalFootprintV3/test_soilQualityIndexLandTransformation.py +176 -0
- tests/models/environmentalFootprintV3/test_soilQualityIndexTotalLandUseEffects.py +55 -0
- tests/models/frischknechtEtAl2000/test_ionisingRadiationKbqU235Eq.py +67 -44
- tests/models/ipcc2019/animal/test_fatContent.py +22 -0
- tests/models/ipcc2019/animal/test_liveweightGain.py +4 -2
- tests/models/ipcc2019/animal/test_liveweightPerHead.py +4 -2
- tests/models/ipcc2019/animal/test_pregnancyRateTotal.py +22 -0
- tests/models/ipcc2019/animal/test_trueProteinContent.py +22 -0
- tests/models/ipcc2019/animal/test_weightAtMaturity.py +2 -1
- tests/models/ipcc2019/test_co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +83 -0
- tests/models/ipcc2019/test_co2ToAirBelowGroundBiomassStockChangeLandUseChange.py +83 -0
- tests/models/ipcc2019/test_co2ToAirCarbonStockChange_utils.py +6 -6
- tests/models/ipcc2019/test_co2ToAirSoilOrganicCarbonStockChangeManagementChange.py +5 -4
- tests/models/poschEtAl2008/test_terrestrialAcidificationPotentialAccumulatedExceedance.py +30 -17
- tests/models/poschEtAl2008/test_terrestrialEutrophicationPotentialAccumulatedExceedance.py +28 -14
- tests/models/site/test_management.py +4 -1
- tests/models/utils/test_input.py +65 -1
- {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.64.7.dist-info → hestia_earth_models-0.64.9.dist-info}/top_level.txt +0 -0
|
@@ -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.trueProteinContent 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,7 +2,8 @@ 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
|
|
5
|
+
from hestia_earth.models.ipcc2019 import MODEL
|
|
6
|
+
from hestia_earth.models.ipcc2019.animal.weightAtMaturity import TERM_ID, run
|
|
6
7
|
|
|
7
8
|
class_path = f"hestia_earth.models.{MODEL}.animal.{TERM_ID}"
|
|
8
9
|
fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{TERM_ID}"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from functools import reduce
|
|
2
|
+
import json
|
|
3
|
+
from os.path import isfile
|
|
4
|
+
from pytest import mark
|
|
5
|
+
from unittest.mock import patch
|
|
6
|
+
|
|
7
|
+
from hestia_earth.models.ipcc2019.co2ToAirAboveGroundBiomassStockChangeLandUseChange import MODEL, run, TERM_ID
|
|
8
|
+
|
|
9
|
+
from tests.utils import fake_new_emission, fixtures_path
|
|
10
|
+
|
|
11
|
+
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
|
12
|
+
utils_path = f"hestia_earth.models.{MODEL}.co2ToAirCarbonStockChange_utils"
|
|
13
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
14
|
+
|
|
15
|
+
RUN_SCENARIOS = [
|
|
16
|
+
("no-overlapping-cycles", 3),
|
|
17
|
+
("overlapping-cycles", 4),
|
|
18
|
+
("complex-overlapping-cycles", 5),
|
|
19
|
+
("missing-measurement-dates", 3),
|
|
20
|
+
("no-biomass-measurements", 1), # Closes issue #700
|
|
21
|
+
("non-consecutive-biomass-measurements", 1), # Closes issue #827
|
|
22
|
+
("multiple-method-classifications", 5), # Closes issue #764
|
|
23
|
+
("non-soil-based-gohac-system", 3), # Closes issue #848
|
|
24
|
+
("soil-based-gohac-system", 3) # Closes issue #848
|
|
25
|
+
]
|
|
26
|
+
"""List of (subfolder: str, num_cycles: int)."""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _load_fixture(path: str, default=None):
|
|
30
|
+
if isfile(path):
|
|
31
|
+
with open(path, encoding="utf-8") as f:
|
|
32
|
+
return json.load(f)
|
|
33
|
+
return default
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
RUN_PARAMS = reduce(
|
|
37
|
+
lambda params, scenario: params + [(scenario[0], scenario[1], i) for i in range(scenario[1])],
|
|
38
|
+
RUN_SCENARIOS,
|
|
39
|
+
list()
|
|
40
|
+
)
|
|
41
|
+
"""List of (subfolder: str, num_cycles: int, cycle_index: int)."""
|
|
42
|
+
|
|
43
|
+
RUN_IDS = [f"{param[0]}, cycle{param[2]}" for param in RUN_PARAMS]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@mark.parametrize("subfolder, num_cycles, cycle_index", RUN_PARAMS, ids=RUN_IDS)
|
|
47
|
+
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
48
|
+
@patch(f"{utils_path}.related_cycles")
|
|
49
|
+
@patch(f"{utils_path}._get_site") # TODO: rationalise order of patches
|
|
50
|
+
def test_run(_get_site_mock, related_cycles_mock, _new_emission_mock, subfolder, num_cycles, cycle_index):
|
|
51
|
+
"""
|
|
52
|
+
Test `run` function for each cycle in each scenario.
|
|
53
|
+
"""
|
|
54
|
+
site = _load_fixture(f"{fixtures_folder}/{subfolder}/site.jsonld")
|
|
55
|
+
cycle = _load_fixture(f"{fixtures_folder}/{subfolder}/cycle{cycle_index}.jsonld")
|
|
56
|
+
expected = _load_fixture(f"{fixtures_folder}/{subfolder}/result{cycle_index}.jsonld", default=[])
|
|
57
|
+
|
|
58
|
+
cycles = [
|
|
59
|
+
_load_fixture(f"{fixtures_folder}/{subfolder}/cycle{i}.jsonld") for i in range(num_cycles)
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
_get_site_mock.return_value = site
|
|
63
|
+
related_cycles_mock.return_value = cycles
|
|
64
|
+
|
|
65
|
+
result = run(cycle)
|
|
66
|
+
assert result == expected
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
70
|
+
@patch(f"{utils_path}.related_cycles")
|
|
71
|
+
@patch(f"{utils_path}._get_site") # TODO: rationalise order of patches
|
|
72
|
+
def test_run_empty(_get_site_mock, related_cycles_mock, _new_emission_mock):
|
|
73
|
+
"""
|
|
74
|
+
Test `run` function for each cycle in each scenario.
|
|
75
|
+
"""
|
|
76
|
+
CYCLE = {}
|
|
77
|
+
EXPECTED = []
|
|
78
|
+
|
|
79
|
+
_get_site_mock.return_value = {}
|
|
80
|
+
related_cycles_mock.return_value = [CYCLE]
|
|
81
|
+
|
|
82
|
+
result = run(CYCLE)
|
|
83
|
+
assert result == EXPECTED
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from functools import reduce
|
|
2
|
+
import json
|
|
3
|
+
from os.path import isfile
|
|
4
|
+
from pytest import mark
|
|
5
|
+
from unittest.mock import patch
|
|
6
|
+
|
|
7
|
+
from hestia_earth.models.ipcc2019.co2ToAirBelowGroundBiomassStockChangeLandUseChange import MODEL, run, TERM_ID
|
|
8
|
+
|
|
9
|
+
from tests.utils import fake_new_emission, fixtures_path
|
|
10
|
+
|
|
11
|
+
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
|
12
|
+
utils_path = f"hestia_earth.models.{MODEL}.co2ToAirCarbonStockChange_utils"
|
|
13
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
14
|
+
|
|
15
|
+
RUN_SCENARIOS = [
|
|
16
|
+
("no-overlapping-cycles", 3),
|
|
17
|
+
("overlapping-cycles", 4),
|
|
18
|
+
("complex-overlapping-cycles", 5),
|
|
19
|
+
("missing-measurement-dates", 3),
|
|
20
|
+
("no-biomass-measurements", 1), # Closes issue #700
|
|
21
|
+
("non-consecutive-biomass-measurements", 1), # Closes issue #827
|
|
22
|
+
("multiple-method-classifications", 5), # Closes issue #764
|
|
23
|
+
("non-soil-based-gohac-system", 3), # Closes issue #848
|
|
24
|
+
("soil-based-gohac-system", 3) # Closes issue #848
|
|
25
|
+
]
|
|
26
|
+
"""List of (subfolder: str, num_cycles: int)."""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _load_fixture(path: str, default=None):
|
|
30
|
+
if isfile(path):
|
|
31
|
+
with open(path, encoding="utf-8") as f:
|
|
32
|
+
return json.load(f)
|
|
33
|
+
return default
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
RUN_PARAMS = reduce(
|
|
37
|
+
lambda params, scenario: params + [(scenario[0], scenario[1], i) for i in range(scenario[1])],
|
|
38
|
+
RUN_SCENARIOS,
|
|
39
|
+
list()
|
|
40
|
+
)
|
|
41
|
+
"""List of (subfolder: str, num_cycles: int, cycle_index: int)."""
|
|
42
|
+
|
|
43
|
+
RUN_IDS = [f"{param[0]}, cycle{param[2]}" for param in RUN_PARAMS]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@mark.parametrize("subfolder, num_cycles, cycle_index", RUN_PARAMS, ids=RUN_IDS)
|
|
47
|
+
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
48
|
+
@patch(f"{utils_path}.related_cycles")
|
|
49
|
+
@patch(f"{utils_path}._get_site")
|
|
50
|
+
def test_run(_get_site_mock, related_cycles_mock, _new_emission_mock, subfolder, num_cycles, cycle_index):
|
|
51
|
+
"""
|
|
52
|
+
Test `run` function for each cycle in each scenario.
|
|
53
|
+
"""
|
|
54
|
+
site = _load_fixture(f"{fixtures_folder}/{subfolder}/site.jsonld")
|
|
55
|
+
cycle = _load_fixture(f"{fixtures_folder}/{subfolder}/cycle{cycle_index}.jsonld")
|
|
56
|
+
expected = _load_fixture(f"{fixtures_folder}/{subfolder}/result{cycle_index}.jsonld", default=[])
|
|
57
|
+
|
|
58
|
+
cycles = [
|
|
59
|
+
_load_fixture(f"{fixtures_folder}/{subfolder}/cycle{i}.jsonld") for i in range(num_cycles)
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
_get_site_mock.return_value = site
|
|
63
|
+
related_cycles_mock.return_value = cycles
|
|
64
|
+
|
|
65
|
+
result = run(cycle)
|
|
66
|
+
assert result == expected
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
70
|
+
@patch(f"{utils_path}.related_cycles")
|
|
71
|
+
@patch(f"{utils_path}._get_site")
|
|
72
|
+
def test_run_empty(_get_site_mock, related_cycles_mock, _new_emission_mock):
|
|
73
|
+
"""
|
|
74
|
+
Test `run` function for each cycle in each scenario.
|
|
75
|
+
"""
|
|
76
|
+
CYCLE = {}
|
|
77
|
+
EXPECTED = []
|
|
78
|
+
|
|
79
|
+
_get_site_mock.return_value = {}
|
|
80
|
+
related_cycles_mock.return_value = [CYCLE]
|
|
81
|
+
|
|
82
|
+
result = run(CYCLE)
|
|
83
|
+
assert result == EXPECTED
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from hestia_earth.schema import EmissionMethodTier, MeasurementMethodClassification
|
|
2
2
|
|
|
3
3
|
from hestia_earth.models.ipcc2019.co2ToAirCarbonStockChange_utils import (
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
_add_carbon_stock_change_emissions, _calc_carbon_stock_change, _calc_carbon_stock_change_emission,
|
|
5
|
+
_convert_c_to_co2, _lerp_carbon_stocks, CarbonStock, CarbonStockChange, CarbonStockChangeEmission
|
|
6
6
|
)
|
|
7
7
|
|
|
8
8
|
|
|
@@ -20,7 +20,7 @@ def test_lerp_carbon_stocks():
|
|
|
20
20
|
21000, "2001-12-31", MeasurementMethodClassification.ON_SITE_PHYSICAL_MEASUREMENT
|
|
21
21
|
)
|
|
22
22
|
|
|
23
|
-
result =
|
|
23
|
+
result = _lerp_carbon_stocks(START, END, TARGET_DATE)
|
|
24
24
|
assert result == EXPECTED
|
|
25
25
|
|
|
26
26
|
|
|
@@ -29,7 +29,7 @@ def test_calc_carbon_stock_change():
|
|
|
29
29
|
END = CarbonStock(21000, "2001", MeasurementMethodClassification.TIER_1_MODEL)
|
|
30
30
|
EXPECTED = CarbonStockChange(1000, "2000", "2001", MeasurementMethodClassification.TIER_1_MODEL)
|
|
31
31
|
|
|
32
|
-
result =
|
|
32
|
+
result = _calc_carbon_stock_change(START, END)
|
|
33
33
|
assert result == EXPECTED
|
|
34
34
|
|
|
35
35
|
|
|
@@ -37,7 +37,7 @@ def test_calc_carbon_stock_change_emission():
|
|
|
37
37
|
SOC_STOCK_CHANGE = CarbonStockChange(-1000, "2000", "2001", MeasurementMethodClassification.TIER_1_MODEL)
|
|
38
38
|
EXPECTED = CarbonStockChangeEmission(3663.836163836164, "2000", "2001", EmissionMethodTier.TIER_1)
|
|
39
39
|
|
|
40
|
-
result =
|
|
40
|
+
result = _calc_carbon_stock_change_emission(SOC_STOCK_CHANGE)
|
|
41
41
|
assert result == EXPECTED
|
|
42
42
|
|
|
43
43
|
|
|
@@ -46,5 +46,5 @@ def test_add_carbon_stock_change_emissions():
|
|
|
46
46
|
EMISSION_2 = CarbonStockChangeEmission(2000, "2001", "2002", EmissionMethodTier.TIER_1)
|
|
47
47
|
EXPECTED = CarbonStockChangeEmission(5000, "2000", "2002", EmissionMethodTier.TIER_1)
|
|
48
48
|
|
|
49
|
-
result =
|
|
49
|
+
result = _add_carbon_stock_change_emissions(EMISSION_1, EMISSION_2)
|
|
50
50
|
assert result == EXPECTED
|
|
@@ -9,6 +9,7 @@ from hestia_earth.models.ipcc2019.co2ToAirSoilOrganicCarbonStockChangeManagement
|
|
|
9
9
|
from tests.utils import fake_new_emission, fixtures_path
|
|
10
10
|
|
|
11
11
|
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
|
12
|
+
utils_path = f"hestia_earth.models.{MODEL}.co2ToAirCarbonStockChange_utils"
|
|
12
13
|
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
13
14
|
|
|
14
15
|
RUN_SCENARIOS = [
|
|
@@ -44,8 +45,8 @@ RUN_IDS = [f"{param[0]}, cycle{param[2]}" for param in RUN_PARAMS]
|
|
|
44
45
|
|
|
45
46
|
@mark.parametrize("subfolder, num_cycles, cycle_index", RUN_PARAMS, ids=RUN_IDS)
|
|
46
47
|
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
47
|
-
@patch(f"{
|
|
48
|
-
@patch(f"{
|
|
48
|
+
@patch(f"{utils_path}.related_cycles")
|
|
49
|
+
@patch(f"{utils_path}._get_site")
|
|
49
50
|
def test_run(_get_site_mock, related_cycles_mock, _new_emission_mock, subfolder, num_cycles, cycle_index):
|
|
50
51
|
"""
|
|
51
52
|
Test `run` function for each cycle in each scenario.
|
|
@@ -66,8 +67,8 @@ def test_run(_get_site_mock, related_cycles_mock, _new_emission_mock, subfolder,
|
|
|
66
67
|
|
|
67
68
|
|
|
68
69
|
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
|
69
|
-
@patch(f"{
|
|
70
|
-
@patch(f"{
|
|
70
|
+
@patch(f"{utils_path}.related_cycles")
|
|
71
|
+
@patch(f"{utils_path}._get_site")
|
|
71
72
|
def test_run_empty(_get_site_mock, related_cycles_mock, _new_emission_mock):
|
|
72
73
|
"""
|
|
73
74
|
Test `run` function for each cycle in each scenario.
|
|
@@ -1,45 +1,58 @@
|
|
|
1
1
|
import json
|
|
2
2
|
from unittest.mock import patch
|
|
3
3
|
|
|
4
|
-
from hestia_earth.models.poschEtAl2008.terrestrialAcidificationPotentialAccumulatedExceedance import MODEL, TERM_ID,
|
|
4
|
+
from hestia_earth.models.poschEtAl2008.terrestrialAcidificationPotentialAccumulatedExceedance import MODEL, TERM_ID, \
|
|
5
|
+
run
|
|
5
6
|
from tests.utils import fixtures_path, fake_new_indicator
|
|
6
7
|
|
|
7
8
|
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
|
8
9
|
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
9
10
|
|
|
10
11
|
|
|
12
|
+
def fake_rounded_indicator(value: float):
|
|
13
|
+
indicator = fake_new_indicator(TERM_ID, MODEL)
|
|
14
|
+
indicator['value'] = round(value, 7)
|
|
15
|
+
return indicator
|
|
16
|
+
|
|
17
|
+
|
|
11
18
|
@patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
|
|
12
19
|
def test_run(*args):
|
|
13
20
|
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
14
|
-
|
|
21
|
+
impactassessment = json.load(f)
|
|
15
22
|
|
|
16
|
-
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
|
23
|
+
with open(f"{fixtures_folder}/Australia/result.jsonld", encoding='utf-8') as f:
|
|
17
24
|
expected = json.load(f)
|
|
18
25
|
|
|
19
|
-
value = run(
|
|
26
|
+
value = run(impactassessment)
|
|
20
27
|
assert value == expected
|
|
21
28
|
|
|
22
29
|
|
|
23
|
-
@patch(f"{class_path}.
|
|
30
|
+
@patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
|
|
24
31
|
def test_lookup_to_bad_country(*args):
|
|
32
|
+
"""
|
|
33
|
+
Should default to region-world value
|
|
34
|
+
"""
|
|
25
35
|
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
26
|
-
|
|
27
|
-
cycle['country']['@id'] = "example-land-not-real"
|
|
36
|
+
impactassessment = json.load(f)
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
impactassessment['country']['@id'] = "example-land-not-real"
|
|
39
|
+
|
|
40
|
+
with open(f"{fixtures_folder}/region-world/result.jsonld", encoding='utf-8') as f:
|
|
41
|
+
expected = json.load(f)
|
|
42
|
+
|
|
43
|
+
value = run(impactassessment)
|
|
44
|
+
assert value == expected
|
|
31
45
|
|
|
32
46
|
|
|
33
47
|
@patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
|
|
34
|
-
def
|
|
48
|
+
def test_run_no_emissions(*args):
|
|
35
49
|
"""
|
|
36
|
-
|
|
50
|
+
Impact assessment with no emissions should return a indicator of 0
|
|
37
51
|
"""
|
|
38
52
|
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
del
|
|
42
|
-
cycle['emissionsResourceUse'][2]['term']['termType'] = "wrong-type"
|
|
53
|
+
impactassessment = json.load(f)
|
|
54
|
+
|
|
55
|
+
del impactassessment['emissionsResourceUse']
|
|
43
56
|
|
|
44
|
-
value = run(
|
|
45
|
-
assert value['value'] == 0
|
|
57
|
+
value = run(impactassessment)
|
|
58
|
+
assert value['value'] == 0
|
|
@@ -9,36 +9,50 @@ class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
|
|
9
9
|
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
def fake_rounded_indicator(value: float):
|
|
13
|
+
indicator = fake_new_indicator(TERM_ID, MODEL)
|
|
14
|
+
indicator['value'] = round(value, 7)
|
|
15
|
+
return indicator
|
|
16
|
+
|
|
17
|
+
|
|
12
18
|
@patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
|
|
13
19
|
def test_run(*args):
|
|
14
20
|
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
15
|
-
|
|
21
|
+
impactassessment = json.load(f)
|
|
16
22
|
|
|
17
|
-
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
|
23
|
+
with open(f"{fixtures_folder}/Belarus/result.jsonld", encoding='utf-8') as f:
|
|
18
24
|
expected = json.load(f)
|
|
19
25
|
|
|
20
|
-
value = run(
|
|
26
|
+
value = run(impactassessment)
|
|
21
27
|
assert value == expected
|
|
22
28
|
|
|
23
29
|
|
|
24
|
-
@patch(f"{class_path}.
|
|
30
|
+
@patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
|
|
25
31
|
def test_lookup_to_bad_country(*args):
|
|
32
|
+
"""
|
|
33
|
+
Should default to region-world value
|
|
34
|
+
"""
|
|
26
35
|
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
27
|
-
|
|
28
|
-
cycle['country']['@id'] = "example-land-not-real"
|
|
36
|
+
impactassessment = json.load(f)
|
|
29
37
|
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
impactassessment['country']['@id'] = "example-land-not-real"
|
|
39
|
+
|
|
40
|
+
with open(f"{fixtures_folder}/region-world/result.jsonld", encoding='utf-8') as f:
|
|
41
|
+
expected = json.load(f)
|
|
42
|
+
|
|
43
|
+
value = run(impactassessment)
|
|
44
|
+
assert value == expected
|
|
32
45
|
|
|
33
46
|
|
|
34
47
|
@patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
|
|
35
|
-
def
|
|
48
|
+
def test_run_no_emissions(*args):
|
|
36
49
|
"""
|
|
37
|
-
|
|
50
|
+
Impact assessment with no emissions should return a indicator of 0
|
|
38
51
|
"""
|
|
39
52
|
with open(f"{fixtures_folder}/impact-assessment.jsonld", encoding='utf-8') as f:
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
impactassessment = json.load(f)
|
|
54
|
+
|
|
55
|
+
del impactassessment['emissionsResourceUse']
|
|
42
56
|
|
|
43
|
-
value = run(
|
|
44
|
-
assert value['value'] ==
|
|
57
|
+
value = run(impactassessment)
|
|
58
|
+
assert value['value'] == 0
|
|
@@ -25,7 +25,10 @@ TERM_BY_ID = {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
LAND_COVER_TERM_BY_SITE_TYPE = {
|
|
28
|
+
LAND_COVER_TERM_BY_SITE_TYPE = {
|
|
29
|
+
SiteSiteType.ANIMAL_HOUSING.value: "animalHousing",
|
|
30
|
+
SiteSiteType.CROPLAND.value: "cropland"
|
|
31
|
+
}
|
|
29
32
|
|
|
30
33
|
|
|
31
34
|
def lookup_side_effect(*args, **kwargs):
|
tests/models/utils/test_input.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import pytest
|
|
1
2
|
from unittest.mock import patch
|
|
3
|
+
from hestia_earth.schema import TermTermType
|
|
2
4
|
from tests.utils import TERM
|
|
3
5
|
|
|
4
|
-
from hestia_earth.models.utils.input import _new_input
|
|
6
|
+
from hestia_earth.models.utils.input import _new_input, get_feed_inputs
|
|
5
7
|
|
|
6
8
|
class_path = 'hestia_earth.models.utils.input'
|
|
7
9
|
|
|
@@ -22,3 +24,65 @@ def test_new_input(*args):
|
|
|
22
24
|
'@type': 'Input',
|
|
23
25
|
'term': TERM
|
|
24
26
|
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.mark.parametrize(
|
|
30
|
+
'test_name,cycle,expected_input_length',
|
|
31
|
+
[
|
|
32
|
+
(
|
|
33
|
+
'no inputs',
|
|
34
|
+
{},
|
|
35
|
+
0
|
|
36
|
+
),
|
|
37
|
+
(
|
|
38
|
+
'with crop feed',
|
|
39
|
+
{
|
|
40
|
+
'inputs': [{
|
|
41
|
+
'term': {'units': 'kg', 'termType': TermTermType.CROP.value, '@id': 'wheatGrain'},
|
|
42
|
+
'isAnimalFeed': True,
|
|
43
|
+
'value': [10]
|
|
44
|
+
}]
|
|
45
|
+
},
|
|
46
|
+
1
|
|
47
|
+
),
|
|
48
|
+
(
|
|
49
|
+
'with crop no feed',
|
|
50
|
+
{
|
|
51
|
+
'inputs': [{
|
|
52
|
+
'term': {'units': 'kg', 'termType': TermTermType.CROP.value, '@id': 'wheatGrain'},
|
|
53
|
+
'isAnimalFeed': False,
|
|
54
|
+
'value': [10]
|
|
55
|
+
}]
|
|
56
|
+
},
|
|
57
|
+
0
|
|
58
|
+
),
|
|
59
|
+
(
|
|
60
|
+
'with feed food additive and energy content',
|
|
61
|
+
{
|
|
62
|
+
'inputs': [{
|
|
63
|
+
'term': {
|
|
64
|
+
'units': 'kg', 'termType': TermTermType.FEEDFOODADDITIVE.value, '@id': 'aminoAcidsUnspecified'
|
|
65
|
+
},
|
|
66
|
+
'isAnimalFeed': True,
|
|
67
|
+
'value': [10]
|
|
68
|
+
}]
|
|
69
|
+
},
|
|
70
|
+
1
|
|
71
|
+
),
|
|
72
|
+
(
|
|
73
|
+
'with feed food additive not energy content',
|
|
74
|
+
{
|
|
75
|
+
'inputs': [{
|
|
76
|
+
'term': {
|
|
77
|
+
'units': 'kg', 'termType': TermTermType.FEEDFOODADDITIVE.value, '@id': 'premixUnspecified'
|
|
78
|
+
},
|
|
79
|
+
'isAnimalFeed': True,
|
|
80
|
+
'value': [10]
|
|
81
|
+
}]
|
|
82
|
+
},
|
|
83
|
+
0
|
|
84
|
+
),
|
|
85
|
+
]
|
|
86
|
+
)
|
|
87
|
+
def test_get_feed_inputs(test_name, cycle, expected_input_length):
|
|
88
|
+
assert len(get_feed_inputs(cycle)) == expected_input_length, test_name
|
|
File without changes
|
|
File without changes
|
|
File without changes
|