hestia-earth-models 0.62.5__py3-none-any.whl → 0.62.6__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/croppingIntensity.py +57 -0
- hestia_earth/models/cycle/longFallowRatio.py +52 -0
- hestia_earth/models/cycle/siteDuration.py +23 -3
- hestia_earth/models/cycle/siteUnusedDuration.py +64 -0
- hestia_earth/models/geospatialDatabase/croppingIntensity.py +32 -22
- hestia_earth/models/geospatialDatabase/longFallowRatio.py +34 -23
- hestia_earth/models/mocking/mock_search.py +14 -8
- hestia_earth/models/mocking/search-results.json +27 -27
- hestia_earth/models/pooreNemecek2018/longFallowPeriod.py +1 -2
- hestia_earth/models/pooreNemecek2018/nurseryDensity.py +1 -2
- hestia_earth/models/pooreNemecek2018/nurseryDuration.py +1 -2
- hestia_earth/models/pooreNemecek2018/plantationDensity.py +1 -2
- hestia_earth/models/pooreNemecek2018/plantationLifespan.py +1 -2
- hestia_earth/models/pooreNemecek2018/plantationProductiveLifespan.py +1 -2
- hestia_earth/models/preload_requests.py +14 -7
- hestia_earth/models/utils/__init__.py +0 -9
- hestia_earth/models/utils/cycle.py +10 -2
- hestia_earth/models/utils/product.py +2 -2
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.62.5.dist-info → hestia_earth_models-0.62.6.dist-info}/METADATA +2 -2
- {hestia_earth_models-0.62.5.dist-info → hestia_earth_models-0.62.6.dist-info}/RECORD +30 -24
- tests/models/cycle/test_croppingIntensity.py +53 -0
- tests/models/cycle/test_longFallowRatio.py +49 -0
- tests/models/cycle/test_siteDuration.py +41 -14
- tests/models/cycle/test_siteUnusedDuration.py +55 -0
- tests/models/geospatialDatabase/test_croppingIntensity.py +5 -3
- tests/models/geospatialDatabase/test_longFallowRatio.py +5 -3
- {hestia_earth_models-0.62.5.dist-info → hestia_earth_models-0.62.6.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.62.5.dist-info → hestia_earth_models-0.62.6.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.62.5.dist-info → hestia_earth_models-0.62.6.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from hestia_earth.schema import CycleStartDateDefinition
|
|
2
|
+
from hestia_earth.utils.model import find_primary_product
|
|
3
|
+
|
|
4
|
+
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
5
|
+
from hestia_earth.models.utils.practice import _new_practice
|
|
6
|
+
from hestia_earth.models.utils.crop import is_plantation
|
|
7
|
+
from . import MODEL
|
|
8
|
+
|
|
9
|
+
REQUIREMENTS = {
|
|
10
|
+
"Cycle": {
|
|
11
|
+
"cycleDuration": "> 0",
|
|
12
|
+
"startDateDefinition": "harvest of previous crop"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
RETURNS = {
|
|
16
|
+
"Practice": [{
|
|
17
|
+
"value": ""
|
|
18
|
+
}]
|
|
19
|
+
}
|
|
20
|
+
LOOKUPS = {
|
|
21
|
+
"crop": "isPlantation"
|
|
22
|
+
}
|
|
23
|
+
TERM_ID = 'croppingIntensity'
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _practice(value: float):
|
|
27
|
+
practice = _new_practice(TERM_ID)
|
|
28
|
+
practice['value'] = [round(value, 7)]
|
|
29
|
+
return practice
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _run(cycle: dict):
|
|
33
|
+
cycleDuration = cycle.get('cycleDuration')
|
|
34
|
+
return [_practice(cycleDuration / 365)]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _should_run(cycle: dict):
|
|
38
|
+
product = find_primary_product(cycle) or {}
|
|
39
|
+
not_plantation = not is_plantation(MODEL, TERM_ID, product.get('term', {}).get('@id'))
|
|
40
|
+
|
|
41
|
+
cycleDuration = cycle.get('cycleDuration', 0)
|
|
42
|
+
has_cycleDuration = cycleDuration > 0
|
|
43
|
+
startDateDefinition = cycle.get('startDateDefinition')
|
|
44
|
+
harvest_previous_crop = CycleStartDateDefinition.HARVEST_OF_PREVIOUS_CROP.value
|
|
45
|
+
is_harvest_previous_crop = startDateDefinition == harvest_previous_crop
|
|
46
|
+
|
|
47
|
+
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
48
|
+
not_plantation=not_plantation,
|
|
49
|
+
cycleDuration=cycleDuration,
|
|
50
|
+
is_harvest_previous_crop=is_harvest_previous_crop)
|
|
51
|
+
|
|
52
|
+
should_run = all([not_plantation, has_cycleDuration, is_harvest_previous_crop])
|
|
53
|
+
logShouldRun(cycle, MODEL, TERM_ID, should_run)
|
|
54
|
+
return should_run
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def run(cycle: dict): return _run(cycle) if _should_run(cycle) else []
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from hestia_earth.utils.model import find_term_match
|
|
2
|
+
from hestia_earth.utils.tools import list_sum
|
|
3
|
+
|
|
4
|
+
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
5
|
+
from hestia_earth.models.utils.practice import _new_practice
|
|
6
|
+
from . import MODEL
|
|
7
|
+
|
|
8
|
+
REQUIREMENTS = {
|
|
9
|
+
"Cycle": {
|
|
10
|
+
"practices": [
|
|
11
|
+
{"@type": "Practice", "value": "> 0", "term.@id": "longFallowPeriod"},
|
|
12
|
+
{"@type": "Practice", "value": "> 0", "term.@id": "rotationDuration"}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
RETURNS = {
|
|
17
|
+
"Practice": [{
|
|
18
|
+
"value": ""
|
|
19
|
+
}]
|
|
20
|
+
}
|
|
21
|
+
TERM_ID = 'longFallowRatio'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _practice(value: float):
|
|
25
|
+
practice = _new_practice(TERM_ID)
|
|
26
|
+
practice['value'] = [round(value, 7)]
|
|
27
|
+
return practice
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _run(longFallowPeriod: float, rotationDuration: float):
|
|
31
|
+
value = rotationDuration / (rotationDuration - longFallowPeriod)
|
|
32
|
+
return [_practice(value)]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _should_run(cycle: dict):
|
|
36
|
+
practices = cycle.get('practices', [])
|
|
37
|
+
|
|
38
|
+
longFallowPeriod = list_sum(find_term_match(practices, 'longFallowPeriod', {}).get('value', 0), 0)
|
|
39
|
+
rotationDuration = list_sum(find_term_match(practices, 'rotationDuration', {}).get('value', 0), 0)
|
|
40
|
+
|
|
41
|
+
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
42
|
+
longFallowPeriod=longFallowPeriod,
|
|
43
|
+
rotationDuration=rotationDuration)
|
|
44
|
+
|
|
45
|
+
should_run = all([longFallowPeriod > 0, rotationDuration > 0])
|
|
46
|
+
logShouldRun(cycle, MODEL, TERM_ID, should_run)
|
|
47
|
+
return should_run, longFallowPeriod, rotationDuration
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def run(cycle: dict):
|
|
51
|
+
should_run, longFallowPeriod, rotationDuration = _should_run(cycle)
|
|
52
|
+
return _run(longFallowPeriod, rotationDuration) if should_run else []
|
|
@@ -3,7 +3,12 @@ Site duration
|
|
|
3
3
|
|
|
4
4
|
This model calculates the `siteDuration` on the `Cycle` to the same value as `cycleDuration`
|
|
5
5
|
when only a single `Site` is present.
|
|
6
|
+
|
|
7
|
+
Note: on `crop` production cycles, the model will only run if `startDateDefinition` = `harvest of previous crop`.
|
|
6
8
|
"""
|
|
9
|
+
from hestia_earth.schema import TermTermType, CycleStartDateDefinition
|
|
10
|
+
from hestia_earth.utils.model import find_primary_product
|
|
11
|
+
|
|
7
12
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
8
13
|
from . import MODEL
|
|
9
14
|
|
|
@@ -12,11 +17,19 @@ REQUIREMENTS = {
|
|
|
12
17
|
"cycleDuration": "> 0",
|
|
13
18
|
"none": {
|
|
14
19
|
"otherSites": ""
|
|
20
|
+
},
|
|
21
|
+
"optional": {
|
|
22
|
+
"products": {
|
|
23
|
+
"@type": "Product",
|
|
24
|
+
"primary": "True",
|
|
25
|
+
"term.termType": "crop"
|
|
26
|
+
},
|
|
27
|
+
"startDateDefinition": ""
|
|
15
28
|
}
|
|
16
29
|
}
|
|
17
30
|
}
|
|
18
31
|
RETURNS = {
|
|
19
|
-
"
|
|
32
|
+
"the duration as a `number`": ""
|
|
20
33
|
}
|
|
21
34
|
MODEL_KEY = 'siteDuration'
|
|
22
35
|
|
|
@@ -28,11 +41,18 @@ def _should_run(cycle: dict):
|
|
|
28
41
|
cycleDuration = cycle.get('cycleDuration', 0)
|
|
29
42
|
has_other_sites = len(cycle.get('otherSites', [])) == 0
|
|
30
43
|
|
|
44
|
+
product = find_primary_product(cycle)
|
|
45
|
+
is_primary_crop_product = (product or {}).get('term', {}).get('termType') == TermTermType.CROP.value
|
|
46
|
+
harvest_previous_crop = CycleStartDateDefinition.HARVEST_OF_PREVIOUS_CROP.value
|
|
47
|
+
is_harvest_previous_crop = cycle.get('startDateDefinition') == harvest_previous_crop
|
|
48
|
+
|
|
31
49
|
logRequirements(cycle, model=MODEL, key=MODEL_KEY,
|
|
32
50
|
cycleDuration=cycleDuration,
|
|
33
|
-
has_other_sites=has_other_sites
|
|
51
|
+
has_other_sites=has_other_sites,
|
|
52
|
+
is_primary_crop_product=is_primary_crop_product,
|
|
53
|
+
is_harvest_previous_crop=is_harvest_previous_crop)
|
|
34
54
|
|
|
35
|
-
should_run = all([cycleDuration > 0, has_other_sites])
|
|
55
|
+
should_run = all([cycleDuration > 0, has_other_sites, not is_primary_crop_product or is_harvest_previous_crop])
|
|
36
56
|
logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY)
|
|
37
57
|
return should_run
|
|
38
58
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Site Unused Duration
|
|
3
|
+
|
|
4
|
+
This model sets the [Cycle siteUnusedDuration](https://hestia.earth/schema/Cycle#siteUnusedDuration) based on
|
|
5
|
+
the `siteDuration` and the `longFallowRatio` practice.
|
|
6
|
+
"""
|
|
7
|
+
from hestia_earth.schema import SiteSiteType
|
|
8
|
+
from hestia_earth.utils.tools import list_sum
|
|
9
|
+
|
|
10
|
+
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
11
|
+
from hestia_earth.models.utils.site import valid_site_type
|
|
12
|
+
from . import MODEL
|
|
13
|
+
|
|
14
|
+
REQUIREMENTS = {
|
|
15
|
+
"Cycle": {
|
|
16
|
+
"site": {
|
|
17
|
+
"@type": "Site",
|
|
18
|
+
"siteType": ["cropland", "glass and high accessible cover"]
|
|
19
|
+
},
|
|
20
|
+
"siteDuration": "> 0",
|
|
21
|
+
"practices": [{"@type": "Practice", "value": "> 0", "term.@id": "longFallowRatio"}]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
RETURNS = {
|
|
25
|
+
"The siteUnusedDuration as a number": ""
|
|
26
|
+
}
|
|
27
|
+
MODEL_KEY = 'siteUnusedDuration'
|
|
28
|
+
VALID_SITE_TYPES = [
|
|
29
|
+
SiteSiteType.CROPLAND.value,
|
|
30
|
+
SiteSiteType.GLASS_OR_HIGH_ACCESSIBLE_COVER.value
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _run(cycle: dict, longFallowRatio: float):
|
|
35
|
+
siteDuration = cycle.get('siteDuration')
|
|
36
|
+
return siteDuration * (longFallowRatio - 1)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _should_run(cycle: dict):
|
|
40
|
+
site_type_valid = valid_site_type(cycle.get('site'), site_types=VALID_SITE_TYPES)
|
|
41
|
+
|
|
42
|
+
siteDuration = cycle.get('siteDuration', 0)
|
|
43
|
+
|
|
44
|
+
practices = cycle.get('practices', [])
|
|
45
|
+
longFallowRatio = list_sum(next((
|
|
46
|
+
p for p in practices if all([
|
|
47
|
+
p.get('term', {}).get('@id') == 'longFallowRatio',
|
|
48
|
+
p.get('site') is None or p.get('site', {}).get('@id') == cycle.get('site', {}).get('@id')
|
|
49
|
+
])
|
|
50
|
+
), {}).get('value'), None)
|
|
51
|
+
|
|
52
|
+
logRequirements(cycle, model=MODEL, key=MODEL_KEY,
|
|
53
|
+
site_type_valid=site_type_valid,
|
|
54
|
+
siteDuration=siteDuration,
|
|
55
|
+
longFallowRatio=longFallowRatio)
|
|
56
|
+
|
|
57
|
+
should_run = all([site_type_valid, siteDuration > 0, longFallowRatio is not None])
|
|
58
|
+
logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY)
|
|
59
|
+
return should_run, longFallowRatio
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def run(cycle: dict):
|
|
63
|
+
should_run, longFallowRatio = _should_run(cycle)
|
|
64
|
+
return _run(cycle, longFallowRatio) if should_run else None
|
|
@@ -1,31 +1,40 @@
|
|
|
1
1
|
from hestia_earth.schema import TermTermType
|
|
2
|
-
from hestia_earth.utils.model import find_primary_product
|
|
2
|
+
from hestia_earth.utils.model import find_primary_product, linked_node
|
|
3
|
+
from hestia_earth.utils.tools import non_empty_list
|
|
3
4
|
|
|
4
|
-
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
5
|
+
from hestia_earth.models.log import logRequirements, logShouldRun, debugValues, log_as_table
|
|
5
6
|
from hestia_earth.models.utils.practice import _new_practice
|
|
6
7
|
from hestia_earth.models.utils.crop import is_plantation
|
|
8
|
+
from hestia_earth.models.utils.cycle import get_allowed_sites
|
|
7
9
|
from .utils import get_region_factor
|
|
8
10
|
from . import MODEL
|
|
9
11
|
|
|
10
12
|
REQUIREMENTS = {
|
|
11
13
|
"Cycle": {
|
|
12
|
-
"products": [{
|
|
13
|
-
"@type": "Product",
|
|
14
|
-
"primary": "True",
|
|
15
|
-
"term.termType": "crop"
|
|
16
|
-
}],
|
|
17
14
|
"site": {
|
|
18
15
|
"@type": "Site",
|
|
19
16
|
"or": [
|
|
20
17
|
{"region": {"@type": "Term"}},
|
|
21
18
|
{"country": {"@type": "Term"}}
|
|
22
19
|
]
|
|
20
|
+
},
|
|
21
|
+
"optional": {
|
|
22
|
+
"otherSites": [
|
|
23
|
+
{
|
|
24
|
+
"@type": "Site",
|
|
25
|
+
"or": [
|
|
26
|
+
{"region": {"@type": "Term"}},
|
|
27
|
+
{"country": {"@type": "Term"}}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
]
|
|
23
31
|
}
|
|
24
32
|
}
|
|
25
33
|
}
|
|
26
34
|
RETURNS = {
|
|
27
35
|
"Practice": [{
|
|
28
|
-
"value": ""
|
|
36
|
+
"value": "",
|
|
37
|
+
"site": ""
|
|
29
38
|
}]
|
|
30
39
|
}
|
|
31
40
|
LOOKUPS = {
|
|
@@ -35,25 +44,14 @@ LOOKUPS = {
|
|
|
35
44
|
TERM_ID = 'croppingIntensity'
|
|
36
45
|
|
|
37
46
|
|
|
38
|
-
def _practice(value: float):
|
|
47
|
+
def _practice(site: dict, value: float):
|
|
39
48
|
practice = _new_practice(TERM_ID)
|
|
49
|
+
practice['site'] = linked_node(site)
|
|
40
50
|
# force conversion to float from numpy, avoiding errors when reading it in other models
|
|
41
51
|
practice['value'] = [float(round(value, 7))]
|
|
42
52
|
return practice
|
|
43
53
|
|
|
44
54
|
|
|
45
|
-
def _run(cycle: dict):
|
|
46
|
-
site = cycle.get('site')
|
|
47
|
-
region_factor = get_region_factor(TERM_ID, site, TermTermType.LANDUSEMANAGEMENT)
|
|
48
|
-
|
|
49
|
-
logRequirements(site, model=MODEL, term=TERM_ID,
|
|
50
|
-
region_factor=region_factor)
|
|
51
|
-
|
|
52
|
-
should_run = all([region_factor])
|
|
53
|
-
logShouldRun(site, MODEL, TERM_ID, should_run)
|
|
54
|
-
return [_practice(region_factor)] if should_run else []
|
|
55
|
-
|
|
56
|
-
|
|
57
55
|
def _should_run(cycle: dict):
|
|
58
56
|
product = find_primary_product(cycle) or {}
|
|
59
57
|
not_plantation = not is_plantation(MODEL, TERM_ID, product.get('term', {}).get('@id'))
|
|
@@ -66,4 +64,16 @@ def _should_run(cycle: dict):
|
|
|
66
64
|
return should_run
|
|
67
65
|
|
|
68
66
|
|
|
69
|
-
def run(cycle: dict):
|
|
67
|
+
def run(cycle: dict):
|
|
68
|
+
sites = get_allowed_sites(MODEL, TERM_ID, TermTermType.LANDUSEMANAGEMENT, cycle) if _should_run(cycle) else []
|
|
69
|
+
sites = [
|
|
70
|
+
(site, get_region_factor(TERM_ID, site, TermTermType.LANDUSEMANAGEMENT)) for site in sites
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
debugValues(cycle, model=MODEL, term=TERM_ID,
|
|
74
|
+
site_factors=log_as_table([{
|
|
75
|
+
'site-id': site.get('@id', site.get('id')),
|
|
76
|
+
'factor': factor
|
|
77
|
+
} for site, factor in sites]))
|
|
78
|
+
|
|
79
|
+
return non_empty_list([_practice(site, factor) for site, factor in sites if bool(factor)])
|
|
@@ -1,31 +1,40 @@
|
|
|
1
1
|
from hestia_earth.schema import TermTermType
|
|
2
|
-
from hestia_earth.utils.model import find_primary_product
|
|
2
|
+
from hestia_earth.utils.model import find_primary_product, linked_node
|
|
3
|
+
from hestia_earth.utils.tools import non_empty_list
|
|
3
4
|
|
|
4
|
-
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
5
|
+
from hestia_earth.models.log import logRequirements, logShouldRun, debugValues, log_as_table
|
|
5
6
|
from hestia_earth.models.utils.practice import _new_practice
|
|
6
7
|
from hestia_earth.models.utils.crop import is_plantation
|
|
8
|
+
from hestia_earth.models.utils.cycle import get_allowed_sites
|
|
7
9
|
from .utils import get_region_factor
|
|
8
10
|
from . import MODEL
|
|
9
11
|
|
|
10
12
|
REQUIREMENTS = {
|
|
11
13
|
"Cycle": {
|
|
12
|
-
"products": [{
|
|
13
|
-
"@type": "Product",
|
|
14
|
-
"primary": "True",
|
|
15
|
-
"term.termType": "crop"
|
|
16
|
-
}],
|
|
17
14
|
"site": {
|
|
18
15
|
"@type": "Site",
|
|
19
16
|
"or": [
|
|
20
17
|
{"region": {"@type": "Term"}},
|
|
21
18
|
{"country": {"@type": "Term"}}
|
|
22
19
|
]
|
|
20
|
+
},
|
|
21
|
+
"optional": {
|
|
22
|
+
"otherSites": [
|
|
23
|
+
{
|
|
24
|
+
"@type": "Site",
|
|
25
|
+
"or": [
|
|
26
|
+
{"region": {"@type": "Term"}},
|
|
27
|
+
{"country": {"@type": "Term"}}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
]
|
|
23
31
|
}
|
|
24
32
|
}
|
|
25
33
|
}
|
|
26
34
|
RETURNS = {
|
|
27
35
|
"Practice": [{
|
|
28
|
-
"value": ""
|
|
36
|
+
"value": "",
|
|
37
|
+
"site": ""
|
|
29
38
|
}]
|
|
30
39
|
}
|
|
31
40
|
LOOKUPS = {
|
|
@@ -35,24 +44,14 @@ LOOKUPS = {
|
|
|
35
44
|
TERM_ID = 'longFallowRatio'
|
|
36
45
|
|
|
37
46
|
|
|
38
|
-
def _practice(value: float):
|
|
47
|
+
def _practice(site: dict, value: float):
|
|
39
48
|
practice = _new_practice(TERM_ID)
|
|
40
|
-
practice['
|
|
49
|
+
practice['site'] = linked_node(site)
|
|
50
|
+
# force conversion to float from numpy, avoiding errors when reading it in other models
|
|
51
|
+
practice['value'] = [float(round(value, 7))]
|
|
41
52
|
return practice
|
|
42
53
|
|
|
43
54
|
|
|
44
|
-
def _run(cycle: dict):
|
|
45
|
-
site = cycle.get('site')
|
|
46
|
-
region_factor = get_region_factor(TERM_ID, site, TermTermType.LANDUSEMANAGEMENT)
|
|
47
|
-
|
|
48
|
-
logRequirements(site, model=MODEL, term=TERM_ID,
|
|
49
|
-
region_factor=region_factor)
|
|
50
|
-
|
|
51
|
-
should_run = all([region_factor])
|
|
52
|
-
logShouldRun(site, MODEL, TERM_ID, should_run)
|
|
53
|
-
return [_practice(region_factor)] if should_run else []
|
|
54
|
-
|
|
55
|
-
|
|
56
55
|
def _should_run(cycle: dict):
|
|
57
56
|
product = find_primary_product(cycle) or {}
|
|
58
57
|
not_plantation = not is_plantation(MODEL, TERM_ID, product.get('term', {}).get('@id'))
|
|
@@ -65,4 +64,16 @@ def _should_run(cycle: dict):
|
|
|
65
64
|
return should_run
|
|
66
65
|
|
|
67
66
|
|
|
68
|
-
def run(cycle: dict):
|
|
67
|
+
def run(cycle: dict):
|
|
68
|
+
sites = get_allowed_sites(MODEL, TERM_ID, TermTermType.LANDUSEMANAGEMENT, cycle) if _should_run(cycle) else []
|
|
69
|
+
sites = [
|
|
70
|
+
(site, get_region_factor(TERM_ID, site, TermTermType.LANDUSEMANAGEMENT)) for site in sites
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
debugValues(cycle, model=MODEL, term=TERM_ID,
|
|
74
|
+
site_factors=log_as_table([{
|
|
75
|
+
'site-id': site.get('@id', site.get('id')),
|
|
76
|
+
'factor': factor
|
|
77
|
+
} for site, factor in sites]))
|
|
78
|
+
|
|
79
|
+
return non_empty_list([_practice(site, factor) for site, factor in sites if bool(factor)])
|
|
@@ -52,20 +52,26 @@ def _load_results(filepath: str):
|
|
|
52
52
|
|
|
53
53
|
def _find_search_result(filepath: str, query: dict):
|
|
54
54
|
search_results = _load_results(filepath)
|
|
55
|
-
res = next((n for n in search_results if n['query'] == query),
|
|
56
|
-
return res.get('results', [])
|
|
55
|
+
res = next((n for n in search_results if n['query'] == query), None)
|
|
56
|
+
return None if res is None else res.get('results', [])
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
def
|
|
60
|
-
def mock(query: dict,
|
|
59
|
+
def _mocked_search(original_func, filepath: str):
|
|
60
|
+
def mock(query: dict, **kwargs):
|
|
61
|
+
result = _find_search_result(filepath, query)
|
|
62
|
+
return original_func(query, **kwargs) if result is None else result
|
|
61
63
|
return mock
|
|
62
64
|
|
|
63
65
|
|
|
64
|
-
def
|
|
65
|
-
def mock(
|
|
66
|
+
def _mocked_find_node(original_func, filepath: str):
|
|
67
|
+
def mock(node_type: str, query: dict, **kwargs):
|
|
68
|
+
result = _find_search_result(filepath, query)
|
|
69
|
+
return original_func(node_type, query, **kwargs) if result is None else result
|
|
66
70
|
return mock
|
|
67
71
|
|
|
68
72
|
|
|
69
73
|
def mock(filepath: str):
|
|
70
|
-
term.search
|
|
71
|
-
term.
|
|
74
|
+
original_search = term.search
|
|
75
|
+
term.search = _mocked_search(original_search, filepath)
|
|
76
|
+
original_find_node = term.find_node
|
|
77
|
+
term.find_node = _mocked_find_node(original_find_node, filepath)
|
|
@@ -1054,11 +1054,11 @@
|
|
|
1054
1054
|
"results": [
|
|
1055
1055
|
{
|
|
1056
1056
|
"@type": "Term",
|
|
1057
|
-
"@id": "
|
|
1057
|
+
"@id": "residueIncorporated"
|
|
1058
1058
|
},
|
|
1059
1059
|
{
|
|
1060
1060
|
"@type": "Term",
|
|
1061
|
-
"@id": "
|
|
1061
|
+
"@id": "residueIncorporatedMoreThan30DaysBeforeCultivation"
|
|
1062
1062
|
},
|
|
1063
1063
|
{
|
|
1064
1064
|
"@type": "Term",
|
|
@@ -1066,7 +1066,7 @@
|
|
|
1066
1066
|
},
|
|
1067
1067
|
{
|
|
1068
1068
|
"@type": "Term",
|
|
1069
|
-
"@id": "
|
|
1069
|
+
"@id": "residueIncorporatedLessThan30DaysBeforeCultivation"
|
|
1070
1070
|
},
|
|
1071
1071
|
{
|
|
1072
1072
|
"@type": "Term",
|
|
@@ -1110,27 +1110,27 @@
|
|
|
1110
1110
|
},
|
|
1111
1111
|
{
|
|
1112
1112
|
"@type": "Term",
|
|
1113
|
-
"@id": "
|
|
1113
|
+
"@id": "discardedCropRemoved"
|
|
1114
1114
|
},
|
|
1115
1115
|
{
|
|
1116
1116
|
"@type": "Term",
|
|
1117
|
-
"@id": "
|
|
1117
|
+
"@id": "aboveGroundCropResidueTotal"
|
|
1118
1118
|
},
|
|
1119
1119
|
{
|
|
1120
1120
|
"@type": "Term",
|
|
1121
|
-
"@id": "
|
|
1121
|
+
"@id": "aboveGroundCropResidueIncorporated"
|
|
1122
1122
|
},
|
|
1123
1123
|
{
|
|
1124
1124
|
"@type": "Term",
|
|
1125
|
-
"@id": "
|
|
1125
|
+
"@id": "aboveGroundCropResidueBurnt"
|
|
1126
1126
|
},
|
|
1127
1127
|
{
|
|
1128
1128
|
"@type": "Term",
|
|
1129
|
-
"@id": "
|
|
1129
|
+
"@id": "belowGroundCropResidue"
|
|
1130
1130
|
},
|
|
1131
1131
|
{
|
|
1132
1132
|
"@type": "Term",
|
|
1133
|
-
"@id": "
|
|
1133
|
+
"@id": "aboveGroundCropResidueLeftOnField"
|
|
1134
1134
|
}
|
|
1135
1135
|
]
|
|
1136
1136
|
},
|
|
@@ -1486,7 +1486,7 @@
|
|
|
1486
1486
|
"@type": "Term",
|
|
1487
1487
|
"name": "Generic crop, seed",
|
|
1488
1488
|
"@id": "genericCropSeed",
|
|
1489
|
-
"_score": 26.
|
|
1489
|
+
"_score": 26.344206
|
|
1490
1490
|
}
|
|
1491
1491
|
]
|
|
1492
1492
|
},
|
|
@@ -1534,10 +1534,6 @@
|
|
|
1534
1534
|
"@type": "Term",
|
|
1535
1535
|
"@id": "rainfedDeepWaterWaterDepth100Cm"
|
|
1536
1536
|
},
|
|
1537
|
-
{
|
|
1538
|
-
"@type": "Term",
|
|
1539
|
-
"@id": "irrigatedTypeUnspecified"
|
|
1540
|
-
},
|
|
1541
1537
|
{
|
|
1542
1538
|
"@type": "Term",
|
|
1543
1539
|
"@id": "irrigatedLocalizedIrrigation"
|
|
@@ -1550,6 +1546,10 @@
|
|
|
1550
1546
|
"@type": "Term",
|
|
1551
1547
|
"@id": "irrigatedSubIrrigation"
|
|
1552
1548
|
},
|
|
1549
|
+
{
|
|
1550
|
+
"@type": "Term",
|
|
1551
|
+
"@id": "irrigatedTypeUnspecified"
|
|
1552
|
+
},
|
|
1553
1553
|
{
|
|
1554
1554
|
"@type": "Term",
|
|
1555
1555
|
"@id": "irrigatedDripIrrigation"
|
|
@@ -1722,61 +1722,61 @@
|
|
|
1722
1722
|
"@type": "Term",
|
|
1723
1723
|
"name": "Glass or high accessible cover",
|
|
1724
1724
|
"@id": "glassOrHighAccessibleCover",
|
|
1725
|
-
"_score": 59.
|
|
1725
|
+
"_score": 59.78251
|
|
1726
1726
|
},
|
|
1727
1727
|
{
|
|
1728
1728
|
"@type": "Term",
|
|
1729
1729
|
"name": "River or stream",
|
|
1730
1730
|
"@id": "riverOrStream",
|
|
1731
|
-
"_score":
|
|
1731
|
+
"_score": 51.118263
|
|
1732
1732
|
},
|
|
1733
1733
|
{
|
|
1734
1734
|
"@type": "Term",
|
|
1735
1735
|
"name": "Other natural vegetation",
|
|
1736
1736
|
"@id": "otherNaturalVegetation",
|
|
1737
|
-
"_score":
|
|
1737
|
+
"_score": 41.25843
|
|
1738
1738
|
},
|
|
1739
1739
|
{
|
|
1740
1740
|
"@type": "Term",
|
|
1741
1741
|
"name": "Natural forest",
|
|
1742
1742
|
"@id": "naturalForest",
|
|
1743
|
-
"_score": 31.
|
|
1743
|
+
"_score": 31.747753
|
|
1744
1744
|
},
|
|
1745
1745
|
{
|
|
1746
1746
|
"@type": "Term",
|
|
1747
1747
|
"name": "Permanent pasture",
|
|
1748
1748
|
"@id": "permanentPasture",
|
|
1749
|
-
"_score": 28.
|
|
1749
|
+
"_score": 28.454437
|
|
1750
1750
|
},
|
|
1751
1751
|
{
|
|
1752
1752
|
"@type": "Term",
|
|
1753
1753
|
"name": "Animal housing",
|
|
1754
1754
|
"@id": "animalHousing",
|
|
1755
|
-
"_score": 27.
|
|
1755
|
+
"_score": 27.424242
|
|
1756
1756
|
},
|
|
1757
1757
|
{
|
|
1758
1758
|
"@type": "Term",
|
|
1759
1759
|
"name": "Root or tuber crop plant",
|
|
1760
1760
|
"@id": "rootOrTuberCropPlant",
|
|
1761
|
-
"_score": 25.
|
|
1761
|
+
"_score": 25.260658
|
|
1762
1762
|
},
|
|
1763
1763
|
{
|
|
1764
1764
|
"@type": "Term",
|
|
1765
1765
|
"name": "High intensity grazing pasture",
|
|
1766
1766
|
"@id": "highIntensityGrazingPasture",
|
|
1767
|
-
"_score":
|
|
1767
|
+
"_score": 24.038225
|
|
1768
1768
|
},
|
|
1769
1769
|
{
|
|
1770
1770
|
"@type": "Term",
|
|
1771
1771
|
"name": "Permanent cropland",
|
|
1772
1772
|
"@id": "permanentCropland",
|
|
1773
|
-
"_score": 20.
|
|
1773
|
+
"_score": 20.689457
|
|
1774
1774
|
},
|
|
1775
1775
|
{
|
|
1776
1776
|
"@type": "Term",
|
|
1777
1777
|
"name": "Forest",
|
|
1778
1778
|
"@id": "forest",
|
|
1779
|
-
"_score": 20.
|
|
1779
|
+
"_score": 20.366226
|
|
1780
1780
|
}
|
|
1781
1781
|
]
|
|
1782
1782
|
},
|
|
@@ -2024,15 +2024,15 @@
|
|
|
2024
2024
|
"results": [
|
|
2025
2025
|
{
|
|
2026
2026
|
"@type": "Term",
|
|
2027
|
-
"@id": "
|
|
2027
|
+
"@id": "noTillage"
|
|
2028
2028
|
},
|
|
2029
2029
|
{
|
|
2030
2030
|
"@type": "Term",
|
|
2031
|
-
"@id": "
|
|
2031
|
+
"@id": "ridgeTillage"
|
|
2032
2032
|
},
|
|
2033
2033
|
{
|
|
2034
2034
|
"@type": "Term",
|
|
2035
|
-
"@id": "
|
|
2035
|
+
"@id": "verticalTillage"
|
|
2036
2036
|
},
|
|
2037
2037
|
{
|
|
2038
2038
|
"@type": "Term",
|
|
@@ -7,8 +7,7 @@ from . import MODEL
|
|
|
7
7
|
|
|
8
8
|
REQUIREMENTS = {
|
|
9
9
|
"Cycle": {
|
|
10
|
-
"products": [{"@type": "Product", "value": "", "term.termType": "crop"}]
|
|
11
|
-
"site": {"@type": "Site", "siteType": "cropland"}
|
|
10
|
+
"products": [{"@type": "Product", "value": "", "term.termType": "crop"}]
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
13
|
LOOKUPS = {
|
|
@@ -7,8 +7,7 @@ from . import MODEL
|
|
|
7
7
|
|
|
8
8
|
REQUIREMENTS = {
|
|
9
9
|
"Cycle": {
|
|
10
|
-
"products": [{"@type": "Product", "value": "", "term.termType": "crop"}]
|
|
11
|
-
"site": {"@type": "Site", "siteType": "cropland"}
|
|
10
|
+
"products": [{"@type": "Product", "value": "", "term.termType": "crop"}]
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
13
|
LOOKUPS = {
|
|
@@ -7,8 +7,7 @@ from . import MODEL
|
|
|
7
7
|
|
|
8
8
|
REQUIREMENTS = {
|
|
9
9
|
"Cycle": {
|
|
10
|
-
"products": [{"@type": "Product", "value": "", "term.termType": "crop"}]
|
|
11
|
-
"site": {"@type": "Site", "siteType": "cropland"}
|
|
10
|
+
"products": [{"@type": "Product", "value": "", "term.termType": "crop"}]
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
13
|
LOOKUPS = {
|
|
@@ -7,8 +7,7 @@ from . import MODEL
|
|
|
7
7
|
|
|
8
8
|
REQUIREMENTS = {
|
|
9
9
|
"Cycle": {
|
|
10
|
-
"products": [{"@type": "Product", "value": "", "term.termType": "crop"}]
|
|
11
|
-
"site": {"@type": "Site", "siteType": "cropland"}
|
|
10
|
+
"products": [{"@type": "Product", "value": "", "term.termType": "crop"}]
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
13
|
LOOKUPS = {
|