From ab4b51b922d836119c5462e92ae47487bf207718 Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Fri, 17 May 2024 18:38:16 -0400 Subject: [PATCH 1/5] EODC --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 883af93..bdba7e9 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ by ``premise``, but can be used with any IAM scenarios and LCA databases. and calculates the environmental impacts of the scenario (or a subset of it) over time.

- +

## Installation From 64897d626a60d9552889b25f665cb7963b4a7b11 Mon Sep 17 00:00:00 2001 From: alvarojhahn Date: Sun, 19 May 2024 11:23:41 +0200 Subject: [PATCH 2/5] fix merge --- pathways/lca.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pathways/lca.py b/pathways/lca.py index 8dfe052..bdf7979 100644 --- a/pathways/lca.py +++ b/pathways/lca.py @@ -13,6 +13,7 @@ import bw_processing as bwp import numpy as np import pyprind +from bw2calc.utils import get_datapackage from bw2calc.monte_carlo import MonteCarloLCA from bw_processing import Datapackage from numpy import dtype, ndarray @@ -263,6 +264,7 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int variables_demand = {} d = [] impacts_by_method = {method: [] for method in methods} + param_keys = set() for v, variable in enumerate(variables): idx, dataset = vars_idx[variable]["idx"], vars_idx[variable]["dataset"] @@ -315,7 +317,6 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int # next(lca) is a generator that yields the inventory matrix temp_results = [] params = {} - param_keys = set() for _ in zip(range(use_distributions), lca): matrix_result = (characterization_matrix @ lca.inventory).toarray() temp_results.append(matrix_result) From 32a158cdd3bd595d9a26a1396d6cf1ca5e5fc39e Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Sun, 19 May 2024 09:24:09 +0000 Subject: [PATCH 3/5] Black reformating --- pathways/lca.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pathways/lca.py b/pathways/lca.py index bdf7979..60d3ed1 100644 --- a/pathways/lca.py +++ b/pathways/lca.py @@ -13,8 +13,8 @@ import bw_processing as bwp import numpy as np import pyprind -from bw2calc.utils import get_datapackage from bw2calc.monte_carlo import MonteCarloLCA +from bw2calc.utils import get_datapackage from bw_processing import Datapackage from numpy import dtype, ndarray from premise.geomap import Geomap From 31eec162ef61fb22c6ebb6ab9605557afd3ab70d Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Thu, 23 May 2024 16:03:59 -0400 Subject: [PATCH 4/5] EODC --- pathways/lca.py | 11 +++++------ pathways/pathways.py | 4 +--- requirements.txt | 3 ++- setup.py | 1 + 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/pathways/lca.py b/pathways/lca.py index 8dfe052..3ec7cd5 100644 --- a/pathways/lca.py +++ b/pathways/lca.py @@ -39,7 +39,6 @@ check_unclassified_activities, fetch_indices, get_unit_conversion_factors, - read_indices_csv, ) logging.basicConfig( @@ -263,6 +262,7 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int variables_demand = {} d = [] impacts_by_method = {method: [] for method in methods} + param_keys = set() for v, variable in enumerate(variables): idx, dataset = vars_idx[variable]["idx"], vars_idx[variable]["dataset"] @@ -293,6 +293,7 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int year=year, ).sum(dim="variables") + # If the total demand is zero, return None if share < demand_cutoff: continue @@ -315,7 +316,7 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int # next(lca) is a generator that yields the inventory matrix temp_results = [] params = {} - param_keys = set() + for _ in zip(range(use_distributions), lca): matrix_result = (characterization_matrix @ lca.inventory).toarray() temp_results.append(matrix_result) @@ -357,7 +358,7 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int id_array = uuid.uuid4() np.save(file=DIR_CACHED_DB / f"{id_array}.npy", arr=np.stack(d)) - # just making sure that the memory is freed. Maybe not needed- check later + # just making sure that the memory is freed. Maybe not needed-check later del d # returning a dictionary containing the id_array and the variables @@ -505,9 +506,7 @@ def _calculate_year(args: tuple): lca.packages.append(get_datapackage(bw_correlated)) lca.use_arrays = True - # - # # Log - # log_subshares_to_excel(model, scenario, year, shares) + characterization_matrix = fill_characterization_factors_matrices( methods=methods, diff --git a/pathways/pathways.py b/pathways/pathways.py index fbd26f0..dac6a9d 100644 --- a/pathways/pathways.py +++ b/pathways/pathways.py @@ -194,9 +194,7 @@ def _get_scenarios(self, scenario_data: pd.DataFrame) -> xr.DataArray: for var in mapping_vars: if var not in scenario_data["variables"].values: if self.debug: - logging.warning( - f"Variable {var} not found in scenario data among: {scenario_data['variables'].values.tolist()}." - ) + logging.warning(f"Variable {var} not found in scenario data.") # remove rows which do not have a value under the `variable` # column that correspond to any value in self.mapping for `scenario variable` diff --git a/requirements.txt b/requirements.txt index aded382..f3399ba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ bw_processing bw2calc == 2.0.DEV16 datapackage pyprind -platformdirs \ No newline at end of file +platformdirs +statsmodels \ No newline at end of file diff --git a/setup.py b/setup.py index 7276fe2..e4b56a5 100644 --- a/setup.py +++ b/setup.py @@ -53,6 +53,7 @@ def package_files(directory): "datapackage", "pyprind", "platformdirs", + "statsmodels" ], url="https://github.com/polca/premise", description="Scenario-level LCA of energy systems and transition pathways", From 7d1ca438b3324b2d469a0081b24fdbc5487c71e4 Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Thu, 23 May 2024 20:06:05 +0000 Subject: [PATCH 5/5] Black reformating --- pathways/lca.py | 2 -- setup.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pathways/lca.py b/pathways/lca.py index 956e48d..cd58e2a 100644 --- a/pathways/lca.py +++ b/pathways/lca.py @@ -294,7 +294,6 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int year=year, ).sum(dim="variables") - # If the total demand is zero, return None if share < demand_cutoff: continue @@ -508,7 +507,6 @@ def _calculate_year(args: tuple): lca.packages.append(get_datapackage(bw_correlated)) lca.use_arrays = True - characterization_matrix = fill_characterization_factors_matrices( methods=methods, biosphere_matrix_dict=lca.dicts.biosphere, diff --git a/setup.py b/setup.py index e4b56a5..45a82ed 100644 --- a/setup.py +++ b/setup.py @@ -53,7 +53,7 @@ def package_files(directory): "datapackage", "pyprind", "platformdirs", - "statsmodels" + "statsmodels", ], url="https://github.com/polca/premise", description="Scenario-level LCA of energy systems and transition pathways",