hestia-earth-aggregation 0.21.13__py3-none-any.whl → 0.21.15__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.
- hestia_earth/aggregation/utils/aggregate_country_nodes.py +45 -3
- hestia_earth/aggregation/utils/aggregate_weighted.py +8 -1
- hestia_earth/aggregation/utils/completeness.py +0 -1
- hestia_earth/aggregation/utils/emission.py +15 -0
- hestia_earth/aggregation/version.py +1 -1
- {hestia_earth_aggregation-0.21.13.dist-info → hestia_earth_aggregation-0.21.15.dist-info}/METADATA +1 -1
- {hestia_earth_aggregation-0.21.13.dist-info → hestia_earth_aggregation-0.21.15.dist-info}/RECORD +10 -10
- {hestia_earth_aggregation-0.21.13.dist-info → hestia_earth_aggregation-0.21.15.dist-info}/WHEEL +1 -1
- {hestia_earth_aggregation-0.21.13.dist-info → hestia_earth_aggregation-0.21.15.dist-info}/licenses/LICENSE +0 -0
- {hestia_earth_aggregation-0.21.13.dist-info → hestia_earth_aggregation-0.21.15.dist-info}/top_level.txt +0 -0
|
@@ -10,6 +10,7 @@ from hestia_earth.utils.tools import (
|
|
|
10
10
|
flatten,
|
|
11
11
|
is_number,
|
|
12
12
|
is_boolean,
|
|
13
|
+
current_time_ms,
|
|
13
14
|
)
|
|
14
15
|
from hestia_earth.utils.blank_node import (
|
|
15
16
|
ArrayTreatment,
|
|
@@ -60,7 +61,11 @@ from .site import (
|
|
|
60
61
|
format_site_description,
|
|
61
62
|
site_parent_region_id,
|
|
62
63
|
)
|
|
63
|
-
from .emission import
|
|
64
|
+
from .emission import (
|
|
65
|
+
get_method_tier,
|
|
66
|
+
get_method_model,
|
|
67
|
+
has_value_without_transformation,
|
|
68
|
+
)
|
|
64
69
|
from .property import aggregate_properties
|
|
65
70
|
from .distribution import generate_blank_node_distribution
|
|
66
71
|
from .covariance import add_covariance_cycles, generate_covariance_cycles
|
|
@@ -109,6 +114,8 @@ class BlankNodeFormatted(TypedDict, total=False):
|
|
|
109
114
|
completeness_key: Optional[str]
|
|
110
115
|
start_date: Optional[str]
|
|
111
116
|
end_date: str
|
|
117
|
+
inputs: List[dict]
|
|
118
|
+
transformation: List[dict]
|
|
112
119
|
|
|
113
120
|
|
|
114
121
|
# --- Cycle
|
|
@@ -242,6 +249,8 @@ def _group_cycle_blank_node(cycle: dict, product: dict, product_value: float):
|
|
|
242
249
|
"economicValueShare": non_empty_list([_blank_node_evs(blank_nodes)]),
|
|
243
250
|
# needed for background emissions
|
|
244
251
|
"inputs": _map_values(blank_nodes, "inputs"),
|
|
252
|
+
# needed to exclude emissions with only transformation value
|
|
253
|
+
"transformation": _map_values(blank_nodes, "transformation"),
|
|
245
254
|
"properties": _map_values(blank_nodes, "properties"),
|
|
246
255
|
"methodTier": _map_values(blank_nodes, "methodTier"),
|
|
247
256
|
"methodModel": _map_values(blank_nodes, "methodModel"),
|
|
@@ -292,14 +301,22 @@ def _group_cycle_blank_nodes(
|
|
|
292
301
|
end_year: int = None,
|
|
293
302
|
):
|
|
294
303
|
def grouper(group: dict, list_key: str) -> Dict[str, Dict[str, BlankNodeFormatted]]:
|
|
304
|
+
now = current_time_ms()
|
|
295
305
|
blank_nodes = _filter_blank_nodes(cycle, list_key, start_year, end_year)
|
|
296
306
|
values = reduce(
|
|
297
307
|
_group_cycle_blank_node(cycle, product, product_value), blank_nodes, {}
|
|
298
308
|
)
|
|
299
309
|
# after combining all values, need to compute the final statistical values
|
|
300
310
|
group[list_key] = {
|
|
301
|
-
k: v | _compute_blank_node_stats(v)
|
|
311
|
+
k: v | _compute_blank_node_stats(v)
|
|
312
|
+
for k, v in values.items()
|
|
313
|
+
if list_key != "emissions" or has_value_without_transformation(v)
|
|
302
314
|
}
|
|
315
|
+
logger.debug(
|
|
316
|
+
"function=_group_cycle_blank_nodes, list_key=%s, time=%s",
|
|
317
|
+
list_key,
|
|
318
|
+
current_time_ms() - now,
|
|
319
|
+
)
|
|
303
320
|
return group
|
|
304
321
|
|
|
305
322
|
return grouper
|
|
@@ -405,6 +422,7 @@ def _combine_cycle_blank_nodes(
|
|
|
405
422
|
cycles: List[CycleFormatted], completeness: Dict[str, int], cycle_count: int
|
|
406
423
|
):
|
|
407
424
|
def combine(group: dict, list_key: str):
|
|
425
|
+
now = current_time_ms()
|
|
408
426
|
# get all possible keys first, then group each key values into a single blank node
|
|
409
427
|
keys = set(flatten([list(cycle.get(list_key, {}).keys()) for cycle in cycles]))
|
|
410
428
|
group[list_key] = reduce(
|
|
@@ -412,6 +430,11 @@ def _combine_cycle_blank_nodes(
|
|
|
412
430
|
keys,
|
|
413
431
|
{},
|
|
414
432
|
)
|
|
433
|
+
logger.debug(
|
|
434
|
+
"function=_combine_cycle_blank_nodes, list_key=%s, time=%s",
|
|
435
|
+
list_key,
|
|
436
|
+
current_time_ms() - now,
|
|
437
|
+
)
|
|
415
438
|
return group
|
|
416
439
|
|
|
417
440
|
return combine
|
|
@@ -511,8 +534,14 @@ def _group_site_blank_nodes(
|
|
|
511
534
|
site: SiteJSONLD, start_year: int = None, end_year: int = None
|
|
512
535
|
):
|
|
513
536
|
def grouper(group: dict, list_key: str) -> Dict[str, BlankNodeFormatted]:
|
|
537
|
+
now = current_time_ms()
|
|
514
538
|
blank_nodes = _filter_blank_nodes(site, list_key, start_year, end_year)
|
|
515
539
|
group[list_key] = reduce(_group_site_blank_node(), blank_nodes, {})
|
|
540
|
+
logger.debug(
|
|
541
|
+
"function=_group_site_blank_nodes, list_key=%s, time=%s",
|
|
542
|
+
list_key,
|
|
543
|
+
current_time_ms() - now,
|
|
544
|
+
)
|
|
516
545
|
return group
|
|
517
546
|
|
|
518
547
|
return grouper
|
|
@@ -559,9 +588,15 @@ def _combine_site_blank_node(sites: List[SiteFormatted], list_key: str):
|
|
|
559
588
|
|
|
560
589
|
def _combine_site_blank_nodes(sites: List[SiteFormatted]):
|
|
561
590
|
def combine(group: dict, list_key: str):
|
|
591
|
+
now = current_time_ms()
|
|
562
592
|
# get all possible keys first, then group each key values into a single blank node
|
|
563
593
|
keys = set(flatten([list(site.get(list_key, {}).keys()) for site in sites]))
|
|
564
594
|
group[list_key] = reduce(_combine_site_blank_node(sites, list_key), keys, {})
|
|
595
|
+
logger.debug(
|
|
596
|
+
"function=_combine_site_blank_nodes, list_key=%s, time=%s",
|
|
597
|
+
list_key,
|
|
598
|
+
current_time_ms() - now,
|
|
599
|
+
)
|
|
565
600
|
return group
|
|
566
601
|
|
|
567
602
|
return combine
|
|
@@ -647,9 +682,16 @@ def _aggregate_formatted(
|
|
|
647
682
|
data: Union[CycleFormatted, SiteFormatted], aggregated_keys: List[str]
|
|
648
683
|
):
|
|
649
684
|
def aggregate(key: str):
|
|
685
|
+
now = current_time_ms()
|
|
650
686
|
values = data.get(key, {}).values()
|
|
651
687
|
logger.debug(f"Aggregating {len(values)} {key}...")
|
|
652
|
-
|
|
688
|
+
values = list(map(_aggregate_blank_node, values))
|
|
689
|
+
logger.debug(
|
|
690
|
+
"function=_aggregate_formatted, key=%s, time=%s",
|
|
691
|
+
key,
|
|
692
|
+
current_time_ms() - now,
|
|
693
|
+
)
|
|
694
|
+
return values
|
|
653
695
|
|
|
654
696
|
return reduce(lambda group, key: group | {key: aggregate(key)}, aggregated_keys, {})
|
|
655
697
|
|
|
@@ -6,9 +6,11 @@ from hestia_earth.utils.tools import (
|
|
|
6
6
|
list_sum,
|
|
7
7
|
list_average,
|
|
8
8
|
is_boolean,
|
|
9
|
+
current_time_ms,
|
|
9
10
|
)
|
|
10
11
|
from hestia_earth.utils.blank_node import get_node_value
|
|
11
12
|
|
|
13
|
+
from hestia_earth.aggregation.log import logger
|
|
12
14
|
from . import weighted_average, _min, _max, _sd, format_evs, pick
|
|
13
15
|
from .emission import get_method_tier, get_method_model
|
|
14
16
|
from .property import aggregate_properties
|
|
@@ -188,14 +190,19 @@ def _aggregate_nodes(
|
|
|
188
190
|
aggregate_keys: List[str], data: dict, weights: dict, missing_weights_node_id_func
|
|
189
191
|
):
|
|
190
192
|
def aggregate_single(key: str):
|
|
193
|
+
now = current_time_ms()
|
|
191
194
|
aggregates_map: dict = data.get(key)
|
|
192
195
|
terms = aggregates_map.keys()
|
|
193
|
-
|
|
196
|
+
values = non_empty_list(
|
|
194
197
|
map(
|
|
195
198
|
_aggregate_term(aggregates_map, weights, missing_weights_node_id_func),
|
|
196
199
|
terms,
|
|
197
200
|
)
|
|
198
201
|
)
|
|
202
|
+
logger.debug(
|
|
203
|
+
"function=_aggregate_nodes, key=%s, time=%s", key, current_time_ms() - now
|
|
204
|
+
)
|
|
205
|
+
return values
|
|
199
206
|
|
|
200
207
|
return reduce(
|
|
201
208
|
lambda prev, curr: prev | {curr: aggregate_single(curr)}, aggregate_keys, {}
|
|
@@ -69,3 +69,18 @@ def get_method_model(emissions: list):
|
|
|
69
69
|
values = non_empty_list(flatten([e.get("methodModel", []) for e in emissions]))
|
|
70
70
|
values = list({v["@id"]: v for v in values}.values())
|
|
71
71
|
return values[0] if len(values) == 1 else None
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def has_value_without_transformation(blank_node: dict):
|
|
75
|
+
values = blank_node.get("value", [])
|
|
76
|
+
transformations = blank_node.get("transformation", [])
|
|
77
|
+
return (
|
|
78
|
+
not transformations
|
|
79
|
+
or len(transformations) != len(values)
|
|
80
|
+
or any(
|
|
81
|
+
[
|
|
82
|
+
value is not None and transformations[index] is None
|
|
83
|
+
for index, value in enumerate(values)
|
|
84
|
+
]
|
|
85
|
+
)
|
|
86
|
+
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = "0.21.
|
|
1
|
+
VERSION = "0.21.15"
|
{hestia_earth_aggregation-0.21.13.dist-info → hestia_earth_aggregation-0.21.15.dist-info}/RECORD
RENAMED
|
@@ -2,18 +2,18 @@ hestia_earth/aggregation/__init__.py,sha256=5r0icTYP5F4DFIX-Xm1Ms3inpAUfpXQwOmO2
|
|
|
2
2
|
hestia_earth/aggregation/aggregate_cycles.py,sha256=9BRX41d0uLhKLUPBlALxAoRMfPriDj3Dhy0sTgmTS5Y,7812
|
|
3
3
|
hestia_earth/aggregation/log.py,sha256=0CibXDtKqFfE-R86qziM2uH7ATUZ6I9p_bVpRSn_e_o,2351
|
|
4
4
|
hestia_earth/aggregation/recalculate_cycles.py,sha256=xCO_tj5BAC407vZ36EVuxeOBmX2y82EXRrTx5W6g4CY,484
|
|
5
|
-
hestia_earth/aggregation/version.py,sha256=
|
|
5
|
+
hestia_earth/aggregation/version.py,sha256=Z3Ng7JCS2UZEW-r2srjuHslYzJkIywa_nSkx0uI3j84,20
|
|
6
6
|
hestia_earth/aggregation/config/Cycle/processedFood.json,sha256=JWelgL-ZLnurS9R8Y-HOXjiWZ5k3kAuUQHDoMcukEq8,1127
|
|
7
7
|
hestia_earth/aggregation/utils/__init__.py,sha256=nVVLgVFZ4415CgQAqgv4jDamA7gDmzOWk5SY4vshAQs,6583
|
|
8
|
-
hestia_earth/aggregation/utils/aggregate_country_nodes.py,sha256=
|
|
9
|
-
hestia_earth/aggregation/utils/aggregate_weighted.py,sha256=
|
|
8
|
+
hestia_earth/aggregation/utils/aggregate_country_nodes.py,sha256=U39M2clD9_6FE0yFYvamP7EI8FrCQ350pzD0y_9Rw_Y,28806
|
|
9
|
+
hestia_earth/aggregation/utils/aggregate_weighted.py,sha256=CUTqR8z3_MRnGhzAOiFswy68Twe1GaNCyrSd5x7qf_Q,7037
|
|
10
10
|
hestia_earth/aggregation/utils/blank_node.py,sha256=f8JBcd5_SLqW8juzFAfbZysAESaZXj8JX6C7rDkLEoc,16812
|
|
11
11
|
hestia_earth/aggregation/utils/combine.py,sha256=EmXUZksdkrtQ6o1gMOG5WMivUhL28NKSM9D4cPohJiE,4904
|
|
12
|
-
hestia_earth/aggregation/utils/completeness.py,sha256=
|
|
12
|
+
hestia_earth/aggregation/utils/completeness.py,sha256=eZ759PAdOSshhys-YKKPEpAYxR3sTrEjI--WJTEwmus,4633
|
|
13
13
|
hestia_earth/aggregation/utils/covariance.py,sha256=2VaNGPvyD4ub3rR-OBn8VIEIeAz4JOefl6ZlAtXKj4U,5884
|
|
14
14
|
hestia_earth/aggregation/utils/cycle.py,sha256=gzU2KofOVGBZvOPTymJGpsbbouABjSzUM35OJ42sFl8,15954
|
|
15
15
|
hestia_earth/aggregation/utils/distribution.py,sha256=2XQKXVu-1XUy1zEHgThERupaj4RizXKO5F-VY-QQlMo,6935
|
|
16
|
-
hestia_earth/aggregation/utils/emission.py,sha256=
|
|
16
|
+
hestia_earth/aggregation/utils/emission.py,sha256=2roXjGmDuS7a3muPJoEOqg7E-TZyQsnoavhU6b3B-Z8,2983
|
|
17
17
|
hestia_earth/aggregation/utils/group.py,sha256=qU9sAuJu0RG80yLs90nsyoOcU57Pb6M1WKwT1TlJEkM,4765
|
|
18
18
|
hestia_earth/aggregation/utils/input.py,sha256=pZ1bcdHR3y4S-3b0JZllbEUWdEyVZbltxv-07j7SucI,1092
|
|
19
19
|
hestia_earth/aggregation/utils/lookup.py,sha256=osJiXTRns5KeBMz3mRsanmFQTATrwcMVBzB07xrb71M,2046
|
|
@@ -28,8 +28,8 @@ hestia_earth/aggregation/utils/site.py,sha256=nc1N4IRiTki69IbCX4G6lagQ5U7IpsOsqi
|
|
|
28
28
|
hestia_earth/aggregation/utils/source.py,sha256=SOiE-jB5WNtbRxreUWQ8c04ywzrwICy1aGyRL3-L0RY,686
|
|
29
29
|
hestia_earth/aggregation/utils/term.py,sha256=uVAfBYnxNkcTNfzuwwHur6JGBahNrPwR2pN-__sj9zk,2758
|
|
30
30
|
hestia_earth/aggregation/utils/weights.py,sha256=3WO2_26bj1RB2h524Gknu0btvTFJucqMtn-tag339aY,6843
|
|
31
|
-
hestia_earth_aggregation-0.21.
|
|
32
|
-
hestia_earth_aggregation-0.21.
|
|
33
|
-
hestia_earth_aggregation-0.21.
|
|
34
|
-
hestia_earth_aggregation-0.21.
|
|
35
|
-
hestia_earth_aggregation-0.21.
|
|
31
|
+
hestia_earth_aggregation-0.21.15.dist-info/licenses/LICENSE,sha256=TD25LoiRJsA5CPUNrcyt1PXlGcbUGFMAeZoBcfCrCNE,1154
|
|
32
|
+
hestia_earth_aggregation-0.21.15.dist-info/METADATA,sha256=XgOXgQA87fTsZYpB8xXvgcz1Mp5LP7Kkec3Ik5wlLZo,2481
|
|
33
|
+
hestia_earth_aggregation-0.21.15.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
34
|
+
hestia_earth_aggregation-0.21.15.dist-info/top_level.txt,sha256=q0QxKEYx9uLpAD5ZtC7Ypq29smEPfOzEAn7Xv8XHGOQ,13
|
|
35
|
+
hestia_earth_aggregation-0.21.15.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|