<jupyter_start><jupyter_text>EnergyPlus Output Data Analysis Example    Created by <NAME> (<EMAIL>)The goal of this notebook is to give a user a glimpse at the loading and manipulation of a .csv output of EnergyPlusExecute the cells in this notebook one at a time and try to understand what each code snippet is doing. There will be text notation before many of the cells attempting to explain what is going on. First we load some libraries that we will use.<jupyter_code>import pandas as pd
import datetime
from datetime import timedelta
import time
%matplotlib inline<jupyter_output><empty_output><jupyter_text>The following is a Python `fucntion` that I created ot read a .csv file, do a conversion and change the timestamp<jupyter_code>def loadsimdata(file,pointname,ConvFactor):
    df = pd.read_csv(file)
    df['desiredpoint'] = df[pointname]*ConvFactor
    df.index = eplustimestamp(df)
    pointdf = df['desiredpoint']
    return pointdf<jupyter_output><empty_output><jupyter_text>Open an EnergyPlus Output CSV fileFirst let's open the .csv output file from an EnergyPlus run and visualize it.<jupyter_code>SimulationData = pd.read_csv('EnergyplusSimulationData.csv')
SimulationData<jupyter_output><empty_output><jupyter_text>We can select a certain column and see what's inside -- there is quite a few columns in this output file. We can see using the `.info` function from pandas that there are 256 columns<jupyter_code>SimulationData.info()
SimulationData['AIRNODE_ZONENODE_U1_S:System Node Setpoint Temp[C](Hourly) ']#.plot()
SimulationData['Date/Time'].tail()<jupyter_output><empty_output><jupyter_text>We need to convert 24:00:00 to 00:00:00 for it to play nice with Pandas<jupyter_code>#Function to convert timestamps
def eplustimestamp(simdata):
    timestampdict={}
    for i,row in simdata.T.iteritems():
        timestamp = str(2013) + row['Date/Time']
        try:
            timestampdict[i] = datetime.datetime.strptime(timestamp,'%Y %m/%d  %H:%M:%S')
        except ValueError:
            tempts = timestamp.replace(' 24', ' 23')
            timestampdict[i] = datetime.datetime.strptime(tempts,'%Y %m/%d  %H:%M:%S')
            timestampdict[i] += timedelta(hours=1)
    timestampseries = pd.Series(timestampdict)
    return timestampseries
