Ask Your Question
2

Loading data from .txt file

asked 2012-04-30 10:41:35 -0600

Fagundes gravatar image

updated 2012-06-14 02:47:59 -0600

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.

edit retag flag offensive close merge delete

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 ( 2012-04-30 20:05:18 -0600 )edit

2 answers

Sort by » oldest newest most voted
1

answered 2012-05-01 07:36:54 -0600

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?

edit flag offensive delete link more
0

answered 2012-05-01 12:45:17 -0600

Fagundes gravatar image

updated 2012-05-02 02:48:59 -0600

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
edit flag offensive delete link more

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 ( 2012-05-01 13:19:51 -0600 )edit

Thanks for your help.

Fagundes gravatar imageFagundes ( 2012-05-02 09:07:16 -0600 )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-04-30 10:41:35 -0600

Seen: 1,580 times

Last updated: May 02 '12