Skip to content

Commit

Permalink
Merge ec98d78 into 51805b0
Browse files Browse the repository at this point in the history
  • Loading branch information
JrtPec committed Apr 29, 2018
2 parents 51805b0 + ec98d78 commit d56a3ea
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
24 changes: 24 additions & 0 deletions opengrid/library/analysis.py
Expand Up @@ -197,3 +197,27 @@ def load_factor(ts, resolution=None, norm=None):
lf = ts / norm

return lf


def load_duration(df, trim_zeros=False):
"""
Create descending load duration series
(mainly for use in a load duration curve)
Parameters
----------
df : pd.DataFrame or pd.Series
trim_zeros : bool
trim trailing zero's
Returns
-------
pd.DataFrame or pd.Series
"""
df = pd.DataFrame(df) # in case a series is passed, wrap it in a dataframe
load_durations = (df[column].reset_index(drop=True).sort_values(ascending=False).reset_index(drop=True) for column in df)
if trim_zeros:
load_durations = (np.trim_zeros(s, trim='b') for s in load_durations)
df = pd.concat(load_durations, axis=1)
result = df.squeeze()
return result
5 changes: 0 additions & 5 deletions opengrid/library/plotting.py
@@ -1,10 +1,7 @@
import os
import os
import numpy as np
import pandas as pd
import matplotlib
import pandas as pd
import numpy as np
import matplotlib.cm as cm
import matplotlib.pyplot as plt
from matplotlib.dates import date2num, num2date, HourLocator, DayLocator, AutoDateLocator, DateFormatter
Expand Down Expand Up @@ -124,7 +121,6 @@ def carpet(timeseries, **kwargs):

return im


def boxplot(df, plot_mean=False, plot_ids=None, title=None, xlabel=None, ylabel=None):
"""
Plot boxplots
Expand Down Expand Up @@ -175,4 +171,3 @@ def boxplot(df, plot_mean=False, plot_ids=None, title=None, xlabel=None, ylabel=
plt.ylabel(ylabel)

return plt.gcf()

7 changes: 7 additions & 0 deletions opengrid/tests/test_analyses.py
Expand Up @@ -64,6 +64,13 @@ def test_load_factor(self):
self.assertIsInstance(ts, pd.Series)
self.assertAlmostEqual(175.0345212009457, (lf2 * 800).iloc[0])

def test_load_duration(self):
ts = pd.Series([1, 5, 7, 0, 6, 0, 3, 2])
ld = og.analysis.load_duration(ts)
self.assertTrue(ld.equals(pd.Series([7, 6, 5, 3, 2, 1, 0, 0])))
ld2 = og.analysis.load_duration(ts, trim_zeros=True)
self.assertTrue(ld2.equals(pd.Series([7, 6, 5, 3, 2, 1])))


if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions opengrid/tests/test_plotting.py
Expand Up @@ -7,6 +7,7 @@

import unittest
import pandas as pd
import opengrid as og
from opengrid.library import plotting


Expand Down

0 comments on commit d56a3ea

Please sign in to comment.