Large data export for multiple building IES model

The VE Python API allows users create simple programs using the Python Programming Language, to interact with a VE Model and/or Vista Results File
DanielCooke
VE Newbie
VE Newbie
Posts: 6
Joined: Wed Dec 02, 2020 12:33 pm

Large data export for multiple building IES model

Post by DanielCooke »

Hello,

I am trying to create a script to automate export of a lot of data from a large IES model with multiple buildings. The model will be ran multiple times with lots of different weather tapes, so I would like to automate the export of results as much as I can into excel documents to ensure consistent data for post processing.

Is there a way to get python to do the following for a given results file:
  • export TM52 reports for the whole model (can python call the inbuilt IES TM52 tool which produces csv files or would I have to code TM52 analysis into python)?
  • export the heating and cooling demand (on a half hourly basis) for each building (can python 'combine rooms' for building groups)?
  • access the weather tape that was used for that run and export matching half hourly temperature data (the weather tape will be different for each run and there will be a lot of weather tapes - 144!)?
I would ideally like to get all the raw data in an excel file for each results file. Can python run a repeating script to loop through all the .aps results files in the vista folder? This way I can copy all the results into one folder and run the script once with a results excel per run.

Any suggestions or example code that people can point me towards would be greatly appreciated as I am new to python. Other than the example scripts in the VEScript tool is there anywhere else that holds example code for IES (I have already checked the other VE Python API forum posts that looked like they might relate to this)?

Thanks!
User avatar
Rhind
IES Staff
IES Staff
Posts: 87
Joined: Fri Mar 22, 2013 5:06 pm

Re: Large data export for multiple building IES model

Post by Rhind »

export TM52 reports for the whole model (can python call the inbuilt IES TM52 tool which produces csv files or would I have to code TM52 analysis into python)
This is not available through the API so you would have to do your own analysis.
export the heating and cooling demand (on a half hourly basis) for each building (can python 'combine rooms' for building groups)?
You can get data from results files using the ResultsReader API. For room groups use the RoomGroups API.
access the weather tape that was used for that run and export matching half hourly temperature data (the weather tape will be different for each run and there will be a lot of weather tapes - 144!)
ResultsReader has an attribute called 'weather_file', which should give you the associated weather file.
Can python run a repeating script to loop through all the .aps results files in the vista folder?
Loops are possible including 'for' loops. Basically any of the loops available in normal Python are also available in VEScript.

Hope that helps.
DanielCooke
VE Newbie
VE Newbie
Posts: 6
Joined: Wed Dec 02, 2020 12:33 pm

Re: Large data export for multiple building IES model

Post by DanielCooke »

I am having issues using the ResultsReader and RoomGroups API. I am trying to export the half hourly data for the 'heating plant sensible load' for a group of rooms combined. I am getting an error on the below code on the line where I am trying to get the results. I want the standard VistaPro output in table format to be generated for writing into excel for each group in my 'Results' grouping scheme. I have the code set up to find this grouping scheme and load the handle and then read into a list the groups in this scheme. But it seems to be an issue with extracting the results. Can you please suggest how I modify the below to get what I need out?

#set col counter to 3 (D) to leave some space for time/date stuff?
col = 3

for group in groups:
heat = asp_file.get_all_results('Room units heating load', 'z')
sheet1.write(col, 0, heat) #use the col counter to position the results in the sheet
col = col + 3 #increment counter for next run round
User avatar
Rhind
IES Staff
IES Staff
Posts: 87
Joined: Fri Mar 22, 2013 5:06 pm

Re: Large data export for multiple building IES model

Post by Rhind »

Do you get a specific error you can post? I ran the following script and it worked ok:

Code: Select all

import iesve
from ies_file_picker import IesFilePicker

file_name = IesFilePicker.pick_vista_file([("APS files", "*.aps")], "Pick a results file")

with iesve.ResultsReader.open(file_name) as aps_file:
    assert aps_file is not None, "Error opening results file"
    print(aps_file.get_all_results('Room units heating load', 'z'))
DanielCooke
VE Newbie
VE Newbie
Posts: 6
Joined: Wed Dec 02, 2020 12:33 pm

Re: Large data export for multiple building IES model

Post by DanielCooke »

I have modified my code (below), so it runs but I am not getting the data I need, its printing the title cell one letter at a time in each column. I need to export the standard columns we would get in VistaPro:
- Column A - date
- Column B - time (in half hour steps)
- Column C - heating plant sensible load (combined for the group)

Do you have any examples as the documents I have from IES doe not show how to use the get_all_results call?

rg = iesve.RoomGroups()
schemes = rg.get_grouping_schemes()
for scheme in schemes:
if scheme['name'] == 'Results':
scheme_handle = scheme['handle']
break
groups = rg.get_room_groups(scheme_handle)

#set col counter to 1 (B)
col = 1

for group in groups:
heat = aps_file.get_all_results('Room units heating load', 'z')
row = 1
for data in heat:
sheet1.write_row(row, col, data) #use the col/row counters to position the results in the sheet
row = row + 1 #increment the counter for next row of data
col = col + 1 #increment counter for next run round
User avatar
Rhind
IES Staff
IES Staff
Posts: 87
Joined: Fri Mar 22, 2013 5:06 pm

Re: Large data export for multiple building IES model

Post by Rhind »

It looks like you're iterating over the dictionary key (the variable 'display name') rather than the value. get_all_results() returns a dictionary so you need to use the value rather than the key to get to the numbers.

Description of the return type from the manual:
Dictionary of numpy array of floats, keyed by variable display name
Here's a modified version of your script that should do what you want:

Code: Select all

import iesve
import xlsxwriter
from ies_file_picker import IesFilePicker

workbook = xlsxwriter.Workbook('C:\\output.xlsx')
sheet1 = workbook.add_worksheet()

file_name = IesFilePicker.pick_vista_file([("APS files", "*.aps")], "Pick a results file")

with iesve.ResultsReader.open(file_name) as aps_file:
    assert aps_file is not None, "Error opening results file"

    rg = iesve.RoomGroups()
    schemes = rg.get_grouping_schemes()
    for scheme in schemes:
        if scheme['name'] == 'Results':
            scheme_handle = scheme['handle']
            break
            
    groups = rg.get_room_groups(scheme_handle)

    # set row counter to 1 (B)
    row = 1

    for group in groups:
        heat = aps_file.get_all_results('Room units heating load', 'z')
        data = heat['Heating plant sensible load']
        col = 1
        sheet1.write_row(row, col, data) # use the col/row counters to position the results in the sheet
        row = row + 1 # increment the counter for next row of data
            
workbook.close()
DanielCooke
VE Newbie
VE Newbie
Posts: 6
Joined: Wed Dec 02, 2020 12:33 pm

Re: Large data export for multiple building IES model

Post by DanielCooke »

Hello,

Thanks for the updated code, I have modified it to export each group per column, as using a row per group does not have enough columns to export all the data (17000+ rows of data if exporting half hourly for the year).

The next issue is that the get_all_results call seems to be combining all the rooms in the model, not all the rooms in the 'Results' grouping scheme. Should I be using the get_all_room_results and passing it the group ID instead of room ID?

My grouping scheme is called 'Results' which has a load of sub-groups called 'A1', 'A2', 'A3', etc. I want a column per sub group which combines all the rooms in that sub group and provides the half hourly data for that group for the year.

Expected output:
Column A - combined heat loads for sub group A1
Column B - combined heat loads for sub group A2
Column C - combined heat loads for sub group A3
etc.

Current code:
rg = iesve.RoomGroups()
schemes = rg.get_grouping_schemes()
for scheme in schemes:
if scheme['name'] == 'Results':
scheme_handle = scheme['handle']
break
groups = rg.get_room_groups(scheme_handle)

#set col counter to 1
col = 1

for index, group in enumerate(groups):
sheet1.write(0, col, index)

heat_data = aps_file.get_all_results('Room units heating load', 'z', 1, 365)
#print(heat_data)
data = heat_data['Heating plant sensible load']
#print(data)
row = 1
sheet1.write_column(row, col, data)
col += 1
User avatar
Rhind
IES Staff
IES Staff
Posts: 87
Joined: Fri Mar 22, 2013 5:06 pm

Re: Large data export for multiple building IES model

Post by Rhind »

Yes, you can use get_all_room_results() but you have to give it a room ID. You can use the RoomGroups API to get room IDs for particular schemes/groups.

You'll probably want to use the following methods to get the relevant information:
get_grouping_schemes ( )-> List of dictionaries
Get a list of room grouping schemes stored as dictionaries. Dictionary entries are:
handle (string)
name (string)
get_room_groups (grouping scheme handle)-> List of dictionaries
Get a list of room groups (stored as dictionaries) for a grouping scheme. Dictionary entries are:
colour (tuple of R,G,B ints) each colour entry in range 0-255
handle (int)
name (string)
rooms (list of strings) list of room IDs assigned to group
DanielCooke
VE Newbie
VE Newbie
Posts: 6
Joined: Wed Dec 02, 2020 12:33 pm

Re: Large data export for multiple building IES model

Post by DanielCooke »

Hello,

As you can see I am using both of those grouping collections in my code, but I cannot see any examples or descriptions around how you use the get_all _room_results with a group of rooms, not just a single room ID?

This line does not seem to work:

heat_data = aps_file.get_all_room_results(group['rooms'], 'Room units heating load', 'z', 1, 365)
User avatar
Rhind
IES Staff
IES Staff
Posts: 87
Joined: Fri Mar 22, 2013 5:06 pm

Re: Large data export for multiple building IES model

Post by Rhind »

You can only pass an individual room id to get_all_room_results(), so you'll have to call get_all_room_results() once for each room.
Post Reply