SimulationData.index = eplustimestamp(SimulationData)
SimulationData.info()
SimulationData['AIRNODE_ZONENODE_U1_S:System Node Setpoint Temp[C](Hourly) ']
ColumnsList = pd.Series(SimulationData.columns)
ColumnsList.head(100)<jupyter_output><empty_output><jupyter_text>Built-in String Query functions to find desired columnsWe can use the string query functions in Pandas to find columns to select for visualization, etc without manually inputting them.<jupyter_code>ColumnsList.str.endswith("Zone Mean Air Temperature [C](Hourly)")
ColumnsList[(ColumnsList.str.endswith("Zone Mean Air Temperature [C](Hourly)"))]
ZoneTempPointList = list(ColumnsList[(ColumnsList.str.endswith("Zone Mean Air Temperature [C](Hourly)"))])
ZoneTempPointList
BasementZoneTemp = list(ColumnsList[(ColumnsList.str.endswith("Zone Mean Air Temperature [C](Hourly)"))&(ColumnsList.str.contains("U1"))])
GroundFloorZoneTemp = list(ColumnsList[(ColumnsList.str.endswith("Zone Mean Air Temperature [C](Hourly)"))&(ColumnsList.str.contains("00"))])
Floor1ZoneTemp = list(ColumnsList[(ColumnsList.str.endswith("Zone Mean Air Temperature [C](Hourly)"))&(ColumnsList.str.contains("01"))])
Floor2ZoneTemp = list(ColumnsList[(ColumnsList.str.endswith("Zone Mean Air Temperature [C](Hourly)"))&(ColumnsList.str.contains("02"))])
Floor3ZoneTemp = list(ColumnsList[(ColumnsList.str.endswith("Zone Mean Air Temperature [C](Hourly)"))&(ColumnsList.str.contains("03"))])
Floor4ZoneTemp = list(ColumnsList[(ColumnsList.str.endswith("Zone Mean Air Temperature [C](Hourly)"))&(ColumnsList.str.contains("04"))])
ZoneTemp = SimulationData[ZoneTempPointList]#.drop(['EMS:All Zones Total Heating Energy {J}(Hourly)'],axis=1)
ZoneTemp.info()<jupyter_output><empty_output><jupyter_text>VisualizationNow that we have the data in a Pandas Dataframe, let's do some analysis -- visualization, statistics, etc<jupyter_code>ZoneTemp.plot(figsize=(25,15))
ZoneTemp[BasementZoneTemp].plot(figsize=(25,10))
ZoneTemp[GroundFloorZoneTemp].truncate(before='2013-03-10',after='2013-03-14').plot(figsize=(25,10))
ZoneTemp[Floor1ZoneTemp].plot(figsize=(25,10))
ZoneTemp[Floor2ZoneTemp].plot(figsize=(25,10))<jupyter_output><empty_output><jupyter_text>Zooming in using the `.truncate()` pandas method<jupyter_code>SimulationData['Environment:Outdoor Dry Bulb [C](Hourly)'].truncate(before='2013-03-10',after='2013-03-14').plot(figsize=(25,10))<jupyter_output><empty_output><jupyter_text>Let's take a deeper look at the Floor 2 Zone Temperations<jupyter_code>Floor2Temps = ZoneTemp[Floor2ZoneTemp]
Floor2Temps.info()
Floor2Temps.describe()<jupyter_output><empty_output><jupyter_text>HeatmapsHeatmaps are a great way to visualize performance data<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.backends.backend_pdf import PdfPages
import os
import matplotlib.dates as mdates
import datetime as dt
Floor1Energy = list(ColumnsList[(ColumnsList.str.endswith("Total Heating Energy {J}(Hourly)"))&(ColumnsList.str.contains("01"))])

Floor1Energy
df_hourly = SimulationData.resample('H').mean()

#Add the Date and time for pivoting
df_hourly['Date'] = df_hourly.index.map(lambda t: t.date())
df_hourly['Time'] = df_hourly.index.map(lambda t: t.time())
numberofplots = len(Floor1Energy)
pointcounter = 1
fig = plt.figure(figsize=(40, 4 * numberofplots))


for energypoint in Floor1Energy:
    
    print "Loading data from "+energypoint
    
    #Pivot
    df_pivot = pd.pivot_table(df_hourly, values=energypoint, index='Time', columns='Date')

    # Get the data
    x = mdates.drange(df_pivot.columns[0], df_pivot.columns[-1] + datetime.timedelta(days=1), dt.timedelta(days=1))
    y = np.linspace(1, 24, 24)

    # Plot
    ax = fig.add_subplot(numberofplots, 1, pointcounter)

    data = np.ma.masked_invalid(np.array(df_pivot))

    qmesh = ax.pcolormesh(x, y, data)
    cbar = fig.colorbar(qmesh, ax=ax)
    cbar.ax.tick_params(labelsize= 24)
    ax.axis('tight')

    try:
        plt.title(energypoint, fontsize=26)

    except IndexError:
        continue

    # Set up as dates
    ax.xaxis_date()
    fig.autofmt_xdate()
    fig.subplots_adjust(hspace=.5)
    
    pointcounter += 1<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12183055040197897, 'fraction_numerical': 0.020717377860235003, 'mean_word_length': 6.1957730812013345, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '143207', 'license': 'CC-BY-3.0', 'n_tokens_mistral': 2265, 'n_tokens_neox': 2114, 'n_words': 488, 'path': '2_AnalyzingEnergyPlusOutputFile/.ipynb_checkpoints/EnergyPlusOutFileAnalysis-checkpoint.ipynb', 'repo_name': 'buds-lab/python-for-building-analysts', 'size': '6496'}