Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Oct 4, 2024
2 parents 2b0cad8 + 3c88e8e commit 40563d3
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 36 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ include premise/data/GAINS_emission_factors/iam_data/MFR/*.csv
include premise/data/geomap/*.yml
include premise/data/geomap/*.yaml
include premise/data/renewables/*.csv
include premise/data/renewables/*.yaml
include premise/data/direct_air_capture/*.yaml
include premise/data/transport/car/*.csv
include premise/data/transport/bus/*.csv
Expand Down
18 changes: 18 additions & 0 deletions premise/cement.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def _update_cement(scenario, version, system_model):
)

if scenario["iam data"].cement_markets is not None:
cement.replace_clinker_production_with_markets()
cement.add_datasets_to_database()
cement.relink_datasets()
scenario["database"] = cement.database
Expand Down Expand Up @@ -662,6 +663,23 @@ def build_clinker_production_datasets(self) -> list:

return datasets

def replace_clinker_production_with_markets(self):
"""
Some cement production datasets in ecoinvent receive an input from clinker production datasets.
This is problematic because it will not benefit from the new cement markets, containing alternative clinker production pathways.
So we replace the clinker production datasets with the clinker markets.
"""

for ds in ws.get_many(
self.database,
ws.contains("name", "cement production"),
ws.contains("reference product", "cement"),
ws.equals("unit", "kilogram"),
):
for exc in ws.technosphere(ds):
if exc["name"] == "clinker production" and exc["product"] == "clinker":
exc["name"] = "market for clinker"

def add_datasets_to_database(self) -> None:
"""
Runs a series of methods that create new clinker and cement production datasets
Expand Down
2 changes: 1 addition & 1 deletion premise/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ def generate_scenario_difference_file(
df.loc[df["flow type"].isin(["technosphere", "production"]), "from categories"] = (
None
)
df.loc[df["flow type"] == "production", list_scenarios] = 1.0
# df.loc[df["flow type"] == "production", list_scenarios] = 1.0

df.loc[df["flow type"] == "biosphere", "from database"] = biosphere_name

Expand Down
65 changes: 41 additions & 24 deletions premise/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,19 +790,28 @@ 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 +873,25 @@ 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
16 changes: 10 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,8 @@ 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 +356,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
13 changes: 8 additions & 5 deletions premise/fuels.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ def generate_hydrogen_activities(self) -> None:

else:
if "from electrolysis" in fuel_type:

# get the electricity consumption
new_energy_use, min_energy_use, max_energy_use = (
adjust_electrolysis_electricity_requirement(
Expand Down Expand Up @@ -609,11 +608,15 @@ def generate_hydrogen_activities(self) -> None:
ws.contains("name", hydrogen_feedstock_name),
ws.equals("unit", hydrogen_feedstock_unit),
):
exc["amount"] = new_energy_use
exc["amount"] *= scaling_factor
exc["uncertainty type"] = 5
exc["loc"] = new_energy_use
exc["minimum"] = min_energy_use
exc["maximum"] = max_energy_use
exc["loc"] = exc["amount"]
exc["minimum"] = exc["amount"] * (
min_energy_use / new_energy_use
)
exc["maximum"] = exc["amount"] * (
max_energy_use / new_energy_use
)

else:
# rescale the fuel consumption exchange
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 40563d3

Please sign in to comment.