hestia-earth-models 0.64.13__py3-none-any.whl → 0.64.14__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/materialAndSubstrate.py +158 -0
- hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +2 -2
- hestia_earth/models/ipcc2019/ch4ToAirExcreta.py +1 -2
- hestia_earth/models/mocking/__init__.py +1 -1
- hestia_earth/models/mocking/search-results.json +1031 -1031
- hestia_earth/models/preload_requests.py +24 -4
- hestia_earth/models/utils/constant.py +3 -0
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.64.13.dist-info → hestia_earth_models-0.64.14.dist-info}/METADATA +1 -1
- {hestia_earth_models-0.64.13.dist-info → hestia_earth_models-0.64.14.dist-info}/RECORD +14 -12
- tests/models/cycle/test_materialsAndSubstrate.py +49 -0
- {hestia_earth_models-0.64.13.dist-info → hestia_earth_models-0.64.14.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.64.13.dist-info → hestia_earth_models-0.64.14.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.64.13.dist-info → hestia_earth_models-0.64.14.dist-info}/top_level.txt +0 -0
|
@@ -3,13 +3,31 @@ Preload all search requests to avoid making the same searches many times while r
|
|
|
3
3
|
"""
|
|
4
4
|
import json
|
|
5
5
|
import os
|
|
6
|
+
from hestia_earth.utils.storage import _load_from_storage
|
|
6
7
|
|
|
7
8
|
from .log import logger
|
|
8
9
|
from .mocking.build_mock_search import create_search_results
|
|
9
10
|
from .mocking import RESULTS_PATH, enable_mock as _mock
|
|
10
11
|
|
|
11
12
|
|
|
12
|
-
def
|
|
13
|
+
def _write_results(filepath: str, data: dict):
|
|
14
|
+
with open(filepath, 'w') as f:
|
|
15
|
+
f.write(json.dumps(data, indent=2, ensure_ascii=False))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _load_data_from_glossary():
|
|
19
|
+
try:
|
|
20
|
+
return json.loads(_load_from_storage(os.path.join('glossary', 'models-search-results.json'), glossary=True))
|
|
21
|
+
except Exception:
|
|
22
|
+
return None
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def enable_preload(
|
|
26
|
+
filepath: str = RESULTS_PATH,
|
|
27
|
+
node: dict = None,
|
|
28
|
+
overwrite_existing: bool = True,
|
|
29
|
+
use_glossary: bool = False
|
|
30
|
+
):
|
|
13
31
|
"""
|
|
14
32
|
Prefetch calls to HESTIA API in a local file.
|
|
15
33
|
|
|
@@ -22,6 +40,9 @@ def enable_preload(filepath: str = RESULTS_PATH, node: dict = None, overwrite_ex
|
|
|
22
40
|
overwrite_existing : bool
|
|
23
41
|
Optional - If the file already exists, the file can be used instead of generating it again.
|
|
24
42
|
Will overwrite by default.
|
|
43
|
+
use_glossary : bool
|
|
44
|
+
Optional - Try to fetch search results from the glossary.
|
|
45
|
+
Only available with access to HESTIA infrastructure.
|
|
25
46
|
"""
|
|
26
47
|
should_generate = overwrite_existing or not os.path.exists(filepath)
|
|
27
48
|
|
|
@@ -29,11 +50,10 @@ def enable_preload(filepath: str = RESULTS_PATH, node: dict = None, overwrite_ex
|
|
|
29
50
|
logger.debug('Preloading search results and storing in %s', filepath)
|
|
30
51
|
|
|
31
52
|
# build the search results
|
|
32
|
-
data = create_search_results()
|
|
53
|
+
data = (_load_data_from_glossary() if use_glossary else None) or create_search_results()
|
|
33
54
|
|
|
34
55
|
# store in file
|
|
35
|
-
|
|
36
|
-
f.write(json.dumps(data, indent=2, ensure_ascii=False))
|
|
56
|
+
_write_results(filepath, data)
|
|
37
57
|
|
|
38
58
|
# enable mock search results from file
|
|
39
59
|
_mock(filepath=filepath, node=node)
|
hestia_earth/models/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = '0.64.
|
|
1
|
+
VERSION = '0.64.14'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: hestia-earth-models
|
|
3
|
-
Version: 0.64.
|
|
3
|
+
Version: 0.64.14
|
|
4
4
|
Summary: HESTIA's set of modules for filling gaps in the activity data using external datasets (e.g. populating soil properties with a geospatial dataset using provided coordinates) and internal lookups (e.g. populating machinery use from fuel use). Includes rules for when gaps should be filled versus not (e.g. never gap fill yield, gap fill crop residue if yield provided etc.).
|
|
5
5
|
Home-page: https://gitlab.com/hestia-earth/hestia-engine-models
|
|
6
6
|
Author: HESTIA Team
|
|
@@ -2,9 +2,9 @@ hestia_earth/__init__.py,sha256=G-d438vPx7m_ks5e9XTtM3u7LDRO5dSSukibukWmyPM,56
|
|
|
2
2
|
hestia_earth/models/__init__.py,sha256=qEFeq3yuf3lQKVseALmL8aPM8fpCS54B_5pry00M3hk,76
|
|
3
3
|
hestia_earth/models/cache_sites.py,sha256=KQp9cUKE-aIcYJoMWEtKFYS8gBFfsx5LKQhqoWpUSoM,6065
|
|
4
4
|
hestia_earth/models/log.py,sha256=_zAfyOkL_VknEnMFvcpvenSMghadlDfZhiSx28545Gk,3558
|
|
5
|
-
hestia_earth/models/preload_requests.py,sha256=
|
|
5
|
+
hestia_earth/models/preload_requests.py,sha256=vK_G1UzhNMhYy7ymnCtHUz_vv3cfApCSKqv29VREEBQ,1943
|
|
6
6
|
hestia_earth/models/requirements.py,sha256=eU4yT443fx7BnaokhrLB_PCizJI7Y6m4auyo8vQauNg,17363
|
|
7
|
-
hestia_earth/models/version.py,sha256=
|
|
7
|
+
hestia_earth/models/version.py,sha256=4fHJn2y0KMV79wSdP8-3psf2aitG-bUGkvk9GQIo5qM,20
|
|
8
8
|
hestia_earth/models/agribalyse2016/__init__.py,sha256=WvK0qCQbnYtg9oZxrACd1wGormZyXibPtpCnIQeDqbw,415
|
|
9
9
|
hestia_earth/models/agribalyse2016/fuelElectricity.py,sha256=tnGxBmJdPfPFfehLUQcefEqy1lHvzsSpx_s7O8nf3Zs,4412
|
|
10
10
|
hestia_earth/models/agribalyse2016/machineryInfrastructureDepreciatedAmountPerCycle.py,sha256=BPjnWmg73i_OxM2ouCdMTWZtPIqyoUAXrvutntyteE0,3390
|
|
@@ -52,6 +52,7 @@ hestia_earth/models/cycle/inorganicFertiliser.py,sha256=Yt5NcP9FQEzWwlritrPGbhh2
|
|
|
52
52
|
hestia_earth/models/cycle/irrigatedTypeUnspecified.py,sha256=KlIa5eDvT47Twz6Q1kpw0rMlRjCK25CExaW58DEvc9w,2125
|
|
53
53
|
hestia_earth/models/cycle/liveAnimal.py,sha256=5dlvuVAu24hLLOVXsozcVzWyDVzddzoungUBwrBDS-g,3986
|
|
54
54
|
hestia_earth/models/cycle/longFallowRatio.py,sha256=_h0kub99sACO87IfjMeiu8IgdK2jaeBlgGA9A9-ViZA,1683
|
|
55
|
+
hestia_earth/models/cycle/materialAndSubstrate.py,sha256=PaTnS3QVxGEMLMn4nuWHYp8npiZjDaDijRJHoUoRV40,5184
|
|
55
56
|
hestia_earth/models/cycle/milkYield.py,sha256=JUwKK9gwXZiir7YK7_tOuV3B4Aml0LnJszfCA3Ygh3o,5816
|
|
56
57
|
hestia_earth/models/cycle/otherSitesArea.py,sha256=Xhi6C1K1v4VXv1Mhkg-b9JCAG-DfTQoEi9ICs71418w,1650
|
|
57
58
|
hestia_earth/models/cycle/otherSitesUnusedDuration.py,sha256=ZqQaI9FvNVpONmsIiRo1BqSJJKC5Mgi-W6lt18sxTiA,2985
|
|
@@ -252,8 +253,8 @@ hestia_earth/models/ipcc2019/belowGroundCropResidue.py,sha256=7AFU2Q0qPAvv6uEKWB
|
|
|
252
253
|
hestia_earth/models/ipcc2019/biomass_utils.py,sha256=aMdAO-Ssfy1DKaNg19G9ea3z18MbfV6coqQjPu6Tu90,15584
|
|
253
254
|
hestia_earth/models/ipcc2019/carbonContent.py,sha256=tlQvu4Auhpjmaz7XrZz86xwxVrJhsYYf8DFA_aQeev4,7255
|
|
254
255
|
hestia_earth/models/ipcc2019/ch4ToAirAquacultureSystems.py,sha256=q6yyEiYQhHJ2VyQy2Fa84cuTl1D8bjBXOK3UpaRuo20,3196
|
|
255
|
-
hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py,sha256=
|
|
256
|
-
hestia_earth/models/ipcc2019/ch4ToAirExcreta.py,sha256=
|
|
256
|
+
hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py,sha256=JmvKP9n3IPO4RkGQ8o7aJ4axuJV_WKDRCFNR_AOmdyM,11685
|
|
257
|
+
hestia_earth/models/ipcc2019/ch4ToAirExcreta.py,sha256=WnKmSQSqr1Jv7_95DLgtufPYGN5TeV3eDcFV3btDoq8,6706
|
|
257
258
|
hestia_earth/models/ipcc2019/ch4ToAirFloodedRice.py,sha256=TJ4J7VA5n4RPrJYZQeR3lc3ZoCw7T1E5Cb1XJewr834,7331
|
|
258
259
|
hestia_earth/models/ipcc2019/co2ToAirAboveGroundBiomassStockChange.py,sha256=fefPcxy7TTG-33dgZecDppMroUAmKoluhomyLuRqQiU,6545
|
|
259
260
|
hestia_earth/models/ipcc2019/co2ToAirBelowGroundBiomassStockChange.py,sha256=l5Mrb8non9JjQhpWMzqHHK7FAjYPuWUzIwa08zdBUpo,6595
|
|
@@ -407,10 +408,10 @@ hestia_earth/models/linkedImpactAssessment/landTransformationFromOtherNaturalVeg
|
|
|
407
408
|
hestia_earth/models/linkedImpactAssessment/landTransformationFromPermanentPasture100YearAverageInputsProduction.py,sha256=7btlXl5PL47qIjfs-w_xLZY_nsRnJAwTREtt8LpY6UI,1052
|
|
408
409
|
hestia_earth/models/linkedImpactAssessment/landTransformationFromPermanentPasture20YearAverageInputsProduction.py,sha256=pdluhfRQuJK0EHq-L0s0TOf37tvOQYB-M-wZiuSbarw,1050
|
|
409
410
|
hestia_earth/models/linkedImpactAssessment/utils.py,sha256=dGwGc2d-8_WQElTpfyPmz5vQtL-LHQRmiZnCTuPXMDs,1876
|
|
410
|
-
hestia_earth/models/mocking/__init__.py,sha256=
|
|
411
|
+
hestia_earth/models/mocking/__init__.py,sha256=9VX50c-grz-snfd-7MBS0KfF7AadtbKuj7kK6PqtsgE,687
|
|
411
412
|
hestia_earth/models/mocking/build_mock_search.py,sha256=p15ccEUmkmLp1RiGNznxMz3OFHbI8P1-29ExuohiQN8,1355
|
|
412
413
|
hestia_earth/models/mocking/mock_search.py,sha256=ccFe_WrI73JElFmxp4hPNLCX7eeU--lBC1JFR901KJY,1069
|
|
413
|
-
hestia_earth/models/mocking/search-results.json,sha256=
|
|
414
|
+
hestia_earth/models/mocking/search-results.json,sha256=Ed4ijfv2ta8OS8JLWAIGp7Wj6RBZGDjymyTHt1EUGYQ,101690
|
|
414
415
|
hestia_earth/models/pooreNemecek2018/__init__.py,sha256=nPboL7ULJzL5nJD5q7q9VOZt_fxbKVm8fmn1Az5YkVY,417
|
|
415
416
|
hestia_earth/models/pooreNemecek2018/aboveGroundCropResidueTotal.py,sha256=Qt-mel4dkhK6N5uUOutNOinCTFjbjtGzITaaI0LvYc4,2396
|
|
416
417
|
hestia_earth/models/pooreNemecek2018/belowGroundCropResidue.py,sha256=JT0RybbvWVlo01FO8K0Yj41HrEaJT3Kj1xfayr2X-xw,2315
|
|
@@ -577,7 +578,7 @@ hestia_earth/models/utils/aquacultureManagement.py,sha256=dxrbC1Xf140cohxTbSw6Tx
|
|
|
577
578
|
hestia_earth/models/utils/array_builders.py,sha256=QEkM7e75Y9aq5yEPEk3R8md36IuvCDkpekdGm3uA0uk,19397
|
|
578
579
|
hestia_earth/models/utils/blank_node.py,sha256=jLUWV0BZVX7NZ4Eo8pP5avV3QqI1HvvoHOAzNtfRe_E,50618
|
|
579
580
|
hestia_earth/models/utils/completeness.py,sha256=2-GusD9UycobDZq8y5jar0ZcOjyqnSbzPRT_5XMc4YA,1259
|
|
580
|
-
hestia_earth/models/utils/constant.py,sha256=
|
|
581
|
+
hestia_earth/models/utils/constant.py,sha256=6wLx8xb2R8HtpEpVy5e-PbioOo7QCu2n-W72fs6OvgE,3411
|
|
581
582
|
hestia_earth/models/utils/crop.py,sha256=5KigEHd15nT8O9_1woxKJF5rEWiSkIkJqDAXet8BB9g,2383
|
|
582
583
|
hestia_earth/models/utils/cropResidue.py,sha256=_0Q35CrliJeo31xGHsPWe8A2oHxijdIsOrf3gBEqhlA,612
|
|
583
584
|
hestia_earth/models/utils/cropResidueManagement.py,sha256=nIDFjf39rDD10UHSVudfDyu-EiL261g8jyrgS-2aDKw,347
|
|
@@ -667,6 +668,7 @@ tests/models/cycle/test_inorganicFertiliser.py,sha256=c-JDYC0qDK4JWlYDaGX53AcKfe
|
|
|
667
668
|
tests/models/cycle/test_irrigatedTypeUnspecified.py,sha256=9YGwpDO_RHMaldvjJZ0xdrdfUzYDnLPt6nMJ2eRXSTI,2151
|
|
668
669
|
tests/models/cycle/test_liveAnimal.py,sha256=rKcd4GKl9kKlp4bft3HEr58Btv-cPQq94XdAL9O1ky8,2138
|
|
669
670
|
tests/models/cycle/test_longFallowRatio.py,sha256=sztr1pysldwedTC78JWUHAVWl2oL0jTIQ13c6Nxzlso,1512
|
|
671
|
+
tests/models/cycle/test_materialsAndSubstrate.py,sha256=pYaNZiLVmmogAebUZjOri41pa7k78gjy7OOD8OXm4bk,1429
|
|
670
672
|
tests/models/cycle/test_milkYield.py,sha256=gl0e9O0idVT6ld9mGc--EYWTJo452C2HOzGzHKrsq_g,1777
|
|
671
673
|
tests/models/cycle/test_otherSitesArea.py,sha256=Mop7guZXEyX4ZFOBpqzsbu-cuaBFAqfIRZhe-WEvVwc,2131
|
|
672
674
|
tests/models/cycle/test_otherSitesUnusedDuration.py,sha256=zQejrYNwq14Pwe3d0zmfhxjdif5s_udbdVCiZcTuC8w,1635
|
|
@@ -1181,8 +1183,8 @@ tests/models/utils/test_term.py,sha256=M5Sa26v2gzQYbZ4H_fo7DspnaCx__-WtL-MULGapC
|
|
|
1181
1183
|
tests/models/utils/test_time_series.py,sha256=LMhRPf8rp3nAriKAC-2K3FDkrMWntRTUUCERw7Lt68g,2686
|
|
1182
1184
|
tests/models/webbEtAl2012AndSintermannEtAl2012/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
1183
1185
|
tests/models/webbEtAl2012AndSintermannEtAl2012/test_nh3ToAirOrganicFertiliser.py,sha256=qi2FNXS5Af2WDtm7nq_FsprH3BfCF0XxnE0XHmC4aIY,2244
|
|
1184
|
-
hestia_earth_models-0.64.
|
|
1185
|
-
hestia_earth_models-0.64.
|
|
1186
|
-
hestia_earth_models-0.64.
|
|
1187
|
-
hestia_earth_models-0.64.
|
|
1188
|
-
hestia_earth_models-0.64.
|
|
1186
|
+
hestia_earth_models-0.64.14.dist-info/LICENSE,sha256=AC7h7GAgCZGJK_Tzh6LUCrML9gQEfowWwecEw2w54QM,1154
|
|
1187
|
+
hestia_earth_models-0.64.14.dist-info/METADATA,sha256=1pXWSGo_8_6-tjNKemoxLZb9wQa56Mbsu30jzIt84v8,3345
|
|
1188
|
+
hestia_earth_models-0.64.14.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
1189
|
+
hestia_earth_models-0.64.14.dist-info/top_level.txt,sha256=1dqA9TqpOLTEgpqa-YBsmbCmmNU1y56AtfFGEceZ2A0,19
|
|
1190
|
+
hestia_earth_models-0.64.14.dist-info/RECORD,,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
import json
|
|
3
|
+
import pytest
|
|
4
|
+
from hestia_earth.utils.tools import to_precision
|
|
5
|
+
|
|
6
|
+
from tests.utils import fixtures_path, fake_new_input
|
|
7
|
+
from hestia_earth.models.cycle.materialAndSubstrate import MODEL, MODEL_KEY, run, calculate_value
|
|
8
|
+
|
|
9
|
+
class_path = f"hestia_earth.models.{MODEL}.{MODEL_KEY}"
|
|
10
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{MODEL_KEY}"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@pytest.mark.parametrize(
|
|
14
|
+
"input_node,cycle_duration,expected_result,test_name",
|
|
15
|
+
[
|
|
16
|
+
(
|
|
17
|
+
{"lifespan": 3, "value": [150]},
|
|
18
|
+
200,
|
|
19
|
+
27.4,
|
|
20
|
+
"lifespan, value and duration"
|
|
21
|
+
),
|
|
22
|
+
(
|
|
23
|
+
{"lifespan": 5},
|
|
24
|
+
200,
|
|
25
|
+
None,
|
|
26
|
+
"missing value"
|
|
27
|
+
),
|
|
28
|
+
]
|
|
29
|
+
)
|
|
30
|
+
def test_calculate_value(input_node, cycle_duration, expected_result, test_name):
|
|
31
|
+
result = calculate_value(
|
|
32
|
+
input_node=input_node,
|
|
33
|
+
field_name="value",
|
|
34
|
+
cycle_duration=cycle_duration
|
|
35
|
+
)
|
|
36
|
+
rounded_result = to_precision(result, 3) if result is not None else None
|
|
37
|
+
assert rounded_result == expected_result, test_name
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@patch(f"{class_path}._new_input", side_effect=fake_new_input)
|
|
41
|
+
def test_run(*args):
|
|
42
|
+
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
|
43
|
+
site = json.load(f)
|
|
44
|
+
|
|
45
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
|
46
|
+
expected = json.load(f)
|
|
47
|
+
|
|
48
|
+
result = run(site)
|
|
49
|
+
assert result == expected
|
|
File without changes
|
|
File without changes
|
{hestia_earth_models-0.64.13.dist-info → hestia_earth_models-0.64.14.dist-info}/top_level.txt
RENAMED
|
File without changes
|