Skip to content

Commit

Permalink
Fix issue with removing unused datasets + version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Sep 14, 2023
1 parent 272b7a8 commit 92c641d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def package_files(directory):

setup(
name="unfold",
version="1.0.8",
version="1.0.9",
python_requires=">=3.9",
packages=packages,
author="Romain Sacchi <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion unfold/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__all__ = ("Unfold", "Fold")
__version__ = (1, 0, 8)
__version__ = (1, 0, 9)

from .fold import Fold
from .unfold import Unfold
26 changes: 21 additions & 5 deletions unfold/unfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ def find_correct_id(self, key: tuple) -> [tuple, None]:
return key[0] + ", in ground", key[1], key[2], key[3]

else:
print("Could not find key", key)
return key
raise f"Could not find key: {key}"
#return key

def fix_key(self, key: tuple) -> tuple:
if key in self.dependency_mapping:
Expand Down Expand Up @@ -761,19 +761,36 @@ def filter_out_datasets(
"""

# Get the list of datasets not used in the current scenario.
df_gr = self.scenario_df.groupby("to activity name").sum(numeric_only=True)
df_gr = self.scenario_df.groupby(["to activity name", "to reference product", "to location"]).sum(numeric_only=True)

datasets_not_in_scenario = df_gr.loc[
(df_gr[scenario_name] == 0) & (df_gr.sum(1) != 0), :
].index.tolist()

# remove items from datasets_not_in_scenario that are
# used in exchanges of database
for act in database:
for exc in act["exchanges"]:
if exc["type"] == "technosphere":
key = (exc["name"], exc["product"], exc["location"])
if key in datasets_not_in_scenario:
datasets_not_in_scenario.remove(key)

# Remove datasets that are not in the current scenario.
database = [
act for act in database if act["name"] not in datasets_not_in_scenario
act for act in database
if (act["name"], act["reference product"], act["location"]) not in datasets_not_in_scenario
]

return database

def check_usage(self, name: str, product: str, location: str, database: list) -> bool:
# check that name, product, location are not used in any exchange of database

pass



def generate_superstructure_database(self) -> List[dict]:
"""
Generates the superstructure database.
Expand Down Expand Up @@ -1097,7 +1114,6 @@ def unfold(
self.check_dependencies(dependencies)
self.extract_source_database()
self.extract_additional_inventories()

self.format_dataframe(scenarios=scenarios, superstructure=superstructure)
self.generate_factors()

Expand Down

0 comments on commit 92c641d

Please sign in to comment.