diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dd4e8fb..66b5f43 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ exclude: "^LICENSES" repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v6.0.0 hooks: - id: check-merge-conflict - id: end-of-file-fixer @@ -19,14 +19,14 @@ repos: # Sort package imports alphabetically - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + rev: 7.0.0 hooks: - id: isort args: ["--profile", "black", "--filter-files"] # Find common spelling mistakes in comments and docstrings - repo: https://github.com/codespell-project/codespell - rev: v2.2.2 + rev: v2.4.1 hooks: - id: codespell args: ['--ignore-regex="\b[A-Z]+\b"'] # Ignore capital case words, e.g. country codes @@ -34,8 +34,8 @@ repos: files: ^(actions|doc)/ # Formatting with "black" coding style -- repo: https://github.com/psf/black - rev: 22.10.0 +- repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.1.0 hooks: # Format Python files - id: black @@ -43,27 +43,27 @@ repos: - id: black-jupyter - repo: https://github.com/nbQA-dev/nbQA - rev: 1.5.3 + rev: 1.9.1 hooks: # Apply isort to Jupyter Python notebooks - id: nbqa-isort # Do YAML formatting (before the linter checks it for misses) - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.4.0 + rev: v2.16.0 hooks: - id: pretty-format-yaml args: [--autofix, --indent, '2', --preserve-quotes] # Format Snakemake rule / workflow files - repo: https://github.com/snakemake/snakefmt - rev: v0.7.0 + rev: v0.11.4 hooks: - id: snakefmt # Check for FSFE REUSE compliance (licensing) - repo: https://github.com/fsfe/reuse-tool - rev: v1.0.0 + rev: v6.2.0 hooks: - id: reuse diff --git a/actions/create_network.py.ipynb b/actions/create_network.py.ipynb index f9ebf4e..dc70a42 100644 --- a/actions/create_network.py.ipynb +++ b/actions/create_network.py.ipynb @@ -314,7 +314,6 @@ "def scale_transportation_with_distance(\n", " n, link_types=[\"HVDC overhead\", \"HVDC submarine\", \"pipeline\", \"submarine pipeline\"]\n", "):\n", - "\n", " \"\"\"Scales the cost and efficiency of specific links (transport options) by distance.\n", "\n", " Only implemented for:\n", @@ -752,9 +751,9 @@ " & (loaded_unloaded_ratio[\"from\"] == \"LOHC (loaded)\")\n", " & (loaded_unloaded_ratio[\"to\"] == \"LOHC (used)\")\n", " ][\"efficiency\"].item()\n", - " n.links.loc[\n", - " f\"{ship_bus} trip demand & losses\", \"bus2\"\n", - " ] = f\"{ship_bus} LOHC (used)\"\n", + " n.links.loc[f\"{ship_bus} trip demand & losses\", \"bus2\"] = (\n", + " f\"{ship_bus} LOHC (used)\"\n", + " )\n", " n.links.loc[f\"{ship_bus} trip demand & losses\", \"efficiency2\"] = (\n", " 1 - shipping_efficiency\n", " ) * loaded_unloaded_ratio\n", diff --git a/actions/solve_network.py.ipynb b/actions/solve_network.py.ipynb index 8dd0f8d..8733903 100644 --- a/actions/solve_network.py.ipynb +++ b/actions/solve_network.py.ipynb @@ -144,7 +144,7 @@ " (\"links\", \"pipeline\", \"CAPEX_pipeline\"),\n", " (\"links\", \"methanolisation\", \"CAPEX_MeOHSynthesis\"),\n", " ]\n", - " for (components_name, search_string, modifier_name) in mapping:\n", + " for components_name, search_string, modifier_name in mapping:\n", " c = getattr(n, components_name)\n", " c.loc[c.index.str.contains(search_string), \"capital_cost\"] *= scenario[\n", " \"modifiers\"\n", diff --git a/analysis/plot_paper_figures.ipynb b/analysis/plot_paper_figures.ipynb index d3c33b3..b85162b 100644 --- a/analysis/plot_paper_figures.ipynb +++ b/analysis/plot_paper_figures.ipynb @@ -51,6 +51,8 @@ "source": [ "# Take a list of labels and rename the ESCs from that list\n", "# to more prettier (and shorter) names\n", + "\n", + "\n", "def prettiefy_esc_names(labels):\n", "\n", " prettier_names = {\n", @@ -628,8 +630,8 @@ "fig = plt.figure(figsize=(12, 4))\n", "ax = plt.gca()\n", "\n", - "for (esc, x) in zip(esc_markers.keys(), xs):\n", - " for ((idx, row), xx) in zip(df.loc[esc].sort_values(\"value\").iterrows(), xxs):\n", + "for esc, x in zip(esc_markers.keys(), xs):\n", + " for (idx, row), xx in zip(df.loc[esc].sort_values(\"value\").iterrows(), xxs):\n", " ax.bar(\n", " x + xx * width - (xxs.shape[0] - 1) * width / 2,\n", " row[\"value\"],\n", @@ -694,8 +696,8 @@ "fig = plt.figure(figsize=(10, 6))\n", "ax = plt.gca()\n", "\n", - "for (esc, x) in zip(esc_markers.keys(), xs):\n", - " for (year, xx) in zip(years, xxs):\n", + "for esc, x in zip(esc_markers.keys(), xs):\n", + " for year, xx in zip(years, xxs):\n", " for idx, row in df.loc[esc, year].iterrows():\n", " # Single value dots\n", " ax.scatter(\n", @@ -777,8 +779,8 @@ "fig = plt.figure(figsize=(10, 6))\n", "ax = plt.gca()\n", "\n", - "for (esc, x) in zip(esc_markers.keys(), xs):\n", - " for (year, xx) in zip(years, xxs):\n", + "for esc, x in zip(esc_markers.keys(), xs):\n", + " for year, xx in zip(years, xxs):\n", " for idx, row in df.loc[esc, year].iterrows():\n", " # Individual dots\n", " ax.scatter(\n", @@ -888,8 +890,8 @@ "ax = plt.gca()\n", "\n", "# Plot each vertical year line and each scatter point separately\n", - "for (esc, x) in zip(conversion_factors.keys(), xs):\n", - " for (year, xx) in zip(years, xxs):\n", + "for esc, x in zip(conversion_factors.keys(), xs):\n", + " for year, xx in zip(years, xxs):\n", " for idx, row in df.loc[esc, year].iterrows():\n", " # each scatter/data point. Marked by color of exporter\n", " ax.scatter(\n", @@ -1000,8 +1002,8 @@ "ax = plt.gca()\n", "\n", "# Plot each vertical year line and each scatter point separately\n", - "for (esc, x) in zip(conversion_factors.keys(), xs):\n", - " for (year, xx) in zip(years, xxs):\n", + "for esc, x in zip(conversion_factors.keys(), xs):\n", + " for year, xx in zip(years, xxs):\n", " for idx, row in df.loc[esc, year].iterrows():\n", " # each scatter/data point. Marked by color of exporter\n", " ax.scatter(\n", diff --git a/analysis/results-plotting.ipynb b/analysis/results-plotting.ipynb index 9a5eb8e..dcd5533 100644 --- a/analysis/results-plotting.ipynb +++ b/analysis/results-plotting.ipynb @@ -90,7 +90,7 @@ "source": [ "# Plot all ESCs per exporter\n", "for name, group in df.groupby(df.index.names[:3]):\n", - " (year, wacc, importer) = name\n", + " year, wacc, importer = name\n", "\n", " tmp = group.loc[name].loc[:, :, \"general\", \"Cost per MWh delivered\"]\n", " tmp.reset_index().pivot(index=\"exporter\", columns=\"esc\", values=\"value\").plot(\n", @@ -118,7 +118,7 @@ "source": [ "# Plot per ESC all exporters\n", "for name, group in df.groupby(df.index.names[:3]):\n", - " (year, wacc, importer) = name\n", + " year, wacc, importer = name\n", "\n", " tmp = group.loc[name].loc[:, :, \"general\", \"Cost per MWh delivered\"]\n", " tmp.reset_index().pivot(index=\"esc\", columns=\"exporter\", values=\"value\").plot(\n", @@ -146,7 +146,7 @@ "source": [ "# Energy surplus factor by ESC for each exporter\n", "for name, group in df.groupby(df.index.names[:3]):\n", - " (year, wacc, importer) = name\n", + " year, wacc, importer = name\n", "\n", " tmp = group.loc[name].loc[:, :, \"general\", \"Energy surplus factor\"]\n", " tmp.reset_index().pivot(index=\"exporter\", columns=\"esc\", values=\"value\").plot(\n", @@ -189,7 +189,7 @@ "cutoff = 0.1\n", "\n", "for name, group in df.groupby(df.index.names[:4]):\n", - " (year, wacc, importer, esc) = name\n", + " year, wacc, importer, esc = name\n", "\n", " group = group.loc[name].loc[:, \"cost\", :] # Select cost only\n", "\n", @@ -289,7 +289,7 @@ "}\n", "\n", "for name, group in df.groupby(df.index.names[:4]):\n", - " (year, wacc, importer, esc) = name\n", + " year, wacc, importer, esc = name\n", "\n", " group = group.loc[name].loc[:, \"capacity factor\", :] # Select CFs only\n", "\n", @@ -359,7 +359,7 @@ "brk = False\n", "\n", "for name, group in df.groupby(df.index.names[:4]):\n", - " (year, wacc, importer, esc) = name\n", + " year, wacc, importer, esc = name\n", "\n", " group = group.loc[name].loc[:, \"installed capacity\", :] # Select capacities only\n", "\n", diff --git a/rules/gegis.smk b/rules/gegis.smk index 80493e3..13da0ed 100644 --- a/rules/gegis.smk +++ b/rules/gegis.smk @@ -14,7 +14,7 @@ if config["GlobalEnergyGIS"].get("init_gegis", False) is True: script: "../actions/set_GEGIS_base_dir.jl" -# Download auxiliary datasets for GEGIS + # Download auxiliary datasets for GEGIS rule download_GEGIS_dataset: output: Path(config["GlobalEnergyGIS"]["base_dir"]) / "protected.jld", # not full list, only dependencies for rules below (proxy all others) @@ -22,7 +22,7 @@ if config["GlobalEnergyGIS"].get("init_gegis", False) is True: script: "../actions/download_GEGIS_datasets.jl" -# Download ERA5 data for wind/solar/synthetic demand for GEGIS + # Download ERA5 data for wind/solar/synthetic demand for GEGIS rule download_GEGIS_era5: output: Path(config["GlobalEnergyGIS"]["base_dir"]) / "era5wind{year}.h5", diff --git a/rules/results.smk b/rules/results.smk index 5ea975d..123d149 100644 --- a/rules/results.smk +++ b/rules/results.smk @@ -5,6 +5,7 @@ # Use paramspace to evaluate which scenarios to run scenarios = Paramspace(pd.read_csv("scenarios/default.csv", dtype=str)) + # Custom pattern for formatting Paramspace, as snakemake # does currently not allow for patterns without the wildcard_name included # see: https://stackoverflow.com/questions/71293563/custom-patterns-with-snakemakes-paramspace/71296522#71296522