Skip to content

Commit

Permalink
networkclustering: Improve aggregategenerators w/o weights
Browse files Browse the repository at this point in the history
  • Loading branch information
coroa committed Feb 13, 2019
1 parent 18529c4 commit 3c49b2e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pypsa/networkclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def aggregategenerators(network, busmap, with_time=True, carriers=None, custom_s
columns = (set(attrs.index[attrs.static & attrs.status.str.startswith('Input')]) | {'weight'}) & set(generators.columns)
grouper = [generators.bus, generators.carrier]

generators.weight.fillna(1., inplace=True)
weighting = generators.weight.groupby(grouper, axis=0).transform(lambda x: x/x.sum() )
def normed_or_uniform(x):
return x/x.sum() if x.notnull().all() else pd.Series(1./len(x), x.index)
weighting = (generators.weight.groupby(grouper, axis=0).transform(normed_or_uniform)
generators['capital_cost'] *= weighting
strategies = {'p_nom_max': np.min, 'weight': np.sum, 'p_nom': np.sum, 'capital_cost': np.sum}
strategies.update(custom_strategies)
Expand Down

0 comments on commit 3c49b2e

Please sign in to comment.