Skip to content

Commit

Permalink
Add list comprehension test for Monte Carlo MultiLCA
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Aug 27, 2024
1 parent 401b10f commit 6d5235f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/multi_lca.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import defaultdict
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -447,3 +448,47 @@ def test_monte_carlo_multiple_iterations_selective_use(dps, func_units):
assert np.unique(lst).shape == (10,)
for key, lst in results_scores.items():
assert np.unique(lst).shape == (10,)


def test_monte_carlo_multiple_iterations_selective_use_in_list_comprehension(dps, func_units):
config = {
"impact_categories": [
("first", "category"),
("second", "category"),
],
"normalizations": {
("n", "1"): [
("first", "category"),
("second", "category"),
]
},
"weightings": {("w", "1"): [("n", "1")]},
}

dps.append(
get_datapackage(fixture_dir / "multi_lca_simple_normalization.zip"),
)
dps.append(
get_datapackage(fixture_dir / "multi_lca_simple_weighting.zip"),
)

su = {
"characterization_matrix": {"use_distributions": True},
"weighting_matrix": {"use_distributions": True},
}

mlca = MultiLCA(demands=func_units, method_config=config, data_objs=dps, selective_use=su)
mlca.lci()
mlca.lcia()
mlca.normalize()
mlca.weight()

results = [mlca.scores for _ in zip(range(10), mlca)]

aggregated = defaultdict(list)
for line in results:
for k, v in line.items():
aggregated[k].append(v)

for key, lst in aggregated.items():
assert np.unique(lst).shape == (10,)

0 comments on commit 6d5235f

Please sign in to comment.