Skip to content

Commit

Permalink
Add function to strip names form spaces (ecoinvent forgot some spaces!)
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi authored and romainsacchi committed Jul 31, 2024
1 parent f3000c4 commit c9e8624
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
40 changes: 40 additions & 0 deletions premise/clean_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,41 @@ def remove_categories(database: List[dict]) -> List[dict]:

return database

def strip_string_from_spaces(database: List[dict]) -> List[dict]:
"""
Strip strings from spaces in the dataset of the wurst inventory database.
Modifies in place (does not return anything).
:param database: wurst inventory database
:type database: list
"""
for dataset in database:
dataset["name"] = dataset["name"].strip()
# also check for unicode characters like \xa0
dataset["name"] = dataset["name"].replace("\xa0", "")

dataset["reference product"] = dataset["reference product"].strip()
dataset["location"] = dataset["location"].strip()
for exc in dataset["exchanges"]:
exc["name"] = exc["name"].strip()
# also check for unicode characters like \xa0
exc["name"] = exc["name"].replace("\xa0", "")
if exc.get("product"):
exc["product"] = exc["product"].strip()
# also check for unicode characters like \xa0
exc["product"] = exc["product"].replace("\xa0", "")
if exc.get("reference product"):
exc["reference product"] = exc["reference product"].strip()
# also check for unicode characters like \xa0
exc["reference product"] = exc["reference product"].replace("\xa0", "")
if exc.get("location"):
exc["location"] = exc["location"].strip()
if exc.get("unit"):
exc["unit"] = exc["unit"].strip()

return database


class DatabaseCleaner:
"""
Expand All @@ -163,6 +198,8 @@ def __init__(
)
self.database = wurst.extract_brightway2_databases(source_db)
self.database = remove_categories(self.database)
# strip strings form spaces
self.database = strip_string_from_spaces(self.database)

if source_type == "ecospold":
# The ecospold data needs to be formatted
Expand All @@ -171,6 +208,9 @@ def __init__(
)
ecoinvent.apply_strategies()
self.database = ecoinvent.data
# strip strings form spaces
self.database = strip_string_from_spaces(self.database)

# Location field is added to exchanges
self.add_location_field_to_exchanges()
# Product field is added to exchanges
Expand Down
4 changes: 4 additions & 0 deletions premise/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,10 @@ def create_B_matrix_coordinates(self):
"Cannot find the biosphere flow",
exc["name"],
exc["categories"],
"in ",
ds["name"],
ds["reference product"],
ds["location"],
)
row = ()
list_rows.append(row)
Expand Down
2 changes: 1 addition & 1 deletion premise/iam_variables_mapping/electricity_variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ Solar PV Residential:
Storage, Flow Battery:
ecoinvent_aliases:
fltr:
- electricity supply, high voltage, from vanadium-redox flow battery system
- market for battery capacity, stationary (TC scenario)
iam_aliases:
image: Secondary Energy|Electricity|Storage
message: Secondary Energy|Electricity|Storage
Expand Down

0 comments on commit c9e8624

Please sign in to comment.