From 26589ed2bb0c38961c55ff0e93fed2b928496181 Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Fri, 23 Feb 2024 07:51:17 +0100 Subject: [PATCH] EODC --- pathways/lca.py | 16 ++++++++++------ pathways/pathways.py | 2 +- pathways/utils.py | 1 - 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pathways/lca.py b/pathways/lca.py index 14b1aa5..bfb40d4 100644 --- a/pathways/lca.py +++ b/pathways/lca.py @@ -177,9 +177,9 @@ def get_lca_matrices( def remove_double_counting(A: csr_matrix, vars_info: dict) -> csr_matrix: """ Remove double counting from a technosphere matrix. - :param A: - :param activities_idx: - :return: + :param A: Technosphere matrix + :param vars_info: Dictionary with information about variables + :return: Technosphere matrix with double counting removed """ # Modify A in COO format for efficiency @@ -188,12 +188,16 @@ def remove_double_counting(A: csr_matrix, vars_info: dict) -> csr_matrix: A_coo = A.tocoo() + list_of_idx = [] + for region in vars_info: for variable in vars_info[region]: idx = vars_info[region][variable]["idx"] - row_mask = np.isin(A_coo.row, idx) - col_mask = np.isin(A_coo.col, idx) - A_coo.data[row_mask & ~col_mask] = 0 # zero out rows + if idx not in list_of_idx: + list_of_idx.append(idx) + row_mask = np.isin(A_coo.row, idx) + col_mask = np.isin(A_coo.col, idx) + A_coo.data[row_mask & ~col_mask] = 0 # zero out rows A_coo.eliminate_zeros() return A_coo.tocsr() diff --git a/pathways/pathways.py b/pathways/pathways.py index 1aeace8..0b54633 100644 --- a/pathways/pathways.py +++ b/pathways/pathways.py @@ -607,7 +607,7 @@ def calculate( ) # Remove contribution from activities in other activities - A = remove_double_counting(A, vars_info) + #A = remove_double_counting(A, vars_info) # check unclassified activities check_unclassified_activities(A_index, self.classifications) diff --git a/pathways/utils.py b/pathways/utils.py index e9aeea9..45fe8c2 100644 --- a/pathways/utils.py +++ b/pathways/utils.py @@ -2,7 +2,6 @@ from typing import Any, Dict, List, Tuple, Union import numpy as np -import pandas as pd import xarray as xr import yaml