diff --git a/pathways/lca.py b/pathways/lca.py index f138bb1..0960425 100644 --- a/pathways/lca.py +++ b/pathways/lca.py @@ -4,11 +4,11 @@ """ import logging +import pickle import uuid from collections import defaultdict from pathlib import Path from typing import Any, Dict, List, Tuple -import pickle import bw2calc as bc import bw_processing as bwp @@ -25,9 +25,9 @@ from .lcia import fill_characterization_factors_matrices from .stats import ( create_mapping_sheet, - log_uncertainty_values, log_results, log_subshares, + log_uncertainty_values, run_GSA_delta, run_GSA_OLS, ) @@ -416,7 +416,10 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int # Save the technosphere indices to disk id_technosphere_indices = uuid.uuid4() - pickle.dump(lca.technosphere_indices, open(DIR_CACHED_DB / f"{id_technosphere_indices}.pkl", "wb")) + pickle.dump( + lca.technosphere_indices, + open(DIR_CACHED_DB / f"{id_technosphere_indices}.pkl", "wb"), + ) # Save the characterization vectors to disk id_results_array = uuid.uuid4() diff --git a/pathways/pathways.py b/pathways/pathways.py index 8353bba..e99ed07 100644 --- a/pathways/pathways.py +++ b/pathways/pathways.py @@ -5,6 +5,7 @@ """ import logging +import pickle from collections import defaultdict from multiprocessing import Pool, cpu_count from typing import Any, List, Optional @@ -14,7 +15,6 @@ import pyprind import xarray as xr import yaml -import pickle from .data_validation import validate_datapackage from .filesystem_constants import DATA_DIR, DIR_CACHED_DB, STATS_DIR, USER_LOGS_DIR @@ -22,9 +22,9 @@ from .lcia import get_lcia_method_names from .stats import ( create_mapping_sheet, - log_uncertainty_values, log_results, log_subshares, + log_uncertainty_values, run_GSA_delta, ) from .subshares import generate_samples @@ -525,7 +525,9 @@ def _fill_in_result_array( ] ) - uncertainty_indices = uncertainty_parameters[data["uncertainty_params"]] + uncertainty_indices = uncertainty_parameters[ + data["uncertainty_params"] + ] uncertainty_vals = uncertainty_values[data["uncertainty_vals"]] df_uncertainty_values = pd.concat( @@ -559,20 +561,34 @@ def _fill_in_result_array( indices = tehnosphere_indices[data["technosphere_indices"]] # only keep indices which are also present in uncertainty_indices - indices = {k: v for k, v in indices.items() if v in set(uncertainty_indices.flatten().tolist())} + indices = { + k: v + for k, v in indices.items() + if v in set(uncertainty_indices.flatten().tolist()) + } df_technosphere_indices = create_mapping_sheet(indices=indices) - df_sum_impacts.to_excel(writer, sheet_name="Total impacts", index=False) - df_uncertainty_values.to_excel(writer, sheet_name="Monte Carlo values", index=False) - df_technology_shares.to_excel(writer, sheet_name="Technology shares", index=False) - df_technosphere_indices.to_excel(writer, sheet_name="Indices mapping", index=False) + df_sum_impacts.to_excel( + writer, sheet_name="Total impacts", index=False + ) + df_uncertainty_values.to_excel( + writer, sheet_name="Monte Carlo values", index=False + ) + df_technology_shares.to_excel( + writer, sheet_name="Technology shares", index=False + ) + df_technosphere_indices.to_excel( + writer, sheet_name="Indices mapping", index=False + ) df_GSA = run_GSA_delta( total_impacts=df_sum_impacts, uncertainty_values=df_uncertainty_values, - technology_shares=df_technology_shares + technology_shares=df_technology_shares, + ) + df_GSA.to_excel( + writer, sheet_name="Global Sensitivity Analysis", index=False ) - df_GSA.to_excel(writer, sheet_name="Global Sensitivity Analysis", index=False) print(f"Statistical analysis: {export_path.resolve()}")