From e16fa286ec505cb18c1e9cad23034dffc16e9fd2 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Sat, 29 Apr 2023 12:41:37 +0200 Subject: [PATCH] merge master --- doc/configtables/load.csv | 2 +- rules/collect.smk | 14 ++++++++++---- scripts/add_electricity.py | 23 +++++++++++------------ scripts/add_extra_components.py | 6 ++++-- scripts/build_cutout.py | 8 ++++---- scripts/build_electricity_demand.py | 16 +++++++++------- scripts/build_hydro_profile.py | 16 +++++++--------- scripts/build_renewable_profiles.py | 4 +++- scripts/cluster_network.py | 4 +++- scripts/prepare_network.py | 7 ++++++- 10 files changed, 58 insertions(+), 42 deletions(-) diff --git a/doc/configtables/load.csv b/doc/configtables/load.csv index 3eeb3a65..a206cc23 100644 --- a/doc/configtables/load.csv +++ b/doc/configtables/load.csv @@ -8,4 +8,4 @@ interpolate_limit,hours,integer,"Maximum gap size (consecutive nans) which inter time_shift_for_large_gaps,string,string,"Periods which are used for copying time-slices in order to fill large gaps of nans. Have to be valid ``pandas`` period strings." manual_adjustments,bool,"{true, false}","Whether to adjust the load data manually according to the function in :func:`manual_adjustment`." scaling_factor,--,float,"Global correction factor for the load time series." -fixed_year,--,Year or False,"To specify a fixed year for the load time series that deviates from the snapshots' year" \ No newline at end of file +fixed_year,--,Year or False,"To specify a fixed year for the load time series that deviates from the snapshots' year" diff --git a/rules/collect.smk b/rules/collect.smk index 603e665e..5092d67e 100644 --- a/rules/collect.smk +++ b/rules/collect.smk @@ -22,20 +22,25 @@ rule all: rule cluster_networks: input: - expand(RESOURCES + "networks/elec{weather_year}_s{simpl}_{clusters}.nc", **config["scenario"]), + expand( + RESOURCES + "networks/elec{weather_year}_s{simpl}_{clusters}.nc", + **config["scenario"] + ), rule extra_components_networks: input: expand( - RESOURCES + "networks/elec{weather_year}_s{simpl}_{clusters}_ec.nc", **config["scenario"] + RESOURCES + "networks/elec{weather_year}_s{simpl}_{clusters}_ec.nc", + **config["scenario"] ), rule prepare_elec_networks: input: expand( - RESOURCES + "networks/elec{weather_year}_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc", + RESOURCES + + "networks/elec{weather_year}_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc", **config["scenario"] ), @@ -52,7 +57,8 @@ rule prepare_sector_networks: rule solve_elec_networks: input: expand( - RESULTS + "networks/elec{weather_year}_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc", + RESULTS + + "networks/elec{weather_year}_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc", **config["scenario"] ), diff --git a/scripts/add_electricity.py b/scripts/add_electricity.py index 0ecd415b..87c06aaf 100755 --- a/scripts/add_electricity.py +++ b/scripts/add_electricity.py @@ -701,19 +701,20 @@ def add_nice_carrier_names(n, config): n.carriers["color"] = colors - def drop_leap_day(n): - if not n.snapshots.is_leap_year.any(): return + if not n.snapshots.is_leap_year.any(): + return leap_days = (n.snapshots.day == 29) & (n.snapshots.month == 2) n.set_snapshots(n.snapshots[~leap_days]) - n.snapshot_weightings[:] = 8760/len(n.snapshots) + n.snapshot_weightings[:] = 8760 / len(n.snapshots) logger.info("Dropped February 29 from leap year.") if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake - snakemake = mock_snakemake('add_electricity', weather_year='') + + snakemake = mock_snakemake("add_electricity", weather_year="") configure_logging(snakemake) n = pypsa.Network(snakemake.input.base_network) @@ -721,15 +722,13 @@ if __name__ == "__main__": weather_year = snakemake.wildcards.weather_year if weather_year: snapshots = dict( - start=weather_year, - end=str(int(weather_year)+1), - closed="left" + start=weather_year, end=str(int(weather_year) + 1), closed="left" ) else: - snapshots = snakemake.config['snapshots'] - n.set_snapshots(pd.date_range(freq='h', **snapshots)) - - Nyears = n.snapshot_weightings.objective.sum() / 8760. + snapshots = snakemake.config["snapshots"] + n.set_snapshots(pd.date_range(freq="h", **snapshots)) + + Nyears = n.snapshot_weightings.objective.sum() / 8760.0 costs = load_costs( snakemake.input.tech_costs, @@ -855,7 +854,7 @@ if __name__ == "__main__": add_nice_carrier_names(n, snakemake.config) - if snakemake.config['enable'].get('drop_leap_days', True): + if snakemake.config["enable"].get("drop_leap_days", True): drop_leap_day(n) n.meta = snakemake.config diff --git a/scripts/add_extra_components.py b/scripts/add_extra_components.py index 8a3496e2..91abbad6 100644 --- a/scripts/add_extra_components.py +++ b/scripts/add_extra_components.py @@ -230,8 +230,10 @@ def attach_hydrogen_pipelines(n, costs, elec_opts): if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake - snakemake = mock_snakemake('add_extra_components', weather_year='', - simpl='', clusters=5) + + snakemake = mock_snakemake( + "add_extra_components", weather_year="", simpl="", clusters=5 + ) configure_logging(snakemake) n = pypsa.Network(snakemake.input.network) diff --git a/scripts/build_cutout.py b/scripts/build_cutout.py index 3ce15bc9..60da4f55 100644 --- a/scripts/build_cutout.py +++ b/scripts/build_cutout.py @@ -108,15 +108,15 @@ if __name__ == "__main__": cutout_params = snakemake.config["atlite"]["cutouts"][snakemake.wildcards.cutout] - if hasattr(snakemake.wildcards, 'weather_year'): + if hasattr(snakemake.wildcards, "weather_year"): time = snakemake.wildcards.weather_year cutout_params["time"] = [time, time] if "time" not in cutout_params: - snapshots = pd.date_range(freq='h', **snakemake.config['snapshots']) - cutout_params["time"] = [snapshots[0], snapshots[-1]] + snapshots = pd.date_range(freq="h", **snakemake.config["snapshots"]) + cutout_params["time"] = [snapshots[0], snapshots[-1]] - cutout_params['time'] = slice(*cutout_params['time']) + cutout_params["time"] = slice(*cutout_params["time"]) if {"x", "y", "bounds"}.isdisjoint(cutout_params): # Determine the bounds from bus regions with a buffer of two grid cells diff --git a/scripts/build_electricity_demand.py b/scripts/build_electricity_demand.py index 6f16d336..4be46014 100755 --- a/scripts/build_electricity_demand.py +++ b/scripts/build_electricity_demand.py @@ -275,23 +275,25 @@ if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake - snakemake = mock_snakemake("build_electricity_demand", weather_year='') + snakemake = mock_snakemake("build_electricity_demand", weather_year="") configure_logging(snakemake) weather_year = snakemake.wildcards.weather_year if weather_year: snapshots = dict( - start=weather_year, - end=str(int(weather_year)+1), - closed="left" + start=weather_year, end=str(int(weather_year) + 1), closed="left" ) else: - snapshots = snakemake.config['snapshots'] - snapshots = pd.date_range(freq='h', **snapshots) + snapshots = snakemake.config["snapshots"] + snapshots = pd.date_range(freq="h", **snapshots) fixed_year = snakemake.config["load"].get("fixed_year", False) - years = slice(str(fixed_year), str(fixed_year)) if fixed_year else slice(snapshots[0], snapshots[-1]) + years = ( + slice(str(fixed_year), str(fixed_year)) + if fixed_year + else slice(snapshots[0], snapshots[-1]) + ) powerstatistics = snakemake.config["load"]["power_statistics"] interpolate_limit = snakemake.config["load"]["interpolate_limit"] diff --git a/scripts/build_hydro_profile.py b/scripts/build_hydro_profile.py index 4996c501..708c0c8d 100644 --- a/scripts/build_hydro_profile.py +++ b/scripts/build_hydro_profile.py @@ -65,9 +65,8 @@ import atlite import country_converter as coco import geopandas as gpd import pandas as pd -from numpy.polynomial import Polynomial from _helpers import configure_logging - +from numpy.polynomial import Polynomial cc = coco.CountryConverter() @@ -132,11 +131,10 @@ def correct_eia_stats_by_capacity(eia_stats, fn, countries, baseyear=2019): eia_stats_corrected = eia_stats / ratio to_keep = ["AL", "AT", "CH", "DE", "GB", "NL", "RS", "RO", "SK"] to_correct = eia_stats_corrected.columns.difference(to_keep) - eia_stats.loc[:,to_correct] = eia_stats_corrected.loc[:,to_correct] + eia_stats.loc[:, to_correct] = eia_stats_corrected.loc[:, to_correct] def approximate_missing_eia_stats(eia_stats, runoff_fn, countries): - runoff = pd.read_csv(runoff_fn, index_col=0).T[countries] # fix ES, PT data points @@ -147,7 +145,6 @@ def approximate_missing_eia_stats(eia_stats, runoff_fn, countries): eia_stats_approximated = {} for c in countries: - X = runoff_eia[c] Y = eia_stats[c] @@ -168,7 +165,8 @@ logger = logging.getLogger(__name__) if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake - snakemake = mock_snakemake('build_hydro_profile', weather_year='') + + snakemake = mock_snakemake("build_hydro_profile", weather_year="") configure_logging(snakemake) config_hydro = snakemake.config["renewable"]["hydro"] @@ -185,18 +183,18 @@ if __name__ == "__main__": fn = snakemake.input.eia_hydro_generation eia_stats = get_eia_annual_hydro_generation(fn, countries) - if config_hydro.get('eia_correct_by_capacity'): + if config_hydro.get("eia_correct_by_capacity"): fn = snakemake.input.eia_hydro_capacity correct_eia_stats_by_capacity(eia_stats, fn, countries) - if config_hydro.get('eia_approximate_missing'): + if config_hydro.get("eia_approximate_missing"): fn = snakemake.input.era5_runoff eia_stats = approximate_missing_eia_stats(eia_stats, fn, countries) eia_stats.to_csv(snakemake.output.eia_hydro) weather_year = snakemake.wildcards.weather_year - norm_year = config_hydro.get('eia_norm_year') + norm_year = config_hydro.get("eia_norm_year") if norm_year: eia_stats.loc[weather_year] = eia_stats.loc[norm_year] elif weather_year and weather_year not in eia_stats.index: diff --git a/scripts/build_renewable_profiles.py b/scripts/build_renewable_profiles.py index 43bc05a1..acdc46de 100644 --- a/scripts/build_renewable_profiles.py +++ b/scripts/build_renewable_profiles.py @@ -199,7 +199,9 @@ if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake - snakemake = mock_snakemake("build_renewable_profiles", technology="solar", weather_year="") + snakemake = mock_snakemake( + "build_renewable_profiles", technology="solar", weather_year="" + ) configure_logging(snakemake) nprocesses = int(snakemake.threads) diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index 0cb70069..95445caf 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -457,7 +457,9 @@ if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake - snakemake = mock_snakemake("cluster_network", simpl="", clusters="5", weather_year="") + snakemake = mock_snakemake( + "cluster_network", simpl="", clusters="5", weather_year="" + ) configure_logging(snakemake) n = pypsa.Network(snakemake.input.network) diff --git a/scripts/prepare_network.py b/scripts/prepare_network.py index eba20033..72d13d2d 100755 --- a/scripts/prepare_network.py +++ b/scripts/prepare_network.py @@ -243,7 +243,12 @@ if __name__ == "__main__": from _helpers import mock_snakemake snakemake = mock_snakemake( - "prepare_network", weather_year="", simpl="", clusters="40", ll="v0.3", opts="Co2L-24H" + "prepare_network", + weather_year="", + simpl="", + clusters="40", + ll="v0.3", + opts="Co2L-24H", ) configure_logging(snakemake)