hestia-earth-models 0.60.0__py3-none-any.whl → 0.60.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.
Potentially problematic release.
This version of hestia-earth-models might be problematic. Click here for more details.
- hestia_earth/models/cache_sites.py +41 -19
- hestia_earth/models/mocking/search-results.json +1 -1
- hestia_earth/models/site/pre_checks/cache_geospatialDatabase.py +2 -2
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.60.0.dist-info → hestia_earth_models-0.60.1.dist-info}/METADATA +1 -1
- {hestia_earth_models-0.60.0.dist-info → hestia_earth_models-0.60.1.dist-info}/RECORD +10 -10
- tests/models/test_cache_sites.py +0 -12
- {hestia_earth_models-0.60.0.dist-info → hestia_earth_models-0.60.1.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.60.0.dist-info → hestia_earth_models-0.60.1.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.60.0.dist-info → hestia_earth_models-0.60.1.dist-info}/top_level.txt +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from functools import reduce
|
|
2
2
|
from enum import Enum
|
|
3
|
+
from pydash.objects import merge
|
|
3
4
|
from hestia_earth.utils.api import download_hestia
|
|
4
5
|
from hestia_earth.utils.tools import flatten
|
|
5
6
|
|
|
@@ -64,12 +65,13 @@ def _run_values(sites: list, param_type: ParamType, rasters: list = [], vectors:
|
|
|
64
65
|
**_cache_results(raster_results, rasters, index),
|
|
65
66
|
**_cache_results(vector_results, vectors, index)
|
|
66
67
|
} | ({CACHE_AREA_SIZE: area_size} if area_size is not None else {})
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
CACHE_KEY
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
cached_data = merge(cached_value(site, CACHE_GEOSPATIAL_KEY, {}), cached_data)
|
|
69
|
+
site_cache = merge(
|
|
70
|
+
site.get(CACHE_KEY, {}),
|
|
71
|
+
{CACHE_GEOSPATIAL_KEY: cached_data},
|
|
72
|
+
({CACHE_YEARS_KEY: cached_value(site, CACHE_YEARS_KEY, []) + years} if years else {})
|
|
73
|
+
)
|
|
74
|
+
return merge(site, {CACHE_KEY: site_cache})
|
|
73
75
|
|
|
74
76
|
return reduce(lambda prev, curr: prev + [_process_site(curr)], sites, [])
|
|
75
77
|
|
|
@@ -82,7 +84,7 @@ def _preload_regions_area_size(sites: dict):
|
|
|
82
84
|
return {term_id: download_hestia(term_id).get('area') for term_id in region_ids}
|
|
83
85
|
|
|
84
86
|
|
|
85
|
-
def _group_sites(sites: dict):
|
|
87
|
+
def _group_sites(sites: dict, check_has_cache: bool = True):
|
|
86
88
|
# preload area size for all regions
|
|
87
89
|
regions_area_size = _preload_regions_area_size(sites)
|
|
88
90
|
|
|
@@ -90,7 +92,7 @@ def _group_sites(sites: dict):
|
|
|
90
92
|
return regions_area_size.get(_site_gadm_id(site)) if _should_preload_region_area_size(site) else None
|
|
91
93
|
|
|
92
94
|
sites = [
|
|
93
|
-
(n, ) + (_should_run(n, get_region_area_size(n))) for n in sites
|
|
95
|
+
(n, ) + (_should_run(n, area_size=get_region_area_size(n), check_has_cache=check_has_cache)) for n in sites
|
|
94
96
|
]
|
|
95
97
|
# restrict sites based on should_cache result
|
|
96
98
|
sites = [(site, area_size) for site, should_cache, area_size in sites if should_cache]
|
|
@@ -112,7 +114,25 @@ def _group_sites(sites: dict):
|
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
|
|
115
|
-
def
|
|
117
|
+
def _run(sites: list, years: list, include_region: bool, years_only: bool = False):
|
|
118
|
+
rasters, vectors = list_collections(years, include_region, years_only)
|
|
119
|
+
filtered_data = _group_sites(sites, not years_only)
|
|
120
|
+
return flatten([
|
|
121
|
+
_run_values(filtered_data.get(param_type), param_type, rasters, vectors, years)
|
|
122
|
+
for param_type in [e for e in ParamType] if len(filtered_data.get(param_type)) > 0
|
|
123
|
+
])
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _group_years(years: list, years_range: int):
|
|
127
|
+
batches = sorted(list(set(list(range(years[0], years[-1] + 1, years_range)) + [years[0], years[-1]])))
|
|
128
|
+
grouped_batches = [batches[i:i+2] for i in range(0, len(batches))]
|
|
129
|
+
return [
|
|
130
|
+
# make sure we don't overlap
|
|
131
|
+
[v[0] + (0 if v[0] == years[0] else 1), v[1]] for v in grouped_batches if len(v) == 2
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def run(sites: list, years: list = None, include_region: bool = False):
|
|
116
136
|
"""
|
|
117
137
|
Run all queries at once for the list of provided Sites.
|
|
118
138
|
Note: Earth Engine needs to be initiliased with `init_gee()` before running this function.
|
|
@@ -126,14 +146,16 @@ def run(sites: list, years: list = None, include_region: bool = False, years_onl
|
|
|
126
146
|
include_region : bool
|
|
127
147
|
Prefecth region IDs.
|
|
128
148
|
This will cache region-level data and will make the request slower. Only use if needed.
|
|
129
|
-
years_only : bool
|
|
130
|
-
Run only the collections that depend on the years (if provided).
|
|
131
149
|
"""
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
150
|
+
try:
|
|
151
|
+
return _run(sites, years, include_region)
|
|
152
|
+
except Exception as e:
|
|
153
|
+
# when querying with multiple years, we can reach a compute memory limit, so run the years separately
|
|
154
|
+
if str(e) == 'User memory limit exceeded.' and years:
|
|
155
|
+
sites = _run(sites, [], include_region)
|
|
156
|
+
# query for subranges
|
|
157
|
+
for sub_years in _group_years(years, years_range=5):
|
|
158
|
+
sites = _run(sites, sub_years, include_region, years_only=True)
|
|
159
|
+
return sites
|
|
160
|
+
|
|
161
|
+
return []
|
|
@@ -125,11 +125,11 @@ def _cache_results(site: dict, area_size: float):
|
|
|
125
125
|
return cache_site_results(raster_results + vector_results, rasters + vectors, area_size)
|
|
126
126
|
|
|
127
127
|
|
|
128
|
-
def _should_run(site: dict, area_size: float = None):
|
|
128
|
+
def _should_run(site: dict, area_size: float = None, check_has_cache: bool = True):
|
|
129
129
|
area_size = area_size or get_area_size(site)
|
|
130
130
|
contains_geospatial_data = has_geospatial_data(site)
|
|
131
131
|
contains_coordinates = has_coordinates(site)
|
|
132
|
-
has_cache = cached_value(site, CACHE_VALUE) is not None
|
|
132
|
+
has_cache = check_has_cache and cached_value(site, CACHE_VALUE) is not None
|
|
133
133
|
|
|
134
134
|
debugValues(site,
|
|
135
135
|
area_size=area_size,
|
hestia_earth/models/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = '0.60.
|
|
1
|
+
VERSION = '0.60.1'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: hestia-earth-models
|
|
3
|
-
Version: 0.60.
|
|
3
|
+
Version: 0.60.1
|
|
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
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
hestia_earth/__init__.py,sha256=G-d438vPx7m_ks5e9XTtM3u7LDRO5dSSukibukWmyPM,56
|
|
2
2
|
hestia_earth/models/__init__.py,sha256=qEFeq3yuf3lQKVseALmL8aPM8fpCS54B_5pry00M3hk,76
|
|
3
|
-
hestia_earth/models/cache_sites.py,sha256=
|
|
3
|
+
hestia_earth/models/cache_sites.py,sha256=KQp9cUKE-aIcYJoMWEtKFYS8gBFfsx5LKQhqoWpUSoM,6065
|
|
4
4
|
hestia_earth/models/log.py,sha256=b63I3qyTtQs17xxbq8RI0Fv2lvZ1oDZ9k0njhxqiFFk,3459
|
|
5
5
|
hestia_earth/models/requirements.py,sha256=znNZJAhwX2iYiKcAQXPftY7z_1MsNa0QxCXkXyHm_U0,17363
|
|
6
|
-
hestia_earth/models/version.py,sha256=
|
|
6
|
+
hestia_earth/models/version.py,sha256=jkZGW0WUYUex4V7qv5qCaUMLtL80ETv20-KbHpaM3KA,19
|
|
7
7
|
hestia_earth/models/agribalyse2016/__init__.py,sha256=WvK0qCQbnYtg9oZxrACd1wGormZyXibPtpCnIQeDqbw,415
|
|
8
8
|
hestia_earth/models/agribalyse2016/fuelElectricity.py,sha256=mrh8seYSYdTgcMDCETLiknuPeJehg071YoG4UiyW0yU,4404
|
|
9
9
|
hestia_earth/models/agribalyse2016/machineryInfrastructureDepreciatedAmountPerCycle.py,sha256=_Rbngu0DzHKa62JwBl58ZC_ui1zLF2que_nB7ukhOQc,3392
|
|
@@ -356,7 +356,7 @@ hestia_earth/models/lcImpactCertainEffectsInfinite/damageToTerrestrialEcosystems
|
|
|
356
356
|
hestia_earth/models/linkedImpactAssessment/__init__.py,sha256=d19wzr4GnWXpMWRhchqwp3S8txrUkpIWrGPwnWdXhjI,6236
|
|
357
357
|
hestia_earth/models/mocking/__init__.py,sha256=kmSeOTSvurMUxw7Ajhf3G-SVPQ1NgmirMTk4TSOEicY,765
|
|
358
358
|
hestia_earth/models/mocking/mock_search.py,sha256=V-ycVBTkJu7PP37Ivy_16hpKBV4aEtJb5S9DfChPNSU,2038
|
|
359
|
-
hestia_earth/models/mocking/search-results.json,sha256=
|
|
359
|
+
hestia_earth/models/mocking/search-results.json,sha256=d8oBES7NajlmrvfYZUeyGhDJsOQIOXQlY4ky6lsmoZ8,39547
|
|
360
360
|
hestia_earth/models/pooreNemecek2018/__init__.py,sha256=nPboL7ULJzL5nJD5q7q9VOZt_fxbKVm8fmn1Az5YkVY,417
|
|
361
361
|
hestia_earth/models/pooreNemecek2018/aboveGroundCropResidueTotal.py,sha256=Qt-mel4dkhK6N5uUOutNOinCTFjbjtGzITaaI0LvYc4,2396
|
|
362
362
|
hestia_earth/models/pooreNemecek2018/belowGroundCropResidue.py,sha256=JT0RybbvWVlo01FO8K0Yj41HrEaJT3Kj1xfayr2X-xw,2315
|
|
@@ -476,7 +476,7 @@ hestia_earth/models/site/measurement/value.py,sha256=7IhUbIj7n5vB7yXoNxXsWbliEJj
|
|
|
476
476
|
hestia_earth/models/site/post_checks/__init__.py,sha256=CkExxesk1GuG8NjrbKfix1iDuVUgU-9i1ccM_X7MZn4,284
|
|
477
477
|
hestia_earth/models/site/post_checks/cache.py,sha256=_MZsNsclecUdHDT2MsYx4cEsVUXydIasddgZNA6SU4k,284
|
|
478
478
|
hestia_earth/models/site/pre_checks/__init__.py,sha256=fjv6nU5fiL-CLyaa-cBpiLB-xujgPzeK7i7ZJuTOjCI,394
|
|
479
|
-
hestia_earth/models/site/pre_checks/cache_geospatialDatabase.py,sha256=
|
|
479
|
+
hestia_earth/models/site/pre_checks/cache_geospatialDatabase.py,sha256=MoQ76e0S63uvoFhqBbhG0GuoJ9bZgX_vrXz2_Id44Jw,5290
|
|
480
480
|
hestia_earth/models/site/pre_checks/cache_sources.py,sha256=RzvSgHJTpVkAB3mEvRju_irDQmdJRK7GUdU6PhS2Gaw,904
|
|
481
481
|
hestia_earth/models/site/pre_checks/cache_years.py,sha256=qGwTaHlWxnVT7iVxXVcpJ-oG6M-VH4ZpCDTdTixUHR4,883
|
|
482
482
|
hestia_earth/models/stehfestBouwman2006/__init__.py,sha256=EhvD4NK6oEPevusLb1WdYV3GT_fCtQx4gvdMhK_dEIQ,420
|
|
@@ -546,7 +546,7 @@ hestia_earth/models/utils/transformation.py,sha256=nyT5Mz4_VgFwhkL8JoNX9kxxow0zu
|
|
|
546
546
|
hestia_earth/models/webbEtAl2012AndSintermannEtAl2012/__init__.py,sha256=Niv7ZFMBCwThlbCKGOwA17QdkpOUDFrqrFItGNqnZAA,434
|
|
547
547
|
hestia_earth/models/webbEtAl2012AndSintermannEtAl2012/nh3ToAirOrganicFertiliser.py,sha256=G2eq00XGdr1ZEZ5Ru1nBIR-sD7iM9hGYhvk8r5wL3dA,3910
|
|
548
548
|
tests/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
549
|
-
tests/models/test_cache_sites.py,sha256=
|
|
549
|
+
tests/models/test_cache_sites.py,sha256=AsZSGb4ruFqag74wRaQxpoZxbMxexPY8q8sMb2ergzg,1986
|
|
550
550
|
tests/models/test_ecoinventV3.py,sha256=zyIWeeS7VndjXAHcROhDi3E0I52U8uQu8u-t1EXwqW8,1492
|
|
551
551
|
tests/models/test_emissionNotRelevant.py,sha256=YXTdRfcdR_JepHuj2P3Y3r0aFMKNOmsXQHY48tmLTQo,1316
|
|
552
552
|
tests/models/test_linkedImpactAssessment.py,sha256=RiBNTF34GMA5YsuJ0MAsEPhMuHNC2W0Qq9YnWYDpXM4,1172
|
|
@@ -1054,8 +1054,8 @@ tests/models/utils/test_source.py,sha256=mv3vHZV5cjpoLA2I1109-YUkuzAiuhbRSnv_76_
|
|
|
1054
1054
|
tests/models/utils/test_term.py,sha256=M5Sa26v2gzQYbZ4H_fo7DspnaCx__-WtL-MULGapCWk,3509
|
|
1055
1055
|
tests/models/webbEtAl2012AndSintermannEtAl2012/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
1056
1056
|
tests/models/webbEtAl2012AndSintermannEtAl2012/test_nh3ToAirOrganicFertiliser.py,sha256=qi2FNXS5Af2WDtm7nq_FsprH3BfCF0XxnE0XHmC4aIY,2244
|
|
1057
|
-
hestia_earth_models-0.60.
|
|
1058
|
-
hestia_earth_models-0.60.
|
|
1059
|
-
hestia_earth_models-0.60.
|
|
1060
|
-
hestia_earth_models-0.60.
|
|
1061
|
-
hestia_earth_models-0.60.
|
|
1057
|
+
hestia_earth_models-0.60.1.dist-info/LICENSE,sha256=AC7h7GAgCZGJK_Tzh6LUCrML9gQEfowWwecEw2w54QM,1154
|
|
1058
|
+
hestia_earth_models-0.60.1.dist-info/METADATA,sha256=tJULz_gVDoPAkvfkSD8ooAES548NXNxa4hQkQ_sS2WM,3134
|
|
1059
|
+
hestia_earth_models-0.60.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
1060
|
+
hestia_earth_models-0.60.1.dist-info/top_level.txt,sha256=1dqA9TqpOLTEgpqa-YBsmbCmmNU1y56AtfFGEceZ2A0,19
|
|
1061
|
+
hestia_earth_models-0.60.1.dist-info/RECORD,,
|
tests/models/test_cache_sites.py
CHANGED
|
@@ -57,15 +57,3 @@ def test_run_include_region(mock_run_query, *args):
|
|
|
57
57
|
"coordinates": coordinates
|
|
58
58
|
})
|
|
59
59
|
])
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
@patch(f"{class_path}._run_query", return_value=[10] * 100)
|
|
63
|
-
def test_run_years_only(*args):
|
|
64
|
-
with open(f"{fixtures_folder}/data.json", encoding='utf-8') as f:
|
|
65
|
-
data = json.load(f)
|
|
66
|
-
with open(f"{fixtures_folder}/years-only/cache.json", encoding='utf-8') as f:
|
|
67
|
-
cache = json.load(f)
|
|
68
|
-
|
|
69
|
-
sites = run(data.get('nodes', []), [2019, 2020], years_only=True)
|
|
70
|
-
expected = [site | {'_cache': cache} for site in data.get('nodes', [])]
|
|
71
|
-
assert sites == expected
|
|
File without changes
|
|
File without changes
|
|
File without changes
|