hestia-earth-models 0.71.0__py3-none-any.whl → 0.72.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/config/Site.json +8 -0
- hestia_earth/models/geospatialDatabase/histosol.py +14 -7
- hestia_earth/models/hestia/histosol.py +53 -0
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1.py +22 -7
- hestia_earth/models/mocking/search-results.json +1177 -1177
- hestia_earth/models/utils/aggregated.py +3 -3
- hestia_earth/models/utils/measurement.py +16 -3
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.71.0.dist-info → hestia_earth_models-0.72.0.dist-info}/METADATA +2 -2
- {hestia_earth_models-0.71.0.dist-info → hestia_earth_models-0.72.0.dist-info}/RECORD +16 -14
- tests/models/geospatialDatabase/test_histosol.py +21 -20
- tests/models/hestia/test_histosol.py +24 -0
- tests/models/ipcc2019/test_organicCarbonPerHa_tier_1.py +4 -3
- {hestia_earth_models-0.71.0.dist-info → hestia_earth_models-0.72.0.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.71.0.dist-info → hestia_earth_models-0.72.0.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.71.0.dist-info → hestia_earth_models-0.72.0.dist-info}/top_level.txt +0 -0
@@ -88,6 +88,14 @@
|
|
88
88
|
"runStrategy": "add_blank_node_if_missing",
|
89
89
|
"mergeStrategy": "list",
|
90
90
|
"stage": 1
|
91
|
+
},
|
92
|
+
{
|
93
|
+
"key": "measurements",
|
94
|
+
"model": "hestia",
|
95
|
+
"value": "histosol",
|
96
|
+
"runStrategy": "add_blank_node_if_missing",
|
97
|
+
"mergeStrategy": "list",
|
98
|
+
"stage": 1
|
91
99
|
}
|
92
100
|
],
|
93
101
|
[
|
@@ -1,7 +1,7 @@
|
|
1
|
-
from hestia_earth.schema import MeasurementMethodClassification
|
1
|
+
from hestia_earth.schema import MeasurementMethodClassification
|
2
2
|
|
3
3
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
4
|
-
from hestia_earth.models.utils.measurement import _new_measurement
|
4
|
+
from hestia_earth.models.utils.measurement import _new_measurement, total_other_soilType_value
|
5
5
|
from hestia_earth.models.utils.source import get_source
|
6
6
|
from .utils import download, has_geospatial_data, should_download
|
7
7
|
from . import MODEL
|
@@ -14,7 +14,13 @@ REQUIREMENTS = {
|
|
14
14
|
{"region": {"@type": "Term", "termType": "region"}}
|
15
15
|
],
|
16
16
|
"none": {
|
17
|
-
"measurements": [{
|
17
|
+
"measurements": [{
|
18
|
+
"@type": "Measurement",
|
19
|
+
"value": "100",
|
20
|
+
"depthUpper": "0",
|
21
|
+
"depthLower": "30",
|
22
|
+
"term.termType": "soilType"
|
23
|
+
}]
|
18
24
|
}
|
19
25
|
}
|
20
26
|
}
|
@@ -50,17 +56,18 @@ def _run(site: dict):
|
|
50
56
|
|
51
57
|
|
52
58
|
def _should_run(site: dict):
|
53
|
-
measurements = site.get('measurements', [])
|
54
|
-
no_soil_type = all([m.get('term', {}).get('termType') != TermTermType.SOILTYPE.value for m in measurements])
|
55
59
|
contains_geospatial_data = has_geospatial_data(site)
|
56
60
|
below_max_area_size = should_download(TERM_ID, site)
|
57
61
|
|
62
|
+
total_measurements_value = total_other_soilType_value(site.get('measurements', []), TERM_ID)
|
63
|
+
|
58
64
|
logRequirements(site, model=MODEL, term=TERM_ID,
|
59
65
|
contains_geospatial_data=contains_geospatial_data,
|
60
66
|
below_max_area_size=below_max_area_size,
|
61
|
-
|
67
|
+
total_soilType_measurements_value=total_measurements_value,
|
68
|
+
total_soilType_measurements_value_is_0=total_measurements_value == 0)
|
62
69
|
|
63
|
-
should_run = all([contains_geospatial_data, below_max_area_size,
|
70
|
+
should_run = all([contains_geospatial_data, below_max_area_size, total_measurements_value == 0])
|
64
71
|
logShouldRun(site, MODEL, TERM_ID, should_run)
|
65
72
|
return should_run
|
66
73
|
|
@@ -0,0 +1,53 @@
|
|
1
|
+
from hestia_earth.schema import MeasurementMethodClassification
|
2
|
+
|
3
|
+
from hestia_earth.models.log import logRequirements, logShouldRun
|
4
|
+
from hestia_earth.models.utils.measurement import _new_measurement, total_other_soilType_value
|
5
|
+
from . import MODEL
|
6
|
+
|
7
|
+
REQUIREMENTS = {
|
8
|
+
"Site": {
|
9
|
+
"measurements": [{
|
10
|
+
"@type": "Measurement",
|
11
|
+
"value": "100",
|
12
|
+
"depthUpper": "0",
|
13
|
+
"depthLower": "30",
|
14
|
+
"term.termType": "soilType"
|
15
|
+
}]
|
16
|
+
}
|
17
|
+
}
|
18
|
+
RETURNS = {
|
19
|
+
"Measurement": [{
|
20
|
+
"value": "0",
|
21
|
+
"depthUpper": "0",
|
22
|
+
"depthLower": "30",
|
23
|
+
"methodClassification": "modelled using other measurements"
|
24
|
+
}]
|
25
|
+
}
|
26
|
+
LOOKUPS = {
|
27
|
+
"soilType": "sumMax100Group"
|
28
|
+
}
|
29
|
+
TERM_ID = 'histosol'
|
30
|
+
|
31
|
+
|
32
|
+
def _measurement():
|
33
|
+
measurement = _new_measurement(TERM_ID)
|
34
|
+
measurement['value'] = [0]
|
35
|
+
measurement['depthUpper'] = 0
|
36
|
+
measurement['depthLower'] = 30
|
37
|
+
measurement['methodClassification'] = MeasurementMethodClassification.MODELLED_USING_OTHER_MEASUREMENTS.value
|
38
|
+
return measurement
|
39
|
+
|
40
|
+
|
41
|
+
def _should_run(site: dict):
|
42
|
+
total_measurements_value = total_other_soilType_value(site.get('measurements', []), TERM_ID)
|
43
|
+
|
44
|
+
logRequirements(site, model=MODEL, term=TERM_ID,
|
45
|
+
total_soilType_measurements_value=total_measurements_value,
|
46
|
+
total_soilType_measurements_value_is_100=total_measurements_value == 100)
|
47
|
+
|
48
|
+
should_run = all([total_measurements_value == 100])
|
49
|
+
logShouldRun(site, MODEL, TERM_ID, should_run)
|
50
|
+
return should_run
|
51
|
+
|
52
|
+
|
53
|
+
def run(site: dict): return [_measurement()] if _should_run(site) else []
|
@@ -3,17 +3,18 @@ from functools import reduce
|
|
3
3
|
from numpy import empty_like, random, vstack
|
4
4
|
from numpy.typing import NDArray
|
5
5
|
from pydash.objects import merge
|
6
|
-
from typing import Callable, Optional, Union
|
6
|
+
from typing import Callable, Literal, Optional, Union
|
7
7
|
|
8
8
|
from hestia_earth.schema import MeasurementMethodClassification, SiteSiteType, TermTermType
|
9
|
-
from hestia_earth.utils.model import find_term_match, filter_list_term_type
|
10
9
|
from hestia_earth.utils.blank_node import get_node_value
|
10
|
+
from hestia_earth.utils.model import find_term_match, filter_list_term_type
|
11
|
+
from hestia_earth.utils.tools import non_empty_list
|
11
12
|
|
12
13
|
from hestia_earth.models.utils import split_on_condition
|
13
14
|
from hestia_earth.models.utils.array_builders import gen_seed
|
14
15
|
from hestia_earth.models.utils.blank_node import (
|
15
|
-
cumulative_nodes_match, cumulative_nodes_lookup_match, cumulative_nodes_term_match,
|
16
|
-
node_term_match, group_nodes_by_year, validate_start_date_end_date
|
16
|
+
cumulative_nodes_match, cumulative_nodes_lookup_match, cumulative_nodes_term_match, group_by_term,
|
17
|
+
node_lookup_match, node_term_match, group_nodes_by_year, validate_start_date_end_date
|
17
18
|
)
|
18
19
|
from hestia_earth.models.utils.ecoClimateZone import EcoClimateZone, get_eco_climate_zone_value
|
19
20
|
from hestia_earth.models.utils.descriptive_stats import calc_descriptive_stats
|
@@ -1031,8 +1032,8 @@ def _assign_ipcc_soil_category(
|
|
1031
1032
|
IpccSoilCategory
|
1032
1033
|
The assigned IPCC soil category.
|
1033
1034
|
"""
|
1034
|
-
soil_types =
|
1035
|
-
usda_soil_types =
|
1035
|
+
soil_types = _get_soil_type_measurements(measurement_nodes, TermTermType.SOILTYPE)
|
1036
|
+
usda_soil_types = _get_soil_type_measurements(measurement_nodes, TermTermType.USDASOILTYPE)
|
1036
1037
|
|
1037
1038
|
clay_content = get_node_value(find_term_match(measurement_nodes, _CLAY_CONTENT_TERM_ID))
|
1038
1039
|
sand_content = get_node_value(find_term_match(measurement_nodes, _SAND_CONTENT_TERM_ID))
|
@@ -1053,6 +1054,20 @@ def _assign_ipcc_soil_category(
|
|
1053
1054
|
) if len(soil_types) > 0 or len(usda_soil_types) > 0 else default
|
1054
1055
|
|
1055
1056
|
|
1057
|
+
def _get_soil_type_measurements(
|
1058
|
+
nodes: list[dict], term_type: Literal[TermTermType.SOILTYPE, TermTermType.USDASOILTYPE]
|
1059
|
+
) -> list[dict]:
|
1060
|
+
grouped = group_by_term(filter_list_term_type(nodes, term_type))
|
1061
|
+
|
1062
|
+
def depth_distance(node):
|
1063
|
+
upper, lower = node.get("depthUpper", 0), node.get("depthLower", 100)
|
1064
|
+
return abs(upper - DEPTH_UPPER) + abs(lower - DEPTH_LOWER)
|
1065
|
+
|
1066
|
+
return non_empty_list(
|
1067
|
+
min(nodes_, key=depth_distance) for key in grouped if (nodes_ := grouped.get(key, []))
|
1068
|
+
)
|
1069
|
+
|
1070
|
+
|
1056
1071
|
def _check_soil_category(
|
1057
1072
|
*,
|
1058
1073
|
key: IpccSoilCategory,
|
@@ -1461,7 +1476,7 @@ Value: Corresponding decision tree for IPCC management categories based on land
|
|
1461
1476
|
"""
|
1462
1477
|
|
1463
1478
|
_IPCC_LAND_USE_CATEGORY_TO_DEFAULT_IPCC_MANAGEMENT_CATEGORY = {
|
1464
|
-
IpccLandUseCategory.GRASSLAND: IpccManagementCategory.
|
1479
|
+
IpccLandUseCategory.GRASSLAND: IpccManagementCategory.UNKNOWN,
|
1465
1480
|
IpccLandUseCategory.ANNUAL_CROPS_WET: IpccManagementCategory.UNKNOWN,
|
1466
1481
|
IpccLandUseCategory.ANNUAL_CROPS: IpccManagementCategory.UNKNOWN
|
1467
1482
|
}
|