In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os.path

# from pydygraphs import pydygraphs
from pandas.tseries.holiday import USFederalHolidayCalendar
from datetime import datetime
from pandas.tseries.holiday import Holiday, USPresidentsDay, USMemorialDay, USLaborDay, USThanksgivingDay, AbstractHolidayCalendar, sunday_to_monday

import tou

from bokeh._legacy_charts import TimeSeries
from bokeh.io import output_notebook, show
output_notebook()


BokehJS successfully loaded.

In [2]:
dirName = os.path.normpath("./rooftop.csv")  # path to PVsyst hourly output normpath converts to correct backslashes for OS
df = pd.read_csv(dirName)  # path to PVsyst hourly output
year = 2015
rng = pd.date_range('1/1/' + str(year), periods=8760, freq='h')
df.index = rng
class SCE_Holidays(AbstractHolidayCalendar):
    """
    Southern California Edison Holidays from the tariff- TOU-GS-2
    """
    rules = [
        Holiday('New Years Day', month=1,  day=1,  observance=sunday_to_monday),
        USPresidentsDay,
        USMemorialDay,
        Holiday('July 4th', month=7,  day=4,  observance=sunday_to_monday),
        USLaborDay,
        Holiday('Veterans Day', month=11, day=11, observance=sunday_to_monday),
        USThanksgivingDay,
        Holiday('Christmas', month=12, day=25, observance=sunday_to_monday)
        ]
    
cal = SCE_Holidays()

SCE_TOU_GS_2 = {'offPeak1': {'dates': ('06/01', '9/30'),
                             'times': ('00:00', '08:00'),
                             'days': {},
                             'price': 0.03855},
                'midPeak1': {'dates': ('06/01', '9/30'),
                             'times': ('09:00', '12:00'),
                             'days': {},
                             'price': 0.06143},
                'onPeak': {'dates': ('06/01', '9/30'),
                           'times': ('13:00', '18:00'),
                           'days': {},
                           'price': 0.31971},
                'midPeak2': {'dates': ('06/01', '9/30'),
                             'times': ('19:00', '23:00'),
                             'days': {},
                             'price': 0.06143},
                'midPeak3': {'dates': ('10/01', '5/31'),
                             'times': ('09:00', '21:00'),
                             'days': {},
                             'price': 0.06073},
                'offPeak2': {'dates': ('10/01', '5/31'),
                             'times': ('22:00', '08:00'),
                             'days': {},
                             'price': 0.04064},
                'holWkndsSummer': {'dates': ('06/01', '09/30'),
                                   'times': ('00:00', '23:00'),
                                   'days': {'dropHol': True, 'dropWknd': True, 'inverse': True},
                                   'price': 0.03584},
                'holWkndsWinter': {'dates': ('10/01', '5/31'),
                                   'times': ('00:00', '23:00'),
                                   'days': {'dropHol': True, 'dropWknd': True, 'inverse': True},
                                   'price': 0.04064}
                }
gs2 = tou.TouRate(year, cal, 0.04482, SCE_TOU_GS_2)

In [3]:
gs2.get_summary(df)


Out[3]:
Energy kWh Prices $/kWh Value $
holWkndsSummer 57577.8022 0.08066 4644.225525
holWkndsWinter 95985.0122 0.08546 8202.879143
midPeak1 68128.4210 0.10625 7238.644731
midPeak2 0.0000 0.10625 0.000000
midPeak3 205467.9377 0.10555 21687.140824
offPeak1 16630.1356 0.08337 1386.454405
offPeak2 18707.1063 0.08546 1598.709304
onPeak 60338.5698 0.36453 21995.218849

In [4]:
gs2.get_summary(df).sum()


Out[4]:
Energy kWh      522834.984800
Prices $/kWh         1.017530
Value $          66753.272782
dtype: float64

In [5]:
gs2_periods = gs2.get_all_periods(df)

In [6]:
#Set first row of data to zero to avoid issue with NaNs
#Bokeh github issue #2780
gs2_periods.loc['2015-01-01 00:00:00'] = 0
gs2_periods['date'] = gs2_periods.index

In [7]:
ts = TimeSeries(gs2_periods, index='date', title="TOU Periods", legend='top_left', ylabel='Energy (kWh)')
show(ts)


/Users/Ben/anaconda/lib/python2.7/site-packages/bokeh/_legacy_charts/_chart.py:92: UserWarning: Instantiating a Legacy Chart from bokeh._legacy_charts
  warn("Instantiating a Legacy Chart from bokeh._legacy_charts")

In [ ]: