Ask Your Question
2

Easier way to change load and gen values and export to excel

asked 2012-08-02 10:18:18 -0500

anonymous user

Anonymous

updated 2012-08-08 01:19:32 -0500

JervisW gravatar image

Hi,

I am new to Python and was wondering how I could create a program to run all my simulations. Currently I am manually changing the load and generator values for each hourly simulation.

I have several weeks worth left to do and was wondering if someone could please show me how to initiate this program to grab the results from excel, load into PSSE then export the results into a single spreadsheet?

Sincere thanks for any assistance as I am running behind schedule.

(edit)

Thanks for the reply but still having trouble with importing the values and exporting the bus voltage results to PSSE.

The following data is what I am trying to enter into PSSE from excel

LOAD, MW,  MMVAR
104, 0.33234344, 0.08304855
106, 0.6118356, 0.087272
109, 2.287867032, 0.760106028
203, 0.58799224, 0.14693205
212, 0.68831505, 0.098181
216, 2.57621391, 0.855904515
217, 0.35180547, 0.0501814
308, 0.86920592, 0.2172039
309, 2.8361988, 0.9422802
311, 0.4588767, 0.065454

Then the gen data is below these entries as follows:

WG A, 1.0189575
WG B, 1.0189575
WG B, 1.0189575
DG 111, 0.48
DG 112, 0.48
DG 113, 0.48
WG 207, 1.5624015
DG 210, 2.2 26 
WG 214, 1.5624015
WG 215, 1.5624015
PV 304, 0
DG 307, 0.8
DG 310, 0.8

Any further whelp would be greatly appreciated!

The excel file is saved as EP401Simulation ResultsUR Algorithm3.0.xlsx

edit retag flag offensive close merge delete

Comments

I saw some information about doing exactly this kind of work. I'll see if there was a script that did this already.

jtrain gravatar imagejtrain ( 2012-08-02 15:42:13 -0500 )edit

(edit) I was thinking about this question: http://psspy.org/psse-help-forum/question/329/how-do-i-change-the-loads-on-psse/ It doesn't get you all the way there yet. (No reading from Excel and no changing machine data)

jtrain gravatar imagejtrain ( 2012-08-02 15:53:47 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-08-03 03:10:30 -0500

JervisW gravatar image

updated 2012-08-08 01:37:10 -0500

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:

  1. Read the load power and generator power for specific bus and machine ids from a CSV file
  2. Update the loads and generators with their new values in PSSE
  3. Export bus voltages into a single spreadsheet

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)

    # 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 :)

edit flag offensive delete link more

Comments

The main benefit here is that the groupby function will group all load and machine data changes for a save file together.

JervisW gravatar imageJervisW ( 2012-08-03 04:41:58 -0500 )edit

Thank you so much, @JervisW. It's very useful!

Phat Huynh gravatar imagePhat Huynh ( 2016-10-01 16:49:42 -0500 )edit

Hi sirs. I tried to use this code but I get this kind of error. for isload, p, q, bus, _id in data: ValueError: need more than 1 value to unpack. any help is very much appreciated. thank you! i tried to search to correct this issue but i still can't find a way.

bert gravatar imagebert ( 2018-09-08 02:44:41 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

Stats

Asked: 2012-08-02 10:18:18 -0500

Seen: 3,303 times

Last updated: Aug 08 '12