hestia-earth-models 0.64.0__py3-none-any.whl → 0.64.2__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/concentrateFeed.py +12 -3
- hestia_earth/models/cycle/endDate.py +47 -0
- hestia_earth/models/cycle/otherSitesUnusedDuration.py +91 -0
- hestia_earth/models/cycle/siteUnusedDuration.py +2 -1
- hestia_earth/models/cycle/startDate.py +38 -10
- hestia_earth/models/cycle/startDateDefinition.py +2 -2
- hestia_earth/models/edip2003/__init__.py +13 -0
- hestia_earth/models/edip2003/ozoneDepletionPotential.py +34 -0
- hestia_earth/models/ipcc2019/ch4ToAirAquacultureSystems.py +96 -0
- hestia_earth/models/mocking/search-results.json +500 -260
- hestia_earth/models/pooreNemecek2018/excretaKgN.py +9 -9
- hestia_earth/models/pooreNemecek2018/excretaKgVs.py +6 -8
- hestia_earth/models/poschEtAl2008/__init__.py +13 -0
- hestia_earth/models/poschEtAl2008/terrestrialAcidificationPotentialAccumulatedExceedance.py +40 -0
- hestia_earth/models/site/waterDepth.py +0 -3
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.64.0.dist-info → hestia_earth_models-0.64.2.dist-info}/METADATA +2 -2
- {hestia_earth_models-0.64.0.dist-info → hestia_earth_models-0.64.2.dist-info}/RECORD +29 -15
- tests/models/cycle/test_endDate.py +22 -0
- tests/models/cycle/test_otherSitesUnusedDuration.py +54 -0
- tests/models/cycle/test_startDate.py +23 -5
- tests/models/edip2003/__init__.py +0 -0
- tests/models/edip2003/test_ozoneDepletionPotential.py +46 -0
- tests/models/ipcc2019/test_ch4ToAirAquacultureSystems.py +60 -0
- tests/models/poschEtAl2008/__init__.py +0 -0
- tests/models/poschEtAl2008/test_terrestrialAcidificationPotentialAccumulatedExceedance.py +45 -0
- {hestia_earth_models-0.64.0.dist-info → hestia_earth_models-0.64.2.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.64.0.dist-info → hestia_earth_models-0.64.2.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.64.0.dist-info → hestia_earth_models-0.64.2.dist-info}/top_level.txt +0 -0
|
@@ -15,7 +15,9 @@ from . import MODEL
|
|
|
15
15
|
|
|
16
16
|
REQUIREMENTS = {
|
|
17
17
|
"Cycle": {
|
|
18
|
-
"inputs": [{
|
|
18
|
+
"inputs": [{
|
|
19
|
+
"@type": "Practice", "value": "", "term.termType": ["crop", "forage", "processedFood", "animalProduct"]
|
|
20
|
+
}],
|
|
19
21
|
"products": [
|
|
20
22
|
{
|
|
21
23
|
"@type": "Product",
|
|
@@ -34,10 +36,17 @@ RETURNS = {
|
|
|
34
36
|
}
|
|
35
37
|
LOOKUPS = {
|
|
36
38
|
"crop-property": "crudeProteinContent",
|
|
39
|
+
"forage-property": "crudeProteinContent",
|
|
40
|
+
"processedFood-property": "crudeProteinContent",
|
|
37
41
|
"property": "commonToSupplementInAnimalFeed"
|
|
38
42
|
}
|
|
39
43
|
TERM_ID = 'concentrateFeedBlend,concentrateFeedUnspecified,feedMix'
|
|
40
|
-
INPUT_TERM_TYPES = [
|
|
44
|
+
INPUT_TERM_TYPES = [
|
|
45
|
+
TermTermType.CROP.value,
|
|
46
|
+
TermTermType.FORAGE.value,
|
|
47
|
+
TermTermType.PROCESSEDFOOD.value,
|
|
48
|
+
TermTermType.ANIMALPRODUCT.value
|
|
49
|
+
]
|
|
41
50
|
|
|
42
51
|
|
|
43
52
|
def _property(term_id: str, value: float):
|
|
@@ -60,7 +69,7 @@ def _weighted_value(values: list):
|
|
|
60
69
|
|
|
61
70
|
def _calculate_value(cycle: dict, product: dict, inputs: list, property_id: str, values: list):
|
|
62
71
|
values = [(prop_value, value) for id, prop_value, value in values if value and prop_value]
|
|
63
|
-
ratio_inputs_with_props = len(
|
|
72
|
+
ratio_inputs_with_props = len(values) / len(inputs) if len(inputs) and len(values) else 0
|
|
64
73
|
min_ratio = _min_ratio(property_id)
|
|
65
74
|
|
|
66
75
|
term_id = product.get('term', {}).get('@id')
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
End Date
|
|
3
|
+
|
|
4
|
+
This model sets the [Cycle endDate](https://hestia.earth/schema/Cycle#endDate) based on:
|
|
5
|
+
* if no `cycleDuration` is provided, and the `endDate` is set to month precision (e.g., `2000-01`),
|
|
6
|
+
assumed it ended on the 14th of the month.
|
|
7
|
+
"""
|
|
8
|
+
from hestia_earth.utils.date import is_in_months
|
|
9
|
+
|
|
10
|
+
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
11
|
+
from . import MODEL
|
|
12
|
+
|
|
13
|
+
REQUIREMENTS = {
|
|
14
|
+
"Cycle": {
|
|
15
|
+
"endDate": "month precision",
|
|
16
|
+
"none": {
|
|
17
|
+
"cycleDuration": ""
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
RETURNS = {
|
|
22
|
+
"The endDate as a string": ""
|
|
23
|
+
}
|
|
24
|
+
MODEL_KEY = 'endDate'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _run(cycle: dict):
|
|
28
|
+
endDate = cycle.get('endDate')
|
|
29
|
+
return f"{endDate}-14"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _should_run(cycle: dict):
|
|
33
|
+
has_endDate = cycle.get('endDate') is not None
|
|
34
|
+
has_month_precision = has_endDate and is_in_months(cycle.get('endDate'))
|
|
35
|
+
no_cycleDuration = cycle.get('cycleDuration') is None
|
|
36
|
+
|
|
37
|
+
logRequirements(cycle, model=MODEL, key=MODEL_KEY, by='endDate',
|
|
38
|
+
has_endDate=has_endDate,
|
|
39
|
+
has_month_precision=has_month_precision,
|
|
40
|
+
no_cycleDuration=no_cycleDuration)
|
|
41
|
+
|
|
42
|
+
should_run = all([has_endDate, has_month_precision, no_cycleDuration])
|
|
43
|
+
logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY, by='endDate')
|
|
44
|
+
return should_run
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def run(cycle: dict): return _run(cycle) if _should_run(cycle) else None
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Other Sites Unused Duration
|
|
3
|
+
|
|
4
|
+
This model sets the [Cycle otherSitesUnusedDuration](https://hestia.earth/schema/Cycle#otherSitesUnusedDuration)
|
|
5
|
+
based on the `otherSites`, `otherSitesDuration`, and the `longFallowRatio` practice associated with each.
|
|
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, log_as_table
|
|
11
|
+
from hestia_earth.models.utils.site import valid_site_type
|
|
12
|
+
from . import MODEL
|
|
13
|
+
|
|
14
|
+
REQUIREMENTS = {
|
|
15
|
+
"Cycle": {
|
|
16
|
+
"otherSites": [{
|
|
17
|
+
"@type": "Site",
|
|
18
|
+
"siteType": ["cropland", "glass and high accessible cover"]
|
|
19
|
+
}],
|
|
20
|
+
"otherSitesDuration": "",
|
|
21
|
+
"practices": [{
|
|
22
|
+
"@type": "Practice",
|
|
23
|
+
"value": "> 0",
|
|
24
|
+
"term.@id": "longFallowRatio",
|
|
25
|
+
"site": {"@type": "Site"}
|
|
26
|
+
}]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
RETURNS = {
|
|
30
|
+
"The otherSitesUnusedDuration as an array of number": ""
|
|
31
|
+
}
|
|
32
|
+
MODEL_KEY = 'otherSitesUnusedDuration'
|
|
33
|
+
VALID_SITE_TYPES = [
|
|
34
|
+
SiteSiteType.CROPLAND.value,
|
|
35
|
+
SiteSiteType.GLASS_OR_HIGH_ACCESSIBLE_COVER.value
|
|
36
|
+
]
|
|
37
|
+
_PRACTICE_TERM_ID = 'longFallowRatio'
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _run(siteDuration: float, longFallowRatio: float):
|
|
41
|
+
return siteDuration * (longFallowRatio - 1)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _find_site_practice(practices: list, site_id: str):
|
|
45
|
+
return list_sum(next(
|
|
46
|
+
(p for p in practices if all([
|
|
47
|
+
p.get('term', {}).get('@id') == _PRACTICE_TERM_ID,
|
|
48
|
+
p.get('site') is None or p.get('site', {}).get('@id', p.get('site', {}).get('id')) == site_id
|
|
49
|
+
])),
|
|
50
|
+
{}
|
|
51
|
+
).get('value'), None)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _should_run(cycle: dict):
|
|
55
|
+
otherSitesDuration = cycle.get('otherSitesDuration', [])
|
|
56
|
+
practices = cycle.get('practices', [])
|
|
57
|
+
|
|
58
|
+
site_data = [
|
|
59
|
+
{
|
|
60
|
+
'site-id': site.get('@id', site.get('id')),
|
|
61
|
+
'siteType': site.get('siteType'),
|
|
62
|
+
'valid-site': valid_site_type(site, site_types=VALID_SITE_TYPES),
|
|
63
|
+
'site-duration': otherSitesDuration[index] if len(otherSitesDuration) > index else None,
|
|
64
|
+
_PRACTICE_TERM_ID: _find_site_practice(practices, site.get('@id'))
|
|
65
|
+
}
|
|
66
|
+
for index, site in enumerate(cycle.get('otherSites', []))
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
has_valid_sites = any([
|
|
70
|
+
all([
|
|
71
|
+
data.get('valid-site'),
|
|
72
|
+
data.get(_PRACTICE_TERM_ID) is not None,
|
|
73
|
+
(data.get('site-duration') or 0) >= 0
|
|
74
|
+
]) for data in site_data
|
|
75
|
+
])
|
|
76
|
+
|
|
77
|
+
logRequirements(cycle, model=MODEL, key=MODEL_KEY,
|
|
78
|
+
has_valid_sites=has_valid_sites,
|
|
79
|
+
site_data=log_as_table(site_data))
|
|
80
|
+
|
|
81
|
+
should_run = all([has_valid_sites])
|
|
82
|
+
logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY)
|
|
83
|
+
return should_run, site_data
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def run(cycle: dict):
|
|
87
|
+
should_run, site_data = _should_run(cycle)
|
|
88
|
+
return [
|
|
89
|
+
_run(data.get('site-duration'), data.get(_PRACTICE_TERM_ID)) if data.get('valid-site') else None
|
|
90
|
+
for data in site_data
|
|
91
|
+
] if should_run else []
|
|
@@ -37,6 +37,7 @@ def _run(cycle: dict, longFallowRatio: float):
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
def _should_run(cycle: dict):
|
|
40
|
+
site_id = cycle.get('site', {}).get('@id', cycle.get('site', {}).get('id'))
|
|
40
41
|
site_type_valid = valid_site_type(cycle.get('site'), site_types=VALID_SITE_TYPES)
|
|
41
42
|
|
|
42
43
|
siteDuration = cycle.get('siteDuration', 0)
|
|
@@ -45,7 +46,7 @@ def _should_run(cycle: dict):
|
|
|
45
46
|
longFallowRatio = list_sum(next((
|
|
46
47
|
p for p in practices if all([
|
|
47
48
|
p.get('term', {}).get('@id') == 'longFallowRatio',
|
|
48
|
-
p.get('site') is None or p.get('site', {}).get('@id'
|
|
49
|
+
p.get('site') is None or p.get('site', {}).get('@id', p.get('site', {}).get('id')) == site_id
|
|
49
50
|
])
|
|
50
51
|
), {}).get('value'), None)
|
|
51
52
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Start Date
|
|
3
3
|
|
|
4
|
-
This model sets the [Cycle startDate](https://hestia.earth/schema/Cycle#startDate) based on
|
|
5
|
-
`cycleDuration
|
|
4
|
+
This model sets the [Cycle startDate](https://hestia.earth/schema/Cycle#startDate) based on:
|
|
5
|
+
* the `cycleDuration` and the `endDate` if it has been provided to a day precision (e.g., `2000-01-01`);
|
|
6
|
+
* if no `cycleDuration` is provided, and the `startDate` is set to month precision (e.g., `2000-01`),
|
|
7
|
+
assumed it started on the 15th of the month.
|
|
6
8
|
"""
|
|
7
9
|
from datetime import timedelta
|
|
8
|
-
from hestia_earth.utils.date import is_in_days
|
|
10
|
+
from hestia_earth.utils.date import is_in_days, is_in_months
|
|
9
11
|
from hestia_earth.utils.tools import safe_parse_date
|
|
10
12
|
|
|
11
13
|
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
@@ -13,8 +15,11 @@ from . import MODEL
|
|
|
13
15
|
|
|
14
16
|
REQUIREMENTS = {
|
|
15
17
|
"Cycle": {
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
+
"optional": {
|
|
19
|
+
"startDate": "month precision",
|
|
20
|
+
"endDate": "day precision",
|
|
21
|
+
"cycleDuration": ""
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
}
|
|
20
25
|
RETURNS = {
|
|
@@ -23,25 +28,48 @@ RETURNS = {
|
|
|
23
28
|
MODEL_KEY = 'startDate'
|
|
24
29
|
|
|
25
30
|
|
|
26
|
-
def
|
|
31
|
+
def _run_by_cycleDuration(cycle: dict):
|
|
27
32
|
endDate = safe_parse_date(cycle.get('endDate'))
|
|
28
33
|
cycleDuration = cycle.get('cycleDuration')
|
|
29
34
|
return (endDate - timedelta(days=cycleDuration)).strftime('%Y-%m-%d')
|
|
30
35
|
|
|
31
36
|
|
|
32
|
-
def
|
|
37
|
+
def _should_run_by_cycleDuration(cycle: dict):
|
|
33
38
|
has_endDate = cycle.get('endDate') is not None
|
|
34
39
|
has_day_precision = has_endDate and is_in_days(cycle.get('endDate'))
|
|
35
40
|
has_cycleDuration = cycle.get('cycleDuration') is not None
|
|
36
41
|
|
|
37
|
-
logRequirements(cycle, model=MODEL, key=MODEL_KEY,
|
|
42
|
+
logRequirements(cycle, model=MODEL, key=MODEL_KEY, by='cycleDuration',
|
|
38
43
|
has_endDate=has_endDate,
|
|
39
44
|
has_day_precision=has_day_precision,
|
|
40
45
|
has_cycleDuration=has_cycleDuration)
|
|
41
46
|
|
|
42
47
|
should_run = all([has_endDate, has_day_precision, has_cycleDuration])
|
|
43
|
-
logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY)
|
|
48
|
+
logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY, by='cycleDuration')
|
|
44
49
|
return should_run
|
|
45
50
|
|
|
46
51
|
|
|
47
|
-
def
|
|
52
|
+
def _run_by_startDate(cycle: dict):
|
|
53
|
+
startDate = cycle.get('startDate')
|
|
54
|
+
return f"{startDate}-15"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _should_run_by_startDate(cycle: dict):
|
|
58
|
+
has_startDate = cycle.get('startDate') is not None
|
|
59
|
+
has_month_precision = has_startDate and is_in_months(cycle.get('startDate'))
|
|
60
|
+
no_cycleDuration = cycle.get('cycleDuration') is None
|
|
61
|
+
|
|
62
|
+
logRequirements(cycle, model=MODEL, key=MODEL_KEY, by='startDate',
|
|
63
|
+
has_startDate=has_startDate,
|
|
64
|
+
has_month_precision=has_month_precision,
|
|
65
|
+
no_cycleDuration=no_cycleDuration)
|
|
66
|
+
|
|
67
|
+
should_run = all([has_startDate, has_month_precision, no_cycleDuration])
|
|
68
|
+
logShouldRun(cycle, MODEL, None, should_run, key=MODEL_KEY, by='startDate')
|
|
69
|
+
return should_run
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def run(cycle: dict):
|
|
73
|
+
return _run_by_cycleDuration(cycle) if _should_run_by_cycleDuration(cycle) else (
|
|
74
|
+
_run_by_startDate(cycle) if _should_run_by_startDate(cycle) else None
|
|
75
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from os.path import dirname, abspath
|
|
2
|
+
import sys
|
|
3
|
+
from importlib import import_module
|
|
4
|
+
|
|
5
|
+
from hestia_earth.models.utils.blank_node import run_if_required
|
|
6
|
+
|
|
7
|
+
CURRENT_DIR = dirname(abspath(__file__)) + '/'
|
|
8
|
+
sys.path.append(CURRENT_DIR)
|
|
9
|
+
MODEL = 'edip2003'
|
|
10
|
+
PKG = '.'.join(['hestia_earth', 'models', MODEL])
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def run(model: str, data): return run_if_required(MODEL, model, data, import_module(f".{model}", package=PKG))
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
2
|
+
from hestia_earth.models.utils.indicator import _new_indicator
|
|
3
|
+
from hestia_earth.models.utils.impact_assessment import impact_lookup_value
|
|
4
|
+
from . import MODEL
|
|
5
|
+
|
|
6
|
+
REQUIREMENTS = {
|
|
7
|
+
"ImpactAssessment": {
|
|
8
|
+
"emissionsResourceUse": [{"@type": "Indicator", "value": "", "term.termType": "emission"}]
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
LOOKUPS = {
|
|
12
|
+
"emission": "ozoneDepletionPotential"
|
|
13
|
+
}
|
|
14
|
+
RETURNS = {
|
|
15
|
+
"Indicator": [{
|
|
16
|
+
"value": ""
|
|
17
|
+
}]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
TERM_ID = 'ozoneDepletionPotential'
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _indicator(value: float):
|
|
24
|
+
indicator = _new_indicator(TERM_ID, MODEL)
|
|
25
|
+
indicator['value'] = value
|
|
26
|
+
return indicator
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def run(impact_assessment: dict):
|
|
30
|
+
value = impact_lookup_value(MODEL, TERM_ID, impact_assessment, LOOKUPS['emission'])
|
|
31
|
+
logRequirements(impact_assessment, model=MODEL, term=TERM_ID,
|
|
32
|
+
value=value)
|
|
33
|
+
logShouldRun(impact_assessment, MODEL, TERM_ID, True)
|
|
34
|
+
return _indicator(value)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from hestia_earth.schema import EmissionMethodTier, EmissionStatsDefinition, CycleFunctionalUnit
|
|
2
|
+
from hestia_earth.utils.model import find_term_match
|
|
3
|
+
from hestia_earth.utils.tools import safe_parse_float, non_empty_list
|
|
4
|
+
|
|
5
|
+
from hestia_earth.models.log import logRequirements, logShouldRun
|
|
6
|
+
from hestia_earth.models.utils.blank_node import get_lookup_value
|
|
7
|
+
from hestia_earth.models.utils.emission import _new_emission
|
|
8
|
+
from . import MODEL
|
|
9
|
+
|
|
10
|
+
REQUIREMENTS = {
|
|
11
|
+
"Cycle": {
|
|
12
|
+
"cycleDuration": "",
|
|
13
|
+
"functionalUnit": "relative",
|
|
14
|
+
"site": {
|
|
15
|
+
"@type": "Site",
|
|
16
|
+
"area": "",
|
|
17
|
+
"measurements": [{
|
|
18
|
+
"@type": "Measurement",
|
|
19
|
+
"term.@id": [
|
|
20
|
+
"salineWater",
|
|
21
|
+
"brackishWater",
|
|
22
|
+
"freshWater"
|
|
23
|
+
]
|
|
24
|
+
}]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
LOOKUPS = {
|
|
29
|
+
"measurement": "IPCC_2019_CH4_aquaculture_EF"
|
|
30
|
+
}
|
|
31
|
+
RETURNS = {
|
|
32
|
+
"Emission": [{
|
|
33
|
+
"value": "",
|
|
34
|
+
"min": "",
|
|
35
|
+
"max": "",
|
|
36
|
+
"methodTier": "tier 1",
|
|
37
|
+
"statsDefinition": "modelled"
|
|
38
|
+
}]
|
|
39
|
+
}
|
|
40
|
+
TERM_ID = 'ch4ToAirAquacultureSystems'
|
|
41
|
+
TIER = EmissionMethodTier.TIER_1.value
|
|
42
|
+
_WATER_TERM_IDS = [
|
|
43
|
+
'salineWater',
|
|
44
|
+
'brackishWater',
|
|
45
|
+
'freshWater'
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _emission(value: float, min: float, max: float):
|
|
50
|
+
emission = _new_emission(TERM_ID, MODEL)
|
|
51
|
+
emission['value'] = [value]
|
|
52
|
+
emission['min'] = [min]
|
|
53
|
+
emission['max'] = [max]
|
|
54
|
+
emission['statsDefinition'] = EmissionStatsDefinition.MODELLED.value
|
|
55
|
+
emission['methodTier'] = TIER
|
|
56
|
+
return emission
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _find_measurement(site: dict):
|
|
60
|
+
measurements = non_empty_list([
|
|
61
|
+
find_term_match(site.get('measurements', []), term_id, None) for term_id in _WATER_TERM_IDS
|
|
62
|
+
])
|
|
63
|
+
return measurements[0] if measurements else None
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _run(cycle: dict):
|
|
67
|
+
cycle_duration = cycle.get('cycleDuration')
|
|
68
|
+
site = cycle.get('site', {})
|
|
69
|
+
site_area = site.get('area')
|
|
70
|
+
water_term = _find_measurement(site).get('term', {})
|
|
71
|
+
factor_value = safe_parse_float(get_lookup_value(water_term, LOOKUPS.get('measurement')))
|
|
72
|
+
factor_min = safe_parse_float(get_lookup_value(water_term, f"{LOOKUPS.get('measurement')}-min"))
|
|
73
|
+
factor_max = safe_parse_float(get_lookup_value(water_term, f"{LOOKUPS.get('measurement')}-max"))
|
|
74
|
+
ratio = site_area * cycle_duration / 365
|
|
75
|
+
return [_emission(ratio * factor_value, ratio * factor_min, ratio * factor_max)]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _should_run(cycle: dict):
|
|
79
|
+
cycle_duration = cycle.get('cycleDuration')
|
|
80
|
+
is_relative = cycle.get('functionalUnit') == CycleFunctionalUnit.RELATIVE.value
|
|
81
|
+
site = cycle.get('site', {})
|
|
82
|
+
site_area = site.get('area')
|
|
83
|
+
has_water_type = _find_measurement(site) is not None
|
|
84
|
+
|
|
85
|
+
logRequirements(cycle, model=MODEL, term=TERM_ID,
|
|
86
|
+
cycle_duration=cycle_duration,
|
|
87
|
+
is_relative=is_relative,
|
|
88
|
+
site_area=site_area,
|
|
89
|
+
has_water_type=has_water_type)
|
|
90
|
+
|
|
91
|
+
should_run = all([cycle_duration, is_relative, site_area, has_water_type])
|
|
92
|
+
logShouldRun(cycle, MODEL, TERM_ID, should_run, methodTier=TIER)
|
|
93
|
+
return should_run
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def run(cycle: dict): return _run(cycle) if _should_run(cycle) else []
|