Skip to content

Commit

Permalink
Custom busmap (#1231)
Browse files Browse the repository at this point in the history
* Added functionality to set custom_busmaps for different base_networks.

* Updated configtables and location for busmaps.

* Added release nots.

* removed run parameter in mock_snakemake (only used for debugging).

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Fabian Neumann <fabian.neumann@outlook.de>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 23, 2024
1 parent 73d1353 commit ef0bbd5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion doc/configtables/enable.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ retrieve_databundle,bool,"{true, false}","Switch to retrieve databundle from zen
retrieve_cost_data,bool,"{true, false}","Switch to retrieve technology cost data from `technology-data repository <https://github.com/PyPSA/technology-data>`_."
build_cutout,bool,"{true, false}","Switch to enable the building of cutouts via the rule :mod:`build_cutout`."
retrieve_cutout,bool,"{true, false}","Switch to enable the retrieval of cutouts from zenodo with :mod:`retrieve_cutout`."
custom_busmap,bool,"{true, false}","Switch to enable the use of custom busmaps in rule :mod:`cluster_network`. If activated the rule looks for provided busmaps at ``data/custom_busmap_elec_s{simpl}_{clusters}.csv`` which should have the same format as ``resources/busmap_elec_s{simpl}_{clusters}.csv``, i.e. the index should contain the buses of ``networks/elec_s{simpl}.nc``."
custom_busmap,bool,"{true, false}","Switch to enable the use of custom busmaps in rule :mod:`cluster_network`. If activated the rule looks for provided busmaps at ``data/busmaps/elec_s{simpl}_{clusters}_{base_network}.csv`` which should have the same format as ``resources/busmap_elec_s{simpl}_{clusters}.csv``, i.e. the index should contain the buses of ``networks/elec_s{simpl}.nc``. {base_network} is the name of the selected base_network in electricity, e.g. ``gridkit``, ``osm-prebuilt``, or ``osm-raw``."
drop_leap_day,bool,"{true, false}","Switch to drop February 29 from all time-dependent data in leap years"
2 changes: 2 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Upcoming Release
* In :mod:`base_network`, replace own voronoi polygon calculation function with
Geopandas `gdf.voronoi_polygons` method.

* Move custom busmaps to ```data/busmaps/elec_s{simpl}_{clusters}_{base_network}.csv``` (if enabled). This allows for different busmaps depending on the base network and scenario.

PyPSA-Eur 0.11.0 (25th May 2024)
=====================================

Expand Down
15 changes: 10 additions & 5 deletions rules/build_electricity.smk
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,15 @@ rule simplify_network:
"../scripts/simplify_network.py"


# Optional input when using custom busmaps - Needs to be tailored to selected base_network
def input_cluster_network(w):
if config_provider("enable", "custom_busmap", default=False)(w):
base_network = config_provider("electricity", "base_network")(w)
custom_busmap = f"data/busmaps/elec_s{w.simpl}_{w.clusters}_{base_network}.csv"
return {"custom_busmap": custom_busmap}
return {"custom_busmap": []}


rule cluster_network:
params:
cluster_network=config_provider("clustering", "cluster_network"),
Expand All @@ -546,15 +555,11 @@ rule cluster_network:
length_factor=config_provider("lines", "length_factor"),
costs=config_provider("costs"),
input:
unpack(input_cluster_network),
network=resources("networks/elec_s{simpl}.nc"),
regions_onshore=resources("regions_onshore_elec_s{simpl}.geojson"),
regions_offshore=resources("regions_offshore_elec_s{simpl}.geojson"),
busmap=ancient(resources("busmap_elec_s{simpl}.csv")),
custom_busmap=lambda w: (
"data/custom_busmap_elec_s{simpl}_{clusters}.csv"
if config_provider("enable", "custom_busmap", default=False)(w)
else []
),
tech_costs=lambda w: resources(
f"costs_{config_provider('costs', 'year')(w)}.csv"
),
Expand Down
6 changes: 2 additions & 4 deletions scripts/cluster_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
- ``resources/regions_offshore_elec_s{simpl}.geojson``: confer :ref:`simplify`
- ``resources/busmap_elec_s{simpl}.csv``: confer :ref:`simplify`
- ``networks/elec_s{simpl}.nc``: confer :ref:`simplify`
- ``data/custom_busmap_elec_s{simpl}_{clusters}.csv``: optional input
- ``data/custom_busmap_elec_s{simpl}_{clusters}_{base_network}.csv``: optional input
Outputs
-------
Expand Down Expand Up @@ -511,9 +511,7 @@ def plot_busmap_for_n_clusters(n, n_clusters, solver_name="scip", fn=None):
# Fast-path if no clustering is necessary
busmap = n.buses.index.to_series()
linemap = n.lines.index.to_series()
clustering = pypsa.clustering.spatial.Clustering(
n, busmap, linemap
)
clustering = pypsa.clustering.spatial.Clustering(n, busmap, linemap)
else:
Nyears = n.snapshot_weightings.objective.sum() / 8760

Expand Down

0 comments on commit ef0bbd5

Please sign in to comment.