Skip to content

Commit

Permalink
Add remove_uncertainty argument to calculate()
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi authored and romainsacchi committed Jun 17, 2024
1 parent ddaf004 commit cbc3419
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pathways/lca.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def get_lca_matrices(
geo: Geomap = None,
remove_infrastructure: bool = False,
double_counting: dict = None,
remove_uncertainty: bool = False,
) -> tuple[
Datapackage,
dict[tuple[str, str, str, str], int],
Expand Down Expand Up @@ -175,6 +176,15 @@ def select_filepath(keyword: str, fps):
for matrix_name, fp in [("technosphere_matrix", fp_A), ("biosphere_matrix", fp_B)]:
data, indices, sign, distributions = load_matrix_and_index(fp)

if remove_uncertainty is True:
distributions = np.array(
[
(0, None, None, None, None, None, False)
for _ in range(len(distributions))
],
dtype=bwp.UNCERTAINTY_DTYPE,
)

if remove_infrastructure is True and matrix_name == "technosphere_matrix":
print("--------- Removing infrastructure exchanges")
infrastructure_indices = np.array(
Expand Down Expand Up @@ -208,7 +218,6 @@ def select_filepath(keyword: str, fps):
axis=0,
)
data = np.append(data, amount)
print(f"Added {amount} from {k} to {activity}")
distributions = np.append(
distributions,
np.array(
Expand Down Expand Up @@ -523,6 +532,7 @@ def _calculate_year(args: tuple):
uncertain_parameters,
remove_infrastructure,
double_counting,
remove_uncertainty,
) = args

print(f"------ Calculating LCA results for {year}...")
Expand Down Expand Up @@ -561,6 +571,7 @@ def _calculate_year(args: tuple):
geo=geo,
remove_infrastructure=remove_infrastructure,
double_counting=double_counting,
remove_uncertainty=remove_uncertainty,
)

except FileNotFoundError:
Expand Down
3 changes: 3 additions & 0 deletions pathways/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def calculate(
subshares: bool = False,
double_counting: dict = None,
remove_infrastructure: bool = False,
remove_uncertainty: bool = False,
) -> None:
"""
Calculate Life Cycle Assessment (LCA) results for given methods, models, scenarios, regions, and years.
Expand Down Expand Up @@ -396,6 +397,7 @@ def calculate(
shares,
remove_infrastructure,
double_counting,
remove_uncertainty,
)
for year in years
]
Expand Down Expand Up @@ -435,6 +437,7 @@ def calculate(
uncertain_parameters,
remove_infrastructure,
double_counting,
remove_uncertainty,
)
)
for year in years
Expand Down

0 comments on commit cbc3419

Please sign in to comment.