Skip to content

Commit

Permalink
Align wrt to dev-da
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Jul 3, 2024
1 parent dd08170 commit 3e46f9d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 44 deletions.
12 changes: 6 additions & 6 deletions dev/sankey_polyviz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/homebrew/Caskroom/miniforge/base/envs/premise/lib/python3.11/site-packages/scikits/umfpack/umfpack.py:736: UmfpackWarning: (almost) singular matrix! (estimated cond. number: 1.21e+13)\n",
"/opt/homebrew/Caskroom/miniforge/base/envs/premise/lib/python3.11/site-packages/scikits/umfpack/umfpack.py:736: UmfpackWarning: (almost) singular matrix! (estimated cond. number: 1.76e+13)\n",
" warnings.warn(msg, UmfpackWarning)\n"
]
}
],
"source": [
"_, df = sankey(\n",
" activity=[a for a in bw2data.Database(\"2020\") if a[\"name\"] == \"market for energy carriers for cars (SPS)\"][0],\n",
" activity=[a for a in bw2data.Database(\"stem 2020\") if a[\"name\"] == \"market for energy carriers for cars (SPS)\"][0],\n",
" method=('ReCiPe 2016 v1.03, midpoint (H)', 'particulate matter formation', 'particulate matter formation potential (PMFP)'),\n",
" level=3,\n",
" amount=1.40562356e+11,\n",
Expand All @@ -92,7 +92,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"id": "97dc3a0e-af67-4a1c-ac2c-ad71a6475c27",
"metadata": {},
"outputs": [],
Expand All @@ -102,7 +102,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"id": "c79ec915-6ace-4c51-a41d-417fa42ef78c",
"metadata": {},
"outputs": [
Expand All @@ -117,7 +117,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/homebrew/Caskroom/miniforge/base/envs/premise/lib/python3.11/site-packages/scikits/umfpack/umfpack.py:736: UmfpackWarning: (almost) singular matrix! (estimated cond. number: 2.41e+13)\n",
"/opt/homebrew/Caskroom/miniforge/base/envs/premise/lib/python3.11/site-packages/scikits/umfpack/umfpack.py:736: UmfpackWarning: (almost) singular matrix! (estimated cond. number: 1.21e+13)\n",
" warnings.warn(msg, UmfpackWarning)\n"
]
}
Expand All @@ -136,7 +136,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"id": "960c8b6d-91e7-436e-a366-39da11610d99",
"metadata": {},
"outputs": [],
Expand Down
39 changes: 1 addition & 38 deletions pathways/lca.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def select_filepath(keyword: str, fps):

def find_uncertain_parameters(
distributions_array: np.ndarray, indices_array: np.ndarray
) -> list[tuple[int, int]]:
) -> list[tuple]:
"""
Find the uncertain parameters in the distributions array.
They will be used for the stats report
Expand All @@ -186,43 +186,6 @@ def find_uncertain_parameters(
return uncertain_parameters


def remove_double_accounting(
lca: bc.LCA,
demand: Dict,
activities_to_exclude: List[int],
exceptions: List[int],
):
"""
Remove double counting from a technosphere matrix.
:param lca: bw2calc.LCA object
:param demand: dict with demand values
:param activities_to_exclude: list of activities to exclude
:param exceptions: list of exceptions
:return: Technosphere matrix with double counting removed.
"""

tm_original = lca.technosphere_matrix.copy()
tm_modified = tm_original.tocoo()

for act in activities_to_exclude:
row_idx = np.where(tm_modified.col == act)[0]

for idx in row_idx:
# Skip the diagonal and exceptions
if tm_modified.row[idx] != act and (
exceptions is None or tm_modified.col[idx] not in exceptions
):
tm_modified.data[idx] = 0

tm_modified = tm_modified.tocsr()
tm_modified.eliminate_zeros()

# Remove double accounting
lca.technosphere_matrix = tm_modified
lca.lci(demand=demand)
return lca


def process_region(data: Tuple) -> dict[str, ndarray[Any, dtype[Any]] | list[int]]:
"""
Process the region data.
Expand Down

0 comments on commit 3e46f9d

Please sign in to comment.