First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
1 | initial version |
A tutorial for learning Python for PSSE.
To address your immediate problem here is a script that completes the following steps:
Step three won't be included, I'm not sure which results that you want exported!
"""
Change the load and generation levels in a PSSE case.
Assume that the CSV file has the following headings:
case_filename, load?, p, q, bus, id
so for a load entry it reads:
c:/files/demo.sav, 1, 200, 150, 20045, 2
and for a generator entry it could look like:
c:/files/demo.sav, 0, 600, 0, 20020, C
We can change many loads and files in the same file, just by adding new rows!
"""
import csv
import psspy
psspy.throwPsseExceptions = True
LOAD_GEN_DATAFILE = 'c:/studies/2012/load-and-gen-data.csv'
STUDY_CASE = 'c:/studies/2012/top-secret-new-generator.sav'
psspy.case(STUDY_CASE)
# read the entire CSV into Python.
data = list(csv.reader(open(LOAD_GEN_DATAFILE)))
# assume CSV has columns as described in the doc string
2 | Added the rest of the script. |
A Here is a tutorial for learning Python for PSSE.
To But to address your immediate problem here this is a script that completes the following steps:
Step three won't be included, I'm not sure which results that you want exported!
"""
Change the load and generation levels in a PSSE case.
Assume that the CSV file has the following headings:
case_filename, load?, p, q, bus, id
so for a load entry it reads:
c:/files/demo.sav, 1, 200, 150, 20045, 2
and for a generator entry it could look like:
c:/files/demo.sav, 0, 600, 0, 20020, C
We can change many loads and files in the same file, just by adding new rows!
"""
import csv
from itertools import groupby
from operators import itemgetter
get_casefilenae = itemgetter(0)
import psspy
psspy.throwPsseExceptions = True
LOAD_GEN_DATAFILE = 'c:/studies/2012/load-and-gen-data.csv'
STUDY_CASE = 'c:/studies/2012/top-secret-new-generator.sav'
psspy.case(STUDY_CASE)
# read the entire CSV into Python.
data = list(csv.reader(open(LOAD_GEN_DATAFILE)))
# assume CSV has columns as described in the doc string
for casefilename, load_and_gens in groupby(get_casefilename, data):
psspy.case(casefilename)
for fname, isload, p, q, bus, _id in load_and_gens:
if isload.isdigit() and int(isload):
psspy.load_data_3(bus, _id, realar1=p, realar2=q)
else:
psspy.machine_data_2(bus, _id, realar1=p, realar2=q)
# solve case after adding all loads / machines.
psspy.fnsl()
Try this out, I haven't got a copy of PSS/E here to see if it works myself :)
3 | No.3 Revision |
Here is a tutorial for learning Python for PSSE.. I'm constantly improving it, message me if you have any ideas.
But to address your immediate problem this is a script that completes the following steps:
Step three won't be included, I'm not sure which results that you want exported!
"""
Change the load and generation levels in a PSSE case.
Assume that the CSV file has the following headings:
case_filename, load?, p, q, bus, id
so for a load entry it reads:
c:/files/demo.sav, 1, 200, 150, 20045, 2
and for a generator entry it could look like:
c:/files/demo.sav, 0, 600, 0, 20020, C
We can change many loads and files in the same file, just by adding new rows!
"""
import csv
from itertools import groupby
from operators import itemgetter
get_casefilenae = itemgetter(0)
import psspy
psspy.throwPsseExceptions = True
LOAD_GEN_DATAFILE = 'c:/studies/2012/load-and-gen-data.csv'
STUDY_CASE = 'c:/studies/2012/top-secret-new-generator.sav'
psspy.case(STUDY_CASE)
# read the entire CSV into Python.
data = list(csv.reader(open(LOAD_GEN_DATAFILE)))
# assume CSV has columns as described in the doc string
for casefilename, load_and_gens in groupby(get_casefilename, data):
psspy.case(casefilename)
for fname, isload, p, q, bus, _id in load_and_gens:
if isload.isdigit() and int(isload):
psspy.load_data_3(bus, _id, realar1=p, realar2=q)
else:
psspy.machine_data_2(bus, _id, realar1=p, realar2=q)
# solve case after adding all loads / machines.
psspy.fnsl()
Try this out, I haven't got a copy of PSS/E here to see if it works myself :)
4 | No.4 Revision |
Here is a tutorial for learning Python for PSSE. I'm constantly improving it, message me if you have any ideas.
But to address your immediate problem this is a script that completes the following steps:
Step three won't be included, I'm not sure which results that you want exported!Here it is:
"""
Change the load and generation levels in a PSSE case.
Assume that the CSV file has the following headings:
case_filename, load?, p, q, bus, id
so for a load entry it reads:
c:/files/demo.sav, 1, 200, 150, 20045, 2
and for a generator entry it could look like:
c:/files/demo.sav, 0, 600, 0, 20020, C
We can change many loads and files in the same file, just by adding new rows!
"""
import csv
from itertools import groupby
from operators import itemgetter
get_casefilenae = itemgetter(0)
import psspy
psspy.throwPsseExceptions = True
LOAD_GEN_DATAFILE = 'c:/studies/2012/load-and-gen-data.csv'
STUDY_CASE = 'c:/studies/2012/top-secret-new-generator.sav'
psspy.case(STUDY_CASE)
# read the entire CSV into Python.
data = list(csv.reader(open(LOAD_GEN_DATAFILE)))
# assume CSV has columns as described in the doc string
for casefilename, load_and_gens in groupby(get_casefilename, data):
psspy.case(casefilename)
for fname, isload, p, q, bus, _id in load_and_gens:
data:
# convert the types from string to Python numbers
p = float(p)
q = q.isdigit() and float(q)
bus = int(bus)
if isload.isdigit() and int(isload):
psspy.load_data_3(bus, _id, realar1=p, realar2=q)
else:
psspy.machine_data_2(bus, _id, realar1=p, realar2=q)
# solve case after adding all loads / machines.
psspy.fnsl()
# now to write the new bus voltages to a file.
Try this out, I haven't got a copy of PSS/E here to see if it works myself :)
5 | added the export voltages |
Here is a tutorial for learning Python for PSSE. I'm constantly improving it, message me if you have any ideas.
But to address your immediate problem this is a script that completes the following steps:
Here it is:
"""
Change the load and generation levels in a PSSE case.
Assume that the CSV file has the following headings:
load?, p, q, bus, id
so for a load entry it reads:
1, 200, 150, 20045, 2
and for a generator entry it could look like:
0, 600, 0, 20020, C
We can change many loads and files in the same file, just by adding new rows!
"""
import csv
import psspy
psspy.throwPsseExceptions = True
LOAD_GEN_DATAFILE = 'c:/studies/2012/load-and-gen-data.csv'
STUDY_CASE = 'c:/studies/2012/top-secret-new-generator.sav'
OUTPUT_VOLTAGES = 'c:/studies/2012/new-bus-voltages.csv'
psspy.case(STUDY_CASE)
# read the entire CSV into Python.
data = list(csv.reader(open(LOAD_GEN_DATAFILE)))
# assume CSV has columns as described in the doc string
for isload, p, q, bus, _id in data:
# convert the types from string to Python numbers
p = float(p)
q = q.isdigit() and float(q)
bus = int(bus)
if isload.isdigit() and int(isload):
psspy.load_data_3(bus, _id, realar1=p, realar2=q)
else:
psspy.machine_data_2(bus, _id, realar1=p, realar2=q)
realar1=p)
# solve case after adding all loads / machines.
psspy.fnsl()
# now to write the new bus voltages to a file.
ierr, (voltages,) = psspy.abusreal(sid=-1, string=["PU"])
ierr, (buses,) = psspy.abusint(sid=-1, string=["NUMBER"])
csvfile = open(OUTPUT_VOLTAGES, 'wb')
writer = csv.writer(csvfile)
for row in zip(buses, voltages):
writer.writerow(row)
csvfile.close()
Try this out, I haven't got a copy of PSS/E here to see if it works myself :)