Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I figured out a way to create all N-1 generator contingency list by writing commands "REMOVE MACHINE [MCID] FROM BUS [BUSID]" explicitly one by one to the .con file. But my module I used in my problem is based on the possibility that you know how to associated a GUI defined subsystem label to a valid subsystem id (0~11). Right now, I use the whole working case as a subsystem, so that the subsystem id is equal to -1.

def createConFile(psspy, conFileName, subsysID, subSysLabel):

    # manipute with working case data- all returned data are in the same order
    allMachID = psspy.amachchar(subsysID, 4, 'ID')   # return total number of machines in working case
    print "machID =", allMachID[1][0]

    #allMachBUSName = psspy.amachchar(subsysID, 4, 'EXNAME') # return total number of in-service machines at in-service plants
    #print "machBusName=", allMachBUSName[1][0]

    busNums = psspy.amachint(subsysID, 4, 'NUMBER')  # change -1 to some subsystem ID
    print "list of bus numbers ", busNums[1][0]

    conFile = open(conFileName, 'w')

    # generate a .con file which
    conFile.write("/PSS(R)E 33\n")
    conFile.write("COM\n")
    conFile.write("COM CONTINGENCY description file entry created by PSS(R)E Config File Builder \n")
    conFile.write("COM\n")
    conFile.write("SINGLE BRANCH IN SUBSYSTEM '%s' \n\n" % subSysLabel)  # define "DayHr2" as a variable

    # contingencies for removing each specified machine 
    for i in range(len(allMachID[1][0])): # use index to enumerate b/c all data in the same order in terms of mach id
        conFile.write("CONTINGENCY 'MACHINE %d-BUS%d' \n" %(int(allMachID[1][0][i]), busNums[1][0][i]))
        conFile.write('REMOVE MACHINE %s FROM BUS %d \n' %(allMachID[1][0][i], busNums[1][0][i]))
        conFile.write('END \n\n')

    conFile.write('END')
    conFile.close()

    return

Hope someone will find this helpful.

click to hide/show revision 2
changed to use zip from index based iteration.

I figured out a way to create all N-1 generator contingency list by writing commands "REMOVE MACHINE [MCID] FROM BUS [BUSID]" explicitly one by one to the .con file. But my module I used in my problem is based on the possibility that you know how to associated a GUI defined subsystem label to a valid subsystem id (0~11). Right now, I use the whole working case as a subsystem, so that the subsystem id is equal to -1.

def createConFile(psspy, conFileName, subsysID, subSysLabel):

    # manipute with working case data- all returned data are in the same order
    allMachID ierr, (allMachID,) = psspy.amachchar(subsysID, 4, 'ID')   # return total number of machines in working case
    print "machID =", allMachID[1][0]

    #allMachBUSName = psspy.amachchar(subsysID, 4, 'EXNAME') # return total number of in-service machines at in-service plants
    #print "machBusName=", allMachBUSName[1][0]

    busNums allMachID

    ierr, (busNums,) = psspy.amachint(subsysID, 4, 'NUMBER')  # change -1 to some subsystem ID
     print "list of bus numbers ", busNums[1][0]
busNums

    conFile = open(conFileName, 'w')

    # generate a .con file which
header
    conFile.write("/PSS(R)E 33\n")
    conFile.write("COM\n")
    conFile.write("COM CONTINGENCY description file entry created by PSS(R)E Config File Builder \n")
    conFile.write("COM\n")
    conFile.write("SINGLE BRANCH IN SUBSYSTEM '%s' \n\n" % subSysLabel)  # define "DayHr2" as a variable
subSysLabel)

    # contingencies for removing each specified machine 
    for i machid, busnum in range(len(allMachID[1][0])): # use index to enumerate b/c all data in the same order in terms of mach id
zip(allMachID, busNums): 
        conFile.write("CONTINGENCY 'MACHINE %d-BUS%d' \n" %(int(allMachID[1][0][i]), busNums[1][0][i]))
%( int(machid), busnum))
        conFile.write('REMOVE MACHINE %s FROM BUS %d \n' %(allMachID[1][0][i], busNums[1][0][i]))
%(machid, busNum))
        conFile.write('END \n\n')

    conFile.write('END')
    conFile.close()

    return

Hope someone will find this helpful.