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

Are there any method we can extract idf content in memory space from eppy?

asked 2019-01-15 02:31:37 -0500

katsuya.obara's avatar

I have code which can generate idf content using eppy.
Those content can be exported as idf file using save method referring to their web site. However, what I want to do is to manipulate further that text data in python.
Are there any method we can extract idf content as text data and store into some variable for further processing in python?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2019-01-15 03:18:45 -0500

updated 2019-01-15 03:21:41 -0500

TL;DR: use the IDF::idfstr() method to get the string, then output that to a file once you're done.


I doubt you are going to be critically bound with I/O here, so the quickest workaround is to save to a file then read it with python. Otherwise, the code use to save is pretty simple and located modeleditor.py#L907:L953. You can easily modify that to only keep the string via IDF::idfstr() method, do stuff on it, and still save ultimately in the same format that eppy does.

Let's load some dummy data, and two system modules we will optionally need to encode:

import platform
import os
from eppy import modeleditor
from eppy.modeleditor import IDF

# Set Idd
iddfile = r'/usr/local/EnergyPlus-9-0-1/Energy+.idd'
IDF.setiddname(iddfile)

# Load example file
p = r'/usr/local/EnergyPlus-9-0-1/ExampleFiles/1ZoneUncontrolled.idf'
idf1 = IDF(p)

Now here's the thing:

# Get the idf as a string
s = idf1.idfstr()

# **Do stuff here**

# Optional Encoding like eppy would do by default (lineendings = 'default', encoding='latin-1') 
encoding = 'latin-1'
system = platform.system()
s = '!- {} Line endings \n'.format(system) + s
slines = s.splitlines()
# Make it a single string
s = os.linesep.join(slines)
s = s.encode(encoding)
# s is your idf enconded string ready to write

with open('myfile.idf', 'wb') as idf_out:
    idf_out.write(s)
edit flag offensive delete link more

Your Answer

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

Add Answer

Careers

Question Tools

1 follower

Stats

Asked: 2019-01-15 02:31:37 -0500

Seen: 154 times

Last updated: Jan 15 '19