Skip to content

Commit

Permalink
Black reformating
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Mar 19, 2024
1 parent dcb8ddf commit 442597f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 84 deletions.
15 changes: 6 additions & 9 deletions pathways/lca.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from pathlib import Path
from typing import Dict, List, Optional, Tuple

import bw_processing as bwp
import numpy as np
import scipy.sparse
import xarray as xr
from scipy import sparse
from scipy.sparse import csr_matrix
import bw_processing as bwp
import numpy as np

from .lcia import get_lcia_methods

Expand Down Expand Up @@ -149,13 +149,13 @@ def get_lca_matrices(
)

dp.add_persistent_vector(
matrix='technosphere_matrix',
matrix="technosphere_matrix",
indices_array=a_indices,
data_array=a_data,
flip_array=a_sign,
)
dp.add_persistent_vector(
matrix='biosphere_matrix',
matrix="biosphere_matrix",
indices_array=b_indices,
data_array=b_data,
flip_array=b_sign,
Expand Down Expand Up @@ -185,10 +185,7 @@ def get_lca_matrices(
return dp, A_inds, B_inds


def fill_characterization_factors_matrix(
biosphere_flows: dict,
methods
) -> np.ndarray:
def fill_characterization_factors_matrix(biosphere_flows: dict, methods) -> np.ndarray:
"""
Create a characterization matrix based on the list of biosphere flows
given.
Expand All @@ -201,7 +198,6 @@ def fill_characterization_factors_matrix(

print(lcia_data)


# create a numpy array filled with zeros
# of size equal to biosphere_flows and lcia methods

Expand All @@ -217,6 +213,7 @@ def fill_characterization_factors_matrix(

return cf_matrix


def remove_double_counting(A: csr_matrix, vars_info: dict) -> csr_matrix:
"""
Remove double counting from a technosphere matrix.
Expand Down
3 changes: 0 additions & 3 deletions pathways/lcia.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,3 @@ def get_lcia_methods(methods: list = None):
data = [x for x in data if " - ".join(x["name"]) in methods]

return {" - ".join(x["name"]): format_lcia_method_exchanges(x) for x in data}



140 changes: 69 additions & 71 deletions pathways/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple, Union

import bw2calc as bc
import numpy as np
import pandas as pd
import pyprind
import xarray as xr
import yaml
from datapackage import DataPackage
from premise.geomap import Geomap
import bw2calc as bc

from . import DATA_DIR
from .data_validation import validate_datapackage
Expand Down Expand Up @@ -309,76 +309,74 @@ def process_region(data: Tuple) -> Union[None, Dict[str, Any]]:
lca.lcia()
lca.score



#
#
# # Create the demand vector
# f = create_demand_vector([idx], A, demand, unit_vector)
#
# # Solve the inventory
# C = solve_inventory(A, B, f)
#
# if lcia_matrix is not None:
# if lcia_matrix.ndim != 2 or lcia_matrix.shape[0] != B.shape[1]:
# raise ValueError("Incompatible dimensions between B and lcia_matrix")
#
# # Solve the LCA problem to get the LCIA scores
# D = characterize_inventory(C, lcia_matrix)
#
# # Sum along the first axis of D to get final result
# D = D.sum(axis=1)
#
# # Initialize the new array with zeros for missing data
# E = np.zeros((len(A_index), len(locations), len(impact_categories)))
#
# # Populate the result array
# act_locs = [a[-1] for a in rev_A_index.values()]
#
# for i, act in enumerate(rev_A_index.values()):
# if act[-1] in act_locs:
# loc_idx = location_to_index[act[-1]]
# E[i, loc_idx, :] = D[i, :]
#
# acts_idx = generate_A_indices(
# A_index,
# reverse_classifications,
# lca_results_coords,
# )
#
# # Sum over the first axis of D,
# # using acts_idx for advanced indexing
# target[:, v] = E[acts_idx, ...].sum(axis=0)
#
# else:
# # else, just sum the results of the inventory
# acts_idx = generate_A_indices(
# A_index,
# reverse_classifications,
# lca_results_coords,
# )
# if flows is not None:
#
# def transf_flow(f):
# return tuple(f.split(" - "))
#
# flows_idx = [int(B_index[transf_flow(f)]) for f in flows]
# C = C[:, flows_idx]
#
# # Initialize the new array with zeros for missing data
# E = np.zeros((len(A_index), len(locations), len(flows_idx)))
#
# # Populate the result array
# act_locs = [a[-1] for a in rev_A_index.values()]
#
# for i, act in enumerate(rev_A_index.values()):
# if act[-1] in act_locs:
# loc_idx = location_to_index[act[-1]]
# E[i, loc_idx, :] = C[i, :]
#
# target[:, v] = E[acts_idx, ...].sum(axis=0)
# else:
# target[:, v] = C[acts_idx, ...].sum(axis=0)
#
#
# # Create the demand vector
# f = create_demand_vector([idx], A, demand, unit_vector)
#
# # Solve the inventory
# C = solve_inventory(A, B, f)
#
# if lcia_matrix is not None:
# if lcia_matrix.ndim != 2 or lcia_matrix.shape[0] != B.shape[1]:
# raise ValueError("Incompatible dimensions between B and lcia_matrix")
#
# # Solve the LCA problem to get the LCIA scores
# D = characterize_inventory(C, lcia_matrix)
#
# # Sum along the first axis of D to get final result
# D = D.sum(axis=1)
#
# # Initialize the new array with zeros for missing data
# E = np.zeros((len(A_index), len(locations), len(impact_categories)))
#
# # Populate the result array
# act_locs = [a[-1] for a in rev_A_index.values()]
#
# for i, act in enumerate(rev_A_index.values()):
# if act[-1] in act_locs:
# loc_idx = location_to_index[act[-1]]
# E[i, loc_idx, :] = D[i, :]
#
# acts_idx = generate_A_indices(
# A_index,
# reverse_classifications,
# lca_results_coords,
# )
#
# # Sum over the first axis of D,
# # using acts_idx for advanced indexing
# target[:, v] = E[acts_idx, ...].sum(axis=0)
#
# else:
# # else, just sum the results of the inventory
# acts_idx = generate_A_indices(
# A_index,
# reverse_classifications,
# lca_results_coords,
# )
# if flows is not None:
#
# def transf_flow(f):
# return tuple(f.split(" - "))
#
# flows_idx = [int(B_index[transf_flow(f)]) for f in flows]
# C = C[:, flows_idx]
#
# # Initialize the new array with zeros for missing data
# E = np.zeros((len(A_index), len(locations), len(flows_idx)))
#
# # Populate the result array
# act_locs = [a[-1] for a in rev_A_index.values()]
#
# for i, act in enumerate(rev_A_index.values()):
# if act[-1] in act_locs:
# loc_idx = location_to_index[act[-1]]
# E[i, loc_idx, :] = C[i, :]
#
# target[:, v] = E[acts_idx, ...].sum(axis=0)
# else:
# target[:, v] = C[acts_idx, ...].sum(axis=0)

# Return a dictionary containing the processed LCA data for the given region
def get_indices():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def package_files(directory):
"scipy",
"premise",
"pyyaml",
"scikit-umfpack"
"scikit-umfpack",
],
url="https://github.com/polca/premise",
description="Scenario-level LCA of energy systems and transition pathways",
Expand Down

0 comments on commit 442597f

Please sign in to comment.