def readMachines(self): ''' Reads and stores bus numbers where generators are connected ''' ierr, [self.machineBusNumbers] = psspy.amachint(-1, 4, 'NUMBER') ierr, [self.machineIDs] = psspy.amachchar(-1, 4, 'ID') assert ierr == 0, 'Error with reading generator bus numbers' return self.machineBusNumbers, self.machineIDs
def read_raw(self): ''' Read the raw file.''' # Read bus numbers ierr, bus_numbers = psspy.abusint(-1, 2, 'NUMBER') assert ierr == 0, 'Error with reading bus numbers' # Reads voltage levels at buses stored in self.busNumbers ierr, voltage_levels = psspy.abusreal(-1, 2, 'PU') assert ierr == 0, 'Error reading voltage levels' # Reads voltage levels at buses stored in self.busNumbers ierr, voltage_angles = psspy.abusreal(-1, 2, 'ANGLED') assert ierr == 0, 'Error reading voltage angles' # Creates a Python dictionary containing bus numbers as keys and associates # a dictionary with voltage and angle to each of the keys for bus, voltage, angle in zip(bus_numbers[0], voltage_levels[0], voltage_angles[0]): self.buses[bus] = {'voltage': voltage, 'angle': angle} # Reads and stores bus numbers where generators are connected ierr, [machine_bus_numbers] = psspy.amachint(-1, 4, 'NUMBER') ierr, [machine_ids] = psspy.amachchar(-1, 4, 'ID') assert ierr == 0, 'Error reading generator bus numbers' # Reads and stores active and reactive powers of each generator ierr1, [machine_power_p] = psspy.amachreal(-1, 4, 'PGEN') ierr2, [machine_power_q] = psspy.amachreal(-1, 4, 'QGEN') assert ierr1 == 0 and ierr2 == 0, 'Error with reading active and reactive powers' # Creates a Python dictionary containing keys in form of # "BUSNUMBER_MACHINEID" and associates a dictionary with active and # reactive powers to each of the keys for k in range(0, len(machine_ids)): self.machines[(str(machine_bus_numbers[k]) + '_' + machine_ids[k][:-1])] = { 'bus': machine_bus_numbers[k], 'P': machine_power_p[k], 'Q': machine_power_q[k] } # Reads and stores bus numbers where loads are connected ierr, [load_bus_numbers] = psspy.aloadint(-1, 4, 'NUMBER') ierr, [load_ids] = psspy.aloadchar(-1, 4, 'ID') assert ierr == 0, 'Error reading load bus numbers' # Reads and stores active and reactive powers of each load ierr1, [load] = psspy.aloadcplx(-1, 4, 'TOTALACT') load_power_p = [] load_power_q = [] for cplxload in load: load_power_p.append(cplxload.real) load_power_q.append(cplxload.imag) assert ierr1 == 0, 'Error with reading active and reactive powers' # Creates a Python dictionary containing keys in form of # "BUSNUMBER_LOADID" and associates a dictionary with active and # reactive powers to each of the keys for load, bus, active, reactive in zip(load_ids, load_bus_numbers, load_power_p, load_power_q): self.loads[(str(bus) + '_' + load[:-1])] = { 'bus': bus, 'P': active, 'Q': reactive } # Reads and stores bus numbers where 2WindingTrafos are connected ierr1, [two_w_trafo_from] = psspy.atrnint(-1, 1, 1, 2, 1, 'FROMNUMBER') ierr2, [two_w_trafo_to] = psspy.atrnint(-1, 1, 1, 2, 1, 'TONUMBER') assert ierr1 == 0 and ierr2 == 0, 'Error reading trafo bus numbers' # Reads and stores 2WindingTrafo ratios taking into account the primary side ierr1, [two_w_trafo_ratio1] = psspy.atrnreal(-1, 1, 1, 2, 1, 'RATIO') ierr2, [two_w_trafo_ratio2] = psspy.atrnreal(-1, 1, 1, 2, 1, 'RATIO2') assert ierr1 == 0 and ierr2 == 0, 'Error reading trafo bus numbers' # Creates a Python dictionary containing keys in form of # "BUSNUMBER_LOADID" and associates a dictionary with active and # reactive powers to each of the keys for f_bus, to_bus, ratio1, ratio2 in zip(two_w_trafo_from, two_w_trafo_to, two_w_trafo_ratio1, two_w_trafo_ratio2): self.trafos[(str(f_bus) + '_' + str(to_bus))] = { 'fromBus': f_bus, 'toBus': to_bus, 't1': ratio1, 't2': ratio2 }
cont_genbus_array.append(partxt[5]) if partxt[5] in swingbus_str: swingbusincont = True fcon.close() print('-------swingbus_str: ') print(swingbus_str) print('------swingbusincont: ') print(swingbusincont) # check if swing bus in contingency: if swingbusincont: #sort in-service generators ierr, iarray = psspy.amachint(-1, 1, 'NUMBER') vtmpgenbusno = iarray[0] ierr, rarray = psspy.amachreal(-1, 1, 'PGEN') vtmpgenpgen = rarray[0] gen_tmp_info = zip(vtmpgenbusno, vtmpgenpgen) gen_tmp_sorted = sorted(gen_tmp_info, key=lambda item: item[1], reverse=True) newswingbus = -1 for igen in range(0, len(gen_tmp_sorted)): if str(gen_tmp_sorted[igen][0]) not in cont_genbus_array: newswingbus = gen_tmp_sorted[igen][0] break if newswingbus != -1:
output = StringIO.StringIO() with silence(output): psspy.psseinit(80000) # initialize PSS\E in python savecase = 'ieee118bus_PSSEcorrected_rq.sav' psspy.case(savecase) # find all the buses psspy.bsys(0, 0, [0.0, 0.0], 1, [1], 0, [], 0, [], 0, []) ierr, all_bus = psspy.abusint(0, 1, ['number']) bus_num = all_bus[0] #List of all machines 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,
output = StringIO.StringIO() with silence(output): psspy.psseinit(80000) # initialize PSS\E in python savecase = 'IEEE 57 bus.sav' psspy.case(savecase) # find all the buses psspy.bsys(0,0,[0.0,0.0],1,[1],0,[],0,[],0,[]) ierr,all_bus = psspy.abusint(0,1,['number']) bus_num = all_bus[0] #List of all machines 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 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]