Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to new pypsa and scipy version #686

Merged
merged 4 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def get_aggregation_strategies(aggregation_strategies):
# when custom values are specified in the config.

import numpy as np
from pypsa.networkclustering import _make_consense
from pypsa.clustering.spatial import _make_consense

bus_strategies = dict(country=_make_consense("Bus", "country"))
bus_strategies.update(aggregation_strategies.get("buses", {}))
Expand Down
2 changes: 1 addition & 1 deletion scripts/add_electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def attach_OPSD_renewables(n, tech_map):
buses = n.buses.loc[gens.bus.unique()]
gens_per_bus = gens.groupby("bus").p_nom.count()

caps = map_country_bus(df.query("Fueltype == @fueltype"), buses)
caps = map_country_bus(df.query("Fueltype == @fueltype and lat == lat"), buses)
caps = caps.groupby(["bus"]).Capacity.sum()
caps = caps / gens_per_bus.reindex(caps.index, fill_value=1)

Expand Down
6 changes: 3 additions & 3 deletions scripts/cluster_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
**Is it possible to run the model without the** ``simplify_network`` **rule?**

No, the network clustering methods in the PyPSA module
`pypsa.networkclustering <https://github.com/PyPSA/PyPSA/blob/master/pypsa/networkclustering.py>`_
`pypsa.clustering.spatial <https://github.com/PyPSA/PyPSA/blob/master/pypsa/clustering/spatial.py>`_
do not work reliably with multiple voltage levels and transformers.

.. tip::
Expand Down Expand Up @@ -134,7 +134,7 @@
import pypsa
import seaborn as sns
from _helpers import configure_logging, get_aggregation_strategies, update_p_nom_max
from pypsa.networkclustering import (
from pypsa.clustering.spatial import (
busmap_by_greedy_modularity,
busmap_by_hac,
busmap_by_kmeans,
Expand Down Expand Up @@ -484,7 +484,7 @@ def plot_busmap_for_n_clusters(n, n_clusters, fn=None):
# Fast-path if no clustering is necessary
busmap = n.buses.index.to_series()
linemap = n.lines.index.to_series()
clustering = pypsa.networkclustering.Clustering(
clustering = pypsa.clustering.spatial.Clustering(
n, busmap, linemap, linemap, pd.Series(dtype="O")
)
else:
Expand Down
4 changes: 2 additions & 2 deletions scripts/simplify_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@
from _helpers import configure_logging, get_aggregation_strategies, update_p_nom_max
from add_electricity import load_costs
from cluster_network import cluster_regions, clustering_for_n_clusters
from pypsa.io import import_components_from_dataframe, import_series_from_dataframe
from pypsa.networkclustering import (
from pypsa.clustering.spatial import (
aggregategenerators,
aggregateoneport,
busmap_by_stubs,
get_clustering_from_busmap,
)
from pypsa.io import import_components_from_dataframe, import_series_from_dataframe
from scipy.sparse.csgraph import connected_components, dijkstra

logger = logging.getLogger(__name__)
Expand Down
3 changes: 1 addition & 2 deletions scripts/solve_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ def add_CCL_constraints(n, config):
p_nom = n.model["Generator-p_nom"]

gens = n.generators.query("p_nom_extendable").rename_axis(index="Generator-ext")
grouper = [gens.bus.map(n.buses.country), gens.carrier]
grouper = xr.DataArray(pd.MultiIndex.from_arrays(grouper), dims=["Generator-ext"])
grouper = pd.concat([gens.bus.map(n.buses.country), gens.carrier])
lhs = p_nom.groupby(grouper).sum().rename(bus="country")

minimum = xr.DataArray(agg_p_nom_minmax["min"].dropna()).rename(dim_0="group")
Expand Down