From a57156a61524f05a7cf14dfedaf4d024b7fbb928 Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Thu, 28 Mar 2024 16:55:25 +0100 Subject: [PATCH] Add quantiles quantification --- pathways/lca.py | 4 +--- pathways/pathways.py | 20 +++++--------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/pathways/lca.py b/pathways/lca.py index 0bacb88..d46968c 100644 --- a/pathways/lca.py +++ b/pathways/lca.py @@ -92,8 +92,6 @@ def load_matrix_and_index( dtype=bwp.UNCERTAINTY_DTYPE, ) - print(distributions_array[:5]) - return data_array, indices_array, flip_array, distributions_array @@ -144,7 +142,7 @@ def get_lca_matrices( matrix="biosphere_matrix", indices_array=b_indices, data_array=b_data, - # flip_array=b_sign, + flip_array=b_sign, distributions_array=b_distributions, ) diff --git a/pathways/pathways.py b/pathways/pathways.py index 4eb5399..ec7f39d 100644 --- a/pathways/pathways.py +++ b/pathways/pathways.py @@ -312,8 +312,9 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int "demand": demand.values * float(unit_vector), } + lca.lci(demand={idx: demand.values * float(unit_vector)}) + if use_distributions == 0: - lca.lci(demand={idx: demand.values * float(unit_vector)}) characterized_inventory = ( characterization_matrix @ lca.inventory ).toarray() @@ -322,29 +323,18 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int # Use distributions for LCA calculations # next(lca) is a generator that yields the inventory matrix - for _ in range(use_distributions): - next(lca) - lca.lci(demand={idx: demand.values * float(unit_vector)}) - print(lca.inventory.shape) - print(lca.inventory.sum()) - results = np.array( [ ( characterization_matrix - @ lca.lci( - demand={idx: demand.values * float(unit_vector)} - ).inventory + @ lca.inventory ).toarray() for _ in zip(range(use_distributions), lca) ] ) - print(results.shape) - for result in results: - print(result.sum(axis=-1)) - - characterized_inventory = np.empty_like(lca.inventory) + # calculate quantiles along the first dimension + characterized_inventory = np.quantile(results, [0.05, 0.5, 0.95], axis=0) # vars_info = fetch_indices(mapping, regions, variables, A_index, Geomap(model)) # characterized_inventory = remove_double_counting(characterized_inventory=characterized_inventory,