hestia-earth-models 0.61.2__py3-none-any.whl → 0.61.3__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.

Files changed (53) hide show
  1. hestia_earth/models/cycle/startDateDefinition.py +0 -1
  2. hestia_earth/models/ecoinventV3/__init__.py +6 -2
  3. hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py +125 -0
  4. hestia_earth/models/ecoinventV3AndEmberClimate/utils.py +125 -0
  5. hestia_earth/models/emepEea2019/nh3ToAirInorganicFertiliser.py +10 -4
  6. hestia_earth/models/ipcc2006/n2OToAirInorganicFertiliserDirect.py +16 -8
  7. hestia_earth/models/ipcc2006/n2OToAirInorganicFertiliserIndirect.py +16 -8
  8. hestia_earth/models/ipcc2006/n2OToAirOrganicFertiliserDirect.py +15 -7
  9. hestia_earth/models/ipcc2006/n2OToAirOrganicFertiliserIndirect.py +15 -7
  10. hestia_earth/models/ipcc2019/animal/pastureGrass.py +1 -1
  11. hestia_earth/models/ipcc2019/animal/weightAtMaturity.py +104 -0
  12. hestia_earth/models/ipcc2019/ch4ToAirFloodedRice.py +15 -2
  13. hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserDirect.py +16 -8
  14. hestia_earth/models/ipcc2019/n2OToAirOrganicFertiliserDirect.py +16 -9
  15. hestia_earth/models/ipcc2019/nh3ToAirInorganicFertiliser.py +6 -0
  16. hestia_earth/models/ipcc2019/nh3ToAirOrganicFertiliser.py +9 -3
  17. hestia_earth/models/ipcc2019/no3ToGroundwaterInorganicFertiliser.py +16 -8
  18. hestia_earth/models/ipcc2019/no3ToGroundwaterOrganicFertiliser.py +6 -0
  19. hestia_earth/models/ipcc2019/noxToAirInorganicFertiliser.py +6 -0
  20. hestia_earth/models/ipcc2019/noxToAirOrganicFertiliser.py +9 -3
  21. hestia_earth/models/mocking/search-results.json +165 -114
  22. hestia_earth/models/pooreNemecek2018/no3ToGroundwaterInorganicFertiliser.py +16 -8
  23. hestia_earth/models/pooreNemecek2018/no3ToGroundwaterOrganicFertiliser.py +16 -8
  24. hestia_earth/models/schererPfister2015/pToDrainageWaterSoilFlux.py +13 -1
  25. hestia_earth/models/schererPfister2015/pToSurfaceWaterSoilFlux.py +13 -1
  26. hestia_earth/models/schererPfister2015/utils.py +3 -3
  27. hestia_earth/models/site/management.py +13 -6
  28. hestia_earth/models/site/organicCarbonPerHa.py +6 -4
  29. hestia_earth/models/stehfestBouwman2006/n2OToAirInorganicFertiliserDirect.py +16 -8
  30. hestia_earth/models/stehfestBouwman2006/n2OToAirOrganicFertiliserDirect.py +16 -8
  31. hestia_earth/models/stehfestBouwman2006/noxToAirInorganicFertiliser.py +16 -8
  32. hestia_earth/models/stehfestBouwman2006/noxToAirOrganicFertiliser.py +16 -8
  33. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirInorganicFertiliser.py +16 -8
  34. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirOrganicFertiliser.py +16 -8
  35. hestia_earth/models/utils/blank_node.py +29 -0
  36. hestia_earth/models/utils/cycle.py +6 -4
  37. hestia_earth/models/utils/fertiliser.py +14 -0
  38. hestia_earth/models/utils/inorganicFertiliser.py +7 -0
  39. hestia_earth/models/utils/organicFertiliser.py +9 -0
  40. hestia_earth/models/utils/pesticideAI.py +6 -17
  41. hestia_earth/models/utils/term.py +22 -0
  42. hestia_earth/models/version.py +1 -1
  43. hestia_earth/models/webbEtAl2012AndSintermannEtAl2012/nh3ToAirOrganicFertiliser.py +17 -9
  44. {hestia_earth_models-0.61.2.dist-info → hestia_earth_models-0.61.3.dist-info}/METADATA +2 -2
  45. {hestia_earth_models-0.61.2.dist-info → hestia_earth_models-0.61.3.dist-info}/RECORD +53 -46
  46. tests/models/ipcc2019/animal/test_weightAtMaturity.py +20 -0
  47. tests/models/ipcc2019/test_ch4ToAirEntericFermentation.py +0 -5
  48. tests/models/site/test_management.py +8 -4
  49. tests/models/test_ecoinventV3.py +1 -1
  50. tests/models/test_ecoinventV3AndEmberClimate.py +93 -0
  51. {hestia_earth_models-0.61.2.dist-info → hestia_earth_models-0.61.3.dist-info}/LICENSE +0 -0
  52. {hestia_earth_models-0.61.2.dist-info → hestia_earth_models-0.61.3.dist-info}/WHEEL +0 -0
  53. {hestia_earth_models-0.61.2.dist-info → hestia_earth_models-0.61.3.dist-info}/top_level.txt +0 -0
