hestia-earth-models 0.67.1__py3-none-any.whl → 0.68.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.
- hestia_earth/models/aware/scarcityWeightedWaterUse.py +5 -6
- hestia_earth/models/blonkConsultants2016/ch4ToAirNaturalVegetationBurning.py +1 -1
- hestia_earth/models/blonkConsultants2016/co2ToAirAboveGroundBiomassStockChangeLandUseChange.py +1 -1
- hestia_earth/models/blonkConsultants2016/n2OToAirNaturalVegetationBurningDirect.py +1 -1
- hestia_earth/models/blonkConsultants2016/utils.py +9 -9
- hestia_earth/models/cache_sites.py +44 -23
- hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsLandOccupation.py +2 -2
- hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsLandTransformation.py +2 -2
- hestia_earth/models/chaudharyBrooks2018/utils.py +13 -8
- hestia_earth/models/cml2001Baseline/abioticResourceDepletionFossilFuels.py +2 -3
- hestia_earth/models/cml2001Baseline/abioticResourceDepletionMineralsAndMetals.py +1 -1
- hestia_earth/models/config/Cycle.json +15 -0
- hestia_earth/models/config/ImpactAssessment.json +14 -1
- hestia_earth/models/config/Site.json +8 -0
- hestia_earth/models/cycle/excretaKgMass.py +2 -2
- hestia_earth/models/cycle/materialAndSubstrate.py +3 -2
- hestia_earth/models/cycle/pastureGrass.py +3 -3
- hestia_earth/models/dammgen2009/noxToAirExcreta.py +1 -1
- hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py +1 -1
- hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +2 -6
- hestia_earth/models/emissionNotRelevant/__init__.py +4 -4
- hestia_earth/models/environmentalFootprintV3_1/environmentalFootprintSingleOverallScore.py +30 -21
- hestia_earth/models/environmentalFootprintV3_1/photochemicalOzoneCreationPotentialHumanHealthNmvocEq.py +36 -0
- hestia_earth/models/environmentalFootprintV3_1/scarcityWeightedWaterUse.py +2 -2
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandOccupation.py +9 -8
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandTransformation.py +25 -22
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexTotalLandUseEffects.py +7 -6
- hestia_earth/models/faostat2018/coldCarcassWeightPerHead.py +2 -2
- hestia_earth/models/faostat2018/coldDressedCarcassWeightPerHead.py +2 -2
- hestia_earth/models/faostat2018/liveweightPerHead.py +7 -8
- hestia_earth/models/faostat2018/product/price.py +34 -28
- hestia_earth/models/faostat2018/readyToCookWeightPerHead.py +2 -2
- hestia_earth/models/faostat2018/utils.py +15 -27
- hestia_earth/models/frischknechtEtAl2000/ionisingRadiationKbqU235Eq.py +16 -9
- hestia_earth/models/geospatialDatabase/altitude.py +60 -0
- hestia_earth/models/geospatialDatabase/croppingIntensity.py +1 -1
- hestia_earth/models/geospatialDatabase/ecoClimateZone.py +2 -2
- hestia_earth/models/geospatialDatabase/longFallowRatio.py +1 -1
- hestia_earth/models/geospatialDatabase/utils.py +4 -1
- hestia_earth/models/globalCropWaterModel2008/rootingDepth.py +2 -3
- hestia_earth/models/haversineFormula/transport/distance.py +3 -3
- hestia_earth/models/hestia/landCover.py +72 -45
- hestia_earth/models/hestia/seed_emissions.py +11 -7
- hestia_earth/models/impact_assessment/__init__.py +3 -3
- hestia_earth/models/ipcc2019/animal/fatContent.py +1 -1
- hestia_earth/models/ipcc2019/animal/hoursWorkedPerDay.py +1 -1
- hestia_earth/models/ipcc2019/animal/liveweightGain.py +1 -1
- hestia_earth/models/ipcc2019/animal/liveweightPerHead.py +1 -1
- hestia_earth/models/ipcc2019/animal/milkYieldPerAnimal.py +1 -1
- hestia_earth/models/ipcc2019/animal/pastureGrass.py +1 -1
- hestia_earth/models/ipcc2019/animal/pregnancyRateTotal.py +1 -1
- hestia_earth/models/ipcc2019/animal/trueProteinContent.py +1 -1
- hestia_earth/models/ipcc2019/animal/utils.py +5 -7
- hestia_earth/models/ipcc2019/animal/weightAtMaturity.py +1 -1
- hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +2 -2
- hestia_earth/models/ipcc2019/ch4ToAirExcreta.py +6 -7
- hestia_earth/models/ipcc2019/ch4ToAirFloodedRice.py +5 -3
- hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +1 -1
- hestia_earth/models/ipcc2019/croppingDuration.py +3 -6
- hestia_earth/models/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning.py +947 -0
- hestia_earth/models/ipcc2019/pastureGrass.py +1 -1
- hestia_earth/models/koble2014/residueBurnt.py +5 -7
- hestia_earth/models/koble2014/residueRemoved.py +5 -7
- hestia_earth/models/lcImpactAllEffects100Years/damageToHumanHealthWaterStress.py +2 -2
- hestia_earth/models/lcImpactAllEffectsInfinite/damageToHumanHealthWaterStress.py +2 -2
- hestia_earth/models/lcImpactCertainEffects100Years/damageToHumanHealthWaterStress.py +2 -2
- hestia_earth/models/lcImpactCertainEffectsInfinite/damageToHumanHealthWaterStress.py +2 -2
- hestia_earth/models/log.py +1 -1
- hestia_earth/models/mocking/search-results.json +3397 -1097
- hestia_earth/models/site/management.py +1 -1
- hestia_earth/models/site/post_checks/__init__.py +3 -2
- hestia_earth/models/site/post_checks/country.py +9 -0
- hestia_earth/models/site/pre_checks/__init__.py +3 -2
- hestia_earth/models/site/pre_checks/country.py +9 -0
- hestia_earth/models/site/soilMeasurement.py +2 -0
- hestia_earth/models/utils/__init__.py +1 -16
- hestia_earth/models/utils/blank_node.py +25 -25
- hestia_earth/models/utils/completeness.py +3 -2
- hestia_earth/models/utils/cycle.py +5 -4
- hestia_earth/models/utils/emission.py +5 -5
- hestia_earth/models/utils/feedipedia.py +6 -6
- hestia_earth/models/utils/impact_assessment.py +1 -2
- hestia_earth/models/utils/indicator.py +9 -7
- hestia_earth/models/utils/inorganicFertiliser.py +4 -6
- hestia_earth/models/utils/input.py +6 -5
- hestia_earth/models/utils/lookup.py +32 -100
- hestia_earth/models/utils/management.py +4 -4
- hestia_earth/models/utils/measurement.py +7 -8
- hestia_earth/models/utils/method.py +20 -0
- hestia_earth/models/utils/practice.py +4 -5
- hestia_earth/models/utils/product.py +4 -5
- hestia_earth/models/utils/property.py +12 -22
- hestia_earth/models/utils/site.py +14 -8
- hestia_earth/models/utils/term.py +27 -1
- hestia_earth/models/version.py +1 -1
- hestia_earth/orchestrator/log.py +0 -11
- hestia_earth/orchestrator/models/__init__.py +17 -4
- hestia_earth/orchestrator/strategies/run/add_blank_node_if_missing.py +2 -20
- {hestia_earth_models-0.67.1.dist-info → hestia_earth_models-0.68.1.dist-info}/METADATA +2 -2
- {hestia_earth_models-0.67.1.dist-info → hestia_earth_models-0.68.1.dist-info}/RECORD +146 -138
- tests/models/cml2001Baseline/test_abioticResourceDepletionFossilFuels.py +3 -3
- tests/models/cml2001Baseline/test_resourceUseEnergyDepletionDuringCycle.py +1 -1
- tests/models/cycle/test_coldCarcassWeightPerHead.py +1 -1
- tests/models/cycle/test_coldDressedCarcassWeightPerHead.py +1 -1
- tests/models/cycle/test_concentrateFeed.py +1 -1
- tests/models/cycle/test_energyContentLowerHeatingValue.py +1 -1
- tests/models/cycle/test_excretaKgMass.py +1 -1
- tests/models/cycle/test_feedConversionRatio.py +3 -3
- tests/models/cycle/test_pastureGrass.py +1 -1
- tests/models/cycle/test_readyToCookWeightPerHead.py +1 -1
- tests/models/environmentalFootprintV3_1/test_photochemicalOzoneCreationPotentialHumanHealthNmvocEq.py +30 -0
- tests/models/environmentalFootprintV3_1/test_soilQualityIndexTotalLandUseEffects.py +30 -7
- tests/models/faostat2018/product/test_price.py +27 -14
- tests/models/faostat2018/test_faostat_utils.py +4 -24
- tests/models/faostat2018/test_liveweightPerHead.py +9 -9
- tests/models/globalCropWaterModel2008/test_rootingDepth.py +7 -3
- tests/models/haversineFormula/transport/test_distance.py +1 -1
- tests/models/hestia/test_landCover.py +53 -5
- tests/models/ipcc2019/animal/test_pastureGrass.py +5 -3
- tests/models/ipcc2019/test_aboveGroundCropResidueTotal.py +4 -4
- tests/models/ipcc2019/test_belowGroundCropResidue.py +4 -4
- tests/models/ipcc2019/test_ch4ToAirEntericFermentation.py +10 -10
- tests/models/ipcc2019/test_croppingDuration.py +1 -1
- tests/models/ipcc2019/test_nonCo2EmissionsToAirNaturalVegetationBurning.py +83 -0
- tests/models/ipcc2019/test_organicCarbonPerHa.py +12 -12
- tests/models/ipcc2019/test_pastureGrass.py +5 -3
- tests/models/pooreNemecek2018/test_excretaKgN.py +5 -5
- tests/models/pooreNemecek2018/test_excretaKgVs.py +2 -2
- tests/models/site/post_checks/test_country.py +6 -0
- tests/models/site/pre_checks/test_cache_geospatialDatabase.py +1 -1
- tests/models/site/pre_checks/test_country.py +12 -0
- tests/models/test_ecoinventV3.py +7 -3
- tests/models/utils/test_blank_node.py +4 -12
- tests/models/utils/test_dataCompleteness.py +5 -5
- tests/models/utils/test_emission.py +2 -2
- tests/models/utils/test_indicator.py +2 -2
- tests/models/utils/test_input.py +2 -2
- tests/models/utils/test_measurement.py +2 -4
- tests/models/utils/test_practice.py +4 -2
- tests/models/utils/test_product.py +2 -2
- tests/models/utils/test_property.py +4 -2
- tests/models/utils/test_site.py +7 -0
- tests/orchestrator/strategies/run/test_add_blank_node_if_missing.py +4 -9
- hestia_earth/models/environmentalFootprintV3_1/utils.py +0 -17
- tests/models/utils/test_lookup.py +0 -10
- {hestia_earth_models-0.67.1.dist-info → hestia_earth_models-0.68.1.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.67.1.dist-info → hestia_earth_models-0.68.1.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.67.1.dist-info → hestia_earth_models-0.68.1.dist-info}/top_level.txt +0 -0
@@ -17,7 +17,7 @@ def fake_rounded_indicator(value: float):
|
|
17
17
|
return indicator
|
18
18
|
|
19
19
|
|
20
|
-
def
|
20
|
+
def fake_get_terms(filename, column_name):
|
21
21
|
data = {
|
22
22
|
'fuel.csv': ["lignite", "conventionalCrudeOil", "naturalGas", "coalTar"],
|
23
23
|
'electricity.csv': ['electricityGridMarketMix', 'electricityGridHardCoal', 'electricityProducedOnSiteHardCoal',
|
@@ -105,7 +105,7 @@ good_nuclear_indicator_mj = {
|
|
105
105
|
"good nuclear fuel use indicator in mj",
|
106
106
|
]
|
107
107
|
)
|
108
|
-
@patch(f"{class_path}.get_all_non_renewable_terms", side_effect=
|
108
|
+
@patch(f"{class_path}.get_all_non_renewable_terms", side_effect=fake_get_terms)
|
109
109
|
def test_should_run(mock_get_all_non_renewable_terms, resources, expected, num_inputs):
|
110
110
|
with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
|
111
111
|
impactassessment = json.load(f)
|
@@ -117,7 +117,7 @@ def test_should_run(mock_get_all_non_renewable_terms, resources, expected, num_i
|
|
117
117
|
assert len(resources) == num_inputs
|
118
118
|
|
119
119
|
|
120
|
-
@patch(f"{class_path}.get_all_non_renewable_terms", side_effect=
|
120
|
+
@patch(f"{class_path}.get_all_non_renewable_terms", side_effect=fake_get_terms)
|
121
121
|
@patch(f"{class_path}._indicator", side_effect=fake_rounded_indicator)
|
122
122
|
def test_run(*args):
|
123
123
|
with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
|
@@ -112,7 +112,7 @@ input_nuclear_fuel_kwh = {
|
|
112
112
|
"bad indicator input in kg no property to convert to mj"
|
113
113
|
]
|
114
114
|
)
|
115
|
-
@patch('hestia_earth.models.utils.property.
|
115
|
+
@patch('hestia_earth.models.utils.property.download_term', return_value={})
|
116
116
|
def test_should_run(mock_download, inputs, expected, num_inputs):
|
117
117
|
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
118
118
|
cycle = json.load(f)
|
@@ -34,7 +34,7 @@ def test_should_run():
|
|
34
34
|
assert should_run is True
|
35
35
|
|
36
36
|
|
37
|
-
@patch("hestia_earth.models.utils.property.
|
37
|
+
@patch("hestia_earth.models.utils.property.download_term", return_value={'units': '%'})
|
38
38
|
@patch(f"{class_path}._new_property", side_effect=fake_new_property)
|
39
39
|
def test_run(*args):
|
40
40
|
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
@@ -34,7 +34,7 @@ def test_should_run():
|
|
34
34
|
assert should_run is True
|
35
35
|
|
36
36
|
|
37
|
-
@patch("hestia_earth.models.utils.property.
|
37
|
+
@patch("hestia_earth.models.utils.property.download_term", return_value={'units': '%'})
|
38
38
|
@patch(f"{class_path}._new_property", side_effect=fake_new_property)
|
39
39
|
def test_run(*args):
|
40
40
|
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
@@ -37,7 +37,7 @@ def test_should_run(mock_primary_product, *args):
|
|
37
37
|
assert should_run is True
|
38
38
|
|
39
39
|
|
40
|
-
@patch('hestia_earth.models.utils.property.
|
40
|
+
@patch('hestia_earth.models.utils.property.download_term', return_value={}) # make sure default props are not loaded
|
41
41
|
@patch(f"{class_path}.get_energy_digestibility_terms", return_value=ED_TERM_IDS)
|
42
42
|
@patch(f"{class_path}.get_digestible_energy_terms", return_value=DE_TERM_IDS)
|
43
43
|
@patch(f"{class_path}._new_property", side_effect=fake_new_property)
|
@@ -24,7 +24,7 @@ def test_should_run_input():
|
|
24
24
|
assert _should_run_input({})(input) is True
|
25
25
|
|
26
26
|
|
27
|
-
@patch("hestia_earth.models.utils.property.
|
27
|
+
@patch("hestia_earth.models.utils.property.download_term", return_value={'units': '%'})
|
28
28
|
@patch(f"{class_path}.get_wood_fuel_terms", return_value=['woodPellets', 'woodFuel'])
|
29
29
|
@patch(f"{class_path}._new_property", side_effect=fake_new_property)
|
30
30
|
def test_run(*args):
|
@@ -84,7 +84,7 @@ def test_should_run():
|
|
84
84
|
assert should_run is True
|
85
85
|
|
86
86
|
|
87
|
-
@patch(f"{class_path}.
|
87
|
+
@patch(f"{class_path}.download_term", side_effect=lambda id, *args: TERMS[id])
|
88
88
|
@patch(f"{class_path}._new_product", side_effect=fake_new_product)
|
89
89
|
def test_run(*args):
|
90
90
|
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
@@ -14,7 +14,7 @@ TERMS_BY_ID = {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
|
17
|
-
def
|
17
|
+
def fake_download_term(term_id: str, *args): return TERMS_BY_ID[term_id]
|
18
18
|
|
19
19
|
|
20
20
|
@patch(f"{class_path}.get_total_value_converted_with_min_ratio", return_value=10)
|
@@ -37,7 +37,7 @@ def test_should_run(*args):
|
|
37
37
|
assert should_run is True
|
38
38
|
|
39
39
|
|
40
|
-
@patch("hestia_earth.models.utils.property.
|
40
|
+
@patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
|
41
41
|
@patch(f"{class_path}.is_run_required", return_value=True)
|
42
42
|
@patch(f"{class_path}._new_practice", side_effect=fake_new_practice)
|
43
43
|
def test_run(*args):
|
@@ -51,7 +51,7 @@ def test_run(*args):
|
|
51
51
|
assert value == expected
|
52
52
|
|
53
53
|
|
54
|
-
@patch("hestia_earth.models.utils.property.
|
54
|
+
@patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_term)
|
55
55
|
@patch(f"{class_path}.is_run_required", return_value=True)
|
56
56
|
@patch(f"{class_path}._new_practice", side_effect=fake_new_practice)
|
57
57
|
def test_run_with_carcass(*args):
|
@@ -18,7 +18,7 @@ def test_should_run():
|
|
18
18
|
assert _should_run(cycle) is True
|
19
19
|
|
20
20
|
|
21
|
-
@patch(f"{class_path}.
|
21
|
+
@patch(f"{class_path}.download_term", return_value={'@type': 'Term', '@id': KEY_TERM_ID})
|
22
22
|
@patch(f"{class_path}._new_practice", side_effect=fake_new_practice)
|
23
23
|
def test_run(*args):
|
24
24
|
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
@@ -34,7 +34,7 @@ def test_should_run():
|
|
34
34
|
assert should_run is True
|
35
35
|
|
36
36
|
|
37
|
-
@patch("hestia_earth.models.utils.property.
|
37
|
+
@patch("hestia_earth.models.utils.property.download_term", return_value={'units': '%'})
|
38
38
|
@patch(f"{class_path}._new_property", side_effect=fake_new_property)
|
39
39
|
def test_run(*args):
|
40
40
|
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import json
|
2
|
+
from unittest.mock import patch
|
3
|
+
|
4
|
+
from hestia_earth.models.environmentalFootprintV3_1 import MODEL_FOLDER
|
5
|
+
from hestia_earth.models.environmentalFootprintV3_1.photochemicalOzoneCreationPotentialHumanHealthNmvocEq import (
|
6
|
+
TERM_ID,
|
7
|
+
run,
|
8
|
+
)
|
9
|
+
from tests.utils import fixtures_path, fake_new_indicator
|
10
|
+
|
11
|
+
class_path = f"hestia_earth.models.{MODEL_FOLDER}.{TERM_ID}"
|
12
|
+
fixtures_folder = f"{fixtures_path}/{MODEL_FOLDER}/{TERM_ID}"
|
13
|
+
|
14
|
+
|
15
|
+
@patch(f"{class_path}._new_indicator", side_effect=fake_new_indicator)
|
16
|
+
def test_run(*args):
|
17
|
+
with open(
|
18
|
+
f"{fixtures_path}/impact_assessment/emissions/impact-assessment.jsonld",
|
19
|
+
encoding="utf-8",
|
20
|
+
) as f:
|
21
|
+
impact = json.load(f)
|
22
|
+
with open(f"{fixtures_folder}/emissions.jsonld", encoding="utf-8") as f:
|
23
|
+
emissions = json.load(f)
|
24
|
+
|
25
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding="utf-8") as f:
|
26
|
+
expected = json.load(f)
|
27
|
+
|
28
|
+
impact["emissionsResourceUse"] = emissions
|
29
|
+
value = run(impact)
|
30
|
+
assert value == expected
|
@@ -10,14 +10,37 @@ from tests.utils import fixtures_path, fake_new_indicator
|
|
10
10
|
class_path = f"hestia_earth.models.{MODEL_FOLDER}.{TERM_ID}"
|
11
11
|
fixtures_folder = f"{fixtures_path}/{MODEL_FOLDER}/{TERM_ID}"
|
12
12
|
|
13
|
-
transform_indicator = {
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
transform_indicator = {
|
14
|
+
"term": {
|
15
|
+
"@id": "soilQualityIndexLandTransformation",
|
16
|
+
"termType": "characterisedIndicator",
|
17
|
+
},
|
18
|
+
"value": 10,
|
19
|
+
}
|
20
|
+
occupation_indicator = {
|
21
|
+
"term": {
|
22
|
+
"@id": "soilQualityIndexLandOccupation",
|
23
|
+
"termType": "characterisedIndicator",
|
24
|
+
},
|
25
|
+
"value": 10,
|
26
|
+
}
|
27
|
+
missing_value_indicator = {
|
28
|
+
"term": {
|
29
|
+
"@id": "soilQualityIndexLandOccupation",
|
30
|
+
"termType": "characterisedIndicator",
|
31
|
+
}
|
32
|
+
}
|
33
|
+
bad_value_indicator = {
|
34
|
+
"term": {
|
35
|
+
"@id": "soilQualityIndexLandOccupation",
|
36
|
+
"termType": "characterisedIndicator",
|
37
|
+
},
|
38
|
+
"value": "42",
|
39
|
+
}
|
17
40
|
|
18
41
|
|
19
42
|
@mark.parametrize(
|
20
|
-
"
|
43
|
+
"impacts, expected, num_expected",
|
21
44
|
[
|
22
45
|
([], False, 0),
|
23
46
|
([transform_indicator], False, 1),
|
@@ -32,11 +55,11 @@ bad_value_indicator = {'term': {'@id': 'soilQualityIndexLandOccupation'}, 'value
|
|
32
55
|
ids=["Empty", "missing obligatory occupation", "duplicate entry", "no value in entry", "bad value in entry",
|
33
56
|
"correct assessment", "just occupation", "multiple occupations and transformations"]
|
34
57
|
)
|
35
|
-
def test_should_run(
|
58
|
+
def test_should_run(impacts, expected, num_expected):
|
36
59
|
with open(f"{fixtures_folder}/impactassessment.jsonld", encoding='utf-8') as f:
|
37
60
|
impactassessment = json.load(f)
|
38
61
|
|
39
|
-
impactassessment['
|
62
|
+
impactassessment['impacts'] = impacts
|
40
63
|
|
41
64
|
should_run, indicators = _should_run(impactassessment)
|
42
65
|
assert should_run is expected
|
@@ -9,12 +9,13 @@ fixtures_folder = f"{fixtures_path}/{MODEL}/product/{MODEL_KEY}"
|
|
9
9
|
|
10
10
|
|
11
11
|
def test_lookup_data():
|
12
|
-
|
12
|
+
country = {'@id': 'GADM-GHA'}
|
13
|
+
assert _lookup_data('cocoaSeedDehulled', 'Cocoa beans', country, 2000, term_type='crop') == 412.9
|
13
14
|
# average price per tonne as year value is missing
|
14
|
-
assert _lookup_data('cocoaSeedDehulled', 'Cocoa beans',
|
15
|
+
assert _lookup_data('cocoaSeedDehulled', 'Cocoa beans', country, 2012, term_type='crop') == 844.0571428571428
|
15
16
|
|
16
17
|
|
17
|
-
@patch(f"{class_path}.
|
18
|
+
@patch(f"{class_path}.download_term", return_value={})
|
18
19
|
def test_run_crop(*args):
|
19
20
|
with open(f"{fixtures_folder}/crop/cycle.jsonld", encoding='utf-8') as f:
|
20
21
|
cycle = json.load(f)
|
@@ -26,7 +27,19 @@ def test_run_crop(*args):
|
|
26
27
|
assert value == expected
|
27
28
|
|
28
29
|
|
29
|
-
@patch(f"{class_path}.
|
30
|
+
@patch(f"{class_path}.download_term", return_value={})
|
31
|
+
def test_run_missing_country_price(*args):
|
32
|
+
with open(f"{fixtures_folder}/missing-country-price/cycle.jsonld", encoding='utf-8') as f:
|
33
|
+
cycle = json.load(f)
|
34
|
+
|
35
|
+
with open(f"{fixtures_folder}/missing-country-price/result.jsonld", encoding='utf-8') as f:
|
36
|
+
expected = json.load(f)
|
37
|
+
|
38
|
+
value = run(cycle)
|
39
|
+
assert value == expected
|
40
|
+
|
41
|
+
|
42
|
+
@patch(f"{class_path}.download_term", return_value={})
|
30
43
|
def test_run_animalProduct_kg(*args):
|
31
44
|
with open(f"{fixtures_folder}/animalProduct/kg/cycle.jsonld", encoding='utf-8') as f:
|
32
45
|
cycle = json.load(f)
|
@@ -38,7 +51,7 @@ def test_run_animalProduct_kg(*args):
|
|
38
51
|
assert value == expected
|
39
52
|
|
40
53
|
|
41
|
-
@patch(f"{class_path}.
|
54
|
+
@patch(f"{class_path}.download_term", return_value={})
|
42
55
|
def test_run_animalProduct_number(*args):
|
43
56
|
with open(f"{fixtures_folder}/animalProduct/number/cycle.jsonld", encoding='utf-8') as f:
|
44
57
|
cycle = json.load(f)
|
@@ -50,15 +63,15 @@ def test_run_animalProduct_number(*args):
|
|
50
63
|
assert value == expected
|
51
64
|
|
52
65
|
|
53
|
-
@patch(f"{class_path}.
|
54
|
-
def test_run_liveAnimal_chicken(
|
66
|
+
@patch(f"{class_path}.download_term")
|
67
|
+
def test_run_liveAnimal_chicken(mock_download_term):
|
55
68
|
with open(f"{fixtures_folder}/liveAnimal/chicken/cycle.jsonld", encoding='utf-8') as f:
|
56
69
|
cycle = json.load(f)
|
57
70
|
|
58
71
|
with open(f"{fixtures_folder}/liveAnimal/chicken/result.jsonld", encoding='utf-8') as f:
|
59
72
|
expected = json.load(f)
|
60
73
|
|
61
|
-
|
74
|
+
mock_download_term.return_value = {
|
62
75
|
"@id": "meatChickenLiveweight",
|
63
76
|
"@type": "Term",
|
64
77
|
"units": "kg liveweight",
|
@@ -68,15 +81,15 @@ def test_run_liveAnimal_chicken(mock_download_hestia):
|
|
68
81
|
assert value == expected
|
69
82
|
|
70
83
|
|
71
|
-
@patch(f"{class_path}.
|
72
|
-
def test_run_liveAnimal_pig(
|
84
|
+
@patch(f"{class_path}.download_term")
|
85
|
+
def test_run_liveAnimal_pig(mock_download_term):
|
73
86
|
with open(f"{fixtures_folder}/liveAnimal/pig/cycle.jsonld", encoding='utf-8') as f:
|
74
87
|
cycle = json.load(f)
|
75
88
|
|
76
89
|
with open(f"{fixtures_folder}/liveAnimal/pig/result.jsonld", encoding='utf-8') as f:
|
77
90
|
expected = json.load(f)
|
78
91
|
|
79
|
-
|
92
|
+
mock_download_term.return_value = {
|
80
93
|
"@id": "meatPigLiveweight",
|
81
94
|
"@type": "Term",
|
82
95
|
"units": "kg liveweight",
|
@@ -86,15 +99,15 @@ def test_run_liveAnimal_pig(mock_download_hestia):
|
|
86
99
|
assert value == expected
|
87
100
|
|
88
101
|
|
89
|
-
@patch(f"{class_path}.
|
90
|
-
def test_run_liveAnimal_sheepLamb(
|
102
|
+
@patch(f"{class_path}.download_term")
|
103
|
+
def test_run_liveAnimal_sheepLamb(mock_download_term):
|
91
104
|
with open(f"{fixtures_folder}/liveAnimal/sheepLamb/cycle.jsonld", encoding='utf-8') as f:
|
92
105
|
cycle = json.load(f)
|
93
106
|
|
94
107
|
with open(f"{fixtures_folder}/liveAnimal/sheepLamb/result.jsonld", encoding='utf-8') as f:
|
95
108
|
expected = json.load(f)
|
96
109
|
|
97
|
-
|
110
|
+
mock_download_term.return_value = {
|
98
111
|
"@id": "meatSheepLiveweight",
|
99
112
|
"@type": "Term",
|
100
113
|
"units": "kg liveweight",
|
@@ -1,30 +1,14 @@
|
|
1
|
-
from
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
from hestia_earth.models.faostat2018.utils import (get_sum_of_columns, MODEL, get_land_ratio,
|
6
|
-
get_change_in_harvested_area_for_crop)
|
1
|
+
from hestia_earth.models.faostat2018.utils import (
|
2
|
+
MODEL, get_sum_of_columns, get_land_ratio, get_change_in_harvested_area_for_crop
|
3
|
+
)
|
7
4
|
from tests.utils import fixtures_path
|
8
5
|
|
9
6
|
CLASS_PATH = f"hestia_earth.models.{MODEL}.utils"
|
10
7
|
fixtures_folder = f"{fixtures_path}/{MODEL}/utils"
|
11
8
|
|
12
9
|
|
13
|
-
def _afg_download_fixture():
|
14
|
-
with open(f"{fixtures_folder}/gadm-afg.csv") as f:
|
15
|
-
afg_lookup = numpy.recfromcsv(
|
16
|
-
fname=f,
|
17
|
-
missing_values="",
|
18
|
-
filling_values="",
|
19
|
-
delimiter=",",
|
20
|
-
encoding="utf-8"
|
21
|
-
)
|
22
|
-
return afg_lookup
|
23
|
-
|
24
|
-
|
25
10
|
def test_get_sum_of_columns():
|
26
11
|
result = get_sum_of_columns(
|
27
|
-
lookup=_afg_download_fixture(),
|
28
12
|
country="GADM-AFG",
|
29
13
|
year=1975,
|
30
14
|
columns_list=["Arable land", "Permanent crops"]
|
@@ -38,14 +22,12 @@ def test_check_sums_for_columns():
|
|
38
22
|
"""
|
39
23
|
for year in range(1961, 2021):
|
40
24
|
sum_arab_perm = get_sum_of_columns(
|
41
|
-
lookup=_afg_download_fixture(),
|
42
25
|
country="GADM-AFG",
|
43
26
|
year=year,
|
44
27
|
columns_list=["Arable land", "Permanent crops"]
|
45
28
|
)
|
46
29
|
|
47
30
|
cropland_value = get_sum_of_columns(
|
48
|
-
lookup=_afg_download_fixture(),
|
49
31
|
country="GADM-AFG",
|
50
32
|
year=year,
|
51
33
|
columns_list=["Cropland"]
|
@@ -53,9 +35,7 @@ def test_check_sums_for_columns():
|
|
53
35
|
assert sum_arab_perm == cropland_value
|
54
36
|
|
55
37
|
|
56
|
-
|
57
|
-
def test_get_land_ratio(mock_lookup):
|
58
|
-
mock_lookup.return_value = _afg_download_fixture()
|
38
|
+
def test_get_land_ratio():
|
59
39
|
result = get_land_ratio(
|
60
40
|
country="GADM-AFG",
|
61
41
|
start_year=1990,
|
@@ -22,15 +22,15 @@ def test_run_animalProduct(*args):
|
|
22
22
|
|
23
23
|
|
24
24
|
@patch(f"{class_path}._new_property", side_effect=fake_new_property)
|
25
|
-
@patch(f"{class_path}.
|
26
|
-
def test_run_liveAnimal_chicken(
|
25
|
+
@patch(f"{class_path}.download_term")
|
26
|
+
def test_run_liveAnimal_chicken(mock_download_term, *args):
|
27
27
|
with open(f"{fixtures_folder}/liveAnimal/chicken/cycle.jsonld", encoding='utf-8') as f:
|
28
28
|
cycle = json.load(f)
|
29
29
|
|
30
30
|
with open(f"{fixtures_folder}/liveAnimal/chicken/result.jsonld", encoding='utf-8') as f:
|
31
31
|
expected = json.load(f)
|
32
32
|
|
33
|
-
|
33
|
+
mock_download_term.return_value = {
|
34
34
|
"@id": "meatChickenReadyToCookWeight",
|
35
35
|
"@type": "Term",
|
36
36
|
"units": "kg ready-to-cook weight",
|
@@ -64,15 +64,15 @@ def test_run_liveAnimal_chicken(mock_download_hestia, *args):
|
|
64
64
|
|
65
65
|
|
66
66
|
@patch(f"{class_path}._new_property", side_effect=fake_new_property)
|
67
|
-
@patch(f"{class_path}.
|
68
|
-
def test_run_liveAnimal_pig(
|
67
|
+
@patch(f"{class_path}.download_term")
|
68
|
+
def test_run_liveAnimal_pig(mock_download_term, *args):
|
69
69
|
with open(f"{fixtures_folder}/liveAnimal/pig/cycle.jsonld", encoding='utf-8') as f:
|
70
70
|
cycle = json.load(f)
|
71
71
|
|
72
72
|
with open(f"{fixtures_folder}/liveAnimal/pig/result.jsonld", encoding='utf-8') as f:
|
73
73
|
expected = json.load(f)
|
74
74
|
|
75
|
-
|
75
|
+
mock_download_term.return_value = {
|
76
76
|
"@id": "meatPigColdDressedCarcassWeight",
|
77
77
|
"@type": "Term",
|
78
78
|
"units": "kg cold dressed carcass weight",
|
@@ -95,15 +95,15 @@ def test_run_liveAnimal_pig(mock_download_hestia, *args):
|
|
95
95
|
|
96
96
|
|
97
97
|
@patch(f"{class_path}._new_property", side_effect=fake_new_property)
|
98
|
-
@patch(f"{class_path}.
|
99
|
-
def test_run_liveAnimal_sheepLamb(
|
98
|
+
@patch(f"{class_path}.download_term")
|
99
|
+
def test_run_liveAnimal_sheepLamb(mock_download_term, *args):
|
100
100
|
with open(f"{fixtures_folder}/liveAnimal/sheepLamb/cycle.jsonld", encoding='utf-8') as f:
|
101
101
|
cycle = json.load(f)
|
102
102
|
|
103
103
|
with open(f"{fixtures_folder}/liveAnimal/sheepLamb/result.jsonld", encoding='utf-8') as f:
|
104
104
|
expected = json.load(f)
|
105
105
|
|
106
|
-
|
106
|
+
mock_download_term.return_value = {
|
107
107
|
"@id": "meatSheepColdDressedCarcassWeight",
|
108
108
|
"@type": "Term",
|
109
109
|
"units": "kg cold dressed carcass weight",
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from unittest.mock import patch
|
2
2
|
import json
|
3
3
|
from hestia_earth.schema import CycleFunctionalUnit
|
4
|
-
from tests.utils import fixtures_path, fake_new_property
|
4
|
+
from tests.utils import fixtures_path, fake_new_property
|
5
5
|
|
6
6
|
from hestia_earth.models.globalCropWaterModel2008.rootingDepth import (
|
7
7
|
MODEL, TERM_ID, run, _should_run, _should_run_product
|
@@ -16,6 +16,10 @@ TERMS = [
|
|
16
16
|
]
|
17
17
|
|
18
18
|
|
19
|
+
def fake_download_term(node_id, *args):
|
20
|
+
return {"@type": "Term", "@id": node_id}
|
21
|
+
|
22
|
+
|
19
23
|
@patch(f"{class_path}.get_irrigation_terms", return_value=TERMS)
|
20
24
|
def test_should_run(*args):
|
21
25
|
cycle = {'products': []}
|
@@ -53,7 +57,7 @@ def test_should_run_product(mock_get_value, *args):
|
|
53
57
|
|
54
58
|
|
55
59
|
@patch(f"{class_path}.get_irrigation_terms", return_value=TERMS)
|
56
|
-
@patch(f"{class_path}.
|
60
|
+
@patch(f"{class_path}.download_term", side_effect=fake_download_term)
|
57
61
|
@patch(f"{class_path}._new_property", side_effect=fake_new_property)
|
58
62
|
def test_run(*args):
|
59
63
|
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
@@ -67,7 +71,7 @@ def test_run(*args):
|
|
67
71
|
|
68
72
|
|
69
73
|
@patch(f"{class_path}.get_irrigation_terms", return_value=TERMS)
|
70
|
-
@patch(f"{class_path}.
|
74
|
+
@patch(f"{class_path}.download_term", side_effect=fake_download_term)
|
71
75
|
@patch(f"{class_path}._new_property", side_effect=fake_new_property)
|
72
76
|
def test_gap_fill_with_irrigation(*args):
|
73
77
|
with open(f"{fixtures_folder}/with-irrigation/cycle.jsonld", encoding='utf-8') as f:
|
@@ -16,7 +16,7 @@ def fake_download_hestia(id: str, *args):
|
|
16
16
|
|
17
17
|
|
18
18
|
@patch(f"{class_path}.download_hestia", side_effect=fake_download_hestia)
|
19
|
-
@patch(f"{class_path}.
|
19
|
+
@patch(f"{class_path}.include_methodModel", side_effect=_set_methodModel)
|
20
20
|
def test_run(*args):
|
21
21
|
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
22
22
|
cycle = json.load(f)
|
@@ -8,7 +8,7 @@ from tests.utils import fixtures_path, fake_new_management
|
|
8
8
|
from hestia_earth.models.faostat2018.utils import MODEL as FAOSTAT_MODEL
|
9
9
|
from hestia_earth.models.hestia.landCover import (
|
10
10
|
MODEL, MODEL_KEY, get_changes, _estimate_maximum_forest_change,
|
11
|
-
run, site_area_sum_to_100, _get_sums_of_crop_expansion
|
11
|
+
run, site_area_sum_to_100, _get_sums_of_crop_expansion, _get_sum_for_land_category, scale_values_to_one
|
12
12
|
)
|
13
13
|
|
14
14
|
CLASS_PATH = f"hestia_earth.models.{MODEL}.{MODEL_KEY}"
|
@@ -55,9 +55,7 @@ def _download_fixture(filepath: str):
|
|
55
55
|
return recfromcsv_mod(filename=filepath)
|
56
56
|
|
57
57
|
|
58
|
-
|
59
|
-
def test_get_changes(mock_lookup):
|
60
|
-
mock_lookup.return_value = _download_fixture(f"{faostat_fixtures_folder}/gadm-afg.csv")
|
58
|
+
def test_get_changes():
|
61
59
|
result, missing_values = get_changes(
|
62
60
|
country_id="GADM-AFG",
|
63
61
|
end_year=2010
|
@@ -185,6 +183,55 @@ def test_get_sums_of_crop_expansion():
|
|
185
183
|
assert result == (940270.0, 28139.0)
|
186
184
|
|
187
185
|
|
186
|
+
def test_get_sum_for_land_category():
|
187
|
+
values = {
|
188
|
+
"mangoes_guavas_and_mangosteens": "2022:5",
|
189
|
+
"kiwi_fruit": "2020:4",
|
190
|
+
"maize_corn": "2020:3",
|
191
|
+
"other_beans_green": "2021:2",
|
192
|
+
"olives": "2020:-1"
|
193
|
+
}
|
194
|
+
fao_stat_to_ipcc_type = {
|
195
|
+
"mangoes_guavas_and_mangosteens": "Perennial crops",
|
196
|
+
'kiwi_fruit': "Perennial crops",
|
197
|
+
'maize_corn': "Annual crops",
|
198
|
+
'other_beans_green': "Annual crops",
|
199
|
+
'olives': "Perennial crops"
|
200
|
+
}
|
201
|
+
result = _get_sum_for_land_category(
|
202
|
+
values=values,
|
203
|
+
year=2020,
|
204
|
+
ipcc_land_use_category="Perennial crops",
|
205
|
+
fao_stat_to_ipcc_type=fao_stat_to_ipcc_type,
|
206
|
+
include_negatives=True
|
207
|
+
)
|
208
|
+
assert result == 3.0
|
209
|
+
|
210
|
+
|
211
|
+
@pytest.mark.parametrize(
|
212
|
+
"dictionary,expected_result",
|
213
|
+
[
|
214
|
+
(
|
215
|
+
{"a": 0, "b": 0, "c": 0},
|
216
|
+
{"a": 0, "b": 0, "c": 0}
|
217
|
+
),
|
218
|
+
(
|
219
|
+
{"a": 1000},
|
220
|
+
{"a": 1}
|
221
|
+
),
|
222
|
+
(
|
223
|
+
{"a": 10, "b": 5, "c": 3},
|
224
|
+
{"a": 0.5556, "b": 0.2778, "c": 0.1667}
|
225
|
+
)
|
226
|
+
]
|
227
|
+
)
|
228
|
+
def test_scale_values_to_one(dictionary, expected_result):
|
229
|
+
result = scale_values_to_one(dictionary)
|
230
|
+
for k, v in result.items():
|
231
|
+
assert k in expected_result
|
232
|
+
assert round(v, 3) == round(expected_result[k], 3)
|
233
|
+
|
234
|
+
|
188
235
|
@pytest.mark.parametrize(
|
189
236
|
"subfolder",
|
190
237
|
[
|
@@ -199,7 +246,8 @@ def test_get_sums_of_crop_expansion():
|
|
199
246
|
"prior_landCover",
|
200
247
|
"nigeria_cassava",
|
201
248
|
"cover_crops",
|
202
|
-
"missing_fao_date"
|
249
|
+
"missing_fao_date",
|
250
|
+
"iran_sistan"
|
203
251
|
]
|
204
252
|
)
|
205
253
|
@patch(f"{CLASS_PATH}._new_management", side_effect=fake_new_management)
|
@@ -10,11 +10,13 @@ class_path_utils = f"hestia_earth.models.{MODEL}.pastureGrass_utils"
|
|
10
10
|
fixtures_folder = f"{fixtures_path}/{MODEL}/animal/{MODEL_KEY}"
|
11
11
|
|
12
12
|
|
13
|
-
def fake_download_hestia(
|
13
|
+
def fake_download_hestia(term, *args):
|
14
|
+
term_id = term.get('@id') if isinstance(term, dict) else term
|
15
|
+
return TERMS_BY_ID.get(term_id, {})
|
14
16
|
|
15
17
|
|
16
18
|
@patch(f"{class_path_utils}.download_hestia", side_effect=fake_download_hestia)
|
17
|
-
@patch("hestia_earth.models.utils.property.
|
19
|
+
@patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_hestia)
|
18
20
|
@patch(f"{class_path}.get_wool_terms", return_value=WOOL_TERMS)
|
19
21
|
@patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=MILK_YIELD_TERMS)
|
20
22
|
@patch(f"{class_path}._new_input", side_effect=fake_new_input)
|
@@ -30,7 +32,7 @@ def test_run_with_feed(*args):
|
|
30
32
|
|
31
33
|
|
32
34
|
@patch(f"{class_path_utils}.download_hestia", side_effect=fake_download_hestia)
|
33
|
-
@patch("hestia_earth.models.utils.property.
|
35
|
+
@patch("hestia_earth.models.utils.property.download_term", side_effect=fake_download_hestia)
|
34
36
|
@patch(f"{class_path}.get_wool_terms", return_value=WOOL_TERMS)
|
35
37
|
@patch(f"hestia_earth.models.{MODEL}.utils.get_milkYield_terms", return_value=MILK_YIELD_TERMS)
|
36
38
|
@patch(f"{class_path}._new_input", side_effect=fake_new_input)
|
@@ -16,7 +16,7 @@ CROP_RESIDUE_TERM = {
|
|
16
16
|
}
|
17
17
|
|
18
18
|
|
19
|
-
@patch('hestia_earth.models.utils.completeness.
|
19
|
+
@patch('hestia_earth.models.utils.completeness.download_term', return_value=CROP_RESIDUE_TERM)
|
20
20
|
@patch(f"{class_path}._should_run_product", return_value=True)
|
21
21
|
def test_should_run(*args):
|
22
22
|
crop_product = {'term': {'termType': TermTermType.CROP.value}}
|
@@ -33,7 +33,7 @@ def test_should_run(*args):
|
|
33
33
|
assert should_run is True
|
34
34
|
|
35
35
|
|
36
|
-
@patch('hestia_earth.models.utils.completeness.
|
36
|
+
@patch('hestia_earth.models.utils.completeness.download_term', return_value=CROP_RESIDUE_TERM)
|
37
37
|
@patch(f"{class_path}.get_yield_dm", return_value=None)
|
38
38
|
def test_should_run_product(mock_get_yield_dm, *args):
|
39
39
|
product = {'term': {'@id': 'maizeGrain'}}
|
@@ -51,7 +51,7 @@ def test_should_run_product(mock_get_yield_dm, *args):
|
|
51
51
|
assert _should_run_product(product) is True
|
52
52
|
|
53
53
|
|
54
|
-
@patch('hestia_earth.models.utils.completeness.
|
54
|
+
@patch('hestia_earth.models.utils.completeness.download_term', return_value=CROP_RESIDUE_TERM)
|
55
55
|
@patch(f"{class_path}._new_product", side_effect=fake_new_product)
|
56
56
|
def test_run_crop(*args):
|
57
57
|
with open(f"{fixtures_folder}/crop/cycle.jsonld", encoding='utf-8') as f:
|
@@ -64,7 +64,7 @@ def test_run_crop(*args):
|
|
64
64
|
assert value == expected
|
65
65
|
|
66
66
|
|
67
|
-
@patch('hestia_earth.models.utils.completeness.
|
67
|
+
@patch('hestia_earth.models.utils.completeness.download_term', return_value=CROP_RESIDUE_TERM)
|
68
68
|
@patch(f"{class_path}._new_product", side_effect=fake_new_product)
|
69
69
|
def test_run_forage(*args):
|
70
70
|
with open(f"{fixtures_folder}/forage/cycle.jsonld", encoding='utf-8') as f:
|