From 9178dde4a7517bdafb05cec33fc796719322e13d Mon Sep 17 00:00:00 2001 From: Fabian Hofmann Date: Mon, 23 Sep 2019 14:32:51 +0200 Subject: [PATCH 1/9] partially resolves #70 --- scripts/cluster_network.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index f1ffdfc4..e40fb6bb 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -8,24 +8,20 @@ logger = logging.getLogger(__name__) import os import numpy as np -import scipy as sp -from scipy.sparse.csgraph import connected_components -import xarray as xr import geopandas as gpd import shapely -import networkx as nx -from shutil import copyfile +import matplotlib.pyplot as plt +import seaborn as sns -from six import iteritems from six.moves import reduce import pyomo.environ as po import pypsa -from pypsa.io import import_components_from_dataframe, import_series_from_dataframe -from pypsa.networkclustering import (busmap_by_stubs, busmap_by_kmeans, - _make_consense, get_clustering_from_busmap, - aggregategenerators, aggregateoneport) +from pypsa.networkclustering import (busmap_by_kmeans, busmap_by_louvain, + busmap_by_spectral_clustering, + _make_consense, get_clustering_from_busmap) + def normed(x): return (x/x.sum()).fillna(0.) @@ -156,6 +152,12 @@ def clustering_for_n_clusters(n, n_clusters, aggregate_carriers=None, generator_strategies={'p_nom_max': p_nom_max_strategy} ) + nc = clustering.network + nc.links['underwater_fraction'] = (n.links.eval('underwater_fraction * length') + .div(nc.links.length).dropna()) +# nc.links['capital_cost'] += (costs.at['HVDC overhead', 'capital_cost'] * +# (nc.links.length - n.links.length) +# .dropna().clip(lower=0)) return clustering def save_to_geojson(s, fn): From 16ff2b51bdf66787b3e1d84a036042d1ee3abaa9 Mon Sep 17 00:00:00 2001 From: Fabian Hofmann Date: Mon, 23 Sep 2019 16:44:48 +0200 Subject: [PATCH 2/9] fix small issues --- Snakefile | 3 ++- scripts/cluster_network.py | 30 ++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Snakefile b/Snakefile index c24bd250..f685d505 100644 --- a/Snakefile +++ b/Snakefile @@ -175,7 +175,8 @@ rule cluster_network: network='networks/{network}_s{simpl}.nc', regions_onshore="resources/regions_onshore_{network}_s{simpl}.geojson", regions_offshore="resources/regions_offshore_{network}_s{simpl}.geojson", - clustermaps=ancient('resources/clustermaps_{network}_s{simpl}.h5') + clustermaps=ancient('resources/clustermaps_{network}_s{simpl}.h5'), + tech_costs=COSTS output: network='networks/{network}_s{simpl}_{clusters}.nc', regions_onshore="resources/regions_onshore_{network}_s{simpl}_{clusters}.geojson", diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index e40fb6bb..5f0cf90e 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -18,10 +18,11 @@ from six.moves import reduce import pyomo.environ as po import pypsa -from pypsa.networkclustering import (busmap_by_kmeans, busmap_by_louvain, - busmap_by_spectral_clustering, +from pypsa.networkclustering import (busmap_by_kmeans, busmap_by_spectral_clustering, _make_consense, get_clustering_from_busmap) +from add_electricity import load_costs + def normed(x): return (x/x.sum()).fillna(0.) @@ -132,7 +133,8 @@ def plot_busmap_for_n_clusters(n, n_clusters=50): def clustering_for_n_clusters(n, n_clusters, aggregate_carriers=None, line_length_factor=1.25, potential_mode='simple', - solver_name="cbc", algorithm="kmeans"): + solver_name="cbc", algorithm="kmeans", + extended_link_costs=0): if potential_mode == 'simple': p_nom_max_strategy = np.sum @@ -149,15 +151,15 @@ def clustering_for_n_clusters(n, n_clusters, aggregate_carriers=None, aggregate_generators_carriers=aggregate_carriers, aggregate_one_ports=["Load", "StorageUnit"], line_length_factor=line_length_factor, - generator_strategies={'p_nom_max': p_nom_max_strategy} - ) + generator_strategies={'p_nom_max': p_nom_max_strategy}, + scale_link_capital_costs=False) nc = clustering.network nc.links['underwater_fraction'] = (n.links.eval('underwater_fraction * length') .div(nc.links.length).dropna()) -# nc.links['capital_cost'] += (costs.at['HVDC overhead', 'capital_cost'] * -# (nc.links.length - n.links.length) -# .dropna().clip(lower=0)) + nc.links['capital_cost'] += (nc.links.length.sub(n.links.length).dropna() + .clip(lower=0) + .mul(extended_link_costs * line_length_factor)) return clustering def save_to_geojson(s, fn): @@ -190,7 +192,9 @@ if __name__ == "__main__": network='networks/{network}_s{simpl}.nc', regions_onshore='resources/regions_onshore_{network}_s{simpl}.geojson', regions_offshore='resources/regions_offshore_{network}_s{simpl}.geojson', - clustermaps='resources/clustermaps_{network}_s{simpl}.h5' + clustermaps='resources/clustermaps_{network}_s{simpl}.h5', + tech_costs='data/costs.csv', + ), output=Dict( network='networks/{network}_s{simpl}_{clusters}.nc', @@ -222,6 +226,11 @@ if __name__ == "__main__": clustering = pypsa.networkclustering.Clustering(n, busmap, linemap, linemap, pd.Series(dtype='O')) else: line_length_factor = snakemake.config['lines']['length_factor'] + overhead_cost = (load_costs(n.snapshot_weightings.sum()/8760, + tech_costs=snakemake.input.tech_costs, + config=snakemake.config['costs'], + elec_config=snakemake.config['electricity']) + .at['HVAC overhead', 'capital_cost']) def consense(x): v = x.iat[0] @@ -234,7 +243,8 @@ if __name__ == "__main__": clustering = clustering_for_n_clusters(n, n_clusters, aggregate_carriers, line_length_factor=line_length_factor, potential_mode=potential_mode, - solver_name=snakemake.config['solving']['solver']['name']) + solver_name=snakemake.config['solving']['solver']['name'], + extended_link_costs=overhead_cost) clustering.network.export_to_netcdf(snakemake.output.network) with pd.HDFStore(snakemake.output.clustermaps, mode='w') as store: From 6c784858532bf559ff6e589329e76ba4af8a9fbd Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 28 Oct 2019 18:03:34 +0100 Subject: [PATCH 3/9] README: add build status --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 10e9075f..eba463c4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ ![Version](https://img.shields.io/github/tag-date/pypsa/pypsa-eur) +[![Build Status](https://travis-ci.org/PyPSA/pypsa-eur.svg?branch=master)](https://travis-ci.org/PyPSA/pypsa-eur) [![Documentation](https://readthedocs.org/projects/pypsa-eur/badge/?version=latest)](https://pypsa-eur.readthedocs.io/en/latest/?badge=latest) ![GitHub](https://img.shields.io/github/license/pypsa/pypsa-eur) ![Size](https://img.shields.io/github/repo-size/pypsa/pypsa-eur) From 28fcd5ca3ab73898639fcc010fa71413f13dd216 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 28 Oct 2019 18:04:44 +0100 Subject: [PATCH 4/9] doc/index: add build status --- doc/index.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/index.rst b/doc/index.rst index bc036220..1d5d921a 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -3,6 +3,9 @@ PyPSA-Eur: An Open Optimisation Model of the European Transmission System .. image:: https://img.shields.io/github/tag-date/pypsa/pypsa-eur :alt: GitHub tag + +.. image:: https://travis-ci.org/PyPSA/pypsa-eur.svg?branch=master + :target: https://travis-ci.org/PyPSA/pypsa-eur .. image:: https://readthedocs.org/projects/pypsa-eur/badge/?version=latest :target: https://pypsa-eur.readthedocs.io/en/latest/?badge=latest @@ -158,4 +161,4 @@ More details are included in * *BY: Attribute Source* * *NC: Non-Commercial Use Only* -* *SA: Share Alike* \ No newline at end of file +* *SA: Share Alike* From a7915eeae5f75128321771037b4460c5a8837927 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 28 Oct 2019 18:08:37 +0100 Subject: [PATCH 5/9] README: add version badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eba463c4..f798419d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Version](https://img.shields.io/github/tag-date/pypsa/pypsa-eur) +![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/pypsa/pypsa-eur?include_prereleases) [![Build Status](https://travis-ci.org/PyPSA/pypsa-eur.svg?branch=master)](https://travis-ci.org/PyPSA/pypsa-eur) [![Documentation](https://readthedocs.org/projects/pypsa-eur/badge/?version=latest)](https://pypsa-eur.readthedocs.io/en/latest/?badge=latest) ![GitHub](https://img.shields.io/github/license/pypsa/pypsa-eur) From b711517bd96af1d427ed128fed04fba730309d85 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 28 Oct 2019 18:09:17 +0100 Subject: [PATCH 6/9] Update index.rst --- doc/index.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/index.rst b/doc/index.rst index 1d5d921a..1fc6d80e 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -1,8 +1,7 @@ PyPSA-Eur: An Open Optimisation Model of the European Transmission System ========================================================================= -.. image:: https://img.shields.io/github/tag-date/pypsa/pypsa-eur - :alt: GitHub tag +.. image:: https://img.shields.io/github/v/release/pypsa/pypsa-eur?include_prereleases :alt: GitHub release (latest by date including pre-releases) .. image:: https://travis-ci.org/PyPSA/pypsa-eur.svg?branch=master :target: https://travis-ci.org/PyPSA/pypsa-eur From c37e8dc799222051a6d9238917f75b7f24b65bcd Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 28 Oct 2019 18:11:19 +0100 Subject: [PATCH 7/9] doc/index.rst: fix type --- doc/index.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/index.rst b/doc/index.rst index 1fc6d80e..72d1c981 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -1,7 +1,8 @@ PyPSA-Eur: An Open Optimisation Model of the European Transmission System ========================================================================= -.. image:: https://img.shields.io/github/v/release/pypsa/pypsa-eur?include_prereleases :alt: GitHub release (latest by date including pre-releases) +.. image:: https://img.shields.io/github/v/release/pypsa/pypsa-eur?include_prereleases + :alt: GitHub release (latest by date including pre-releases) .. image:: https://travis-ci.org/PyPSA/pypsa-eur.svg?branch=master :target: https://travis-ci.org/PyPSA/pypsa-eur From b5f6a946876bdb6a875687711d9259213c99f445 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Tue, 29 Oct 2019 16:48:15 +0100 Subject: [PATCH 8/9] added release notes v0.1.0 --- doc/release_notes.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 5aa24fd7..6b1b3b3c 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -5,6 +5,14 @@ Release Notes PyPSA-Eur 0.1.0 (DATE) ====================== -This is the first release of PyPSA-Eur. It now features: +This is the first release of PyPSA-Eur: -* Documentation on installation, workflows and configuration settings. +* Documentation on installation, workflows and configuration settings is now available online at `pypsa-eur.readthedocs.io `_ (`#65 `_). + +* The ``conda`` environment files were updated and extended (`#81 `_). + +* The power plant database was updated (`#83 `_). + +* Continuous integration testing with `Travis CI `_ is now included (`#82 `_). + +* Data dependencies were moved to `zenodo `_ (`#60 `_). From 142434b5295d582f94f35a39d85c6d6cbda2e280 Mon Sep 17 00:00:00 2001 From: Fabian Hofmann Date: Thu, 31 Oct 2019 10:37:49 +0100 Subject: [PATCH 9/9] incorporate suggestions --- scripts/cluster_network.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index 5f0cf90e..46b1dadb 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -157,9 +157,10 @@ def clustering_for_n_clusters(n, n_clusters, aggregate_carriers=None, nc = clustering.network nc.links['underwater_fraction'] = (n.links.eval('underwater_fraction * length') .div(nc.links.length).dropna()) - nc.links['capital_cost'] += (nc.links.length.sub(n.links.length).dropna() - .clip(lower=0) - .mul(extended_link_costs * line_length_factor)) + nc.links['capital_cost'] = (nc.links['capital_cost'] + .add((nc.links.length - n.links.length) + .clip(lower=0).mul(extended_link_costs), + fill_value=0)) return clustering def save_to_geojson(s, fn): @@ -226,11 +227,11 @@ if __name__ == "__main__": clustering = pypsa.networkclustering.Clustering(n, busmap, linemap, linemap, pd.Series(dtype='O')) else: line_length_factor = snakemake.config['lines']['length_factor'] - overhead_cost = (load_costs(n.snapshot_weightings.sum()/8760, + hvac_overhead_cost = (load_costs(n.snapshot_weightings.sum()/8760, tech_costs=snakemake.input.tech_costs, config=snakemake.config['costs'], elec_config=snakemake.config['electricity']) - .at['HVAC overhead', 'capital_cost']) + .at['HVAC overhead', 'capital_cost']) def consense(x): v = x.iat[0] @@ -244,7 +245,7 @@ if __name__ == "__main__": line_length_factor=line_length_factor, potential_mode=potential_mode, solver_name=snakemake.config['solving']['solver']['name'], - extended_link_costs=overhead_cost) + extended_link_costs=hvac_overhead_cost) clustering.network.export_to_netcdf(snakemake.output.network) with pd.HDFStore(snakemake.output.clustermaps, mode='w') as store: