Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed May 14, 2024
2 parents 24be753 + b37b19a commit 70316c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 4 additions & 2 deletions unfold/data_cleaning.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,14 @@ def check_commonality_between_databases(original_db, scenario_db, db_name):
f"and {db_name}."
)


def change_db_name(data, name):
"""
Originally from `wurst.linking` module.
Change the database of all datasets in ``data`` to ``name``.
Raises errors if each dataset does not have exactly one reference production exchange."""
Raises errors if each dataset does not have exactly one reference production exchange.
"""

get_input_databases = lambda data: {ds.get("database") for ds in data}
old_names = get_input_databases(data)
Expand All @@ -423,4 +425,4 @@ def change_db_name(data, name):
for exc in ds["exchanges"]:
if exc.get("input") and exc["input"][0] in old_names:
exc["input"] = (name, exc["input"][1])
return data
return data
24 changes: 14 additions & 10 deletions unfold/unfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,19 @@
from prettytable import PrettyTable
from scipy import sparse as nsp
from wurst import extract_brightway2_databases
from wurst.linking import (
check_duplicate_codes,
check_internal_linking,
link_internal,
)
from wurst.linking import check_duplicate_codes, check_internal_linking, link_internal

from .data_cleaning import (
add_biosphere_links,
add_product_field_to_exchanges,
change_db_name,
check_exchanges_input,
check_for_duplicates,
correct_fields_format,
get_outdated_flows,
get_outdated_units,
remove_categories_for_technosphere_flows,
remove_missing_fields,
change_db_name
)

try:
Expand Down Expand Up @@ -376,11 +372,19 @@ def generate_factors(self) -> None:
"""
self.factors = (
self.scenario_df[[
c for c in self.scenario_df.columns if c not in [
"to database",
self.scenario_df[
[
c
for c in self.scenario_df.columns
if c
not in [
"to database",
]
]
]].groupby("flow id").sum(numeric_only=True).to_dict("index")
]
.groupby("flow id")
.sum(numeric_only=True)
.to_dict("index")
)

def store_datasets_metadata(self) -> None:
Expand Down

0 comments on commit 70316c5

Please sign in to comment.