@@ -8,15 +8,23 @@ from . import MODEL
8
8
  REQUIREMENTS = {
9
9
  "Cycle": {
10
10
  "completeness.fertiliser": "True",
11
- "inputs": [{
12
- "@type": "Input",
13
- "value": "",
14
- "term.units": ["kg", "kg N"],
15
- "term.termType": "inorganicFertiliser",
16
- "optional": {
17
- "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
11
+ "inputs": [
12
+ {
13
+ "@type": "Input",
14
+ "value": "",
15
+ "term.units": ["kg", "kg N"],
16
+ "term.termType": "inorganicFertiliser",
17
+ "optional": {
18
+ "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
19
+ }
20
+ },
21
+ {
22
+ "@type": "Input",
23
+ "value": "",
24
+ "term.termType": "fertiliserBrandName",
25
+ "properties": [{"@type": "Property", "value": "", "key.termType": "inorganicFertiliser"}]
18
26
  }
19
- }],
27
+ ],
20
28
  "site": {
21
29
  "@type": "Site",
22
30
  "measurements": [
@@ -8,15 +8,23 @@ from . import MODEL
8
8
  REQUIREMENTS = {
9
9
  "Cycle": {
10
10
  "completeness.fertiliser": "True",
11
- "inputs": [{
12
- "@type": "Input",
13
- "value": "",
14
- "term.units": ["kg", "kg N"],
15
- "term.termType": "organicFertiliser",
16
- "optional": {
17
- "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
11
+ "inputs": [
12
+ {
13
+ "@type": "Input",
14
+ "value": "",
15
+ "term.units": ["kg", "kg N"],
16
+ "term.termType": "organicFertiliser",
17
+ "optional": {
18
+ "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
19
+ }
20
+ },
21
+ {
22
+ "@type": "Input",
23
+ "value": "",
24
+ "term.termType": "fertiliserBrandName",
25
+ "properties": [{"@type": "Property", "value": "", "key.termType": "organicFertiliser"}]
18
26
  }
19
- }],
27
+ ],
20
28
  "site": {
21
29
  "@type": "Site",
22
30
  "measurements": [
@@ -9,7 +9,19 @@ from . import MODEL
9
9
  REQUIREMENTS = {
10
10
  "Cycle": {
11
11
  "endDate": "",
12
- "inputs": [{"@type": "Input", "value": "", "term.termType": "organicFertiliser"}],
12
+ "inputs": [
13
+ {
14
+ "@type": "Input",
15
+ "value": "",
16
+ "term.termType": "organicFertiliser"
17
+ },
18
+ {
19
+ "@type": "Input",
20
+ "value": "",
21
+ "term.termType": "fertiliserBrandName",
22
+ "properties": [{"@type": "Property", "value": "", "key.termType": "organicFertiliser"}]
23
+ }
24
+ ],
13
25
  "site": {
14
26
  "@type": "Site",
15
27
  "country": {"@type": "Term", "termType": "region"},
@@ -10,7 +10,19 @@ from .utils import get_liquid_slurry_sludge_P_total
10
10
  REQUIREMENTS = {
11
11
  "Cycle": {
12
12
  "endDate": "",
13
- "inputs": [{"@type": "Input", "value": "", "term.termType": "organicFertiliser"}],
13
+ "inputs": [
14
+ {
15
+ "@type": "Input",
16
+ "value": "",
17
+ "term.termType": "organicFertiliser"
18
+ },
19
+ {
20
+ "@type": "Input",
21
+ "value": "",
22
+ "term.termType": "fertiliserBrandName",
23
+ "properties": [{"@type": "Property", "value": "", "key.termType": "organicFertiliser"}]
24
+ }
25
+ ],
14
26
  "site": {
15
27
  "@type": "Site",
16
28
  "country": {"@type": "Term", "termType": "region"},
@@ -1,11 +1,11 @@
1
- from hestia_earth.models.utils.term import get_tillage_terms
2
1
  from hestia_earth.schema import TermTermType
3
2
  from hestia_earth.utils.tools import list_sum, safe_parse_float
4
3
  from hestia_earth.utils.model import filter_list_term_type, find_primary_product
5
4
 
6
5
  from hestia_earth.models.utils.blank_node import get_total_value, get_P2O5_total
7
- from hestia_earth.models.utils.term import get_lookup_value
6
+ from hestia_earth.models.utils.term import get_lookup_value, get_tillage_terms
8
7
  from hestia_earth.models.utils.input import match_lookup_value
8
+ from hestia_earth.models.utils.organicFertiliser import get_cycle_inputs as get_organicFertiliser_inputs
9
9
 
10
10
  SLOPE_RANGE = [
11
11
  [0.0, 0.03, 1.2],
@@ -20,7 +20,7 @@ SLOPE_RANGE = [
20
20
 
21
21
 
22
22
  def get_liquid_slurry_sludge_P_total(cycle: dict):
23
- inputs = filter_list_term_type(cycle.get('inputs', []), TermTermType.ORGANICFERTILISER)
23
+ inputs = get_organicFertiliser_inputs(cycle)
24
24
  lookup_name = 'OrganicFertiliserClassification'
25
25
  lss_P_total = list_sum(get_P2O5_total([
26
26
  i for i in inputs if match_lookup_value(i, col_name=lookup_name, col_value='Liquid, Slurry, Sewage Sludge')
@@ -1,7 +1,7 @@
1
1
  """
2
2
  Management node with data gap-filled data from cycles.
3
3
  """
4
- from typing import List, Any
4
+ from typing import List, Any, Callable
5
5
  from functools import reduce
6
6
  from hestia_earth.schema import SchemaType, TermTermType
7
7
  from hestia_earth.utils.api import download_hestia
@@ -118,8 +118,12 @@ def _extract_node_value(node: dict) -> dict:
118
118
  def _include(value: dict, keys: list): return {k: v for k, v in value.items() if k in keys}
119
119
 
120
120
 
121
- def _include_start_end(cycle: dict, values: list):
122
- return [(_include(cycle, ['startDate', 'endDate']) | v) for v in values]
121
+ def _default_dates(cycle: dict, values: list):
122
+ return [(_include(cycle, ["startDate", "endDate"]) | v) for v in values]
123
+
124
+
125
+ def _overwrite_dates(cycle: dict, values: list) -> list:
126
+ return [v | _include(cycle, ["startDate", "endDate"]) for v in values]
123
127
 
124
128
 
125
129
  def _copy_item_if_exists(source: dict, keys: List[str] = None, dest: dict = None) -> dict:
@@ -134,11 +138,13 @@ def _get_landCover_term_id(product: dict) -> str:
134
138
  return value.split(';')[0] if value else None
135
139
 
136
140
 
137
- def _get_items_with_relevant_term_type(cycles: List[dict], item_name: str, relevant_values: list):
141
+ def _get_items_with_relevant_term_type(
142
+ cycles: List[dict], item_name: str, relevant_values: list, date_fill: Callable = _default_dates
143
+ ):
138
144
  """Get items from the list of cycles with any of the relevant values. Also adds dates if missing."""
139
145
  return flatten(
140
146
  [
141
- _include_start_end(
147
+ date_fill(
142
148
  cycle=cycle,
143
149
  values=filter_list_term_type(cycle.get(item_name, []), relevant_values)
144
150
  ) for cycle in cycles
@@ -210,7 +216,8 @@ def _should_run(site: dict):
210
216
  products_crop_forage = _get_items_with_relevant_term_type(
211
217
  cycles=cycles,
212
218
  item_name="products",
213
- relevant_values=[TermTermType.CROP, TermTermType.FORAGE]
219
+ relevant_values=[TermTermType.CROP, TermTermType.FORAGE],
220
+ date_fill=_overwrite_dates
214
221
  )
215
222
  products_crop_forage = [
216
223
  _copy_item_if_exists(
@@ -1,4 +1,4 @@
1
- from typing import Optional
1
+ from typing import Optional, Union
2
2
 
3
3
  from hestia_earth.schema import MeasurementMethodClassification
4
4
  from hestia_earth.utils.date import diff_in_days
@@ -53,11 +53,13 @@ SOIL_BULK_DENSITY_TERM_ID = 'soilBulkDensity'
53
53
  ORGANIC_CARBON_PER_KG_SOIL_TERM_ID = 'organicCarbonPerKgSoil'
54
54
 
55
55
 
56
- def _measurement(site: dict, value: float, depthUpper: int, depthLower: int, date: Optional[str] = None):
56
+ def _measurement(
57
+ site: dict, value: float, depthUpper: Union[int, float], depthLower: Union[int, float], date: Optional[str] = None
58
+ ) -> dict:
57
59
  data = _new_measurement(TERM_ID)
58
60
  data['value'] = [value]
59
- data['depthUpper'] = depthUpper
60
- data['depthLower'] = depthLower
61
+ data['depthUpper'] = int(depthUpper)
62
+ data['depthLower'] = int(depthLower)
61
63
  data['methodClassification'] = MeasurementMethodClassification.MODELLED_USING_OTHER_MEASUREMENTS.value
62
64
  if date is not None:
63
65
  data['dates'] = [date]
@@ -8,15 +8,23 @@ from . import MODEL
8
8
  REQUIREMENTS = {
9
9
  "Cycle": {
10
10
  "completeness.fertiliser": "True",
11
- "inputs": [{
12
- "@type": "Input",
13
- "value": "",
14
- "term.units": ["kg", "kg N"],
15
- "term.termType": "inorganicFertiliser",
16
- "optional": {
17
- "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
11
+ "inputs": [
12
+ {
13
+ "@type": "Input",
14
+ "value": "",
15
+ "term.units": ["kg", "kg N"],
16
+ "term.termType": "inorganicFertiliser",
17
+ "optional": {
18
+ "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
19
+ }
20
+ },
21
+ {
22
+ "@type": "Input",
23
+ "value": "",
24
+ "term.termType": "fertiliserBrandName",
25
+ "properties": [{"@type": "Property", "value": "", "key.termType": "inorganicFertiliser"}]
18
26
  }
19
- }],
27
+ ],
20
28
  "site": {
21
29
  "@type": "Site",
22
30
  "measurements": [
@@ -8,15 +8,23 @@ from . import MODEL
8
8
  REQUIREMENTS = {
9
9
  "Cycle": {
10
10
  "completeness.fertiliser": "True",
11
- "inputs": [{
12
- "@type": "Input",
13
- "value": "",
14
- "term.units": ["kg", "kg N"],
15
- "term.termType": "organicFertiliser",
16
- "optional": {
17
- "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
11
+ "inputs": [
12
+ {
13
+ "@type": "Input",
14
+ "value": "",
15
+ "term.units": ["kg", "kg N"],
16
+ "term.termType": "organicFertiliser",
17
+ "optional": {
18
+ "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
19
+ }
20
+ },
21
+ {
22
+ "@type": "Input",
23
+ "value": "",
24
+ "term.termType": "fertiliserBrandName",
25
+ "properties": [{"@type": "Property", "value": "", "key.termType": "organicFertiliser"}]
18
26
  }
19
- }],
27
+ ],
20
28
  "site": {
21
29
  "@type": "Site",
22
30
  "measurements": [
@@ -8,15 +8,23 @@ from . import MODEL
8
8
  REQUIREMENTS = {
9
9
  "Cycle": {
10
10
  "completeness.fertiliser": "True",
11
- "inputs": [{
12
- "@type": "Input",
13
- "value": "",
14
- "term.units": ["kg", "kg N"],
15
- "term.termType": "inorganicFertiliser",
16
- "optional": {
17
- "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
11
+ "inputs": [
12
+ {
13
+ "@type": "Input",
14
+ "value": "",
15
+ "term.units": ["kg", "kg N"],
16
+ "term.termType": "inorganicFertiliser",
17
+ "optional": {
18
+ "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
19
+ }
20
+ },
21
+ {
22
+ "@type": "Input",
23
+ "value": "",
24
+ "term.termType": "fertiliserBrandName",
25
+ "properties": [{"@type": "Property", "value": "", "key.termType": "inorganicFertiliser"}]
18
26
  }
19
- }],
27
+ ],
20
28
  "site": {
21
29
  "@type": "Site",
22
30
  "measurements": [
@@ -8,15 +8,23 @@ from . import MODEL
8
8
  REQUIREMENTS = {
9
9
  "Cycle": {
10
10
  "completeness.fertiliser": "True",
11
- "inputs": [{
12
- "@type": "Input",
13
- "value": "",
14
- "term.units": ["kg", "kg N"],
15
- "term.termType": "organicFertiliser",
16
- "optional": {
17
- "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
11
+ "inputs": [
12
+ {
13
+ "@type": "Input",
14
+ "value": "",
15
+ "term.units": ["kg", "kg N"],
16
+ "term.termType": "organicFertiliser",
17
+ "optional": {
18
+ "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
19
+ }
20
+ },
21
+ {
22
+ "@type": "Input",
23
+ "value": "",
24
+ "term.termType": "fertiliserBrandName",
25
+ "properties": [{"@type": "Property", "value": "", "key.termType": "organicFertiliser"}]
18
26
  }
19
- }],
27
+ ],
20
28
  "site": {
21
29
  "@type": "Site",
22
30
  "measurements": [
@@ -8,15 +8,23 @@ from . import MODEL
8
8
  REQUIREMENTS = {
9
9
  "Cycle": {
10
10
  "completeness.fertiliser": "True",
11
- "inputs": [{
12
- "@type": "Input",
13
- "value": "",
14
- "term.units": ["kg", "kg N"],
15
- "term.termType": "inorganicFertiliser",
16
- "optional": {
17
- "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
11
+ "inputs": [
12
+ {
13
+ "@type": "Input",
14
+ "value": "",
15
+ "term.units": ["kg", "kg N"],
16
+ "term.termType": "inorganicFertiliser",
17
+ "optional": {
18
+ "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
19
+ }
20
+ },
21
+ {
22
+ "@type": "Input",
23
+ "value": "",
24
+ "term.termType": "fertiliserBrandName",
25
+ "properties": [{"@type": "Property", "value": "", "key.termType": "inorganicFertiliser"}]
18
26
  }
19
- }],
27
+ ],
20
28
  "site": {
21
29
  "@type": "Site",
22
30
  "country": {"@type": "Term", "termType": "region"}
@@ -8,15 +8,23 @@ from . import MODEL
8
8
  REQUIREMENTS = {
9
9
  "Cycle": {
10
10
  "completeness.fertiliser": "True",
11
- "inputs": [{
12
- "@type": "Input",
13
- "value": "",
14
- "term.units": ["kg", "kg N"],
15
- "term.termType": "organicFertiliser",
16
- "optional": {
17
- "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
11
+ "inputs": [
12
+ {
13
+ "@type": "Input",
14
+ "value": "",
15
+ "term.units": ["kg", "kg N"],
16
+ "term.termType": "organicFertiliser",
17
+ "optional": {
18
+ "properties": [{"@type": "Property", "value": "", "term.@id": "nitrogenContent"}]
19
+ }
20
+ },
21
+ {
22
+ "@type": "Input",
23
+ "value": "",
24
+ "term.termType": "fertiliserBrandName",
25
+ "properties": [{"@type": "Property", "value": "", "key.termType": "organicFertiliser"}]
18
26
  }
19
- }],
27
+ ],
20
28
  "site": {
21
29
  "@type": "Site",
22
30
  "country": {"@type": "Term", "termType": "region"}
@@ -14,7 +14,9 @@ from typing import (
14
14
  Optional,
15
15
  Union
16
16
  )
17
+ from hestia_earth.schema import TermTermType
17
18
  from hestia_earth.utils.api import download_hestia
19
+ from hestia_earth.utils.model import filter_list_term_type
18
20
  from hestia_earth.utils.tools import (
19
21
  flatten,
20
22
  list_sum,
@@ -1229,3 +1231,30 @@ def group_nodes_by_last_date(nodes: list) -> dict[str, list[dict]]:
1229
1231
  return group | {key: group.get(key, []) + [node]}
1230
1232
 
1231
1233
  return reduce(group_by, nodes, {})
1234
+
1235
+
1236
+ def get_inputs_from_properties(input: dict, term_types: Union[TermTermType, List[TermTermType]]):
1237
+ """
1238
+ Compute a list of inputs from the input properties, in the `key:value` form.
1239
+
1240
+ Parameters
1241
+ ----------
1242
+ input : dict
1243
+ The Input.
1244
+ term_types : TermTermType | List[TermTermType]
1245
+ List of `termType` valid for the properties `key`.
1246
+
1247
+ Return
1248
+ ------
1249
+ dict
1250
+ A dictionary of nodes grouped by latest date, in the format `{date: list[node]}`.
1251
+ """
1252
+ input_value = list_sum(input.get('value', []))
1253
+ properties = input.get('properties') or download_hestia(input.get('term', {}).get('@id')).get('defaultProperties')
1254
+ inputs = non_empty_list([
1255
+ {
1256
+ 'term': p.get('key'),
1257
+ 'value': [(p.get('value') / 100) * (p.get('share', 100) / 100) * input_value]
1258
+ } for p in (properties or []) if all([p.get('key'), p.get('value')])
1259
+ ]) if input_value > 0 else []
1260
+ return filter_list_term_type(inputs, term_types)
@@ -12,6 +12,8 @@ from .measurement import most_relevant_measurement_value
12
12
  from .site import valid_site_type as site_valid_site_type
13
13
  from .crop import is_plantation
14
14
  from .currency import DEFAULT_CURRENCY
15
+ from .inorganicFertiliser import get_cycle_inputs as get_inorganicFertiliser_inputs
16
+ from .organicFertiliser import get_cycle_inputs as get_organicFertiliser_inputs
15
17
 
16
18
 
17
19
  def unique_currencies(cycle: dict) -> list:
@@ -121,7 +123,7 @@ def get_organic_fertiliser_N_total(cycle: dict) -> float:
121
123
  float
122
124
  The total value as a number.
123
125
  """
124
- values = get_N_total(filter_list_term_type(cycle.get('inputs', []), TermTermType.ORGANICFERTILISER))
126
+ values = get_N_total(get_organicFertiliser_inputs(cycle))
125
127
  default_value = 0 if _is_term_type_complete(cycle, 'fertiliser') else None
126
128
  return list_sum(values, default_value)
127
129
 
@@ -147,7 +149,7 @@ def get_organic_fertiliser_P_total(cycle: dict) -> float:
147
149
  float
148
150
  The total value as a number.
149
151
  """
150
- values = get_P2O5_total(filter_list_term_type(cycle.get('inputs', []), TermTermType.ORGANICFERTILISER))
152
+ values = get_P2O5_total(get_organicFertiliser_inputs(cycle))
151
153
  default_value = 0 if _is_term_type_complete(cycle, 'fertiliser') else None
152
154
  return list_sum(values, default_value)
153
155
 
@@ -171,7 +173,7 @@ def get_inorganic_fertiliser_N_total(cycle: dict) -> float:
171
173
  float
172
174
  The total value as a number.
173
175
  """
174
- values = get_N_total(filter_list_term_type(cycle.get('inputs', []), TermTermType.INORGANICFERTILISER))
176
+ values = get_N_total(get_inorganicFertiliser_inputs(cycle))
175
177
  default_value = 0 if _is_term_type_complete(cycle, 'fertiliser') else None
176
178
  return list_sum(values, default_value)
177
179
 
@@ -195,7 +197,7 @@ def get_inorganic_fertiliser_P_total(cycle: dict) -> float:
195
197
  float
196
198
  The total value as a number.
197
199
  """
198
- values = get_P2O5_total(filter_list_term_type(cycle.get('inputs', []), TermTermType.INORGANICFERTILISER))
200
+ values = get_P2O5_total(get_inorganicFertiliser_inputs(cycle))
199
201
  default_value = 0 if _is_term_type_complete(cycle, 'fertiliser') else None
200
202
  return list_sum(values, default_value)
201
203
 
@@ -0,0 +1,14 @@
1
+ from typing import Union, List
2
+ from hestia_earth.schema import TermTermType
3
+ from hestia_earth.utils.model import filter_list_term_type
4
+ from hestia_earth.utils.tools import flatten
5
+
6
+ from .blank_node import get_inputs_from_properties
7
+
8
+ _TERM_TYPES = [TermTermType.INORGANICFERTILISER, TermTermType.ORGANICFERTILISER]
9
+
10
+
11
+ def get_fertilisers_from_inputs(cycle: dict, term_types: Union[TermTermType, List[TermTermType]] = _TERM_TYPES):
12
+ inputs = flatten(cycle.get('inputs', []) + [a.get('inputs', []) for a in cycle.get('animals', [])])
13
+ inputs = filter_list_term_type(inputs, TermTermType.FERTILISERBRANDNAME)
14
+ return flatten([get_inputs_from_properties(i, term_types) for i in inputs])
@@ -1,9 +1,11 @@
1
1
  from hestia_earth.schema import TermTermType
2
2
  from hestia_earth.utils.lookup import column_name, download_lookup, get_table_value, extract_grouped_data
3
3
  from hestia_earth.utils.tools import safe_parse_float
4
+ from hestia_earth.utils.model import filter_list_term_type
4
5
 
5
6
  from ..log import debugMissingLookup
6
7
  from .term import get_lookup_value
8
+ from .fertiliser import get_fertilisers_from_inputs
7
9
 
8
10
  BREAKDOWN_LOOKUP = 'region-inorganicFertiliser-fertGroupingNitrogen-breakdown.csv'
9
11
 
@@ -37,3 +39,8 @@ def get_country_breakdown(model: str, term_id: str, country_id: str, col_name: s
37
39
  value = get_table_value(lookup, 'termid', country_id, column_name(col_name))
38
40
  debugMissingLookup(BREAKDOWN_LOOKUP, 'termid', country_id, col_name, value, model=model, term=term_id)
39
41
  return safe_parse_float(value, 1)
42
+
43
+
44
+ def get_cycle_inputs(cycle: dict):
45
+ return filter_list_term_type(cycle.get('inputs', []), TermTermType.INORGANICFERTILISER) + \
46
+ get_fertilisers_from_inputs(cycle, TermTermType.INORGANICFERTILISER)
@@ -0,0 +1,9 @@
1
+ from hestia_earth.schema import TermTermType
2
+ from hestia_earth.utils.model import filter_list_term_type
3
+
4
+ from .fertiliser import get_fertilisers_from_inputs
5
+
6
+
7
+ def get_cycle_inputs(cycle: dict):
8
+ return filter_list_term_type(cycle.get('inputs', []), TermTermType.ORGANICFERTILISER) + \
9
+ get_fertilisers_from_inputs(cycle, TermTermType.ORGANICFERTILISER)
@@ -1,36 +1,25 @@
1
1
  from hestia_earth.schema import TermTermType
2
- from hestia_earth.utils.api import download_hestia
3
2
  from hestia_earth.utils.model import filter_list_term_type
4
- from hestia_earth.utils.tools import flatten, non_empty_list, list_sum
3
+ from hestia_earth.utils.tools import flatten
5
4
 
6
5
  from hestia_earth.models.log import logRequirements, logShouldRun
6
+ from .blank_node import get_inputs_from_properties
7
7
  from .impact_assessment import convert_value_from_cycle, get_product
8
8
  from .cycle import impact_lookup_value as cycle_lookup_value
9
9
 
10
10
 
11
- def _get_input_from_properties(input: dict):
12
- input_value = list_sum(input.get('value', []))
13
- properties = input.get('properties') or download_hestia(input.get('term', {}).get('@id')).get('defaultProperties')
14
- return non_empty_list([
15
- {'term': p.get('key'), 'value': [p.get('value') / 100 * input_value]} for p in (properties or []) if all([
16
- p.get('key'), p.get('value')
17
- ])
18
- ]) if input_value > 0 else []
19
-
20
-
21
- def get_from_inputs(cycle: dict):
11
+ def get_pesticides_from_inputs(cycle: dict):
22
12
  inputs = flatten(cycle.get('inputs', []) + [a.get('inputs', []) for a in cycle.get('animals', [])])
23
13
  inputs = filter_list_term_type(inputs, TermTermType.PESTICIDEBRANDNAME)
24
- return flatten([
25
- _get_input_from_properties(i) for i in inputs
26
- ])
14
+ return flatten([get_inputs_from_properties(i, TermTermType.PESTICIDEAI) for i in inputs])
27
15
 
28
16
 
29
17
  def impact_lookup_value(model: str, term_id: str, impact_assessment: dict, lookup_col: str):
30
18
  cycle = impact_assessment.get('cycle', {})
31
19
  is_complete = cycle.get('completeness', {}).get('pesticideVeterinaryDrug', False)
32
20
  product = get_product(impact_assessment)
33
- pesticides = filter_list_term_type(cycle.get('inputs', []), TermTermType.PESTICIDEAI) + get_from_inputs(cycle)
21
+ pesticides = filter_list_term_type(cycle.get('inputs', []), TermTermType.PESTICIDEAI) + \
22
+ get_pesticides_from_inputs(cycle)
34
23
  has_pesticides_inputs = len(pesticides) > 0
35
24
  pesticides_total_value = convert_value_from_cycle(
36
25
  product, cycle_lookup_value(model, term_id, pesticides, lookup_col, False), model=model, term_id=term_id
@@ -603,3 +603,25 @@ def get_pasture_system_terms():
603
603
  'name': 'pasture'
604
604
  }, limit=LIMIT)
605
605
  return list(map(lambda n: n["@id"], terms))
606
+
607
+
608
+ def get_electricity_grid_mix_terms():
609
+ """
610
+ Find all `Electricity` terms with the name `grid mix`:
611
+ https://hestia.earth/glossary?termType=electricity&query=grid%20mix
612
+
613
+ Returns
614
+ -------
615
+ list
616
+ List of matching `Term` as dict.
617
+ """
618
+ return search({
619
+ "bool": {
620
+ "must": [
621
+ {"match": {"@type": SchemaType.TERM.value}},
622
+ {"match": {"termType.keyword": TermTermType.ELECTRICITY.value}},
623
+ {"match": {"name": "grid"}},
624
+ {"match": {"name": "mix"}}
625
+ ],
626
+ }
627
+ }, limit=LIMIT, fields=['@type', '@id', 'name', 'termType', 'units'])
@@ -1 +1 @@
1
- VERSION = '0.61.2'
1
+ VERSION = '0.61.3'