hestia-earth-models 0.70.5__py3-none-any.whl → 0.71.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hestia_earth/models/cache_nodes.py +157 -0
- hestia_earth/models/cache_sites.py +1 -1
- hestia_earth/models/config/Cycle.json +0 -30
- hestia_earth/models/data/ecoinventV3/__init__.py +7 -5
- hestia_earth/models/ecoinventV3/__init__.py +8 -1
- hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py +1 -0
- hestia_earth/models/emepEea2019/co2ToAirFuelCombustion.py +20 -15
- hestia_earth/models/emepEea2019/n2OToAirFuelCombustionDirect.py +21 -16
- hestia_earth/models/emepEea2019/noxToAirFuelCombustion.py +20 -15
- hestia_earth/models/emepEea2019/so2ToAirFuelCombustion.py +20 -15
- hestia_earth/models/emepEea2019/utils.py +73 -25
- hestia_earth/models/hestia/aboveGroundCropResidue.py +3 -3
- hestia_earth/models/hestia/management.py +12 -7
- hestia_earth/models/hestia/seed_emissions.py +25 -21
- hestia_earth/models/mocking/search-results.json +1506 -1502
- hestia_earth/models/utils/background_emissions.py +24 -0
- hestia_earth/models/utils/blank_node.py +4 -1
- hestia_earth/models/utils/pesticideAI.py +1 -1
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.70.5.dist-info → hestia_earth_models-0.71.0.dist-info}/METADATA +2 -2
- {hestia_earth_models-0.70.5.dist-info → hestia_earth_models-0.71.0.dist-info}/RECORD +31 -33
- tests/models/emepEea2019/test_co2ToAirFuelCombustion.py +1 -14
- tests/models/emepEea2019/test_n2OToAirFuelCombustionDirect.py +1 -14
- tests/models/emepEea2019/test_noxToAirFuelCombustion.py +1 -14
- tests/models/emepEea2019/test_so2ToAirFuelCombustion.py +1 -14
- tests/models/emepEea2019/test_utils.py +1 -49
- tests/models/hestia/test_management.py +2 -1
- tests/models/test_cache_nodes.py +31 -0
- hestia_earth/models/ipcc2006/co2ToAirOrganicSoilCultivation.py +0 -100
- hestia_earth/models/ipcc2006/n2OToAirOrganicSoilCultivationDirect.py +0 -99
- tests/models/ipcc2006/test_co2ToAirOrganicSoilCultivation.py +0 -49
- tests/models/ipcc2006/test_n2OToAirOrganicSoilCultivationDirect.py +0 -32
- {hestia_earth_models-0.70.5.dist-info → hestia_earth_models-0.71.0.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.70.5.dist-info → hestia_earth_models-0.71.0.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.70.5.dist-info → hestia_earth_models-0.71.0.dist-info}/top_level.txt +0 -0
@@ -1,99 +0,0 @@
|
|
1
|
-
from hestia_earth.schema import EmissionMethodTier
|
2
|
-
|
3
|
-
from hestia_earth.models.log import logRequirements, logShouldRun
|
4
|
-
from hestia_earth.models.utils.constant import Units, get_atomic_conversion
|
5
|
-
from hestia_earth.models.utils.emission import _new_emission
|
6
|
-
from hestia_earth.models.utils.measurement import most_relevant_measurement_value
|
7
|
-
from hestia_earth.models.utils.ecoClimateZone import get_ecoClimateZone_lookup_value
|
8
|
-
from hestia_earth.models.utils.cycle import land_occupation_per_ha
|
9
|
-
from . import MODEL
|
10
|
-
|
11
|
-
REQUIREMENTS = {
|
12
|
-
"Cycle": {
|
13
|
-
"or": [
|
14
|
-
{
|
15
|
-
"cycleDuration": "",
|
16
|
-
"practices": [{"@type": "Practice", "value": "", "term.@id": "longFallowRatio"}]
|
17
|
-
},
|
18
|
-
{
|
19
|
-
"@doc": "for plantations, additional properties are required",
|
20
|
-
"practices": [
|
21
|
-
{"@type": "Practice", "value": "", "term.@id": "nurseryDensity"},
|
22
|
-
{"@type": "Practice", "value": "", "term.@id": "nurseryDuration"},
|
23
|
-
{"@type": "Practice", "value": "", "term.@id": "plantationProductiveLifespan"},
|
24
|
-
{"@type": "Practice", "value": "", "term.@id": "plantationDensity"},
|
25
|
-
{"@type": "Practice", "value": "", "term.@id": "plantationLifespan"},
|
26
|
-
{"@type": "Practice", "value": "", "term.@id": "rotationDuration"}
|
27
|
-
]
|
28
|
-
}
|
29
|
-
],
|
30
|
-
"site": {
|
31
|
-
"@type": "Site",
|
32
|
-
"measurements": [
|
33
|
-
{"@type": "Measurement", "value": "", "term.@id": "histosol"},
|
34
|
-
{"@type": "Measurement", "value": "", "term.@id": "ecoClimateZone"}
|
35
|
-
]
|
36
|
-
},
|
37
|
-
"optional": {
|
38
|
-
"cycleDuration": ""
|
39
|
-
}
|
40
|
-
}
|
41
|
-
}
|
42
|
-
LOOKUPS = {
|
43
|
-
"crop": "isPlantation",
|
44
|
-
"ecoClimateZone": "IPCC_2006_ORGANIC_SOILS_KG_N2O-N_HECTARE"
|
45
|
-
}
|
46
|
-
RETURNS = {
|
47
|
-
"Emission": [{
|
48
|
-
"value": "",
|
49
|
-
"methodTier": "tier 1"
|
50
|
-
}]
|
51
|
-
}
|
52
|
-
TERM_ID = 'n2OToAirOrganicSoilCultivationDirect'
|
53
|
-
TIER = EmissionMethodTier.TIER_1.value
|
54
|
-
|
55
|
-
|
56
|
-
def _emission(value: float):
|
57
|
-
emission = _new_emission(TERM_ID, MODEL)
|
58
|
-
emission['value'] = [value]
|
59
|
-
emission['methodTier'] = TIER
|
60
|
-
return emission
|
61
|
-
|
62
|
-
|
63
|
-
def _run(histosol: float, organic_soil_factor: float, land_occupation: float):
|
64
|
-
value = land_occupation * histosol / 100 * organic_soil_factor
|
65
|
-
return [_emission(value)]
|
66
|
-
|
67
|
-
|
68
|
-
def _get_N2O_factor(eco_climate_zone: str):
|
69
|
-
return get_ecoClimateZone_lookup_value(
|
70
|
-
eco_climate_zone, LOOKUPS['ecoClimateZone']
|
71
|
-
) * get_atomic_conversion(Units.KG_N2O, Units.TO_N)
|
72
|
-
|
73
|
-
|
74
|
-
def _should_run(cycle: dict):
|
75
|
-
end_date = cycle.get('endDate')
|
76
|
-
site = cycle.get('site', {})
|
77
|
-
measurements = site.get('measurements', [])
|
78
|
-
|
79
|
-
def _get_measurement_content(term_id: str):
|
80
|
-
return most_relevant_measurement_value(measurements, term_id, end_date)
|
81
|
-
|
82
|
-
histosol = _get_measurement_content('histosol') or 0
|
83
|
-
eco_climate_zone = _get_measurement_content('ecoClimateZone')
|
84
|
-
organic_soil_factor = _get_N2O_factor(eco_climate_zone) if eco_climate_zone else 0
|
85
|
-
land_occupation = land_occupation_per_ha(MODEL, TERM_ID, cycle)
|
86
|
-
|
87
|
-
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
88
|
-
organic_soil_factor=organic_soil_factor,
|
89
|
-
land_occupation=land_occupation,
|
90
|
-
histosol=histosol)
|
91
|
-
|
92
|
-
should_run = all([organic_soil_factor, land_occupation])
|
93
|
-
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
94
|
-
return should_run, histosol, organic_soil_factor, land_occupation
|
95
|
-
|
96
|
-
|
97
|
-
def run(cycle: dict):
|
98
|
-
should_run, histosol, organic_soil_factor, land_occupation = _should_run(cycle)
|
99
|
-
return _run(histosol, organic_soil_factor, land_occupation) if should_run else []
|
@@ -1,49 +0,0 @@
|
|
1
|
-
import json
|
2
|
-
from unittest.mock import patch
|
3
|
-
from hestia_earth.schema import SiteSiteType
|
4
|
-
|
5
|
-
from hestia_earth.models.ipcc2006.co2ToAirOrganicSoilCultivation import MODEL, TERM_ID, _should_run, run
|
6
|
-
from tests.utils import fake_new_emission, fixtures_path
|
7
|
-
|
8
|
-
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
9
|
-
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
10
|
-
|
11
|
-
|
12
|
-
@patch(f"{class_path}.land_occupation_per_ha", return_value=10)
|
13
|
-
@patch(f"{class_path}.most_relevant_measurement_value", return_value=0)
|
14
|
-
def test_should_run(mock_measurement, *args):
|
15
|
-
cycle = {}
|
16
|
-
should_run, *args = _should_run(cycle)
|
17
|
-
assert not should_run
|
18
|
-
|
19
|
-
mock_measurement.return_value = 10
|
20
|
-
should_run, *args = _should_run(cycle)
|
21
|
-
assert not should_run
|
22
|
-
|
23
|
-
cycle = {"site": {"siteType": SiteSiteType.CROPLAND.value}}
|
24
|
-
should_run, *args = _should_run(cycle)
|
25
|
-
assert should_run is True
|
26
|
-
|
27
|
-
|
28
|
-
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
29
|
-
def test_run(*args):
|
30
|
-
with open(f"{fixtures_folder}/cycle.jsonld", encoding="utf-8") as f:
|
31
|
-
cycle = json.load(f)
|
32
|
-
|
33
|
-
with open(f"{fixtures_folder}/result.jsonld", encoding="utf-8") as f:
|
34
|
-
expected = json.load(f)
|
35
|
-
|
36
|
-
value = run(cycle)
|
37
|
-
assert value == expected
|
38
|
-
|
39
|
-
|
40
|
-
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
41
|
-
def test_run_pasture(*args):
|
42
|
-
with open(f"{fixtures_folder}/pasture/cycle.jsonld", encoding="utf-8") as f:
|
43
|
-
cycle = json.load(f)
|
44
|
-
|
45
|
-
with open(f"{fixtures_folder}/pasture/result.jsonld", encoding="utf-8") as f:
|
46
|
-
expected = json.load(f)
|
47
|
-
|
48
|
-
value = run(cycle)
|
49
|
-
assert value == expected
|
@@ -1,32 +0,0 @@
|
|
1
|
-
import json
|
2
|
-
from unittest.mock import patch
|
3
|
-
|
4
|
-
from hestia_earth.models.ipcc2006.n2OToAirOrganicSoilCultivationDirect import MODEL, TERM_ID, _should_run, run
|
5
|
-
from tests.utils import fake_new_emission, fixtures_path
|
6
|
-
|
7
|
-
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
8
|
-
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
9
|
-
|
10
|
-
|
11
|
-
@patch(f"{class_path}.land_occupation_per_ha", return_value=10)
|
12
|
-
@patch(f"{class_path}.most_relevant_measurement_value", return_value=0)
|
13
|
-
def test_should_run(mock_measurement, *args):
|
14
|
-
cycle = {}
|
15
|
-
should_run, *args = _should_run(cycle)
|
16
|
-
assert not should_run
|
17
|
-
|
18
|
-
mock_measurement.return_value = 10
|
19
|
-
should_run, *args = _should_run(cycle)
|
20
|
-
assert should_run is True
|
21
|
-
|
22
|
-
|
23
|
-
@patch(f"{class_path}._new_emission", side_effect=fake_new_emission)
|
24
|
-
def test_run(*args):
|
25
|
-
with open(f"{fixtures_folder}/cycle.jsonld", encoding="utf-8") as f:
|
26
|
-
cycle = json.load(f)
|
27
|
-
|
28
|
-
with open(f"{fixtures_folder}/result.jsonld", encoding="utf-8") as f:
|
29
|
-
expected = json.load(f)
|
30
|
-
|
31
|
-
value = run(cycle)
|
32
|
-
assert value == expected
|
File without changes
|
File without changes
|
File without changes
|