First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
0

MW & Mvar flow in Python to Excel

asked Jun 30 '15

PSSE_ABCD gravatar image

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?

1 answer

Sort by » oldest newest most voted
0

answered Jul 1 '15

sheng gravatar image

updated Jul 2 '15

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')
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

Stats

Asked: Jun 30 '15

Seen: 1,357 times

Last updated: Jul 01 '15