Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Anyone developing Python code for direct idf manipulation?

asked 2014-12-18 22:40:35 -0500

Sam's avatar

If not, I want to slowly build a code base that allows for easy, straightforward sensitivity studies for client engagement.

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted

answered 2014-12-18 22:49:28 -0500

updated 2015-07-15 11:23:13 -0500

A good place to start might be Eppy. There's a good high-level introduction to what Eppy is and can do on Github.

Also, something the author, Santosh Philip said in a release email (April 2014) about Eppy's background:

"Eppy was developed over the last year, for the ASHRAE 1651-RP research project that required modifying large number of files and analyzing the results.

Eppy was partially funded by ASHRAE and the original code was written in 2004 as a text interface for Energyplus and the scripting language was built on it's foundations."

The open source license was GPLv3, but as of v0.5.0 it is MIT.

OpenStudio also has Python bindings, and works at a higher level of abstraction.

edit flag offensive delete link more


I have been using Eppy since mid-2013 for a large research project involving lots of parametric analyses using EnergyPlus and it has proven to be a great tool.

JasonGlazer's avatar JasonGlazer  ( 2014-12-19 13:35:42 -0500 )edit

Seems like the OpenStudio part of the answer that should really be a separate answer since it is a completely different approach

JasonGlazer's avatar JasonGlazer  ( 2014-12-23 05:44:51 -0500 )edit

I would tend to agree if it was developed but it's not. And one cannot post two answers under the same question :)

Julien Marrec's avatar Julien Marrec  ( 2014-12-23 11:48:27 -0500 )edit

Edited comments into the answer for future searchers.

Jamie Bull's avatar Jamie Bull  ( 2015-07-15 11:24:42 -0500 )edit

answered 2015-07-15 16:36:08 -0500

I use the OpenStudio Python bindings. You can build the initial model using the OpenStudio model and then convert to an IDF model with the built in translators. Any simulation components that are not directly available within OpenStudio can be added within the IDF model. The interface allows model objects to be queried using simple Python iterators.

zones = [zone for zone in openstudio.model.getThermalZones(model) if "Office" in]

This makes manipulating models and running parametrics fairly simple. Also, the development team is continuing to improve the tool at a fast pace. There is excellent support for the product through Unmet Hours.

The downside is that you need to compile the bindings yourself. In Windows this requires working with Visual Studio. There is some guidance to compiling the bindings here. Getting the various paths set up properly is not always straight forward. See Python SDK Bindings for OpenStudio.

edit flag offensive delete link more


I don't think bundling the Python bindings into the already large OpenStudio distribution is something that we want to entertain, but maybe some talented Pythonist out there <cough>@Mark Adams</cough> will compile them and make them available.

Kyle Benne's avatar Kyle Benne  ( 2015-07-17 20:35:53 -0500 )edit

+1 for OpenStudio + Python. @Kyle Benne your XML tags confused the @mention of @Mark Adams.

MatthewSteen's avatar MatthewSteen  ( 2015-07-19 20:28:45 -0500 )edit

I'm sure more people would use them if they were pre-bundled on github. That would be a great help.

jmcneill's avatar jmcneill  ( 2015-07-20 09:23:23 -0500 )edit

answered 2014-12-19 07:12:48 -0500

updated 2015-08-18 09:07:35 -0500

Here's a function I use for editing an IDF or IMF file in place that might be useful. It's inspired by the approach in jEPlus where you mark the variables you want to change in your IDF or IMF file by giving them a name in the form @@VariableName@@. It's handy for handling parametric runs where you are generating the values in Python code. Generally though it's easier to call jEPlus directly from Python (or not using Python at all...) if you just want a pre-set list of values or values from a known distribution.

import fileinput

def edit_template(substitutions, imf_path):
    Replace all placeholder @@variables@@ in a template file with the
    correct values for the current run.

    substitutions: dict
        A dictionary mapping the variable to be substituted to the value
        to be substitute in its place, e.g. {"BoilerEfficiency": 0.9} 
        will replace @@BoilerEfficiency@@ with 0.9 in the input file.
    imf_path : str
        The path to the IDF or IMF.

        Raised if a value to replace was not found in the template file.

    for key in substitutions:
        if key not in open(imf_path, 'rb').read():
            raise ValueError("%s not in %s" % (key, imf_path))
        for line in fileinput.FileInput(imf_path, inplace=True):
            for s in substitutions:
                 line = line.replace("@@%s@@" % s, str(substitutions[s]))  # enforce str
            print line,

Eppy is a really useful tool with a lot of thought gone into it as well so I wouldn't go reinventing the wheel. I'm sure any contributions you'd like to make would be welcomed. It's quite large, but the introductory tutorial is helpful (although if you already speak Python it can be a bit too detailed).

I haven't used the OpenStudio Python bindings so can't comment on that.

edit flag offensive delete link more

answered 2014-12-19 07:20:46 -0500

updated 2014-12-23 03:46:46 -0500

pyidf also became available several weeks ago. Haven't tried it and don't know how it differs from eppy, but it's there.

edit flag offensive delete link more


Reading the Github page for pyidf (on 2014-12-23), there's an interesting disclaimer:

"This is a work in progress, do NOT expect it to actually work! As this is an early work, changes in the API are very likely to happen."

I'll check it out nonetheless!

Julien Marrec's avatar Julien Marrec  ( 2014-12-23 03:47:39 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops


Question Tools



Asked: 2014-12-18 22:40:35 -0500

Seen: 1,546 times

Last updated: Aug 18 '15