From da10374158a43982b1d07b1de1c9f76fa017e3cd Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Tue, 21 May 2024 15:28:24 +0200 Subject: [PATCH] apply ruff linting --- scripts/add_existing_baseyear.py | 4 +--- scripts/base_network.py | 4 ++-- scripts/build_biomass_potentials.py | 3 ++- scripts/build_energy_totals.py | 1 - scripts/build_existing_heating_distribution.py | 1 - scripts/retrieve_electricity_demand.py | 4 ++-- scripts/solve_network.py | 1 - scripts/time_aggregation.py | 1 + 8 files changed, 8 insertions(+), 11 deletions(-) diff --git a/scripts/add_existing_baseyear.py b/scripts/add_existing_baseyear.py index 8eac44f64..8b8ea6b06 100644 --- a/scripts/add_existing_baseyear.py +++ b/scripts/add_existing_baseyear.py @@ -63,7 +63,7 @@ def add_existing_renewables(df_agg, costs): """ tech_map = {"solar": "PV", "onwind": "Onshore", "offwind": "Offshore"} - countries = snakemake.config["countries"] + countries = snakemake.config["countries"] # noqa: F841 irena = pm.data.IRENASTAT().powerplant.convert_country_to_alpha2() irena = irena.query("Country in @countries") irena = irena.groupby(["Technology", "Country", "Year"]).Capacity.sum() @@ -440,8 +440,6 @@ def add_heating_capacities_installed_before_baseyear( snakemake.input.existing_heating_distribution, header=[0, 1], index_col=0 ) - techs = existing_heating.columns.get_level_values(1).unique() - for name in existing_heating.columns.get_level_values(0).unique(): name_type = "central" if name == "urban central" else "decentral" diff --git a/scripts/base_network.py b/scripts/base_network.py index b811f6250..df3bc2b2c 100644 --- a/scripts/base_network.py +++ b/scripts/base_network.py @@ -896,7 +896,7 @@ def build_bus_shapes(n, country_shapes, offshore_shapes, countries): shapes = pd.concat(onshore_regions, ignore_index=True) - return onshore_regions, offshore_regions, shapes + return onshore_regions, offshore_regions, shapes, offshore_shapes def append_bus_shapes(n, shapes, type): @@ -950,7 +950,7 @@ def append_bus_shapes(n, shapes, type): snakemake.config, ) - onshore_regions, offshore_regions, shapes = build_bus_shapes( + onshore_regions, offshore_regions, shapes, offshore_shapes = build_bus_shapes( n, snakemake.input.country_shapes, snakemake.input.offshore_shapes, diff --git a/scripts/build_biomass_potentials.py b/scripts/build_biomass_potentials.py index 79e2c2037..cebbe22ff 100644 --- a/scripts/build_biomass_potentials.py +++ b/scripts/build_biomass_potentials.py @@ -13,10 +13,11 @@ import numpy as np import pandas as pd +from _helpers import configure_logging, set_scenario_config + logger = logging.getLogger(__name__) AVAILABLE_BIOMASS_YEARS = [2010, 2020, 2030, 2040, 2050] -from _helpers import configure_logging, set_scenario_config def build_nuts_population_data(year=2013): diff --git a/scripts/build_energy_totals.py b/scripts/build_energy_totals.py index fc0887ec7..420a6c7c7 100644 --- a/scripts/build_energy_totals.py +++ b/scripts/build_energy_totals.py @@ -124,7 +124,6 @@ def build_eurostat(input_eurostat, countries, nprocesses=1, disable_progressbar= df = pd.concat([temp, df.loc[~int_avia]]) # Fill in missing data on "Domestic aviation" for each country. - domestic_avia = df.index.get_level_values(4) == "Domestic aviation" for country in countries: slicer = idx[country, :, :, :, "Domestic aviation"] # For the Total and Fossil energy columns, fill in zeros with diff --git a/scripts/build_existing_heating_distribution.py b/scripts/build_existing_heating_distribution.py index eb2361c28..af4a50a76 100644 --- a/scripts/build_existing_heating_distribution.py +++ b/scripts/build_existing_heating_distribution.py @@ -55,7 +55,6 @@ def build_existing_heating(): nodal_heating = nodal_heating.multiply(pop_layout.fraction, axis=0) district_heat_info = pd.read_csv(snakemake.input.district_heat_share, index_col=0) - dist_fraction = district_heat_info["district fraction of node"] urban_fraction = district_heat_info["urban fraction"] energy_layout = pd.read_csv( diff --git a/scripts/retrieve_electricity_demand.py b/scripts/retrieve_electricity_demand.py index 94077fdf1..80d44f154 100644 --- a/scripts/retrieve_electricity_demand.py +++ b/scripts/retrieve_electricity_demand.py @@ -10,10 +10,10 @@ import pandas as pd -logger = logging.getLogger(__name__) - from _helpers import configure_logging, set_scenario_config +logger = logging.getLogger(__name__) + if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 9d4521db7..4c3fc2c58 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -693,7 +693,6 @@ def add_BAU_constraints(n, config): ext_i = n.generators.query("p_nom_extendable") ext_carrier_i = xr.DataArray(ext_i.carrier.rename_axis("Generator-ext")) lhs = p_nom.groupby(ext_carrier_i).sum() - index = mincaps.index.intersection(lhs.indexes["carrier"]) rhs = mincaps[lhs.indexes["carrier"]].rename_axis("carrier") n.model.add_constraints(lhs >= rhs, name="bau_mincaps") diff --git a/scripts/time_aggregation.py b/scripts/time_aggregation.py index 1c01a08de..713b9522b 100644 --- a/scripts/time_aggregation.py +++ b/scripts/time_aggregation.py @@ -47,6 +47,7 @@ import pandas as pd import pypsa import xarray as xr +import tsam.timeseriesaggregation as tsam from _helpers import ( configure_logging, set_scenario_config,