<jupyter_start><jupyter_text>EnergyPlus simulation and analysis using Python  Setup<jupyter_code>import subprocess
import pandas as pd
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Step 1: Check the EnergyPlus.exe file can be run<jupyter_code>energyplus_install_dir=r'C:\Users\cvskf\EnergyPlusV9-6-0'  # change this to the local EnergyPlus install directory location
cl_st=f'{energyplus_install_dir}\\EnergyPlus'
cl_st
result=subprocess.run(cl_st,
                      capture_output=True
                     )
print('---ARGS---\n',result.args)
print('---RETURNCODE---\n',result.returncode, '(SUCCESS)' if result.returncode==0 else '(FAIL)')
print('---STDOUT---\n',result.stdout.decode())
print('---STDERR---\n',result.stderr.decode())
cl_st=f'{energyplus_install_dir}\\EnergyPlus --help'
cl_st
result=subprocess.run(cl_st,
                      capture_output=True
                     )
print('---ARGS---\n',result.args)
print('---RETURNCODE---\n',result.returncode, '(SUCCESS)' if result.returncode==0 else '(FAIL)')
print('---STDOUT---\n',result.stdout.decode())
print('---STDERR---\n',result.stderr.decode())<jupyter_output>---ARGS---
 C:\Users\cvskf\EnergyPlusV9-6-0\EnergyPlus --help
---RETURNCODE---
 0 (SUCCESS)
---STDOUT---
 EnergyPlus, Version 9.6.0-f420c06a69, YMD=2022.03.01 07:04
PythonLinkage: Linked to Python Version: "3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)]"
Built on Platform: Windows_x86_64
Usage: energyplus [options] [input-file]
Options:
  -a, --annual                 Force annual simulation
  -c, --convert                Output IDF->epJSON or epJSON->IDF, dependent on
                               input file type
  -d, --output-directory ARG   Output directory path (default: current
                               directory)
  -D, --design-day             Force design-day-only simulation
  -h, --help                   Display help information
  -i, --idd ARG                Input data dictionary path (default: Energy+.idd
                               in executable directory)
  -j, --jobs ARG               Multi-thread with N threads; 1 thr[...]<jupyter_text>Step 2: Set up directory and files for an EnergyPlus simulation<jupyter_code>idf_relative_filepath=r'sim\1ZoneUncontrolled.idf'
epw_relative_filepath=r'sim\USA_CA_San.Francisco.Intl.AP.724940_TMY3.epw'#
output_relative_directory='sim'<jupyter_output><empty_output><jupyter_text>Step 3: Run an EnergyPlus simulation<jupyter_code>cl_st=(f'"{energyplus_install_dir}\\EnergyPlus" '
       + '--readvars '  # included to create a .csv file of the results
       + f'--output-directory "{output_relative_directory}" '
       + f'--weather "{epw_relative_filepath}" '
       + f'"{idf_relative_filepath}"'
      )
print(cl_st)
result=subprocess.run(cl_st,
                      capture_output=True
                     )
print('---ARGS---\n',result.args)
print('---RETURNCODE---\n',result.returncode, '(SUCCESS)' if result.returncode==0 else '(FAIL)')
print('---STDOUT---\n',result.stdout.decode())
print('---STDERR---\n',result.stderr.decode())<jupyter_output>---ARGS---
 "C:\Users\cvskf\EnergyPlusV9-6-0\EnergyPlus" --readvars --output-directory "sim" --weather "sim\USA_CA_San.Francisco.Intl.AP.724940_TMY3.epw" "sim\1ZoneUncontrolled.idf"
---RETURNCODE---
 0 (SUCCESS)
---STDOUT---
 EnergyPlus Starting
EnergyPlus, Version 9.6.0-f420c06a69, YMD=2022.03.01 07:04
Adjusting Air System Sizing
Adjusting Standard 62.1 Ventilation Sizing
Initializing Simulation
Reporting Surfaces
Beginning Primary Simulation
Initializing New Environment Parameters
Warming up {1}
Warming up {2}
Warming up {3}
Warming up {4}
Warming up {5}
Warming up {6}
Warming up {7}
Warming up {8}
Warming up {9}
Warming up {10}
Warming up {11}
Warming up {12}
Warming up {13}
Warming up {14}
Warming up {15}
Warming up {16}
Warming up {17}
Warming up {18}
Warming up {19}
Warming up {20}
Warming up {21}
Warming up {22}
Starting Simulation at 12/21 for DENVER CENTENNIAL  GOLDEN   N ANN HTG 99% CONDNS DB
Initializing New Environment Parameters
Warming up {1}
Warming up {2}
Warming up {[...]<jupyter_text>Step 5: Create a parser for the EnergyPlus datetime strings in the results file<jupyter_code>def parse_energyplus_datetime_string(st, year=2021):
    st=st.strip()
    month=int(st[0:2])
    day=int(st[3:5])
    hour=int(st[7:9])
    minute=int(st[10:12])
    second=(st[13:15])
    if not hour==24:
        dt=pd.Timestamp(year,month,day,hour,minute)
    else:
        hour=0
        dt=pd.Timestamp(year,month,day,hour,minute)
        dt+=pd.Timedelta('1 day')
    return dt

# test of function - should output `Timestamp('2021-12-21 01:00:00')`
parse_energyplus_datetime_string(' 12/21  01:00:00')<jupyter_output><empty_output><jupyter_text>Step 6: Read in the EnergyPlus results file<jupyter_code>df=pd.read_csv(r'sim\eplusout.csv', 
               parse_dates=[0],
               index_col=[0],
               date_parser=parse_energyplus_datetime_string  # parses the date strings using the function defined above
              )
df<jupyter_output><empty_output><jupyter_text>Step 7: Analyse the EnergyPlus results<jupyter_code>fig, ax = plt.subplots(figsize=(16,6))
ax.plot(df['ZONE ONE:Zone Mean Air Temperature [C](Hourly)'][48:],  # excludes the first 48 rows which are the winter and summer design day results
        color='grey',
        linewidth=0.75
       )
ax.set_xlabel('Date')
ax.set_ylabel('Air temperature (${^o}C$)')  # using LaTeX to create a degree symbol
plt.show()
print('Figure 1: Time series plot of hourly Zone One mean air temperatures.')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13785170766236066, 'fraction_numerical': 0.03910812245620244, 'mean_word_length': 3.3950233281493003, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '159994', 'license': 'MIT', 'n_tokens_mistral': 2097, 'n_tokens_neox': 1907, 'n_words': 442, 'path': 'energyplus-simulation-and-analysis-using-python/EnergyPlus simulation and analysis using Python.ipynb', 'repo_name': 'stevenkfirth/stevenfirth', 'size': '5651'}