Skip to content

load duration curve #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions opengrid/library/analysis.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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()