Ask Your Question
0

Reading PSSE output files (*.dat) and saving in a useful format (CSV)

asked 2014-01-30 20:06:15 -0600

Don gravatar image

updated 2014-02-03 13:58:53 -0600

chip gravatar image

Hi I need some guidance/help on Python – Esp reading a text data file and re-arranging the information in a tabular form (probably in an Excel/CSV file) Please refer to the output of the ”Report.dat” file given below

For each branch, there is a sensitivity list for buses ( the number of buses are not fixed for all contingencies)

I would like to get these information in the following format. Bus, Branch, Sensitivity

Appreciate your help to get this done in a Pythonic way

Ta

Output of the Report.Dat file

TI INTERACTIVE POWER SYSTEM SIMULATOR--PSS(R)E     WED, DEC 29 1814  14:57
SENSITIVITY FACTORS ARE CALCULATED WITH DC NETWORK
SYSTEM SWING BUS(es) IS USED FOR OPPOSING SYSTEM FOR MW POWER DISPATCH

SENSITIVITY FACTORS OF BRANCH FLOW (MW) ON  10000 LA    275.00 TO  20000 NY    275.00 1  GREATER THAN  0.10000

<------- BUS NAME ------>   MW-SENS

 10000 LA    275.00    0.1041

 20000 NY    275.00   -0.7613

 30000 WDC   275.00   -0.2254

 40000 SF    275.00   -0.2254

 50000 AZ    275.00   -0.2144



SENSITIVITY FACTORS OF BRANCH FLOW (MW) ON  40000 SF    275.00 TO  50000 AZ    275.00 1  GREATER THAN  0.10000

<------- BUS NAME ------>   MW-SENS

 20000 NY    275.00    0.7613

 30000 WDC   275.00    0.2254

 40000 SF    275.00    0.2254

 50000 AZ    275.00    0.2144



SENSITIVITY FACTORS OF BRANCH FLOW (MW) ON  40000 SF    275.00 TO  60000 PD    275.00 1  GREATER THAN  0.10000

------- BUS NAME ------>   MW-SENS

 10000 LA    275.00    0.1613

 30000 WDC   275.00    0.3254

 40000 SF    275.00    0.1540

 50000 AZ    275.00    0.3244
edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
0

answered 2014-02-13 12:17:55 -0600

yfwing gravatar image

Isn't it easier to use the function: pssarrays.sensitivity_flow_to_mw

edit flag offensive delete link more
0

answered 2014-02-03 12:47:32 -0600

jsexauer gravatar image

updated 2014-02-03 12:48:33 -0600

In a bit of a hurry, so probably didn't make this as clear as I could have. I also took some liberties in assuming your data is fixed width, as your sample was. Let me know if you have any questions.

current_branch = None
data = []
# Read data
with open("data.txt") as f:
    for l in f:
        if l[:11] == "SENSITIVITY":
            current_branch = l[44:88]
        elif l[:2] == "<-":
            continue
        elif len(l) > 2:
            assert current_branch is not None
            data.append( [l[:20], current_branch, l[20:]] )

# Strip out white space
data = [map(lambda x: x.strip(), l) for l in data]

# Create lines
data = [','.join(l) for l in data]

# Display file
print '\n'.join(data)

Output:

10000 LA    275.00,10000 LA    275.00 TO  20000 NY    275.00 1,0.1041
20000 NY    275.00,10000 LA    275.00 TO  20000 NY    275.00 1,-0.7613
30000 WDC   275.00,10000 LA    275.00 TO  20000 NY    275.00 1,-0.2254
40000 SF    275.00,10000 LA    275.00 TO  20000 NY    275.00 1,-0.2254
50000 AZ    275.00,10000 LA    275.00 TO  20000 NY    275.00 1,-0.2144
20000 NY    275.00,40000 SF    275.00 TO  50000 AZ    275.00 1,0.7613
30000 WDC   275.00,40000 SF    275.00 TO  50000 AZ    275.00 1,0.2254
40000 SF    275.00,40000 SF    275.00 TO  50000 AZ    275.00 1,0.2254
50000 AZ    275.00,40000 SF    275.00 TO  50000 AZ    275.00 1,0.2144
10000 LA    275.00,40000 SF    275.00 TO  60000 PD    275.00 1,0.1613
30000 WDC   275.00,40000 SF    275.00 TO  60000 PD    275.00 1,0.3254
40000 SF    275.00,40000 SF    275.00 TO  60000 PD    275.00 1,0.1540
50000 AZ    275.00,40000 SF    275.00 TO  60000 PD    275.00 1,0.3244
edit flag offensive delete link more

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: 2014-01-30 20:06:15 -0600

Seen: 1,524 times

Last updated: Feb 13 '14