Skip to content

Commit

Permalink
raise error for unknown identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoDiepers committed Jun 7, 2024
1 parent 4990884 commit 89167aa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions timex_lca/dynamic_characterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,20 +339,25 @@ def add_default_characterization_functions(self):
"""
self.characterization_function_dict = dict()

# load pre-calculated decay multipliers for GHGs (except for CO2, CH4, N2O & CO)
filepath = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "data", "decay_multipliers.json"
)

with open(filepath) as json_file:
decay_multipliers = json.load(json_file)


# look up which GHGs are characterized in the selected static LCA method
method_data = bd.Method(self.method).load()

# the bioflow-identifier stored in the method data can be the database id or the tuple (database, code)
def get_bioflow_node(identifier):
if isinstance(identifier, Collection) and len(identifier) == 2: # is code tuple
if isinstance(identifier, Collection) and len(identifier) == 2: # is code tuple
return bd.get_node(database=identifier[0], code=identifier[1])
else:
elif isinstance(identifier, int): # id is an int
return bd.get_node(id=identifier)
else:
raise ValueError("The flow-identifier stored in the selected method is neither an id nor the tuple (database, code). No automatic matching possible.")

bioflow_nodes = set(get_bioflow_node(identifier) for identifier, _ in method_data)

Expand Down

1 comment on commit 89167aa

@TimoDiepers
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#49

Please sign in to comment.