Skip to content

Commit

Permalink
Merge 07f9715 into 4003b24
Browse files Browse the repository at this point in the history
  • Loading branch information
JrtPec committed Apr 23, 2018
2 parents 4003b24 + 07f9715 commit 67cf12d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
30 changes: 30 additions & 0 deletions opengrid/library/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,33 @@ def count_peaks(ts):
result = on_toggles & shifted
count = result.sum()
return count


def load_factor(ts, resolution=None, norm=None):
"""
Calculate the ratio of input vs. norm over a given interval.
Parameters
----------
ts : pandas.Series
timeseries
resolution : str, optional
interval over which to calculate the ratio
default: resolution of the input timeseries
norm : int | float, optional
denominator of the ratio
default: the maximum of the input timeseries
Returns
-------
pandas.Series
"""
if norm is None:
norm = ts.max()

if resolution is not None:
ts = ts.resample(rule=resolution).mean()

lf = ts / norm

return lf
11 changes: 11 additions & 0 deletions opengrid/tests/test_analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ def test_count_peaks(self):
count = og.analysis.count_peaks(ts)
self.assertEqual(count, 13)

def test_load_factor(self):
ts = og.datasets.get('electricity_2016_hour')
ts = ts['e1de'].truncate(after=pd.Timestamp('20160107'))
lf1 = og.analysis.load_factor(ts)
self.assertIsInstance(ts, pd.Series)
self.assertAlmostEqual(ts.iloc[0], (lf1 * ts.max()).iloc[0])

lf2 = og.analysis.load_factor(ts, resolution='3h', norm=800)
self.assertIsInstance(ts, pd.Series)
self.assertAlmostEqual(175.0345212009457, (lf2 * 800).iloc[0])


if __name__ == '__main__':
unittest.main()

0 comments on commit 67cf12d

Please sign in to comment.