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

Ask Your Question
1

Extract contingencies for dfax file?

asked Aug 14 '12

waltterval gravatar image

updated Aug 16 '12

Hi all? I want to know if exists a way to extract the name of the contingencies from a dfax files. I have a dfax file, and I'm lookig for an API that give the contingencies in a variable. Is this possible?


Well I took the code that Jervis wrote and did a little change.

With Jervis'code I got this answer ["'S1'\n", "'S2'\n", "'S3'\n", "'S4'\n", "'S5'\n", "'S6'\n", "'S7'\n", "'S8'\n", "'S9'\n", "'S10'\n", "'S11'\n", "'S12'\n", "'S13'\n", "'S14'\n", "'S15'\n", "'S16'\n", "'S17'\n", "'S18'\n", "'S19'\n", "'S20'\n", "'S21'\n", "'S22'\n", "'S23'\n", "'S24'\n", "'S25'\n", "'S26'\n", "'S27'\n", "'S28'\n", "'S30'\n", "'S31'\n", "'S32'\n"]

With the changed code I got what I really need: ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'S11', 'S12', 'S13', 'S14', 'S15', 'S16', 'S17', 'S18', 'S19', 'S20', 'S21', 'S22', 'S23', 'S24', 'S25', 'S26', 'S27', 'S28', 'S30', 'S31', 'S32']

Here is the code:

contingency_names = []
with open('Contingencias_SER_EMT2012_SAL2.con') as confile:

    for line in confile:
        if line.strip().lower().startswith('contingency'):
        # assumes the last word on the line is the contingency name.
            words = line.split(' ')
            name = words[-1]
            contingency_names.append(name)
            contingency_ID = []
            for contingency_name in contingency_names:
                contingency_ID.append(contingency_name[1:-2])

print "\n contingency_ID = ", contingency_ID

Comments

I couldn't find one either. Can you read the contingencies from the `.con` file instead?

JervisW gravatar imageJervisW (Aug 14 '12)

@JervisW Actually what I need is a eassy way to extract the name of my contingencies that are in .con file? Any idea?

waltterval gravatar imagewaltterval (Aug 14 '12)

1 answer

Sort by » oldest newest most voted
1

answered Aug 15 '12

JervisW gravatar image

Here is a simple script to get the contingencies names from a .con file:

contingency_names = []
with open('contingency.con') as confile:

 for line in confile:

   if line.strip().lower().startswith('contingency'):

     # assumes the last word on the line is the contingency name.
     words = line.split(' ')
     name = words[-1]

     contingency_names.append(name)

print contingency_names

I've assumed that your file looks a bit like this:

CONTINGENCY firstcontingency
REMOVE UNIT 3 FROM BUS 20002
END
CONTINGENCY somethingelse
...

The script wont work if:

  1. You have spaces in your contingency names
  2. There is text on the CONTINGENCY line other than the word CONTINGENCY and the contingency name

Does it work for you?

link

Comments

@JervisW I will check it and i'll let you know if work as I need. Thanks

waltterval gravatar imagewaltterval (Aug 15 '12)

@JervisW I did a little change to your script, I updated my question to post the final code. Thank you

waltterval gravatar imagewaltterval (Aug 16 '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

1 follower

Stats

Asked: Aug 14 '12

Seen: 1,071 times

Last updated: Aug 16 '12