diff --git a/pathways/lca.py b/pathways/lca.py index 1e2d629..0bacb88 100644 --- a/pathways/lca.py +++ b/pathways/lca.py @@ -80,13 +80,13 @@ def load_matrix_and_index( distributions_array = np.array( list( zip( - array[:, 3].astype(int), # uncertainty type - array[:, 4].astype(float), # loc - array[:, 5].astype(float), # scale - array[:, 6].astype(float), # shape - array[:, 7].astype(float), # minimum - array[:, 8].astype(float), # maximum - array[:, 9].astype(bool), # negative + array[:, 3].astype(int), # uncertainty type + array[:, 4].astype(float), # loc + array[:, 5].astype(float), # scale + array[:, 6].astype(float), # shape + array[:, 7].astype(float), # minimum + array[:, 8].astype(float), # maximum + array[:, 9].astype(bool), # negative ) ), dtype=bwp.UNCERTAINTY_DTYPE, @@ -144,12 +144,13 @@ def get_lca_matrices( matrix="biosphere_matrix", indices_array=b_indices, data_array=b_data, - #flip_array=b_sign, - distributions_array= b_distributions, + # flip_array=b_sign, + distributions_array=b_distributions, ) return dp, A_inds, B_inds + def fill_characterization_factors_matrices( biosphere_flows: dict, methods, biosphere_dict, debug=False ) -> csr_matrix: diff --git a/pathways/pathways.py b/pathways/pathways.py index 1789adf..4eb5399 100644 --- a/pathways/pathways.py +++ b/pathways/pathways.py @@ -13,12 +13,12 @@ from typing import Any, Dict, List, Optional, Tuple import bw2calc as bc -from bw2calc.monte_carlo import MonteCarloLCA import numpy as np import pandas as pd import pyprind import xarray as xr import yaml +from bw2calc.monte_carlo import MonteCarloLCA from datapackage import DataPackage from numpy import dtype, ndarray from premise.geomap import Geomap @@ -312,10 +312,11 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int "demand": demand.values * float(unit_vector), } - if use_distributions == 0: lca.lci(demand={idx: demand.values * float(unit_vector)}) - characterized_inventory = (characterization_matrix @ lca.inventory).toarray() + characterized_inventory = ( + characterization_matrix @ lca.inventory + ).toarray() else: # Use distributions for LCA calculations @@ -327,19 +328,24 @@ def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int print(lca.inventory.shape) print(lca.inventory.sum()) - - results = np.array([ - (characterization_matrix @ lca.lci(demand={idx: demand.values * float(unit_vector)}).inventory).toarray() for _ in zip(range(use_distributions), lca) - ]) + results = np.array( + [ + ( + characterization_matrix + @ lca.lci( + demand={idx: demand.values * float(unit_vector)} + ).inventory + ).toarray() + for _ in zip(range(use_distributions), lca) + ] + ) print(results.shape) for result in results: print(result.sum(axis=-1)) - characterized_inventory = np.empty_like(lca.inventory) - # vars_info = fetch_indices(mapping, regions, variables, A_index, Geomap(model)) # characterized_inventory = remove_double_counting(characterized_inventory=characterized_inventory, # vars_info=vars_idx,