Skip to content

Commit

Permalink
fix LocalUnboundError in sort_plot_elements
Browse files Browse the repository at this point in the history
  • Loading branch information
ojdo committed Dec 16, 2015
1 parent 4adb3c0 commit 010dff0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions urbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1628,16 +1628,19 @@ def sort_plot_elements(elements):
Returns:
elements_sorted: sorted timeseries of created or consumed
"""
if len(elements.columns) > 1:
# calculate standard deviation
std = pd.DataFrame(np.zeros_like(elements.tail(1)),
index=elements.index[-1:]+1, columns=elements.columns)
for col in std.columns:
std[col] = np.std(elements[col])
# sort created/consumed ascencing with std i.e. base load first
elements = elements.append(std)
new_columns = elements.columns[elements.ix[elements.last_valid_index()].argsort()]
elements_sorted = elements[new_columns][:-1]
# no need of sorting the columns if there's only one
if len(elements.columns) < 2:
return elements

# calculate standard deviation
std = pd.DataFrame(np.zeros_like(elements.tail(1)),
index=elements.index[-1:]+1, columns=elements.columns)
for col in std.columns:
std[col] = np.std(elements[col])
# sort created/consumed ascencing with std i.e. base load first
elements = elements.append(std)
new_columns = elements.columns[elements.ix[elements.last_valid_index()].argsort()]
elements_sorted = elements[new_columns][:-1]

return elements_sorted

Expand Down

0 comments on commit 010dff0

Please sign in to comment.