def compare_lean_timediff(timestep): buildings = ['KS0094ZZ', 'UT0017ZZ', 'NE0531ZZ', 'UT0032ZZ'] ss = ['KMKC', 'KSLC', 'KLNK', 'KPVU'] for b in buildings[:1]: # df1 = util.read_building_eui(b, timestep) df1 = pd.read_csv(interval_dir + 'single_monthly/{0}_Electric_M.csv'.format(b)) df1.rename(columns={'Electric (kBtu)': 'Electric (kBtu) daily'}, inplace=True) df2 = util.read_building_eui(b, 'M') df_all = pd.merge(df1, df2, on=['year', 'month'], how='inner') print df_all.head()
def compare_hourly(timestep): bds = ['NE0531ZZ', 'UT0017ZZ', 'UT0032ZZ'] for b in bds: print b df = pd.read_csv(interval_dir + 'single_hourly/{0}.csv'.format(b)) df_temp = df.copy() df_temp['Date'] = pd.to_datetime(df_temp['Date']) df_dt = df_temp.set_index(pd.DatetimeIndex(df_temp['Date'])) df_re = df_dt.resample(timestep, how='sum') # df_re.reset_index(inplace=True) df_re.rename(columns={'Gas (kBtu)': 'Gas (kBtu) hourly', 'Electric (kBtu)': 'Electric (kBtu) ' + 'hourly'}, inplace=True) if timestep == 'D': df2 = pd.read_csv(interval_dir + 'single/{0}_Gas.csv'.format(b)) df2.rename(columns={'Gas(kBtu)':'Gas (kBtu) daily'}, inplace=True) df2['Date'] = pd.to_datetime(df2['Date']) elif timestep == 'M': df1 = util.read_building_eui(b, 'M') df1.rename(columns={'Electricity (kBtu)': 'Electric (kBtu) monthly', 'Gas (kBtu)': 'Gas (kBtu) monthly'}, inplace=True) df1 = df1[['year', 'month', 'Electric (kBtu) monthly', 'Gas (kBtu) monthly']] df1['Date'] = pd.to_datetime(df1.apply(lambda r: '{0}-{1}-1'.format(int(r['year']), int(r['month'])), axis=1)) df1.set_index(pd.DatetimeIndex(df1['Date']), inplace=True) df2 = df1.resample('M', how='mean') df2.drop(labels=['year', 'month'], axis=1, inplace=True) sns.set_style("whitegrid") sns.set_palette("Set2") sns.set_context("talk", font_scale=1) df_all = pd.merge(df_re, df2, how='inner', left_index=True, right_index=True) line1, = plt.plot(df_all.index, df_all['Gas (kBtu) monthly'], marker="o") line2, = plt.plot(df_all.index, df_all['Gas (kBtu) hourly'], marker="o") plt.legend([line1, line2], ['monthly', 'hourly aggregated']) plt.ylabel('kBtu') path = os.getcwd() + '/input/FY/interval/plot_cmp/{0}_Gas.png'.format(b) P.savefig(path, dpi = my_dpi, figsize = (2000/my_dpi, 500/my_dpi), bbox_inches='tight') plt.close()