Created
October 5, 2011 23:55
-
-
Save jtrain/1266097 to your computer and use it in GitHub Desktop.
add generators to PSSE case from csv file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import with_statement | |
import os | |
import sys | |
import csv | |
# Location of libraries | |
sys.path.append("C:\\Code\\trunk\\libs\\psselib") # psse_utilities | |
sys.path.append("C:\\Code\\trunk\\libs\\filelib") # file utils | |
sys.path.append("C:\\program files\\pti\\psse32\\pssbin") # psspy | |
import psspy | |
def machines(): | |
""" | |
Add machines (gens and svcs) to the working case. | |
For gens we add all to the case with status off. ECDI will take care of status. | |
For SVCs we only want them to be in service in and after the year specified in the CSV. | |
(Neither ECDI nor OPF [since fict SVCs control their own bus] will control status of fict SVCs) | |
""" | |
csv_file = 'genlist.csv' | |
fict_gens = list(csv.reader(open(csv_file, "r"))) | |
Qlimit = 700 | |
for i in range(len(fict_gens)-1): | |
busno = int(fict_gens[i+1][0]) | |
genid = int(fict_gens[i+1][1]) | |
pgen = int(fict_gens[i+1][2]) | |
pmax = int(fict_gens[i+1][3]) | |
status = int(fict_gens[i+1][4]) | |
excluded = fict_gens[i+1][5] | |
vsched = fict_gens[i+1][6] | |
print vsched | |
if(excluded == 'FALSE'): | |
ierr, rval = psspy.busdat(busno ,'PU') | |
if(rval > 1.085): | |
rval = 1.085 | |
if(vsched <> ""): # if a value for vsched is written in the csv, use it. | |
rval = float(vsched) | |
ierr = psspy.plant_data(busno,0,[ rval, 100.0]) | |
psspy.bus_data_2(busno,[2,_i,_i,_i],[_f,_f,_f],_s) | |
# file name will be something like: | |
# "C:\WorkingFiles\GenProject\WP_201112_and_beyond\WP_201112_lofl.sav" | |
savefilename, snpfilnam = psspy.sfiles() | |
# Need to extract the case year from savefilename | |
# front part of path deleted to leave something like: "WP_201112_lofl.sav" | |
case_year = savefilename.split("\\") | |
case_year = case_year[len(case_year)-1] | |
# Now extract number from case name. PROVIDED case name starts "WP_201112..." | |
case_year = case_year[4:10] | |
#ERROR saved file name not getting updated (stays at what is selected)!!!!!!!! | |
print "saved file is................................ %s" % savefilename | |
# fictitious SVC defined by machine with Pmax == 0 | |
if(pmax == 0): | |
if(int(case_year) < (status-101)): # Subtract 101 from 'status' so SVC will be on in correct year (e.g. 1415 when adding to 1314 case) | |
psspy.machine_data_2(busno,str(genid),[0,1,0,0,0,0],[pgen,0.0, Qlimit, -Qlimit, pmax, 0.0, 100.0,0.0, 1.0,0.0,0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) | |
print "SVC %s is o.o.s.....until year %s..................." % (busno, status) | |
else: | |
psspy.machine_data_2(busno,str(genid),[1,1,0,0,0,0],[pgen,0.0, Qlimit, -Qlimit, pmax, 0.0, 100.0,0.0, 1.0,0.0,0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) | |
print "SVC %s in service......................." % busno | |
else: #Assuming a gen; defined by machine with Pmax != 0 | |
psspy.machine_data_2(busno,str(genid),[0,1,0,0,0,0],[pgen,0.0, Qlimit, -Qlimit, pmax, 0.0, 100.0,0.0, 1.0,0.0,0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) | |
psspy.fnsl([1,1,0,1,0,0,99,0]) | |
if __name__ == "__main__": | |
machines() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment