Skip to content

Commit

Permalink
Make dataset names in config file insensitive to case
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi authored and romainsacchi committed Oct 3, 2024
1 parent c518e17 commit 3999231
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
62 changes: 38 additions & 24 deletions premise/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,19 +790,26 @@ def check_existence_of_market_suppliers(self):
# by order of preference
try:
while not suppliers:
suppliers = list(
ws.get_many(
self.database,
ws.equals("name", name),
ws.equals(
"reference product",
ref_prod,
),
ws.equals(
"location", possible_locations[counter]
),
)
)
# suppliers = list(
# ws.get_many(
# self.database,
# ws.equals("name", name),
# ws.equals(
# "reference product",
# ref_prod,
# ),
# ws.equals(
# "location", possible_locations[counter]
# ),
# )
# )

suppliers = [
s for s in self.database
if s["name"].lower() == name.lower()
and s["reference product"].lower() == ref_prod.lower()
and s["location"] == possible_locations[counter]
]

counter += 1

Expand Down Expand Up @@ -864,17 +871,24 @@ def fetch_potential_suppliers(
act, counter = [], 0
try:
while not act:
act = list(
ws.get_many(
self.database,
ws.equals("name", name),
ws.equals(
"reference product",
ref_prod,
),
ws.equals("location", possible_locations[counter]),
)
)
# act = list(
# ws.get_many(
# self.database,
# ws.equals("name", name),
# ws.equals(
# "reference product",
# ref_prod,
# ),
# ws.equals("location", possible_locations[counter]),
# )
# )

act = [
a for a in self.database
if a["name"].lower() == name.lower()
and a["reference product"].lower() == ref_prod.lower()
and a["location"] == possible_locations[counter]
]

counter += 1
except IndexError:
Expand Down
15 changes: 9 additions & 6 deletions premise/external_data_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ def check_inventories(

d_datasets = {
(
val["ecoinvent alias"]["name"],
val["ecoinvent alias"]["reference product"],
val["ecoinvent alias"]["name"].lower(),
val["ecoinvent alias"]["reference product"].lower(),
): {
"exists in original database": val["ecoinvent alias"].get(
"exists in original database", True
Expand Down Expand Up @@ -309,7 +309,7 @@ def check_inventories(
if "regionalize" in configuration:
d_datasets.update(
{
(val["name"], val["reference product"]): {
(val["name"].lower(), val["reference product"].lower()): {
"exists in original database": val.get(
"exists in original database", False
),
Expand All @@ -331,7 +331,7 @@ def check_inventories(

try:
assert all(
(i[0], i[1]) in list_datasets
(i[0], i[1]) in [(x[0].lower(), x[1].lower()) for x in list_datasets]
for i, v in d_datasets.items()
if not v["exists in original database"]
and not v.get("new dataset")
Expand All @@ -343,7 +343,7 @@ def check_inventories(
for i, v in d_datasets.items()
if not v["exists in original database"]
and not v.get("new dataset")
and (i[0], i[1]) not in list_datasets
and (i[0].lower(), i[1].lower()) in [(x[0].lower(), x[1].lower()) for x in list_datasets]
]

raise AssertionError(
Expand All @@ -355,7 +355,10 @@ def check_inventories(
# flag imported inventories
for i, dataset in enumerate(inventory_data):
key = (dataset["name"], dataset["reference product"])
if key in d_datasets:
if (key[0].lower(), key[1].lower()) in d_datasets:
# replace key in d_datasets with the key in the inventory data
d_datasets[key] = d_datasets.pop((key[0].lower(), key[1].lower()))

if d_datasets[key]["exists in original database"] is False:
dataset["custom scenario dataset"] = True
data_vars = d_datasets[(dataset["name"], dataset["reference product"])]
Expand Down
3 changes: 3 additions & 0 deletions premise/inventory_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,9 @@ def add_biosphere_links(self) -> None:
print(
f"Could not find a biosphere flow for {key} in {self.path.name}. You need to fix this."
)
# remove the exchange if it is not linked
y["delete"] = True

x["exchanges"] = [y for y in x["exchanges"] if "delete" not in y]

def lower_case_technosphere_exchanges(self) -> None:
Expand Down

0 comments on commit 3999231

Please sign in to comment.