Ask Your Question
0

MW & Mvar flow in Python to Excel

asked 2015-06-30 04:44:36 -0600

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-07-01 06:24:16 -0600

sheng gravatar image

updated 2015-07-01 18:50:28 -0600

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

[hide preview]

Question Tools

Stats

Asked: 2015-06-30 04:44:36 -0600

Seen: 1,346 times

Last updated: Jul 01 '15