Skip to content

Instantly share code, notes, and snippets.

@cwebber314
Created February 12, 2015 16:38
Show Gist options
  • Save cwebber314/cf95c6b2cf86e9f042de to your computer and use it in GitHub Desktop.
Save cwebber314/cf95c6b2cf86e9f042de to your computer and use it in GitHub Desktop.
PSSE .sav file to .raw file
"""
Convert sav file to raw file.
Requires pssepath from:
https://github.com/cwebber314/pssepath
"""
import os.path as osp
import sys
import argparse
import pssepath
pssepath.add_pssepath()
import psspy
def main():
op = argparse.ArgumentParser()
op.add_argument('sav')
op.add_argument('-o', '--overwrite', help='overwrite', default=False)
op.add_argument('raw', default=None, nargs='?')
args = op.parse_args()
if args.raw is None:
outfn = osp.splitext(args.sav)[0] + '.raw'
else:
outfn = args.raw
# init
if not args.overwrite and osp.exists(outfn):
print ".sav file already exists %s. Skipping conversion" % outfn
return 0
psspy.psseinit(50000)
err = psspy.case(args.sav)
err = psspy.rawd(sid=0, all=1, status=[1,1,1,0,0,0], out=0, ofile=outfn)
if __name__ == '__main__':
result = main()
sys.exit(result)
@bahkosh
Copy link

bahkosh commented Jan 30, 2016

Hi,
I am very new to python. Can you list the step by step way to use this code.

I have PSSE ver 33 university edition(50 bus limited).

My requirement: to convert a *.sav file of more than 50 buses to *.raw format which i need to give as input for another power system application. In my pyhton 2.7 shell, i made a module run for "pssepath.py" and it has given the following output:

""""
Found the following PSSE versions installed:

  1. PSSE Version 33
    Requires Python 2.7 (Current running Python)
    Press Enter to continue... """"

But upon the sav2raw.py run, i got the following:

""""
usage: sav2raw.py [-h] [-o OVERWRITE] sav [raw]
sav2raw.py: error: too few arguments

Traceback (most recent call last):
File "C:\Python27\sav2raw.py", line 38, in
result = main()
File "C:\Python27\sav2raw.py", line 23, in main
args = op.parse_args()
File "C:\Python27\lib\argparse.py", line 1656, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "C:\Python27\lib\argparse.py", line 1688, in parse_known_args
return self._parse_known_args(args, namespace)
File "C:\Python27\lib\argparse.py", line 1901, in parse_known_args
self.error(
('too few arguments'))
File "C:\Python27\lib\argparse.py", line 2311, in error
self.exit(2, _('%s: error: %s\n') % (self.prog, message))
File "C:\Python27\lib\argparse.py", line 2299, in exit
_sys.exit(status)
SystemExit: 2 """""

Kindly help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment