Skip to content

Commit

Permalink
pf, descriptors: Add degree function for compatibility with NX2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
coroa committed Dec 1, 2017
1 parent cab8a1a commit a6a40cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pypsa/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ def __init__(self, data=None, **attr):
else:
raise ImportError("NetworkX version {} is too old. At least 1.10 is needed.".format(nx.__version__))

if _nx_version >= '2.0':
def degree(G):
return G.degree()
else:
def degree(G):
return G.degree_iter()

class Dict(dict):
"""
Dict is a subclass of dict, which allows you to get AND SET
Expand Down
4 changes: 2 additions & 2 deletions pypsa/pf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from itertools import chain
import time

from .descriptors import get_switchable_as_dense, allocate_series_dataframes, Dict, zsum
from .descriptors import get_switchable_as_dense, allocate_series_dataframes, Dict, zsum, degree

pd.Series.zsum = zsum

Expand Down Expand Up @@ -836,7 +836,7 @@ def find_tree(sub_network, weight='x_pu'):
sub_network.tree = nx.minimum_spanning_tree(graph)

#find bus with highest degree to use as slack
tree_slack_bus, slack_degree = max(sub_network.tree.degree_iter(), key=itemgetter(1))
tree_slack_bus, slack_degree = max(degree(sub_network.tree), key=itemgetter(1))
logger.info("Tree slack bus is %s with degree %d.", tree_slack_bus, slack_degree)

#determine which buses are supplied in tree through branch from slack
Expand Down

0 comments on commit a6a40cf

Please sign in to comment.