First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
2

Loading data from .txt file

asked Apr 30 '12

Fagundes gravatar image

updated Jun 14 '12

JervisW gravatar image

Hi,

My question is how to get data from a file and use it in PSSE. I´m using python, and i would like to extract information from a file, values, to alter, i.e, the load values.

I can make this but only if i run the code on a console. When i try to run the python file in PSSE it says that does not recognize some of the code lines.

The idea is to make a cicle of 24 hours, varying the values of the load and generation. I have the data stored on a .txt file. So if i could do this it would save me a lot of time. But i'm incapable to extract the values from the files when i run the python file in psse.

Thanks for your time and help.

Comments

You could write a few lines of regular expressions to extract the data, then use the API to attach them at the appropriate locations. I could give it a try but then I would need your txt file and your saved case file to start with.

amaity gravatar imageamaity (May 1 '12)

2 answers

Sort by » oldest newest most voted
1

answered May 1 '12

jtrain gravatar image

Hi Fagundes,

What does your text file look like? Are you able to write a short example?

For a text file that looks like this:

date, load (MW)
02-03-12, 100
03-03-12, 110
04-03-12, 105

We would use the csv module to read the values in:

import csv
reader - csv.reader(open('fagundes.csv'))
header = reader.next()
data = list(reader)

Now you could apply the load in your saved case:

import psspy
psspy.case('fagundes.sav')

# set the load on the first day
day, load = data[0]

psspy.load_data_3(101, '1 ',
                  realar1=load) # Constant Power MW

Does your code look like this example?

link
0

answered May 1 '12

Fagundes gravatar image

updated May 2 '12

jtrain gravatar image

Thank you for your help!!

I got there very easy. I know how to work with PSS/E, although programming PSS/E with python it's new to me.

My code stayed like this:

import csv

z=r'D:\ISEL\TESE\zTestes_python\hora'

w=".txt"

hora = 1

while(hora != 4):   
    direct=''

    number=str(hora)

    direct += z
    direct += number
    direct += w

    reader=csv.reader(open(direct))
    header = reader.next()
    data = list(reader)

    hora = hora + 1
    validade=0
    aux=0
    while(validade != 3):
        barr, pot=data[aux]
        barr1=int(barr)
        pot1=int(pot)
        psspy.load_data(barr1,r"""1""",[_i,_i,_i,_i],[ pot1,_f,_f,_f,_f,_f])
        aux=aux+1
        validade=validade+1

The barr1=int(barr) statement was necessary do to PSSE interpret barr as a string and not as integer ou float number. Do you know any doc that could help me get all the functions of psspy library?

By the way, the txt file had this written inside:

barr Pot

2 , 10

3 , 20

4 , 30
link

Comments

1

All the psspy API docs are in $PSSE_HOME\DOCS\PSSEAPI\API.pdf. I'm not sure if you've seen PEP8, but it's a good reference IMHO if you're starting python.

chip gravatar imagechip (May 1 '12)

Thanks for your help.

Fagundes gravatar imageFagundes (May 2 '12)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

Stats

Asked: Apr 30 '12

Seen: 1,613 times

Last updated: May 02 '12