Exporting thermal loads results into excel file

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
Post Reply
KHAN
VE Newbie
VE Newbie
Posts: 4
Joined: Fri Sep 01, 2023 11:18 am

Exporting thermal loads results into excel file

Post by KHAN »

Hi, I do building physics stuff and use IESVE to calculate the thermal loads. I want to use Python to export my Vistapro heating and cooling loads results directly to the excel. Can anyone please help me in achieving this. I have tried watching webinar, and on IES website but couldn't make it.
bbrannon4
VE Professor
VE Professor
Posts: 111
Joined: Wed Feb 12, 2014 6:56 pm

Re: Exporting thermal loads results into excel file

Post by bbrannon4 »

Hello,

Do you have experience with Python? If not, you might need to do some general tutorials first.

If so, here are some code snippits that might help. Note these are from around one of my scripts and probably won't work on their own without a litte debugging, but I hope get you started:

Code: Select all


class LoadResultsData:
    def __init__(self):
        self.name = None
        self.filetype = None
        self.sens_total = None
        self.sens_lighting = None
        self.sens_equipment = None
        self.sens_people = None
        self.sens_external_conduction = None
        self.sens_internal_conduction = None
        self.sens_infiltration = None
        self.sens_solar = None
        self.sens_mass = None
        self.lat_total = None
        self.lat_equipment = None
        self.lat_people = None
        self.lat_infiltration = None

def get_room_load_results(rooms, results_file_reader, var_type):

    #rooms = results_file_reader.get_room_list() # no need to pull room list from results file, because we're passing it from the model.  might cause issues if the results file doesn't allign with the model'

    if len(rooms) < 1:
        raise_error("Looks like there aren't any rooms in your model.")

    # Initialize dict with keys but no values
    results = dict.fromkeys(rooms)

    # Get unit conversions
    units = results_file_reader.get_units()
    if outputunits == 'ip':
        units_display_name = units['Gain']['units_IP']['display_name']
        units_divisor = units['Gain']['units_IP']['divisor']
    elif outputunits == 'si':
        units_display_name = units['Gain']['units_SI']['display_name']
        units_divisor = units['Gain']['units_SI']['divisor']
    else:
        print("Select units at the top of the scripts.  Options are: 'ip' or 'si'")

    for room_id in rooms:
        # Instantiate class for results data
        results_data = LoadResultsData()

        results_data.filetype = var_type # maybe do this and the filename in the main function, rather than looping and redoing here?

        # Pull data for each variable and assign and divide to change units
        results_data.sens_total = results_file_reader.get_room_results(room_id, 'System plant etc. gains','Space conditioning sensible','z')/units_divisor
        results_data.sens_lighting = results_file_reader.get_room_results(room_id, 'Lighting gain','Lighting gain','z')/units_divisor
        results_data.sens_equipment = results_file_reader.get_room_results(room_id, 'Equipment gain','Equipment gain','z')/units_divisor
        results_data.sens_people = results_file_reader.get_room_results(room_id, 'People gain','People gain','z')/units_divisor
        results_data.sens_external_conduction = results_file_reader.get_room_results(room_id, 'Conduction from ext elements','External conduction gain','z')/units_divisor
        results_data.sens_internal_conduction = results_file_reader.get_room_results(room_id, 'Conduction from int surfaces','Internal conduction gain','z')/units_divisor
        results_data.sens_infiltration = results_file_reader.get_room_results(room_id, 'Infiltration gain','Infiltration gain','z')/units_divisor
        results_data.sens_solar = results_file_reader.get_room_results(room_id, 'Window solar gains','Solar gain','z')/units_divisor
        results_data.sens_mass = results_file_reader.get_room_results(room_id, 'Air & furniture dynamics gain','Air & furniture dynamics gain','z')/units_divisor
        results_data.lat_total = results_file_reader.get_room_results(room_id, 'Room latent load','Space conditioning latent','z')/units_divisor
        results_data.lat_equipment = results_file_reader.get_room_results(room_id, 'Equipment latent gain','Equipment latent gain','z')/units_divisor
        results_data.lat_people = results_file_reader.get_room_results(room_id, 'People latent gain','People latent gain','z')/units_divisor
        results_data.lat_infiltration = results_file_reader.get_room_results(room_id, 'Infiltration lat gain','Infiltration lat gain','z')/units_divisor

        # Assign class to overall dictionary with ID as key
        results[room_id] = results_data
        
        if room_id == 'L0000034':
            print(results['L0000030'].sens_total)
            print(results['L0000034'].sens_total)
        elif room_id == 'L0000080':
            print(results['L0000080'].sens_total)


    return results, units_display_name

if __name__ == "__main__":

    # import current (open) project
    project = iesve.VEProject.get_current_project()
    # create a list of VEModel objects
    models = project.models
    # The 'real building' model is always the first model in the 'models' list
    model = models[0]
    # create list of VEBody objects from VEModel object
    bodies = model.get_bodies_and_ids(False) # get dictionary of VEBody objects, IDs as keys
    # format body details into DFs for exporting to excel
    room_data_simple, room_data_complex = get_room_details(bodies)
    # get list of room IDs
    room_ids = list(bodies.keys())
    
    # Open results file (multiple types) (example just for heating file)
    htg_file_name = IesFilePicker.pick_vista_file([("HTG files", "*.htg")], "Pick a heating room loads results file")
    filetype_heating =  htg_file_name.rsplit('.', 1)[1]
    
    # read results data
    with iesve.ResultsReader.open(htg_file_name) as results_file_reader_htg:
        assert results_file_reader_htg is not None, "Results file appears empty or corrupted."
        # get all (hourly) results data
        space_heating_loads, units_display_name_htg = get_room_load_results(room_ids, results_file_reader_htg, filetype_heating)
    

KHAN
VE Newbie
VE Newbie
Posts: 4
Joined: Fri Sep 01, 2023 11:18 am

Re: Exporting thermal loads results into excel file

Post by KHAN »

Hi,

Many thanks Sir, I don't have prior experience in python but have little understanding of coding. I was finding difficulty in functions and objects etc that you have mentioned. I'll have a look and if need assistance will post here again.

Please keep an eye on the forum. It would be really appreciated.
Regards,
Khan
Graduate Building Physics Engineer
Post Reply