Ask Your Question
2

Read from PSSE and then write to CSV

asked 2012-07-17 21:19:09 -0500

Don gravatar image

updated 2012-08-15 06:55:20 -0500

JervisW gravatar image

Hi

I wish to read Machine info from a psse case Bus No, Bus Name, Machine Id

Then automatically write a *.con file for all generator contingencies

CONTINGENCY "Bus Name" REMOVE MACHINE "Machine Id" FROM BUS "BUS NUMBER" ... This is repeated for all generators

Really appreciate if you wish to suggest a python code for doing this

Thanking you

Don

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
2

answered 2012-07-24 12:47:08 -0500

waltterval gravatar image

updated 2012-07-25 05:34:17 -0500

JervisW gravatar image

Hi, I took what Jervis did and modified a little the script. Here is my version

sid = -1
flag = 4
string1 = 'NUMBER'
string2 = ['NAME','ID']

TEMPLATE = """
CONTINGENCY %(name)s
REMOVE UNIT %(id)s FROM BUS %(number)s
END
"""
ierr1, numbers = psspy.amachint(sid, flag, string1)  # machines at all buses
#print numbers, ierr1
ierr2, name_id = psspy.amachchar(sid, flag, string2) # names and ids
#print name_id, ierr2

# convert from columns to rows [(num, name, id), (num, name, id)]
num_name_id = zip(*(numbers + name_id))
confile = open("contingency.con", "wb")
for number, name, id in num_name_id:
    confile.write(TEMPLATE % dict(name=name, id=id, number=number))
confile.close()

I couldn't work whit the original script, so I did the modifications

edit flag offensive delete link more

Comments

This looks great. I've updated my script based on the corrections in yours.

JervisW gravatar imageJervisW ( 2012-07-25 05:35:29 -0500 )edit
2

answered 2012-07-19 02:36:02 -0500

JervisW gravatar image

updated 2012-07-25 05:31:39 -0500

Here is something to get you started:

busno: use psspy.amachint

name: use psspy.amachchar

id: use psspy.amachchar

TEMPLATE = "CONTINGENCY %(name)s REMOVE MACHINE %(id)s FROM BUS %(num)s\n"
ierr, numbers = psspy.amachint(sid=-1, string=["NUMBER"])  # machines at all buses
ierr, name_id = psspy.amachchar(sid=-1, string=["NAME", "ID"]) # names and ids

# convert from columns to rows [(num, name, id), (num, name, id)]
num_name_id = zip(*(numbers + name_id))
confile = open("contingency.con", "wb")
for number, name, id in num_name_id:
  confile.write(TEMPLATE % dict(name=name, id=id, number=number))
confile.close()
edit flag offensive delete link more
0

answered 2012-07-25 15:41:48 -0500

waltterval gravatar image

Hi here a newer version of ths script

sid = -1
flag = 4
string1 = 'NUMBER'
string2 = ['NAME', 'ID']

TEMPLATE = "CONTINGENCY %(name)s \nREMOVE UNIT %(id)s FROM BUS %(number)s\nEND\n"
ierr1, numbers = psspy.amachint(sid, flag, string1)  # machines at all buses
ierr2, name_id = psspy.amachchar(sid, flag, string2) # names and ids

#The name of the contingency will have bus' name and the machine's id
nameCont =[[1] * len(name_id[0])]
n = 0
while n < len(name_id[0]):
    nameCont[0][n] = "'" + name_id[0][n] + name_id[1][n] + "'"
    n +=1

# convert from columns to rows [(num, name, id), (num, name, id)]
num_name_id = zip(*(nameCont + numbers + [name_id[1]]))
confile = open("contingencyC.con", "wb")
for nameCont, number, id in num_name_id:
    confile.write(TEMPLATE % dict(name=nameCont, id=id, number=number))
confile.write ('END')
confile.close()
edit flag offensive delete link more

Comments

What does the variable `nameCont` contain after the while loop? is it this: `["MAC1", "MAC2", ...]`

JervisW gravatar imageJervisW ( 2012-07-26 03:33:44 -0500 )edit

Yes, the variable nameCont = BusName+MachineID , in some buses we could have more that one machine

waltterval gravatar imagewaltterval ( 2012-07-26 08:56:27 -0500 )edit

Good point. There is often more than one machine at a bus.

JervisW gravatar imageJervisW ( 2012-07-27 08:32:41 -0500 )edit

I found that this script gives contingency names of the form 'busname id'. In a PSS/E .con file PSS/E will only read the name up to the space, therefore 'busname id1' , 'busname id2' will both be read as 'busname', and PSS/E will only perform the first of the two contingencies. What is required is names in the format 'busname_id' or something similar. I've had a brief look at how to do this but don't have an answer, it's a bit trcky with strings being immutable.

Peter B gravatar imagePeter B ( 2012-08-06 20:19:38 -0500 )edit

I'll edit the answer here, good pick up Peter.

JervisW gravatar imageJervisW ( 2012-08-07 01:42:51 -0500 )edit

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

2 followers

Stats

Asked: 2012-07-17 21:19:09 -0500

Seen: 1,810 times

Last updated: Jul 25 '12