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

Ask Your Question
2

Read from PSSE and then write to CSV

asked Jul 18 '12

Don gravatar image

updated Aug 15 '12

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

3 answers

Sort by » oldest newest most voted
2

answered Jul 24 '12

waltterval gravatar image

updated Jul 25 '12

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

link

Comments

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

JervisW gravatar imageJervisW (Jul 25 '12)
2

answered Jul 19 '12

JervisW gravatar image

updated Jul 25 '12

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()
link
0

answered Jul 25 '12

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

Comments

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

JervisW gravatar imageJervisW (Jul 26 '12)

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

waltterval gravatar imagewaltterval (Jul 26 '12)

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

JervisW gravatar imageJervisW (Jul 27 '12)

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 (Aug 7 '12)

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

JervisW gravatar imageJervisW (Aug 7 '12)

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

2 followers

Stats

Asked: Jul 18 '12

Seen: 2,758 times

Last updated: Jul 25 '12