diff --git a/MANIFEST.in b/MANIFEST.in index 9c31ce74..c8d8af5a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/premise/cement.py b/premise/cement.py index 3ac2e95c..5dfbb596 100644 --- a/premise/cement.py +++ b/premise/cement.py @@ -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 @@ -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 diff --git a/premise/export.py b/premise/export.py index 69cbfa19..95e243dd 100644 --- a/premise/export.py +++ b/premise/export.py @@ -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 diff --git a/premise/external.py b/premise/external.py index 298dbde0..d614b989 100644 --- a/premise/external.py +++ b/premise/external.py @@ -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 @@ -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: diff --git a/premise/external_data_validation.py b/premise/external_data_validation.py index 4d23d725..a4fc49ae 100644 --- a/premise/external_data_validation.py +++ b/premise/external_data_validation.py @@ -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 @@ -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 ), @@ -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") @@ -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( @@ -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"])] diff --git a/premise/fuels.py b/premise/fuels.py index 84196bfe..22d4a169 100644 --- a/premise/fuels.py +++ b/premise/fuels.py @@ -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( @@ -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 diff --git a/premise/inventory_imports.py b/premise/inventory_imports.py index 4abbf1df..8c255860 100644 --- a/premise/inventory_imports.py +++ b/premise/inventory_imports.py @@ -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: