psse_log = 'savnw.log' redirect.psse2py() psspy.psseinit(buses=80000) psspy.report_output(2, psse_log, [0, 0]) psspy.progress_output(2, psse_log, [0, 0]) psspy.alert_output(2, psse_log, [0, 0]) psspy.prompt_output(2, psse_log, [0, 0]) _i = psspy.getdefaultint() _f = psspy.getdefaultreal() _s = psspy.getdefaultchar() print "\n Reading raw file:", settings['filename'] ierr = psspy.read(0, settings['filename']) # get a list of all the non-transformer branches ierr, brnchs = psspy.abrnint( _i, _i, _i, _i, _i, ['FROMNUMBER', 'TONUMBER']) # page 1789 of API book ierr, carray = psspy.abrnchar( _i, _i, _i, _i, _i, ['ID']) # get the character ids (page 1798 of API book) fromBusList = brnchs[0] toBusList = brnchs[1] cktIDList = carray[0] #print '\n\n\n' #print 'Branch1' + '\t' + 'Branch2' + '\t' + 'Non-convergence?' # nested loop to simulate N-2 line outages for i in range(len(toBusList)): # disconnect each branch fromBus1 = fromBusList[i] toBus1 = toBusList[i] cktID1 = cktIDList[i].strip("'").strip()
psspy.bsys(sid=1, numbus=len(bus_num), buses=bus_num) ierr, machine_bus = psspy.amachint(1, 1, ['NUMBER']) machine_bus = machine_bus[0] ierr, machine_id = psspy.amachchar(1, 1, ['ID']) machine_id = machine_id[0] #List of all load psspy.bsys(sid=1, numbus=len(bus_num), buses=bus_num) ierr, load_bus = psspy.alodbusint(1, 1, ['NUMBER']) load_bus = load_bus[0] ierr, load_id = psspy.aloadchar(1, 1, ['ID']) load_id = load_id[0] #List of branches ierr, internal_linesfbtb = psspy.abrnint(sid=1, ties=1, flag=1, string=['FROMNUMBER', 'TONUMBER']) ierr, internal_linesid = psspy.abrnchar(sid=1, ties=1, flag=1, string=['ID']) #Building the list of contingencies line_trip = internal_linesfbtb + internal_linesid # [[fb1,tb1,id1]] response_buses = list(bus_num) # export the pq bus ierr, bus_type = psspy.abusint(1, 1, 'type') bus_type = bus_type[0] pq = [] for index, bus in enumerate(bus_num):
current_a = bus_voltage_a[i] bus_voltage.append(current_m) bus_voltage.append(current_a) # save voltage magnitudes and imags in csv db_row = [] db_row.extend(bus_voltage) writer = csv.writer(f1, delimiter=',', lineterminator='\n') writer.writerow(db_row) ## find all the injections of each concerned bus total_bus_num = len(bus_number) # All transmission lines ierr, from_bus_number_set = psspy.abrnint(sid=1, ties=3, entry=2, string='FROMNUMBER') from_bus_number_set = from_bus_number_set[0] ierr, to_bus_number_set = psspy.abrnint(sid=1, ties=3, entry=2, string='TONUMBER') to_bus_number_set = to_bus_number_set[0] ierr, from_bus_PQ_set = psspy.abrncplx(sid=1, ties=3, entry=2, string='PQ') from_bus_PQ_set = from_bus_PQ_set[0] ierr, branch_ID_set = psspy.abrnchar(sid=1, ties=3, entry=2,
## connectionstyle="arc3") plt.text(x1 + dxt, y1 + dyt, j[2], fontsize=6) elif businfo[idx][1] == 220.0: plt.plot(x, y, 'b-') ax.arrow(x1, y1, dx, dy, width=.5, color='b') plt.text(x1 + dxt, y1 + dyt, j[2], fontsize=6) elif businfo[idx][1] == 400.0: plt.plot(x, y, 'r-') ax.arrow(x1, y1, dx, dy, width=.5, color='r') plt.text(x1 + dxt, y1 + dyt, j[2], fontsize=6) else: pass # Find in-service, non-transformer branches in_branches = psspy.abrnint(sid=1, string=["FROMNUMBER", "TONUMBER"], flag=1, ties=3) # Find all non-transformer branches all_branches = psspy.abrnint(sid=1, string=["FROMNUMBER", "TONUMBER"], flag=2, ties=3) # Flatten a arbitrarily nested lists and return the result as a single list def flatten(l): ret = [] for i in l: if isinstance(i, (list, tuple)): ret.extend(flatten(i)) else:
machine_id = machine_id[0] #List of all Gen psspy.bsys(sid = 1,numbus = len(bus_num), buses = bus_num) ierr,gen_bus = psspy.agenbusint(1,1,['NUMBER']) gen_bus = gen_bus[0] #List of all load psspy.bsys(sid = 1,numbus = len(bus_num), buses = bus_num) ierr,load_bus = psspy.alodbusint(1,1,['NUMBER']) load_bus = load_bus[0] ierr,load_id = psspy.aloadchar(1,1,['ID']) load_id = load_id[0] #List of branches ierr,internal_linesfbtb = psspy.abrnint(sid=1,ties=1,flag=1,string=['FROMNUMBER','TONUMBER']) ierr,internal_linesid = psspy.abrnchar(sid=1,ties=1,flag=1,string=['ID']) #Building the list of contingencies line_trip = internal_linesfbtb + internal_linesid # [[fb1,tb1,id1]] response_buses = list(bus_num) # export the pq bus ierr, bus_type = psspy.abusint(1,1,'type') bus_type = bus_type[0] pq = [] for index,bus in enumerate(bus_num): if bus_type[index] == 1: pq.append(bus) # export the slack bus
import sys PSSE_LOCATION = r'c:/program files/pti/psse32/pssbin' sys.path.append(PSSE_LOCATION) os.environ['PATH'] += ';' + PSSE_LOCATION import psspy import redirect redirect.psse2py() psspy.throwPsseExceptions = True psspy.psseinit(1000) psspy.case(savedcase) ierr, (fromnumber, tonumber) = psspy.abrnint( sid=-1, flag=3, # for all in service branches and two winding transformers. string=["FROMNUMBER", "TONUMBER"]) ierr, (weights, ) = psspy.abrncplx(sid=-1, flag=3, string=["RX"]) def inverse(cplx): return 1 / cplx.imag weights = map(abs, weights) G = nx.DiGraph() G.add_weighted_edges_from(zip(fromnumber, tonumber, weights)) plt.figure(1, figsize=(20, 20)) pos = nx.spring_layout(G, iterations=100)
## patchA=None, ## patchB=None, ## connectionstyle="arc3") plt.text(x1+dxt, y1+dyt, j[2], fontsize=6) elif businfo[idx][1] == 220.0: plt.plot(x, y, 'b-') ax.arrow(x1, y1, dx, dy, width=.5, color='b') plt.text(x1+dxt, y1+dyt, j[2], fontsize=6) elif businfo[idx][1] == 400.0: plt.plot(x, y, 'r-') ax.arrow(x1, y1, dx, dy, width=.5, color='r') plt.text(x1+dxt, y1+dyt, j[2], fontsize=6) else: pass # Find in-service, non-transformer branches in_branches = psspy.abrnint(sid=1, string=["FROMNUMBER", "TONUMBER"], flag=1, ties=3) # Find all non-transformer branches all_branches = psspy.abrnint(sid=1, string=["FROMNUMBER", "TONUMBER"], flag=2, ties=3) # Flatten a arbitrarily nested lists and return the result as a single list def flatten(l): ret = [] for i in l: if isinstance(i, (list, tuple)): ret.extend(flatten(i)) else: ret.append(i) return ret # Remove zeros in_branches = filter(lambda a: a != 0, flatten(in_branches)) all_branches = filter(lambda a: a != 0, flatten(all_branches))
import sys PSSE_LOCATION = r'c:/program files/pti/psse32/pssbin' sys.path.append(PSSE_LOCATION) os.environ['PATH'] += ';' + PSSE_LOCATION import psspy import redirect redirect.psse2py() psspy.throwPsseExceptions = True psspy.psseinit(1000) psspy.case(savedcase) ierr, (fromnumber, tonumber) = psspy.abrnint( sid=-1, flag=3, # for all in service branches and two winding transformers. string=["FROMNUMBER", "TONUMBER"]) ierr, (weights,) = psspy.abrncplx( sid=-1, flag=3, string=["RX"] ) def inverse(cplx): return 1 / cplx.imag weights = map(abs, weights) G = nx.DiGraph() G.add_weighted_edges_from(zip(fromnumber, tonumber, weights))