From 0744bb999b9523e49a3106c2cc6d6bb43e100861 Mon Sep 17 00:00:00 2001 From: romainsacchi Date: Fri, 14 Jul 2023 13:21:10 +0000 Subject: [PATCH] Black reformating --- premise/electricity.py | 29 ++++++++----- premise/inventory_imports.py | 19 +++++--- premise/report.py | 84 +++++++++++++++++++++++++++--------- premise/transformation.py | 20 +++++---- 4 files changed, 107 insertions(+), 45 deletions(-) diff --git a/premise/electricity.py b/premise/electricity.py index d579c3e6..5ee4b3f0 100644 --- a/premise/electricity.py +++ b/premise/electricity.py @@ -1592,8 +1592,7 @@ def create_region_specific_power_plants(self): dataset["name"] for dataset in self.database if dataset["name"] - in [y for k, v in self.powerplant_map.items() - for y in v if k in techs] + in [y for k, v in self.powerplant_map.items() for y in v if k in techs] ] list_datasets_to_duplicate.extend( @@ -1605,7 +1604,6 @@ def create_region_specific_power_plants(self): "carbon dioxide, captured from natural gas", "carbon dioxide, captured at wood burning", "carbon dioxide, captured at hydrogen burning", - ] ) @@ -1632,8 +1630,7 @@ def create_region_specific_power_plants(self): providers = [ e for e in plant["exchanges"] - if e["type"] == "technosphere" - and e["unit"] == "kilowatt hour" + if e["type"] == "technosphere" and e["unit"] == "kilowatt hour" ] for provider in providers: @@ -1729,13 +1726,14 @@ def update_electricity_efficiency(self) -> None: ] ), ): - if ( dataset["name"], dataset["reference product"], dataset["location"], dataset["unit"], - ) in self.modified_datasets[(self.model, self.scenario, self.year)]["emptied"]: + ) in self.modified_datasets[(self.model, self.scenario, self.year)][ + "emptied" + ]: continue # Find current efficiency @@ -1744,8 +1742,15 @@ def update_electricity_efficiency(self) -> None: ) if not self.use_absolute_efficiency: - iam_location = self.geo.ecoinvent_to_iam_location(dataset["location"]) - if iam_location in self.iam_data.electricity_efficiencies.coords["region"].values: + iam_location = self.geo.ecoinvent_to_iam_location( + dataset["location"] + ) + if ( + iam_location + in self.iam_data.electricity_efficiencies.coords[ + "region" + ].values + ): # Find relative efficiency change indicated by the IAM scaling_factor = 1 / self.find_iam_efficiency_change( data=self.iam_data.electricity_efficiencies, @@ -1760,7 +1765,9 @@ def update_electricity_efficiency(self) -> None: new_efficiency = self.find_iam_efficiency_change( data=self.iam_data.electricity_efficiencies, variable=technology, - location=self.geo.ecoinvent_to_iam_location(dataset["location"]), + location=self.geo.ecoinvent_to_iam_location( + dataset["location"] + ), ) if ei_eff != 1 and not np.isnan(new_efficiency): @@ -1917,7 +1924,7 @@ def adjust_coal_power_plant_emissions(self) -> None: } ) - #self.write_log(dataset=dataset, status="updated") + # self.write_log(dataset=dataset, status="updated") def update_electricity_markets(self) -> None: """ diff --git a/premise/inventory_imports.py b/premise/inventory_imports.py index 305ce627..063f539c 100644 --- a/premise/inventory_imports.py +++ b/premise/inventory_imports.py @@ -569,7 +569,6 @@ def add_biosphere_links(self, delete_missing: bool = False) -> None: ) def lower_case_technosphere_exchanges(self) -> None: - blakclist = [ "NOx", "SOx", @@ -582,20 +581,30 @@ def lower_case_technosphere_exchanges(self) -> None: if not any([x in ds["name"] for x in blakclist]): ds["name"] = ds["name"][0].lower() + ds["name"][1:] if not any([x in ds["reference product"] for x in blakclist]): - ds["reference product"] = ds["reference product"][0].lower() + ds["reference product"][1:] + ds["reference product"] = ( + ds["reference product"][0].lower() + ds["reference product"][1:] + ) for exc in ds["exchanges"]: if exc["type"] in ["technosphere", "production"]: if not any([x in exc["name"] for x in blakclist]): exc["name"] = exc["name"][0].lower() + exc["name"][1:] - if not any([x in exc.get("reference product", "") for x in blakclist]): + if not any( + [x in exc.get("reference product", "") for x in blakclist] + ): if exc.get("reference product") is not None: - exc["reference product"] = exc["reference product"][0].lower() + exc["reference product"][1:] + exc["reference product"] = ( + exc["reference product"][0].lower() + + exc["reference product"][1:] + ) if not any([x in exc.get("product", "") for x in blakclist]): if exc.get("product") is not None: - exc["product"] = exc["product"][0].lower() + exc["product"][1:] + exc["product"] = ( + exc["product"][0].lower() + exc["product"][1:] + ) + def remove_ds_and_modifiy_exchanges(self, name: str, ex_data: dict) -> None: """ Remove an activity dataset from :attr:`import_db` and replace the corresponding diff --git a/premise/report.py b/premise/report.py index 8a47ad2b..4d67ce43 100644 --- a/premise/report.py +++ b/premise/report.py @@ -62,27 +62,69 @@ def fetch_data( "GDP": iam_data.other_vars if hasattr(iam_data, "other_vars") else None, "CO2": iam_data.other_vars if hasattr(iam_data, "other_vars") else None, "GMST": iam_data.other_vars if hasattr(iam_data, "other_vars") else None, - "Electricity - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None, - "Electricity (biom) - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None, - "Electricity - efficiency": iam_data.electricity_efficiencies if hasattr(iam_data, "electricity_efficiencies") else None, - "Fuel (gasoline) - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None, - "Fuel (gasoline) - efficiency": iam_data.petrol_efficiencies if hasattr(iam_data, "petrol_efficiencies") else None, - "Fuel (diesel) - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None, - "Fuel (diesel) - efficiency": iam_data.diesel_efficiencies if hasattr(iam_data, "diesel_efficiencies") else None, - "Fuel (gas) - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None, - "Fuel (gas) - efficiency": iam_data.gas_efficiencies if hasattr(iam_data, "gas_efficiencies") else None, - "Fuel (hydrogen) - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None, - "Fuel (hydrogen) - efficiency": iam_data.hydrogen_efficiencies if hasattr(iam_data, "hydrogen_efficiencies") else None, - "Cement - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None, - "Cement - efficiency": iam_data.cement_efficiencies if hasattr(iam_data, "cement_efficiencies") else None, - "Cement - CCS": iam_data.carbon_capture_rate if hasattr(iam_data, "carbon_capture_rate") else None, - "Steel - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None, - "Steel - efficiency": iam_data.steel_efficiencies if hasattr(iam_data, "steel_efficiencies") else None, - "Steel - CCS": iam_data.carbon_capture_rate if hasattr(iam_data, "carbon_capture_rate") else None, - "Direct Air Capture - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None, - "Transport (cars)": iam_data.trsp_cars if hasattr(iam_data, "trsp_cars") else None, - "Transport (buses)": iam_data.trsp_buses if hasattr(iam_data, "trsp_buses") else None, - "Transport (trucks)": iam_data.trsp_trucks if hasattr(iam_data, "trsp_trucks") else None, + "Electricity - generation": iam_data.production_volumes + if hasattr(iam_data, "production_volumes") + else None, + "Electricity (biom) - generation": iam_data.production_volumes + if hasattr(iam_data, "production_volumes") + else None, + "Electricity - efficiency": iam_data.electricity_efficiencies + if hasattr(iam_data, "electricity_efficiencies") + else None, + "Fuel (gasoline) - generation": iam_data.production_volumes + if hasattr(iam_data, "production_volumes") + else None, + "Fuel (gasoline) - efficiency": iam_data.petrol_efficiencies + if hasattr(iam_data, "petrol_efficiencies") + else None, + "Fuel (diesel) - generation": iam_data.production_volumes + if hasattr(iam_data, "production_volumes") + else None, + "Fuel (diesel) - efficiency": iam_data.diesel_efficiencies + if hasattr(iam_data, "diesel_efficiencies") + else None, + "Fuel (gas) - generation": iam_data.production_volumes + if hasattr(iam_data, "production_volumes") + else None, + "Fuel (gas) - efficiency": iam_data.gas_efficiencies + if hasattr(iam_data, "gas_efficiencies") + else None, + "Fuel (hydrogen) - generation": iam_data.production_volumes + if hasattr(iam_data, "production_volumes") + else None, + "Fuel (hydrogen) - efficiency": iam_data.hydrogen_efficiencies + if hasattr(iam_data, "hydrogen_efficiencies") + else None, + "Cement - generation": iam_data.production_volumes + if hasattr(iam_data, "production_volumes") + else None, + "Cement - efficiency": iam_data.cement_efficiencies + if hasattr(iam_data, "cement_efficiencies") + else None, + "Cement - CCS": iam_data.carbon_capture_rate + if hasattr(iam_data, "carbon_capture_rate") + else None, + "Steel - generation": iam_data.production_volumes + if hasattr(iam_data, "production_volumes") + else None, + "Steel - efficiency": iam_data.steel_efficiencies + if hasattr(iam_data, "steel_efficiencies") + else None, + "Steel - CCS": iam_data.carbon_capture_rate + if hasattr(iam_data, "carbon_capture_rate") + else None, + "Direct Air Capture - generation": iam_data.production_volumes + if hasattr(iam_data, "production_volumes") + else None, + "Transport (cars)": iam_data.trsp_cars + if hasattr(iam_data, "trsp_cars") + else None, + "Transport (buses)": iam_data.trsp_buses + if hasattr(iam_data, "trsp_buses") + else None, + "Transport (trucks)": iam_data.trsp_trucks + if hasattr(iam_data, "trsp_trucks") + else None, } if data[sector] is not None: diff --git a/premise/transformation.py b/premise/transformation.py index eb67fde1..ffdc22b5 100644 --- a/premise/transformation.py +++ b/premise/transformation.py @@ -325,7 +325,9 @@ def select_multiple_suppliers( suppliers = list( ws.get_many( self.database, - ws.either(*[ws.contains("name", sup) for sup in possible_names]), + ws.either( + *[ws.contains("name", sup) for sup in possible_names] + ), ws.either( *[ ws.equals("location", item) @@ -339,9 +341,13 @@ def select_multiple_suppliers( ) counter += 1 except IndexError: - raise IndexError("No supplier found for {} in {}, " - "looking for terms: {} " - "and with blacklist: {}".format(possible_names, possible_locations, look_for, blacklist)) + raise IndexError( + "No supplier found for {} in {}, " + "looking for terms: {} " + "and with blacklist: {}".format( + possible_names, possible_locations, look_for, blacklist + ) + ) suppliers = get_shares_from_production_volume(suppliers) @@ -648,8 +654,7 @@ def fetch_proxies( ds for ds in self.database if not ( - ds["name"] == ds_name - and ds["reference product"] == ds_ref_prod + ds["name"] == ds_name and ds["reference product"] == ds_ref_prod ) ] @@ -700,8 +705,7 @@ def empty_original_datasets( # add tag existing_ds["has_downstream_consumer"] = False existing_ds["exchanges"] = [ - e for e in existing_ds["exchanges"] - if e["type"] == "production" + e for e in existing_ds["exchanges"] if e["type"] == "production" ] # for cases where external scenarios are used