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

@@ -7,6 +7,7 @@ from functools import reduce
7
7
  from typing import Tuple
8
8
 
9
9
  from hestia_earth.utils.tools import list_sum, flatten
10
+ from hestia_earth.utils.model import linked_node
10
11
  from hestia_earth.schema import EmissionMethodTier
11
12
 
12
13
  from hestia_earth.models.log import logShouldRun, logRequirements, log_blank_nodes_id
@@ -14,6 +15,7 @@ from hestia_earth.models.utils.emission import _new_emission
14
15
  from hestia_earth.models.utils.blank_node import group_by_keys
15
16
  from hestia_earth.models.utils.completeness import _is_term_type_complete
16
17
  from hestia_earth.models.utils.term import get_electricity_grid_mix_terms
18
+ from hestia_earth.models.utils.cycle import cycle_end_year
17
19
  from .utils import get_emission, get_all_emission_terms
18
20
 
19
21
  REQUIREMENTS = {
@@ -52,7 +54,7 @@ def _emission(value: float, term_id: str, inputs: list, operation: dict) -> dict
52
54
  emission = _new_emission(term_id, MODEL)
53
55
  emission['value'] = [value]
54
56
  emission['methodTier'] = TIER
55
- emission["inputs"] = list(inputs)
57
+ emission['inputs'] = list(map(linked_node, inputs))
56
58
  if operation:
57
59
  emission["operation"] = operation
58
60
  return emission
@@ -65,23 +67,34 @@ def _grid_inputs(inputs: list, electricity_grid_terms: list):
65
67
  ]
66
68
 
67
69
 
68
- def _run_input(cycle: dict, inputs: list, emission_term_id: str, input_term: dict):
69
- inputs = _grid_inputs(inputs, [input_term])
70
- return [
71
- _emission(
72
- value=get_emission(
73
- term_id=emission_term_id,
74
- country=cycle.get("site", {}).get("country", {}).get("@id", ""),
75
- energy=list_sum(flatten([i.get("value", []) for i in op_inputs])),
76
- year=cycle.get("endDate", ""),
77
- model=MODEL
78
- ),
70
+ def _run_input(cycle: dict, inputs: list, emission_term_id: str, electricity_grid_term: dict):
71
+ electricity_grid_inputs = [electricity_grid_term]
72
+ inputs = _grid_inputs(inputs, electricity_grid_inputs)
73
+
74
+ def run(grouped_inputs: list):
75
+ input = grouped_inputs[0]
76
+ term_id = input.get('term', {}).get('@id')
77
+ input_value = list_sum(flatten(input.get('value', []) for input in grouped_inputs))
78
+ country_id = cycle.get("site", {}).get("country", {}).get("@id")
79
+ year = cycle_end_year(cycle)
80
+ value = get_emission(
79
81
  term_id=emission_term_id,
80
- inputs=[input_term],
81
- operation=op_inputs[0].get("operation")
82
+ country=country_id,
83
+ energy=input_value,
84
+ year=year,
85
+ model=MODEL
82
86
  )
83
- for op_inputs in _group_by_operation(inputs).values()
84
- ] if inputs else []
87
+
88
+ logRequirements(cycle, model=MODEL, term=term_id,
89
+ input_value=input_value,
90
+ emission_value=value)
91
+
92
+ should_run = all([input_value > 0, value])
93
+ logShouldRun(cycle, MODEL, term_id, should_run, methodTier=TIER)
94
+
95
+ return _emission(value, emission_term_id, electricity_grid_inputs, input.get("operation"))
96
+
97
+ return list(map(run, _group_by_operation(inputs).values() if inputs else []))
85
98
 
86
99
 
87
100
  def _group_by_operation(inputs: list) -> dict:
@@ -94,8 +107,8 @@ def _run_emission(cycle: dict, electricity_grid_terms: list, inputs: list, emiss
94
107
  cycle=cycle,
95
108
  inputs=inputs,
96
109
  emission_term_id=emission_term_id,
97
- input_term=input_term
98
- ) for input_term in electricity_grid_terms
110
+ electricity_grid_term=electricity_grid_term
111
+ ) for electricity_grid_term in electricity_grid_terms
99
112
  ])
100
113
 
101
114
 
