First time here? Check our help page!
9

Anyone developing Python code for direct idf manipulation?

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

Sam's avatar
91
Sam
asked 2014-12-18 22:40:35 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

4 Answers

8

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.

ljbrackney's avatar
3.8k
ljbrackney
answered 2014-12-18 22:49:28 -0500
Jamie Bull's avatar
5.1k
Jamie Bull
updated 2015-07-15 11:23:13 -0500
edit flag offensive 0 remove flag delete link

Comments

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
add a comment see more comments
8

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 zone.name().get()]

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.

jmcneill's avatar
1.7k
jmcneill
answered 2015-07-15 16:36:08 -0500
edit flag offensive 0 remove flag delete link

Comments

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
2

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
add a comment see more comments
4

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.

    Parameters
    ----------
    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.

    Raises
    ------
    ValueError
        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.

Jamie Bull's avatar
5.1k
Jamie Bull
answered 2014-12-19 07:12:48 -0500, updated 2015-08-18 09:07:35 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
1

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

__AmirRoth__'s avatar
4.4k
__AmirRoth__
answered 2014-12-19 07:20:46 -0500
Julien Marrec's avatar
29.7k
Julien Marrec
updated 2014-12-23 03:46:46 -0500
edit flag offensive 0 remove flag delete link

Comments

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
add a comment see more comments