Skip to content

Commit

Permalink
EODC
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Feb 23, 2024
1 parent 9a8555f commit 26589ed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
16 changes: 10 additions & 6 deletions pathways/lca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pathways/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pathways/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 26589ed

Please sign in to comment.