0

MW & Mvar flow in Python to Excel

Hi I am new to python, and I am really enjoying my time spent on understanding its application. What is the python code for obtaining all the branch flows (MW, Mvar, loading, MVA etc) for all my circuits on my network and then exporting it to excel?

PSSE_ABCD's avatar
11
PSSE_ABCD
asked 2015-06-30 04:44:36 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

You can either use excelpy or CSV module. I would stick to CSV if you were to store plain data, i.e. no requirements for features of XLSX etc.

First of all, get the data that you need.

# get bus numbers, circuit IDs and loading of in-service branches
ierr,busnum = psspy.abrnint(string=['FROMNUMBER','TONUMBER'])
ierr,ckt = psspy.abrnchar(string='ID')
ierr,loading = psspy.abrnreal(string=['P','Q'])

CSV option:

import csv

# open a CSV file for writing
csv_out = open('branch_flows.csv','wb')

# create the csv writer object
csvobj= csv.writer(csv_out)

# write header
csvobj.writerow(('From bus','To bus','ID','MW','MVAr'))

# write data
csvobj.writerows(zip(busnum[0],busnum[1],ckt[0],loading[0],loading[1]))

# close CSV file
csv_out.close()

excelpy option:

import excelpy

# create a Excel workbook for writing
xlobj = excelpy.workbook()

# write header
xlobj.set_range(1,'a',['From bus','To bus','ID','MW','MVAr'])

# write data
xlobj.set_range(2,'a',zip(*busnum))
xlobj.set_range(2,'c',zip(*ckt))
xlobj.set_range(2,'d',zip(*loading))

# save workbook
xlobj.save('branch_flows.xlsx')
sheng's avatar
141
sheng
answered 2015-07-01 06:24:16 -0500, updated 2015-07-01 18:50:28 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments

Your Answer

Login/Signup to Answer