How to plot temperature results in IES using Python
An image generated by the Python script showing the hourly temperature data in the Medium Office IES starter geometry building.

How to plot temperature results in IES using Python

This post looks at how to use Python to plot temperature data results from an IES building model.

What is this?

  • An IES Python script has been developed.
  • This can be downloaded from the web and then uploaded to the IES software.
  • The Python script will create a horizontal boxplot of the hourly room air temperature results for all rooms in a building model (see the main figure of this blog post).

Can I get the Python script?

Yes, it is available for download here.

See this blog post for how to install the script in your IES installation.

How does it work?

The Python script has 5 steps.

Step 1 - Setup

As well as importing a number of standard Python packages, this step imports the iesve module which allows us to interact with the IES model itself.

import iesve
current_project = iesve.VEProject.get_current_project()
dir_current_project = current_project.path.replace('\\','/')
dir_vista = os.path.join(dir_current_project, 'vista')        

Step 2 - Select results file

The IES results file (.aps file) to be used is selected using a open file dialog box, a part of the Tkinter Python package.

root = Tk()
root.withdraw()
fp_in = askopenfilename(title = 'Select IES results file', parent = root, initialdir = dir_vista, filetypes = [("APS files","*.aps")])
root.destroy()        

Step 3 - Get room data

Information on the rooms in an IES model is available via the body objects. This step creates a dictionary with the room data for all rooms in the IES model.

realmodel = current_project.models[0]
bodies = realmodel.get_bodies(False)  # False means get all bodies
room_data_dict = {body.id: body.get_room_data().get_general() for body in bodies}        

Step 4 - Load temperature data

The results data is accessed via the ResultsReader class. This step creates a dictionary with the hourly room air temperature results for all rooms in the IES model.

with iesve.ResultsReader.open(fp_in) as f:
    air_temperatures_dict = { 
        room_id: f.get_room_results(room_id, 'Room air temperature', 'Air temperature', 'z')
        for room_id in f.get_room_ids()
        }        

Step 5 - Plot figure

Matplotlib is used to create the final figure.

fig, ax = plt.subplots(
    figsize = (
        6, 
        min(0.4 * len(room_data_dict), 4)  # increase height of plot based on number of rooms
        ), 
    dpi = 200
    )
ax.boxplot(
    air_temperatures_dict.values(), 
    vert = False,
    notch = True,
    patch_artist = True,  # to enable box facecolor editing
    labels = [room_data_dict[x]['name'] for x in air_temperatures_dict.keys()],  # converts room ids to room names
    boxprops={'facecolor': 'lightgrey'},
    flierprops={'marker': '.', 'markersize': 1, 'markerfacecolor': 'grey', 'markeredgecolor': 'grey'},
    medianprops={'color': 'grey'}
    )
ax.set_ylabel('Room')
ax.set_xlabel('Room air temperature ($^\circ$C)')
ax.yaxis.set_tick_params(labelsize=10 - len(room_data_dict) * 3 / 30)    # reduces room name font size based on nmber of rooms
fig.tight_layout()
plt.show()        

The code above can be modified to alter the appearance of the final figure.

Below is an example of the figure generated by the Python script for the Small Office IES starter geometry building.

Article content
Hourly room air temperature boxplot for the Small Office IES starter geometry, as generated by this Python script.

Next steps

  • For more information on using Python with IES, please see this post.
  • View the IES technical documentation on its Python API here.
  • Any issues please let me know. I will update the Python script file on GitHub as needed.
  • Any requests for other Python scripts for IES? Please contact me.

To view or add a comment, sign in

More articles by Steven Firth

  • How to export results from IES using Python

    This post looks at how to export results from the IES building simulation software using Python. Why do this? The…

    6 Comments
  • How to hack a SAP 10 calculation

    This article provides instructions for "hacking" a Standard Assessment Procedure version 10 (SAP 10) calculation for…

    6 Comments
  • How to run a SAP 10 calculation in Excel

    This article looks at using an Excel workbook to run SAP 10.2 energy calculations for new and existing dwellings.

    1 Comment
  • How to run a SAP 10 calculation in Python

    This post shows how to use the sap10calcs Python package to run a Standard Assessment Procedure 10.2 (SAP10)…

    8 Comments
  • How to run the Home Energy Model

    This article looks at how to run an energy calculation using the latest available version of the Home Energy Model…

    4 Comments

Others also viewed

Explore content categories