hestia-earth-models 0.64.1__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.

@@ -15,7 +15,9 @@ from . import MODEL
15
15
 
16
16
  REQUIREMENTS = {
17
17
  "Cycle": {
18
- "inputs": [{"@type": "Practice", "value": "", "term.termType": ["crop", "animalProduct"]}],
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 = [TermTermType.CROP.value, TermTermType.ANIMALPRODUCT.value]
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(inputs) / len(values) if len(inputs) and len(values) else 0
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,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 []