Skip to content

Commit

Permalink
Black reformating
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Mar 28, 2024
1 parent 2c3ca0d commit 7ede75a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
19 changes: 10 additions & 9 deletions pathways/lca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
24 changes: 15 additions & 9 deletions pathways/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 7ede75a

Please sign in to comment.