diff --git a/premise/battery.py b/premise/battery.py index be116f68..c75d9e1f 100644 --- a/premise/battery.py +++ b/premise/battery.py @@ -149,7 +149,7 @@ def adjust_battery_market_shares(self) -> None: "NMC811": "market for battery capacity, Li-ion, NMC811, stationary", "VRFB": "market for battery capacity, redox-flow, Vanadium, stationary", "LEAD-ACID": "market for battery capacity, lead acid, rechargeable, stationary", - "NAS": "market for battery capacity, Sodium-Nickel-Chloride, Na-NiCl, stationary" + "NAS": "market for battery capacity, Sodium-Nickel-Chloride, Na-NiCl, stationary", }.items() } diff --git a/premise/fuels.py b/premise/fuels.py index d9f99036..3955ecc1 100644 --- a/premise/fuels.py +++ b/premise/fuels.py @@ -2589,7 +2589,9 @@ def generate_fuel_markets(self): # we also need to add old fuel markets which now take an # input for new fuel markets - for location in self.iam_to_ecoinvent_loc[dataset["location"]]: + for location in self.iam_to_ecoinvent_loc[ + dataset["location"] + ]: self.new_fuel_markets.update( { (dataset["name"], location): { @@ -2606,8 +2608,6 @@ def generate_fuel_markets(self): } ) - - # add to log self.write_log(dataset) # add it to list of created datasets @@ -2649,10 +2649,9 @@ def generate_fuel_markets(self): for dataset in ws.get_many( self.database, - ws.either(*[ - ws.equals("name", x[0]) - for x in list(self.new_fuel_markets.keys()) - ]) + ws.either( + *[ws.equals("name", x[0]) for x in list(self.new_fuel_markets.keys())] + ), ): if "log parameters" not in dataset: dataset["log parameters"] = {} @@ -2670,8 +2669,6 @@ def generate_fuel_markets(self): } ) - - # add to database self.database.extend(new_datasets) diff --git a/premise/heat.py b/premise/heat.py index 88835a56..428613b4 100644 --- a/premise/heat.py +++ b/premise/heat.py @@ -184,13 +184,19 @@ def regionalize_heat_production(self): exc["name"], exc["location"], ) in self.carbon_intensity_markets: - fossil_co2 += exc[ - "amount" - ] * self.carbon_intensity_markets[(exc["name"], exc["location"])]["fossil"] + fossil_co2 += ( + exc["amount"] + * self.carbon_intensity_markets[ + (exc["name"], exc["location"]) + ]["fossil"] + ) - non_fossil_co2 += exc[ - "amount" - ] * self.carbon_intensity_markets[(exc["name"], exc["location"])]["non-fossil"] + non_fossil_co2 += ( + exc["amount"] + * self.carbon_intensity_markets[ + (exc["name"], exc["location"]) + ]["non-fossil"] + ) if fossil_co2 + non_fossil_co2 > 0: @@ -210,8 +216,10 @@ def regionalize_heat_production(self): ) ds["exchanges"] = [ - e for e in ds["exchanges"] - if e["name"] not in ( + e + for e in ds["exchanges"] + if e["name"] + not in ( "Carbon dioxide, fossil", "Carbon dioxide, non-fossil", ) @@ -234,7 +242,7 @@ def regionalize_heat_production(self): "Carbon dioxide, fossil", "air", "unspecified", - "kilogram" + "kilogram", ) ], ), @@ -259,7 +267,7 @@ def regionalize_heat_production(self): "Carbon dioxide, non-fossil", "air", "unspecified", - "kilogram" + "kilogram", ) ], ), @@ -269,11 +277,18 @@ def regionalize_heat_production(self): if "log parameters" not in ds: ds["log parameters"] = {} - ds["log parameters"]["initial amount of fossil CO2"] = initial_fossil_co2 - ds["log parameters"]["new amount of fossil CO2"] = float(fossil_co2) - ds["log parameters"]["initial amount of biogenic CO2"] = initial_non_fossil_co2 - ds["log parameters"]["new amount of biogenic CO2"] = float(non_fossil_co2) - + ds["log parameters"][ + "initial amount of fossil CO2" + ] = initial_fossil_co2 + ds["log parameters"]["new amount of fossil CO2"] = float( + fossil_co2 + ) + ds["log parameters"][ + "initial amount of biogenic CO2" + ] = initial_non_fossil_co2 + ds["log parameters"]["new amount of biogenic CO2"] = float( + non_fossil_co2 + ) for new_dataset in list(new_ds.values()): self.write_log(new_dataset) diff --git a/premise/validation.py b/premise/validation.py index 99217edd..56e232da 100644 --- a/premise/validation.py +++ b/premise/validation.py @@ -628,26 +628,24 @@ def check_battery_capacity(self): ws.either( *[ ws.contains("name", s) - for s in [ - "(MIX)", - "(LFP)", - "(NCx)", - "(PLiB)", - "(CONT", - "(TC" - ] + for s in ["(MIX)", "(LFP)", "(NCx)", "(PLiB)", "(CONT", "(TC"] ] - ) + ), ): # check that sum of technosphere exchanges sum to 1 - total = sum([exc["amount"] for exc in ds["exchanges"] if exc["type"] == "technosphere"]) + total = sum( + [ + exc["amount"] + for exc in ds["exchanges"] + if exc["type"] == "technosphere" + ] + ) if not np.isclose(total, 1.0, rtol=1e-3): message = f"Total exchange amount is {total}, not 1.0" self.log_issue( ds, "Incorrect market shares", message, issue_type="major" ) - for ds in ws.get_many( self.database, ws.contains("name", "market for battery capacity, "), @@ -657,29 +655,37 @@ def check_battery_capacity(self): ws.either( *[ ws.contains("name", s) - for s in [ - "MIX", - "LFP", - "NCx", - "PLiB", - "TC", - "CONT" - ] + for s in ["MIX", "LFP", "NCx", "PLiB", "TC", "CONT"] ] ) - ) + ), ): # check that um of technosphere exchanges equal zero - total = sum([exc["amount"] for exc in ds["exchanges"] if exc["type"] == "technosphere"]) + total = sum( + [ + exc["amount"] + for exc in ds["exchanges"] + if exc["type"] == "technosphere" + ] + ) if not np.isclose(total, 0.0, rtol=1e-3): message = f"Total exchange amount is {total}, not 0.0" self.log_issue( - ds, "EoL not balanced with battery input", message, issue_type="major" + ds, + "EoL not balanced with battery input", + message, + issue_type="major", ) # also check that sum of positive technosphere exchanges # have a correct value - total = sum([exc["amount"] for exc in ds["exchanges"] if exc["type"] == "technosphere" and exc["amount"] > 0]) + total = sum( + [ + exc["amount"] + for exc in ds["exchanges"] + if exc["type"] == "technosphere" and exc["amount"] > 0 + ] + ) # this sum needs to be at least 2 if total < 2: message = f"Total exchange amount is {total}, not at least 2" @@ -692,8 +698,9 @@ def run_battery_checks(self): self.save_log() if len(self.major_issues_log) > 0: - print("---> MAJOR anomalies found during battery update: check the change report.") - + print( + "---> MAJOR anomalies found during battery update: check the change report." + ) class HeatValidation(BaseDatasetValidator): @@ -906,8 +913,9 @@ def run_heat_checks(self): self.save_log() if len(self.major_issues_log) > 0: - print("---> MAJOR anomalies found during heat update: check the change report.") - + print( + "---> MAJOR anomalies found during heat update: check the change report." + ) class TransportValidation(BaseDatasetValidator): @@ -1148,9 +1156,9 @@ def run_vehicle_checks(self): self.save_log() if len(self.major_issues_log) > 0: - print("---> MAJOR anomalies found during transport update: check the change report.") - - + print( + "---> MAJOR anomalies found during transport update: check the change report." + ) class TruckValidation(TransportValidation): @@ -1495,8 +1503,9 @@ def run_electricity_checks(self): self.save_log() if len(self.major_issues_log) > 0: - print("---> MAJOR anomalies found during electricity update: check the change report.") - + print( + "---> MAJOR anomalies found during electricity update: check the change report." + ) class FuelsValidation(BaseDatasetValidator): @@ -1590,8 +1599,9 @@ def run_fuel_checks(self): self.save_log() if len(self.major_issues_log) > 0: - print("---> MAJOR anomalies found during fuels update: check the change report.") - + print( + "---> MAJOR anomalies found during fuels update: check the change report." + ) class SteelValidation(BaseDatasetValidator): @@ -1797,8 +1807,9 @@ def run_steel_checks(self): self.save_log() if len(self.major_issues_log) > 0: - print("---> MAJOR anomalies found during steel update: check the change report.") - + print( + "---> MAJOR anomalies found during steel update: check the change report." + ) class CementValidation(BaseDatasetValidator): @@ -1963,8 +1974,9 @@ def run_cement_checks(self): self.save_log() if len(self.major_issues_log) > 0: - print("---> MAJOR anomalies found during cement update: check the change report.") - + print( + "---> MAJOR anomalies found during cement update: check the change report." + ) class BiomassValidation(BaseDatasetValidator): @@ -2059,5 +2071,6 @@ def run_biomass_checks(self): self.save_log() if len(self.major_issues_log) > 0: - print("---> MAJOR anomalies found during biomass update: check the change report.") - + print( + "---> MAJOR anomalies found during biomass update: check the change report." + ) diff --git a/tests/test_process_ei310_cutoff.py b/tests/test_process_ei310_cutoff.py index 771e1d04..c953330d 100644 --- a/tests/test_process_ei310_cutoff.py +++ b/tests/test_process_ei310_cutoff.py @@ -73,7 +73,6 @@ def test_brightway(): assert all(isinstance(result, float) for result in results) print(results) - # destroy all objects del ndb del lca