hestia-earth-aggregation 0.21.12__py3-none-any.whl → 0.21.14__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/aggregate_cycles.py +15 -13
- hestia_earth/aggregation/utils/aggregate_country_nodes.py +33 -1
- hestia_earth/aggregation/utils/aggregate_weighted.py +10 -13
- hestia_earth/aggregation/utils/completeness.py +0 -1
- hestia_earth/aggregation/utils/cycle.py +17 -2
- hestia_earth/aggregation/utils/weights.py +16 -1
- hestia_earth/aggregation/version.py +1 -1
- {hestia_earth_aggregation-0.21.12.dist-info → hestia_earth_aggregation-0.21.14.dist-info}/METADATA +1 -1
- {hestia_earth_aggregation-0.21.12.dist-info → hestia_earth_aggregation-0.21.14.dist-info}/RECORD +12 -12
- {hestia_earth_aggregation-0.21.12.dist-info → hestia_earth_aggregation-0.21.14.dist-info}/WHEEL +1 -1
- {hestia_earth_aggregation-0.21.12.dist-info → hestia_earth_aggregation-0.21.14.dist-info}/licenses/LICENSE +0 -0
- {hestia_earth_aggregation-0.21.12.dist-info → hestia_earth_aggregation-0.21.14.dist-info}/top_level.txt +0 -0
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
from typing import Tuple
|
|
2
2
|
from hestia_earth.utils.tools import non_empty_list
|
|
3
3
|
|
|
4
|
-
from
|
|
5
|
-
from
|
|
6
|
-
from
|
|
7
|
-
from
|
|
4
|
+
from .log import logger, log_memory_usage
|
|
5
|
+
from .utils import CYCLE_AGGREGATION_KEYS, SITE_AGGREGATION_KEYS
|
|
6
|
+
from .utils.term import is_global
|
|
7
|
+
from .utils.queries import (
|
|
8
8
|
find_global_nodes,
|
|
9
9
|
find_country_nodes,
|
|
10
10
|
download_site,
|
|
11
11
|
)
|
|
12
|
-
from
|
|
13
|
-
from
|
|
14
|
-
from
|
|
12
|
+
from .utils.group import group_blank_nodes
|
|
13
|
+
from .utils.blank_node import cleanup_node_blank_nodes
|
|
14
|
+
from .utils.aggregate_weighted import (
|
|
15
15
|
aggregate as aggregate_weighted,
|
|
16
16
|
)
|
|
17
|
-
from
|
|
18
|
-
from
|
|
17
|
+
from .utils.aggregate_country_nodes import aggregate_cycles
|
|
18
|
+
from .utils.weights import (
|
|
19
19
|
country_weights,
|
|
20
20
|
country_weight_node_id,
|
|
21
21
|
world_weights,
|
|
22
22
|
world_weight_node_id,
|
|
23
23
|
)
|
|
24
|
-
from
|
|
24
|
+
from .utils.site import (
|
|
25
25
|
format_site,
|
|
26
26
|
format_site_description_weighted,
|
|
27
27
|
)
|
|
28
|
-
from
|
|
28
|
+
from .utils.cycle import (
|
|
29
29
|
aggregate_with_matrix,
|
|
30
30
|
format_for_grouping,
|
|
31
31
|
format_terms_results,
|
|
32
32
|
format_country_results,
|
|
33
33
|
update_cycle,
|
|
34
34
|
)
|
|
35
|
-
from
|
|
35
|
+
from .utils.covariance import (
|
|
36
36
|
init_covariance_files,
|
|
37
37
|
remove_covariance_files,
|
|
38
38
|
generate_covariance_country,
|
|
@@ -83,7 +83,9 @@ def _aggregate_country(
|
|
|
83
83
|
sites, weights, use_description=not is_global(country)
|
|
84
84
|
)
|
|
85
85
|
|
|
86
|
-
cycle_data = format_country_results(
|
|
86
|
+
cycle_data = format_country_results(
|
|
87
|
+
cycle_data, product, country, aggregated_site, weights
|
|
88
|
+
)
|
|
87
89
|
aggregated_cycle = update_cycle(
|
|
88
90
|
country, start_year, end_year, source, functional_unit, False
|
|
89
91
|
)(cycle_data)
|
|
@@ -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,
|
|
@@ -292,6 +293,7 @@ def _group_cycle_blank_nodes(
|
|
|
292
293
|
end_year: int = None,
|
|
293
294
|
):
|
|
294
295
|
def grouper(group: dict, list_key: str) -> Dict[str, Dict[str, BlankNodeFormatted]]:
|
|
296
|
+
now = current_time_ms()
|
|
295
297
|
blank_nodes = _filter_blank_nodes(cycle, list_key, start_year, end_year)
|
|
296
298
|
values = reduce(
|
|
297
299
|
_group_cycle_blank_node(cycle, product, product_value), blank_nodes, {}
|
|
@@ -300,6 +302,11 @@ def _group_cycle_blank_nodes(
|
|
|
300
302
|
group[list_key] = {
|
|
301
303
|
k: v | _compute_blank_node_stats(v) for k, v in values.items()
|
|
302
304
|
}
|
|
305
|
+
logger.debug(
|
|
306
|
+
"function=_group_cycle_blank_nodes, list_key=%s, time=%s",
|
|
307
|
+
list_key,
|
|
308
|
+
current_time_ms() - now,
|
|
309
|
+
)
|
|
303
310
|
return group
|
|
304
311
|
|
|
305
312
|
return grouper
|
|
@@ -405,6 +412,7 @@ def _combine_cycle_blank_nodes(
|
|
|
405
412
|
cycles: List[CycleFormatted], completeness: Dict[str, int], cycle_count: int
|
|
406
413
|
):
|
|
407
414
|
def combine(group: dict, list_key: str):
|
|
415
|
+
now = current_time_ms()
|
|
408
416
|
# get all possible keys first, then group each key values into a single blank node
|
|
409
417
|
keys = set(flatten([list(cycle.get(list_key, {}).keys()) for cycle in cycles]))
|
|
410
418
|
group[list_key] = reduce(
|
|
@@ -412,6 +420,11 @@ def _combine_cycle_blank_nodes(
|
|
|
412
420
|
keys,
|
|
413
421
|
{},
|
|
414
422
|
)
|
|
423
|
+
logger.debug(
|
|
424
|
+
"function=_combine_cycle_blank_nodes, list_key=%s, time=%s",
|
|
425
|
+
list_key,
|
|
426
|
+
current_time_ms() - now,
|
|
427
|
+
)
|
|
415
428
|
return group
|
|
416
429
|
|
|
417
430
|
return combine
|
|
@@ -511,8 +524,14 @@ def _group_site_blank_nodes(
|
|
|
511
524
|
site: SiteJSONLD, start_year: int = None, end_year: int = None
|
|
512
525
|
):
|
|
513
526
|
def grouper(group: dict, list_key: str) -> Dict[str, BlankNodeFormatted]:
|
|
527
|
+
now = current_time_ms()
|
|
514
528
|
blank_nodes = _filter_blank_nodes(site, list_key, start_year, end_year)
|
|
515
529
|
group[list_key] = reduce(_group_site_blank_node(), blank_nodes, {})
|
|
530
|
+
logger.debug(
|
|
531
|
+
"function=_group_site_blank_nodes, list_key=%s, time=%s",
|
|
532
|
+
list_key,
|
|
533
|
+
current_time_ms() - now,
|
|
534
|
+
)
|
|
516
535
|
return group
|
|
517
536
|
|
|
518
537
|
return grouper
|
|
@@ -559,9 +578,15 @@ def _combine_site_blank_node(sites: List[SiteFormatted], list_key: str):
|
|
|
559
578
|
|
|
560
579
|
def _combine_site_blank_nodes(sites: List[SiteFormatted]):
|
|
561
580
|
def combine(group: dict, list_key: str):
|
|
581
|
+
now = current_time_ms()
|
|
562
582
|
# get all possible keys first, then group each key values into a single blank node
|
|
563
583
|
keys = set(flatten([list(site.get(list_key, {}).keys()) for site in sites]))
|
|
564
584
|
group[list_key] = reduce(_combine_site_blank_node(sites, list_key), keys, {})
|
|
585
|
+
logger.debug(
|
|
586
|
+
"function=_combine_site_blank_nodes, list_key=%s, time=%s",
|
|
587
|
+
list_key,
|
|
588
|
+
current_time_ms() - now,
|
|
589
|
+
)
|
|
565
590
|
return group
|
|
566
591
|
|
|
567
592
|
return combine
|
|
@@ -647,9 +672,16 @@ def _aggregate_formatted(
|
|
|
647
672
|
data: Union[CycleFormatted, SiteFormatted], aggregated_keys: List[str]
|
|
648
673
|
):
|
|
649
674
|
def aggregate(key: str):
|
|
675
|
+
now = current_time_ms()
|
|
650
676
|
values = data.get(key, {}).values()
|
|
651
677
|
logger.debug(f"Aggregating {len(values)} {key}...")
|
|
652
|
-
|
|
678
|
+
values = list(map(_aggregate_blank_node, values))
|
|
679
|
+
logger.debug(
|
|
680
|
+
"function=_aggregate_formatted, key=%s, time=%s",
|
|
681
|
+
key,
|
|
682
|
+
current_time_ms() - now,
|
|
683
|
+
)
|
|
684
|
+
return values
|
|
653
685
|
|
|
654
686
|
return reduce(lambda group, key: group | {key: aggregate(key)}, aggregated_keys, {})
|
|
655
687
|
|
|
@@ -6,18 +6,17 @@ 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
|
|
15
17
|
from .completeness import blank_node_completeness_key
|
|
16
18
|
from .distribution import sample_weighted_distributions, _nb_iterations
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def _format_weight_key(key: str):
|
|
20
|
-
return ", ".join(key.split("_")).capitalize()
|
|
19
|
+
from .weights import format_weights
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
def _format_description(completeness_key: str, weights: dict):
|
|
@@ -26,14 +25,7 @@ def _format_description(completeness_key: str, weights: dict):
|
|
|
26
25
|
for w in weights.values()
|
|
27
26
|
if w.get("completeness", {}).get(completeness_key, False)
|
|
28
27
|
]
|
|
29
|
-
|
|
30
|
-
description = ";".join(
|
|
31
|
-
[
|
|
32
|
-
f"{_format_weight_key(weight.get('key'))}: {round(weight.get('weight') * 100 / total, 2)}"
|
|
33
|
-
for weight in complete_weights
|
|
34
|
-
if weight.get("key")
|
|
35
|
-
]
|
|
36
|
-
)
|
|
28
|
+
description = format_weights(complete_weights)
|
|
37
29
|
return {"description": description}
|
|
38
30
|
|
|
39
31
|
|
|
@@ -198,14 +190,19 @@ def _aggregate_nodes(
|
|
|
198
190
|
aggregate_keys: List[str], data: dict, weights: dict, missing_weights_node_id_func
|
|
199
191
|
):
|
|
200
192
|
def aggregate_single(key: str):
|
|
193
|
+
now = current_time_ms()
|
|
201
194
|
aggregates_map: dict = data.get(key)
|
|
202
195
|
terms = aggregates_map.keys()
|
|
203
|
-
|
|
196
|
+
values = non_empty_list(
|
|
204
197
|
map(
|
|
205
198
|
_aggregate_term(aggregates_map, weights, missing_weights_node_id_func),
|
|
206
199
|
terms,
|
|
207
200
|
)
|
|
208
201
|
)
|
|
202
|
+
logger.debug(
|
|
203
|
+
"function=_aggregate_nodes, key=%s, time=%s", key, current_time_ms() - now
|
|
204
|
+
)
|
|
205
|
+
return values
|
|
209
206
|
|
|
210
207
|
return reduce(
|
|
211
208
|
lambda prev, curr: prev | {curr: aggregate_single(curr)}, aggregate_keys, {}
|
|
@@ -39,6 +39,7 @@ from .emission import new_emission
|
|
|
39
39
|
from .input import new_input
|
|
40
40
|
from .practice import new_practice, organic_practice
|
|
41
41
|
from .product import new_product
|
|
42
|
+
from .weights import format_weights
|
|
42
43
|
|
|
43
44
|
_MEAN_DATE_DESCRIPTION = (
|
|
44
45
|
"Additional notes: the mean endDate of all aggregated Cycles is "
|
|
@@ -61,6 +62,11 @@ def _combine_mean_dates(cycles: list):
|
|
|
61
62
|
return _mean_date(dates)
|
|
62
63
|
|
|
63
64
|
|
|
65
|
+
def _aggregated_weights(weights: dict):
|
|
66
|
+
description = format_weights(weights.values())
|
|
67
|
+
return ("Sub-aggregation weighting: " + description) if description else ""
|
|
68
|
+
|
|
69
|
+
|
|
64
70
|
def is_organic(cycle: dict):
|
|
65
71
|
term_type = TermTermType.STANDARDSLABELS
|
|
66
72
|
practices = filter_list_term_type(cycle.get("practices", []), term_type)
|
|
@@ -234,7 +240,9 @@ def format_terms_results(data: dict, product: dict, country: dict):
|
|
|
234
240
|
return None
|
|
235
241
|
|
|
236
242
|
|
|
237
|
-
def format_country_results(
|
|
243
|
+
def format_country_results(
|
|
244
|
+
data: dict, product: dict, country: dict, site: dict, weights: dict
|
|
245
|
+
):
|
|
238
246
|
inputs = data.get("inputs", [])
|
|
239
247
|
practices = data.get("practices", [])
|
|
240
248
|
products = data.get("products", [])
|
|
@@ -247,7 +255,14 @@ def format_country_results(data: dict, product: dict, country: dict, site: dict)
|
|
|
247
255
|
completeness = aggregate_completeness(data.get("node-completeness", []))
|
|
248
256
|
return remove_empty_fields(
|
|
249
257
|
{
|
|
250
|
-
"description":
|
|
258
|
+
"description": ". ".join(
|
|
259
|
+
non_empty_list(
|
|
260
|
+
[
|
|
261
|
+
_aggregated_weights(weights),
|
|
262
|
+
_MEAN_DATE_DESCRIPTION + _combine_mean_dates(cycles),
|
|
263
|
+
]
|
|
264
|
+
)
|
|
265
|
+
),
|
|
251
266
|
"name": _cycle_name(cycle, primary_product, False, False, False),
|
|
252
267
|
"id": _cycle_id(cycle, primary_product, False, False, False),
|
|
253
268
|
**_format_results(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from functools import reduce, lru_cache
|
|
2
2
|
from hestia_earth.utils.lookup import download_lookup, get_table_value
|
|
3
|
-
from hestia_earth.utils.tools import to_precision, non_empty_list
|
|
3
|
+
from hestia_earth.utils.tools import to_precision, non_empty_list, list_sum
|
|
4
4
|
|
|
5
5
|
from hestia_earth.aggregation.log import debugWeights, debugRequirements
|
|
6
6
|
from .lookup import (
|
|
@@ -16,6 +16,21 @@ from .term import (
|
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
def _format_weight_key(key: str):
|
|
20
|
+
return ", ".join(key.split("_")).capitalize()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def format_weights(weights: list):
|
|
24
|
+
total = list_sum(non_empty_list([w.get("weight") for w in weights]))
|
|
25
|
+
return ";".join(
|
|
26
|
+
[
|
|
27
|
+
f"{_format_weight_key(weight.get('key'))}: {round(weight.get('weight') * 100 / total, 2)}"
|
|
28
|
+
for weight in weights
|
|
29
|
+
if weight.get("key")
|
|
30
|
+
]
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
19
34
|
def _country_organic_weight(country_id: str, start_year: int, end_year: int):
|
|
20
35
|
lookup = download_lookup("region-standardsLabels-isOrganic.csv")
|
|
21
36
|
data = get_table_value(lookup, "term.id", country_id, "organic")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = "0.21.
|
|
1
|
+
VERSION = "0.21.14"
|
{hestia_earth_aggregation-0.21.12.dist-info → hestia_earth_aggregation-0.21.14.dist-info}/RECORD
RENAMED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
hestia_earth/aggregation/__init__.py,sha256=5r0icTYP5F4DFIX-Xm1Ms3inpAUfpXQwOmO2y_DV3zs,3202
|
|
2
|
-
hestia_earth/aggregation/aggregate_cycles.py,sha256=
|
|
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=zqCwaEmEyCPuIxRLzAP6Ds1U0koeoYfXnJ0e800-MWo,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=c2rosOtI7B8vwb2CbDye-YPx4xyPc-o4kKKPsyAVoyU,28456
|
|
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
|
-
hestia_earth/aggregation/utils/cycle.py,sha256=
|
|
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
16
|
hestia_earth/aggregation/utils/emission.py,sha256=6MpDdf_izru0PGmkr2y9gOf9x_zfafyvSJSWALsseos,2554
|
|
17
17
|
hestia_earth/aggregation/utils/group.py,sha256=qU9sAuJu0RG80yLs90nsyoOcU57Pb6M1WKwT1TlJEkM,4765
|
|
@@ -27,9 +27,9 @@ hestia_earth/aggregation/utils/queries.py,sha256=kzob6CHL1a60CRJdGICiWS98LKJRyq3
|
|
|
27
27
|
hestia_earth/aggregation/utils/site.py,sha256=nc1N4IRiTki69IbCX4G6lagQ5U7IpsOsqiPuHwbl1HM,5455
|
|
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
|
-
hestia_earth/aggregation/utils/weights.py,sha256=
|
|
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.
|
|
30
|
+
hestia_earth/aggregation/utils/weights.py,sha256=3WO2_26bj1RB2h524Gknu0btvTFJucqMtn-tag339aY,6843
|
|
31
|
+
hestia_earth_aggregation-0.21.14.dist-info/licenses/LICENSE,sha256=TD25LoiRJsA5CPUNrcyt1PXlGcbUGFMAeZoBcfCrCNE,1154
|
|
32
|
+
hestia_earth_aggregation-0.21.14.dist-info/METADATA,sha256=DId0r59jDje3k-jfnNbBa1G9mcBRvi2rAbEjyvZQGnU,2481
|
|
33
|
+
hestia_earth_aggregation-0.21.14.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
34
|
+
hestia_earth_aggregation-0.21.14.dist-info/top_level.txt,sha256=q0QxKEYx9uLpAD5ZtC7Ypq29smEPfOzEAn7Xv8XHGOQ,13
|
|
35
|
+
hestia_earth_aggregation-0.21.14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|