diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e66bcc53f..7e2f1149f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,7 @@ repos: # Make docstrings PEP 257 compliant - repo: https://github.com/PyCQA/docformatter - rev: v1.5.1 + rev: v1.6.0 hooks: - id: docformatter args: ["--in-place", "--make-summary-multi-line", "--pre-summary-newline"] @@ -74,7 +74,7 @@ repos: # Format Snakemake rule / workflow files - repo: https://github.com/snakemake/snakefmt - rev: v0.8.3 + rev: v0.8.4 hooks: - id: snakefmt diff --git a/scripts/_helpers.py b/scripts/_helpers.py index 281ee9c28..dc10eac16 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -400,7 +400,6 @@ def override_component_attrs(directory): ------- Dictionary of overridden component attributes. """ - attrs = Dict({k: v.copy() for k, v in component_attrs.items()}) for component, list_name in components.list_name.items(): @@ -418,7 +417,6 @@ def generate_periodic_profiles(dt_index, nodes, weekly_profile, localize=None): country for the period dt_index, taking account of time zones and summer time. """ - weekly_profile = pd.Series(weekly_profile, range(24 * 7)) week_df = pd.DataFrame(index=dt_index, columns=nodes) diff --git a/scripts/add_existing_baseyear.py b/scripts/add_existing_baseyear.py index a81d606d8..992f3f98d 100644 --- a/scripts/add_existing_baseyear.py +++ b/scripts/add_existing_baseyear.py @@ -38,7 +38,6 @@ def add_build_year_to_new_assets(n, baseyear): baseyear : int year in which optimized assets are built """ - # Give assets with lifetimes and no build year the build year baseyear for c in n.iterate_components(["Link", "Generator", "Store"]): assets = c.df.index[(c.df.lifetime != np.inf) & (c.df.build_year == 0)] @@ -62,7 +61,6 @@ def add_existing_renewables(df_agg): Append existing renewables to the df_agg pd.DataFrame with the conventional power plants. """ - carriers = {"solar": "solar", "onwind": "onwind", "offwind": "offwind-ac"} for tech in ["solar", "onwind", "offwind"]: diff --git a/scripts/build_biomass_potentials.py b/scripts/build_biomass_potentials.py index 7387418af..50f2583ca 100644 --- a/scripts/build_biomass_potentials.py +++ b/scripts/build_biomass_potentials.py @@ -68,7 +68,6 @@ def enspreso_biomass_potentials(year=2020, scenario="ENS_Low"): Biomass potentials for given year and scenario in TWh/a by commodity and NUTS2 region. """ - glossary = pd.read_excel( str(snakemake.input.enspreso_biomass), sheet_name="Glossary", @@ -124,7 +123,6 @@ def disaggregate_nuts0(bio): ------- pd.DataFrame """ - pop = build_nuts_population_data() # get population in nuts2 @@ -149,7 +147,6 @@ def build_nuts2_shapes(): - add RS, AL, BA country shapes (not covered in NUTS 2013) - consistently name ME, MK """ - nuts2 = gpd.GeoDataFrame( gpd.read_file(snakemake.input.nuts2).set_index("id").geometry ) @@ -186,7 +183,6 @@ def convert_nuts2_to_regions(bio_nuts2, regions): ------- gpd.GeoDataFrame """ - # calculate area of nuts2 regions bio_nuts2["area_nuts2"] = area(bio_nuts2) diff --git a/scripts/build_cop_profiles.py b/scripts/build_cop_profiles.py index fa04e4a1c..94cc8fb48 100644 --- a/scripts/build_cop_profiles.py +++ b/scripts/build_cop_profiles.py @@ -7,10 +7,11 @@ Build coefficient of performance (COP) time series for air- or ground-sourced heat pumps. -The COP is a function of the temperature difference between -source and sink. +The COP is a function of the temperature difference between source and +sink. The quadratic regression used is based on Staffell et al. (2012) + https://doi.org/10.1039/C2EE22653G. """ diff --git a/scripts/build_energy_totals.py b/scripts/build_energy_totals.py index 1480732ae..f11c134f3 100644 --- a/scripts/build_energy_totals.py +++ b/scripts/build_energy_totals.py @@ -124,7 +124,6 @@ def build_eurostat(input_eurostat, countries, report_year, year): """ Return multi-index for all countries' energy data in TWh/a. """ - filenames = { 2016: f"/{year}-Energy-Balances-June2016edition.xlsx", 2017: f"/{year}-ENERGY-BALANCES-June2017edition.xlsx", @@ -163,7 +162,6 @@ def build_swiss(year): """ Return a pd.Series of Swiss energy data in TWh/a. """ - fn = snakemake.input.swiss df = pd.read_csv(fn, index_col=[0, 1]).loc["CH", str(year)] diff --git a/scripts/build_gas_network.py b/scripts/build_gas_network.py index b34ebe9fc..907b151c4 100644 --- a/scripts/build_gas_network.py +++ b/scripts/build_gas_network.py @@ -22,14 +22,15 @@ def diameter_to_capacity(pipe_diameter_mm): """ Calculate pipe capacity in MW based on diameter in mm. - 20 inch (500 mm) 50 bar -> 1.5 GW CH4 pipe capacity (LHV) - 24 inch (600 mm) 50 bar -> 5 GW CH4 pipe capacity (LHV) - 36 inch (900 mm) 50 bar -> 11.25 GW CH4 pipe capacity (LHV) - 48 inch (1200 mm) 80 bar -> 21.7 GW CH4 pipe capacity (LHV) + 20 inch (500 mm) 50 bar -> 1.5 GW CH4 pipe capacity (LHV) 24 inch + (600 mm) 50 bar -> 5 GW CH4 pipe capacity (LHV) 36 inch (900 + mm) 50 bar -> 11.25 GW CH4 pipe capacity (LHV) 48 inch (1200 mm) 80 + bar -> 21.7 GW CH4 pipe capacity (LHV) - Based on p.15 of https://gasforclimate2050.eu/wp-content/uploads/2020/07/2020_European-Hydrogen-Backbone_Report.pdf - """ + Based on p.15 of + https://gasforclimate2050.eu/wp-content/uploads/2020/07/2020_European-Hydrogen-Backbone_Report.pdf + """ # slopes definitions m0 = (1500 - 0) / (500 - 0) m1 = (5000 - 1500) / (600 - 500) diff --git a/scripts/build_industrial_distribution_key.py b/scripts/build_industrial_distribution_key.py index 5f2f6893b..d4518d1ce 100644 --- a/scripts/build_industrial_distribution_key.py +++ b/scripts/build_industrial_distribution_key.py @@ -27,7 +27,6 @@ def locate_missing_industrial_sites(df): Should only be used if the model's spatial resolution is coarser than individual cities. """ - try: from geopy.extra.rate_limiter import RateLimiter from geopy.geocoders import Nominatim @@ -71,7 +70,6 @@ def prepare_hotmaps_database(regions): """ Load hotmaps database of industrial sites and map onto bus regions. """ - df = pd.read_csv(snakemake.input.hotmaps_industrial_database, sep=";", index_col=0) df[["srid", "coordinates"]] = df.geom.str.split(";", expand=True) @@ -103,7 +101,6 @@ def build_nodal_distribution_key(hotmaps, regions, countries): """ Build nodal distribution keys for each sector. """ - sectors = hotmaps.Subsector.unique() keys = pd.DataFrame(index=regions.index, columns=sectors, dtype=float) diff --git a/scripts/build_industrial_production_per_country.py b/scripts/build_industrial_production_per_country.py index 8a4c19c24..1c2e45573 100644 --- a/scripts/build_industrial_production_per_country.py +++ b/scripts/build_industrial_production_per_country.py @@ -247,7 +247,6 @@ def separate_basic_chemicals(demand, year): """ Separate basic chemicals into ammonia, chlorine, methanol and HVC. """ - ammonia = pd.read_csv(snakemake.input.ammonia_production, index_col=0) there = ammonia.index.intersection(demand.index) diff --git a/scripts/build_retro_cost.py b/scripts/build_retro_cost.py index 037139d1e..72792c92c 100644 --- a/scripts/build_retro_cost.py +++ b/scripts/build_retro_cost.py @@ -150,7 +150,6 @@ def prepare_building_stock_data(): type and period """ - building_data = pd.read_csv(snakemake.input.building_stock, usecols=list(range(13))) # standardize data @@ -318,7 +317,6 @@ def prepare_building_topology(u_values, same_building_topology=True): Reads in typical building topologies (e.g. average surface of building elements) and typical losses through thermal bridging and air ventilation. """ - data_tabula = pd.read_csv( snakemake.input.data_tabula, skiprows=lambda x: x in range(1, 11), diff --git a/scripts/build_salt_cavern_potentials.py b/scripts/build_salt_cavern_potentials.py index 082c688f1..3fed7f91f 100644 --- a/scripts/build_salt_cavern_potentials.py +++ b/scripts/build_salt_cavern_potentials.py @@ -6,8 +6,8 @@ """ Build salt cavern potentials for hydrogen storage. -Technical Potential of Salt Caverns for Hydrogen Storage in Europe -CC-BY 4.0 +Technical Potential of Salt Caverns for Hydrogen Storage in Europe CC-BY +4.0 https://doi.org/10.20944/preprints201910.0187.v1 https://doi.org/10.1016/j.ijhydene.2019.12.161 @@ -39,7 +39,6 @@ def load_bus_regions(onshore_path, offshore_path): """ Load pypsa-eur on- and offshore regions and concat. """ - bus_regions_offshore = gpd.read_file(offshore_path) bus_regions_onshore = gpd.read_file(onshore_path) bus_regions = concat_gdf([bus_regions_offshore, bus_regions_onshore]) diff --git a/scripts/build_transport_demand.py b/scripts/build_transport_demand.py index a684036d0..29973da30 100644 --- a/scripts/build_transport_demand.py +++ b/scripts/build_transport_demand.py @@ -124,7 +124,6 @@ def bev_availability_profile(fn, snapshots, nodes, options): """ Derive plugged-in availability for passenger electric vehicles. """ - traffic = pd.read_csv(fn, skiprows=2, usecols=["count"]).squeeze("columns") avail_max = options["bev_avail_max"] diff --git a/scripts/cluster_gas_network.py b/scripts/cluster_gas_network.py index d180041cb..441886384 100755 --- a/scripts/cluster_gas_network.py +++ b/scripts/cluster_gas_network.py @@ -30,7 +30,6 @@ def load_bus_regions(onshore_path, offshore_path): """ Load pypsa-eur on- and offshore regions and concat. """ - bus_regions_offshore = gpd.read_file(offshore_path) bus_regions_onshore = gpd.read_file(onshore_path) bus_regions = concat_gdf([bus_regions_offshore, bus_regions_onshore]) diff --git a/scripts/make_summary.py b/scripts/make_summary.py index 5d1ee3dc2..7b33aed86 100644 --- a/scripts/make_summary.py +++ b/scripts/make_summary.py @@ -320,7 +320,6 @@ def calculate_supply(n, label, supply): Calculate the max dispatch of each component at the buses aggregated by carrier. """ - bus_carriers = n.buses.carrier.unique() for i in bus_carriers: @@ -372,7 +371,6 @@ def calculate_supply_energy(n, label, supply_energy): Calculate the total energy supply/consuption of each component at the buses aggregated by carrier. """ - bus_carriers = n.buses.carrier.unique() for i in bus_carriers: diff --git a/scripts/plot_summary.py b/scripts/plot_summary.py index af028116e..339a84574 100644 --- a/scripts/plot_summary.py +++ b/scripts/plot_summary.py @@ -441,7 +441,6 @@ def plot_carbon_budget_distribution(input_eurostat): """ Plot historical carbon emissions in the EU and decarbonization path. """ - import seaborn as sns sns.set() diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index da6eab726..5937eb969 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -51,7 +51,6 @@ def define_spatial(nodes, options): ---------- nodes : list-like """ - global spatial spatial.nodes = nodes @@ -362,7 +361,6 @@ def update_wind_solar_costs(n, costs): Update costs for wind and solar generators added with pypsa-eur to those cost in the planning year. """ - # NB: solar costs are also manipulated for rooftop # when distribution grid is inserted n.generators.loc[n.generators.carrier == "solar", "capital_cost"] = costs.at[ @@ -440,7 +438,6 @@ def add_carrier_buses(n, carrier, nodes=None): """ Add buses to connect e.g. coal, nuclear and oil plants. """ - if nodes is None: nodes = vars(spatial)[carrier].nodes location = vars(spatial)[carrier].locations @@ -487,7 +484,6 @@ def remove_elec_base_techs(n): batteries and H2) from base electricity-only network, since they're added here differently using links. """ - for c in n.iterate_components(snakemake.config["pypsa_eur"]): to_keep = snakemake.config["pypsa_eur"][c.name] to_remove = pd.Index(c.df.carrier.unique()).symmetric_difference(to_keep) diff --git a/scripts/simplify_network.py b/scripts/simplify_network.py index 5e50c4ab6..58c4ad17f 100644 --- a/scripts/simplify_network.py +++ b/scripts/simplify_network.py @@ -112,15 +112,12 @@ def simplify_network_to_380(n): Fix all lines to a voltage level of 380 kV and remove all transformers. The function preserves the transmission capacity for each line while - updating - its voltage level, line type and number of parallel bundles + updating its voltage level, line type and number of parallel bundles (num_parallel). Transformers are removed and connected components are moved from - their - starting bus to their ending bus. The corresponding starting buses - are - removed as well. + their starting bus to their ending bus. The corresponding starting + buses are removed as well. """ logger.info("Mapping all network lines onto a single 380kV layer")