@@ -104,11 +117,16 @@ def _should_run_emission(cycle: dict, electricity_grid_terms: list, term_id: str
104
117
  inputs = _grid_inputs(cycle.get('inputs', []), electricity_grid_terms)
105
118
  has_relevant_inputs = bool(inputs)
106
119
  has_country = bool(cycle.get("site", {}).get("country", {}))
120
+ has_end_date = bool(cycle.get("endDate"))
107
121
 
108
122
  logRequirements(cycle, model=MODEL, term=term_id,
109
- input_ids=log_blank_nodes_id(inputs))
123
+ term_type_electricityFuel_complete=term_type_complete,
124
+ input_ids=log_blank_nodes_id(inputs),
125
+ has_relevant_inputs=has_relevant_inputs,
126
+ has_country=has_country,
127
+ has_end_date=has_end_date)
110
128
 
111
- should_run = all([term_type_complete, has_relevant_inputs, has_country])
129
+ should_run = all([term_type_complete, has_relevant_inputs, has_country, has_end_date])
112
130
  logShouldRun(cycle, MODEL, term_id, should_run, methodTier=TIER)
113
131
  return should_run, inputs
114
132
 
@@ -120,6 +138,6 @@ def _run_emissions(cycle: dict, electricity_grid_terms: list):
120
138
  return run_emissions_for_term
121
139
 
122
140
 
123
- def run(cycle: dict):
141
+ def run(_, cycle: dict):
124
142
  electricity_grid_terms = get_electricity_grid_mix_terms()
125
143
  return flatten(list(map(_run_emissions(cycle, electricity_grid_terms), get_all_emission_terms())))
@@ -10,27 +10,18 @@ from hestia_earth.models.data.ecoinventV3 import ecoinventV3_emissions
10
10
  EMBER_ECOINVENT_LOOKUP_NAME = "ember-ecoinvent-mapping.csv"
11
11
 
12
12
 
13
- def _lookup_data(term_id: str, grouping: str, country_id: str, year: int, lookup_name: str, **log_args):
13
+ def _lookup_data(term_id: str, grouping: str, country_id: str, year: str, lookup_name: str, **log_args):
14
14
  lookup = download_lookup(lookup_name)
15
- data = get_table_value(lookup, 'termid', country_id, column_name(grouping))
16
- debugMissingLookup(lookup_name, 'termid', country_id, grouping, data, term=term_id, **log_args)
17
- percentage = extract_grouped_data(data, str(year))
15
+ column = column_name(grouping)
16
+ data = get_table_value(lookup, 'termid', country_id, column)
17
+ percentage = extract_grouped_data(data, year)
18
+ debugMissingLookup(lookup_name, 'termid', country_id, column, percentage, year=year, term=term_id, **log_args)
18
19
  return safe_parse_float(percentage, None)
19
20
 
20
21
 
21
22
  def _convert_name(name: str) -> str: return name.replace(";", ",")
22
23
 
23
24
 
24
- def _safe_parse_int(value: str, default=0):
25
- """
26
- Parse a string into an int.
27
- """
28
- try:
29
- return int(value)
30
- except ValueError:
31
- return default
32
-
33
-
34
25
  def _zero_from_non_numeric(value: Any) -> float:
35
26
  try:
36
27
  return float(value)
@@ -62,7 +53,7 @@ def _get_emission_rate_per_source(ember_ecoinvent_mapping: Dict, emission_term_i
62
53
  }
63
54
 
64
55
 
