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

Suppose I have 100 variables calculated using Energyplus and I want to print the 100 in 10 CSV files, how may I achieve it ?

asked 2018-07-13 23:31:10 -0600

Siv's avatar

updated 2018-08-25 18:26:14 -0600

Suppose I have 100 variables calculated using Energyplus and I want to print the 100 in 10 CSV files in such a way that each CSV file contains only 10 variables, how may I achieve it ?

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
2

answered 2018-07-20 06:41:56 -0600

You can use rvi input files to filter and order the variables from the eso output when ReadVarsESO produces the csv output. You can write a batch script to run ReadVarsESO multiple times on the same eso output, each with a different rvi input. There are many example rvi files in the EnergyPlus ExampleFiles folder, e.g. 1ZoneUncontrolled.rvi. See "Using ReadVarsESO" in the Input Output Reference for more information.

edit flag offensive delete link more
5

answered 2018-07-16 02:58:40 -0600

updated 2018-07-16 03:11:24 -0600

Python and pandas would do that quite easily. This code will output as many csv files as needed regardless of your actual number of variables, each file with 10 variables (except the latest which could have between 1 and 10). Each will be named like eplusout_0.csv, eplusout_1.csv, etc.

import pandas as pd
import numpy as np

df = pd.read_csv('eplusout.csv', index_col=0)
# Chunck size
n = 10
for i in range(0, df.shape[1], n):
    df_chunck = df.iloc[:, i:i+n]
    df_chunck.to_csv('eplusout_{}.csv'.format(i))

Note: If you wanted, you do a bit better to properly parse the Date/Time CSV column as a valid DateTimeIndex.


I'll allow myself to go into a small rant here: the time conventions used by E+ as a MAJOR pain. The Date/Time index doesn't include the year, but more importantly it uses end of timestep conventions AND labels midnight as "24:00". Try to parse that in Python, you'll see.

In [1]
def dateparse(x):          
    return pd.datetime.strptime("2005/{}".format(x.strip()), '%Y/%m/%d %H:%M:%S')

df = pd.read_csv('eplusout.csv', index_col=0, parse_dates=True, date_parser=dateparse)

Out[1]:
ValueError: time data '2005/01/01  24:00:00' does not match format '%Y/%m/%d %H:%M:%S'

This is because datetime logically expects 0-23 for hour.

In [2]: import datetime
        datetime.datetime(2005, 1, 1, 24, 0, 0)

Out[2]: ValueError: hour must be in 0..23
edit flag offensive delete link more

Comments

1

FYI: https://github.com/NREL/EnergyPlus/is... (should probably be tagged 'NewFeatureRequest')

ericringold's avatar ericringold  ( 2018-07-16 10:11:40 -0600 )edit

Go upvote this issue please!

Julien Marrec's avatar Julien Marrec  ( 2018-07-17 02:25:58 -0600 )edit

The utility that is responsible for converting the ESO (which has dates and times that make sense internally to E+) into CSV is ReadVarsESO. Yes, it is in F90, but it is open source and we are happy to take contributions (even in other programming languages). The contribution policy is right here.

Jason DeGraw's avatar Jason DeGraw  ( 2018-07-17 09:57:09 -0600 )edit

Jason, I'll answer on the Github Issue here

Julien Marrec's avatar Julien Marrec  ( 2018-07-18 02:46:48 -0600 )edit
2

answered 2018-07-14 12:23:48 -0600

Avi's avatar

updated 2018-07-14 12:24:55 -0600

I would import the csv file into Excel and then separate whatever I need into different worksheets.

That should be quiet easy to do. You could write simple macro script to automate that.

You could also run simulation 10 times each time with different output list but that is inefficient.

edit flag offensive delete link more
0

answered 2021-07-20 09:03:20 -0600

psymo87's avatar

Re Julien's rant above, regarding the poor E+ time conventions. Here is a snippet of python code that might be useful:

def read_eplusout(datafile, year=2018):

ep_datas={}
if os.path.exists(datafile):
    with open(datafile,mode='r') as inf:
        hline=inf.readline()             ##Reads the line of headers

        for hhead in hline.split(','):
            hhead=hhead.rstrip()
            ##Make sure that we read a variable that we want
            ep_datas[hhead]=[]

        ##Creates a huge data structure
        for i, lline in enumerate(inf):
            for hhead,dd in zip(hline.split(','),lline.split(',')):
                hhead=hhead.rstrip()
                if hhead=='Date/Time':
                    tyy,thh=dd.split()
                    mm,dd=tyy.split('/')
                    hh,mmm,ss=thh.split(':')
                    if hh=='24':
                        ddt=ep_datas[hhead][-1]+(ep_datas[hhead][-1]-ep_datas[hhead][-2])
                    else:
                        ddt=datetime.datetime(year,int(mm),int(dd),int(hh),int(mmm),int(ss))

                    ep_datas[hhead].append(ddt)
                    continue

                if dd=="":
                    dd=0.0

                ep_datas[hhead].append(float(dd))

    data_frame = pd.DataFrame(ep_datas)
    data_frame = data_frame.set_index(pd.DatetimeIndex(ep_datas['Date/Time']))

    return data_frame
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

Training Workshops

Careers

Question Tools

3 followers

Stats

Asked: 2018-07-13 23:31:10 -0600

Seen: 858 times

Last updated: Jul 20 '21