65
- def get_emission(term_id: str, country: str, year: str, energy: float, model: str) -> float:
56
+ def get_emission(term_id: str, country: str, year: int, energy: float, model: str) -> float:
66
57
  """
67
58
  Get the <term_id> emissions in kg for the energy consumed.
68
59
  a: ecoInventId of each source - from "ember-ecoinvent-mapping.csv"
@@ -89,7 +80,7 @@ def get_emission(term_id: str, country: str, year: str, energy: float, model: st
89
80
  term_id=source,
90
81
  grouping=source,
91
82
  country_id=country,
92
- year=_safe_parse_int(year),
83
+ year=str(year),
93
84
  lookup_name="region-ember-energySources.csv",
94
85
  model=model
95
86
  )
@@ -1,6 +1,7 @@
1
1
  import os
2
2
  from inspect import getmembers, isfunction
3
3
  import json
4
+ from hestia_earth.utils.tools import flatten
4
5
 
5
6
  from hestia_earth.models.log import logger
6
7
  from hestia_earth.models.utils import term
@@ -14,7 +15,7 @@ def _map_results(results):
14
15
  # returning the whole term
15
16
  return [results] if isinstance(results, dict) else (
16
17
  {'@type': 'Term', '@id': results} if isinstance(results, str) else
17
- list(map(_map_results, results)) if isinstance(results, list) else
18
+ flatten(map(_map_results, results)) if isinstance(results, list) else
18
19
  None
19
20
  )
20
21
 
@@ -1113,26 +1113,22 @@
1113
1113
  }
1114
1114
  },
1115
1115
  "results": [
1116
- [
1117
- {
1118
- "@type": "Term",
1119
- "name": "Electricity, grid, renewable mix",
1120
- "termType": "electricity",
1121
- "@id": "electricityGridRenewableMix",
1122
- "units": "kWh",
1123
- "_score": 27.711746
1124
- }
1125
- ],
1126
- [
1127
- {
1128
- "@type": "Term",
1129
- "name": "Electricity, grid, market mix",
1130
- "termType": "electricity",
1131
- "@id": "electricityGridMarketMix",
1132
- "units": "kWh",
1133
- "_score": 27.711746
1134
- }
1135
- ]
1116
+ {
1117
+ "@type": "Term",
1118
+ "name": "Electricity, grid, renewable mix",
1119
+ "termType": "electricity",
1120
+ "@id": "electricityGridRenewableMix",
1121
+ "units": "kWh",
1122
+ "_score": 27.711746
1123
+ },
1124
+ {
1125
+ "@type": "Term",
1126
+ "name": "Electricity, grid, market mix",
1127
+ "termType": "electricity",
1128
+ "@id": "electricityGridMarketMix",
1129
+ "units": "kWh",
1130
+ "_score": 27.711746
1131
+ }
1136
1132
  ]
1137
1133
  },
1138
1134
  {
@@ -1 +1 @@
1
- VERSION = '0.61.3'
1
+ VERSION = '0.61.5'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hestia-earth-models
3
- Version: 0.61.3
3
+ Version: 0.61.5
4
4
  Summary: Hestia's set of modules for filling gaps in the activity data using external datasets (e.g. populating soil properties with a geospatial dataset using provided coordinates) and internal lookups (e.g. populating machinery use from fuel use). Includes rules for when gaps should be filled versus not (e.g. never gap fill yield, gap fill crop residue if yield provided etc.).
5
5
  Home-page: https://gitlab.com/hestia-earth/hestia-engine-models
6
6
  Author: Hestia Team
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3.6
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: hestia-earth.schema ==28.*
15
- Requires-Dist: hestia-earth.utils >=0.12.6
15
+ Requires-Dist: hestia-earth.utils >=0.13.0
16
16
  Requires-Dist: python-dateutil >=2.8.1
17
17
  Requires-Dist: CurrencyConverter ==0.16.8
18
18
  Requires-Dist: haversine >=2.7.0
@@ -3,7 +3,7 @@ hestia_earth/models/__init__.py,sha256=qEFeq3yuf3lQKVseALmL8aPM8fpCS54B_5pry00M3
3
3
  hestia_earth/models/cache_sites.py,sha256=KQp9cUKE-aIcYJoMWEtKFYS8gBFfsx5LKQhqoWpUSoM,6065
4
4
  hestia_earth/models/log.py,sha256=b63I3qyTtQs17xxbq8RI0Fv2lvZ1oDZ9k0njhxqiFFk,3459
5
5
  hestia_earth/models/requirements.py,sha256=znNZJAhwX2iYiKcAQXPftY7z_1MsNa0QxCXkXyHm_U0,17363
6
- hestia_earth/models/version.py,sha256=udATuWRkjmyXbQMDrQ7L8ZfZbgPNc9NrQyIikiyw35s,19
6
+ hestia_earth/models/version.py,sha256=B-nNMbNCza5Xs1ctuDa5VlUAhx8D4prlU9I-wHx7Hcg,19
7
7
  hestia_earth/models/agribalyse2016/__init__.py,sha256=WvK0qCQbnYtg9oZxrACd1wGormZyXibPtpCnIQeDqbw,415
8
8
  hestia_earth/models/agribalyse2016/fuelElectricity.py,sha256=mrh8seYSYdTgcMDCETLiknuPeJehg071YoG4UiyW0yU,4404
9
9
  hestia_earth/models/agribalyse2016/machineryInfrastructureDepreciatedAmountPerCycle.py,sha256=_Rbngu0DzHKa62JwBl58ZC_ui1zLF2que_nB7ukhOQc,3392
@@ -106,8 +106,8 @@ hestia_earth/models/data/ecoinventV3/__init__.py,sha256=oevyurRuioXy_CsQCtG-S_FX
106
106
  hestia_earth/models/deRuijterEtAl2010/__init__.py,sha256=lbH6mB98dmZZlwdZctNYtEmVwAow957l80Dv7JSPDsI,418
107
107
  hestia_earth/models/deRuijterEtAl2010/nh3ToAirCropResidueDecomposition.py,sha256=2z10WqMsGUDDO8xJ3lmXvSUHgzz2t6PPRDha5NHoT5s,3291
108
108
  hestia_earth/models/ecoinventV3/__init__.py,sha256=nSktsE0c9ohx1FyDEEi-YlnGgMGNd-actCwPs_htzC0,6309
109
- hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py,sha256=ZReEjdgfg_pBOQqCCk24r7z7MaEng6yr-ZP1QgCfyoY,4385
110
- hestia_earth/models/ecoinventV3AndEmberClimate/utils.py,sha256=Vh8cGkgvbcq3b8tE8Y_8LI1PYqrt9E53fPwInKoYmaY,4577
109
+ hestia_earth/models/ecoinventV3AndEmberClimate/__init__.py,sha256=H5fxfUy6HLHxRgvG3oPZ8pnLbq3Axm0Ejkp9CQ2UGlM,5306
110
+ hestia_earth/models/ecoinventV3AndEmberClimate/utils.py,sha256=mV55GMUxe_fORBVDWGBxOqmH2JVDKhLoKodJ7UzC38c,4420
111
111
  hestia_earth/models/emepEea2019/__init__.py,sha256=l90-pWrqIzt1ap1WNk0gF4iZeF5_TSG62hE83bIi4rQ,412
112
112
  hestia_earth/models/emepEea2019/co2ToAirFuelCombustion.py,sha256=DfoGlB5HjA1gafO0OutJjfsA6yPP_PsAd-p16evwCiQ,1609
113
113
  hestia_earth/models/emepEea2019/n2OToAirFuelCombustionDirect.py,sha256=R3lRF5-Md4Jd7irvTe8WJZJPc9-wa1pD6UWVk7lnGtQ,1616
@@ -358,8 +358,8 @@ hestia_earth/models/linkedImpactAssessment/landTransformationFromPermanentPastur
358
358
  hestia_earth/models/linkedImpactAssessment/landTransformationFromPermanentPasture20YearAverageInputsProduction.py,sha256=pdluhfRQuJK0EHq-L0s0TOf37tvOQYB-M-wZiuSbarw,1050
359
359
  hestia_earth/models/linkedImpactAssessment/utils.py,sha256=dGwGc2d-8_WQElTpfyPmz5vQtL-LHQRmiZnCTuPXMDs,1876
360
360
  hestia_earth/models/mocking/__init__.py,sha256=kmSeOTSvurMUxw7Ajhf3G-SVPQ1NgmirMTk4TSOEicY,765
361
- hestia_earth/models/mocking/mock_search.py,sha256=V-ycVBTkJu7PP37Ivy_16hpKBV4aEtJb5S9DfChPNSU,2038
362
- hestia_earth/models/mocking/search-results.json,sha256=FuWHaK_s8PNp46cP3fBfE7kwkm4Tu_HlMGz8Y62UWLk,41248
361
+ hestia_earth/models/mocking/mock_search.py,sha256=B_ATXOyeP_zVhQRktqJP5BZfLFCzE09o9XqDitkggG8,2086
362
+ hestia_earth/models/mocking/search-results.json,sha256=kD4tqX17b_Nijn8P4aPLe6E8Otipufy2XV-zLqEyhd0,41184
363
363
  hestia_earth/models/pooreNemecek2018/__init__.py,sha256=nPboL7ULJzL5nJD5q7q9VOZt_fxbKVm8fmn1Az5YkVY,417
364
364
  hestia_earth/models/pooreNemecek2018/aboveGroundCropResidueTotal.py,sha256=Qt-mel4dkhK6N5uUOutNOinCTFjbjtGzITaaI0LvYc4,2396
365
365
  hestia_earth/models/pooreNemecek2018/belowGroundCropResidue.py,sha256=JT0RybbvWVlo01FO8K0Yj41HrEaJT3Kj1xfayr2X-xw,2315
@@ -557,7 +557,7 @@ hestia_earth/models/webbEtAl2012AndSintermannEtAl2012/nh3ToAirOrganicFertiliser.
557
557
  tests/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
558
558
  tests/models/test_cache_sites.py,sha256=AsZSGb4ruFqag74wRaQxpoZxbMxexPY8q8sMb2ergzg,1986
559
559
  tests/models/test_ecoinventV3.py,sha256=gde7ny9ThMmezkDcTmS3ZKn82MNOaNSrpMcbkTjFJxk,1491
560
- tests/models/test_ecoinventV3AndEmberClimate.py,sha256=r_Wy7rvzM1G9mqsFgdIsEJ3BPdRE91cx4FobxVmpmtg,3621
560
+ tests/models/test_ecoinventV3AndEmberClimate.py,sha256=_V4d01j6itpwa_22H2GbSlRfOLN5KZLCxCIjkPdwoNg,3660
561
561
  tests/models/test_emissionNotRelevant.py,sha256=YXTdRfcdR_JepHuj2P3Y3r0aFMKNOmsXQHY48tmLTQo,1316
562
562
  tests/models/agribalyse2016/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
563
563
  tests/models/agribalyse2016/test_fuelElectricity.py,sha256=u_wNlqngJc8NELPr16kYsYQ-_2PcL8BnrfJucY7dccU,1353
@@ -1069,8 +1069,8 @@ tests/models/utils/test_source.py,sha256=mv3vHZV5cjpoLA2I1109-YUkuzAiuhbRSnv_76_
1069
1069
  tests/models/utils/test_term.py,sha256=M5Sa26v2gzQYbZ4H_fo7DspnaCx__-WtL-MULGapCWk,3509
1070
1070
  tests/models/webbEtAl2012AndSintermannEtAl2012/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1071
1071
  tests/models/webbEtAl2012AndSintermannEtAl2012/test_nh3ToAirOrganicFertiliser.py,sha256=qi2FNXS5Af2WDtm7nq_FsprH3BfCF0XxnE0XHmC4aIY,2244
1072
- hestia_earth_models-0.61.3.dist-info/LICENSE,sha256=AC7h7GAgCZGJK_Tzh6LUCrML9gQEfowWwecEw2w54QM,1154
1073
- hestia_earth_models-0.61.3.dist-info/METADATA,sha256=useT0uZJrlTEXw8_mab7qYrr94U0oOCUgqeB-l39Qcw,3134
1074
- hestia_earth_models-0.61.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
1075
- hestia_earth_models-0.61.3.dist-info/top_level.txt,sha256=1dqA9TqpOLTEgpqa-YBsmbCmmNU1y56AtfFGEceZ2A0,19
1076
- hestia_earth_models-0.61.3.dist-info/RECORD,,
1072
+ hestia_earth_models-0.61.5.dist-info/LICENSE,sha256=AC7h7GAgCZGJK_Tzh6LUCrML9gQEfowWwecEw2w54QM,1154
1073
+ hestia_earth_models-0.61.5.dist-info/METADATA,sha256=ysVUlLWO6-b7GOw12O3oUg5q9uC43Fy3GeMDawIAHEQ,3134
1074
+ hestia_earth_models-0.61.5.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
1075
+ hestia_earth_models-0.61.5.dist-info/top_level.txt,sha256=1dqA9TqpOLTEgpqa-YBsmbCmmNU1y56AtfFGEceZ2A0,19
1076
+ hestia_earth_models-0.61.5.dist-info/RECORD,,
@@ -10,8 +10,8 @@ from hestia_earth.models.ecoinventV3AndEmberClimate import MODEL, _should_run_em
10
10
  class_path = f"hestia_earth.models.{MODEL}"
11
11
  fixtures_folder = f"{fixtures_path}/{MODEL}"
12
12
 
13
- cycle_with_country = {"site": {"country": {"@type": "Term", "termType": "region"}}}
14
- cycle_without_country = {"site": {"country": {}}}
13
+ cycle_with_country = {"endDate": "2010", "site": {"country": {"@type": "Term", "termType": "region"}}}
14
+ cycle_without_country = {"endDate": "2010", "site": {"country": {}}}
15
15
  ELECTRICITY_TERMS = [
16
16
  {"@type": "Term", "@id": "electricityGridMarketMix"},
17
17
  {"@type": "Term", "@id": "electricityGridRenewableMix"}
@@ -89,5 +89,5 @@ def test_run(mock_ecoinventV3_emissions, *args):
89
89
  with open(f"{fixtures_folder}/result.jsonld", encoding="utf-8") as f:
90
90
  expected = json.load(f)
91
91
 
92
- value = run(cycle=cycle)
92
+ value = run('all', cycle)
93
93
  assert value == expected