def _initialize_psyops(): from . import config import os import sys from warnings import warn # If this __init__.py file is in ./psyops/ then import is within a source dir is_psyops_source_dir = (os.path.abspath( os.path.dirname(__file__)) == os.path.abspath('psyops') and os.path.exists('setup.py')) # try to import pssepath and pssypy try: import pssepath pssepath.add_pssepath() import psspy except: ret = _alt_init_psspy() print print 'init_psspy result:', ret def _alt_init_psspy(psse_ver_req=0, control_psse=True \ , pti_path='C:\\Program Files (x86)\\PTI' \ , bug_prt=False): ''' # _alt_init_psspy is an alternative psse/python initializer in case pssepath # is not available. # alternatively, you can use just the commented out lines of code directly # below, but it is less robust than pssepath. # for PSSE 32 and Python 2.5 #import sys #sys.path.append(r'C:\Program Files (x86)\PTI\PSSE32.2.2\PSSBIN') # dbl-check path #import psspy #import redirect #redirect.psse2py() # for PSSE 34 and Python 2.7 #import sys #sys.path.append(r'C:\Program Files (x86)\PTI\PSSE34\PSSBIN') # dbl-check path #import psspy #import redirect #redirect.psse2py() # init_psspy() # 1. Confirms user has required PSS/e version installed. # 2. Confirms user is running version of Python # required # 3. Initializes Python for PSSE interaction. # Returns list of [code, remark] #code: # + value = success # - value = error #remark: informational remark such as failure reason. # Parameters (inputs) # psse_ver_req: PSSE version required for this # script to function properly. # valid values are integers: 31, 32, 33, 34. # control_psse: # True: issue command: redirect.redirect.psse2py(). # False: do not issue the psse2py() command. ''' import sys import os errs = [] # run compatibility check? check_result = [1, 'PSS//e and Python versions are compatible. ' ] # check passed until proven to failed cont = True if psse_ver_req == 0: check_result = [2, 'Compatibility check declined. '] cont = False # skip compatibility check # ----- Start: Check user PSSE and PY versions for compatibility) ----- # initialize variables psse_py = [[31, 2.5], [32, 2.5], [33, 2.7], [34, 2.7]] # psse/py compatibility # validate psse_ver_req parameter: is it a number if cont: try: psse_ver_req = int(float(psse_ver_req)) type(psse_ver_req) except: cont = False check_result = [ -1, 'psse_ver_req must be a version number from 31 to 34. ' ] if bug_prt: print check_result # validate psse_ver_req parameter: is it in the psse_py compatability list if cont: cont = False # don't cont compatibility check for i in range(len(psse_py)): if psse_py[i][0] == psse_ver_req: cont = True if not cont: check_result = [ -1, 'psse_ver_req must be a version number from 31 to 34. ' ] if bug_prt: print check_result py_ver = 0 # get version number for python instance running now (sys.version command) if cont: try: py_ver = str(sys.version).split(' ')[0].split( '.') #extract version from beginning of string py_ver = float( str(py_ver[0]) + '.' + str(py_ver[1]) ) # keep only 1 level of subversioning, e.g., keep 2.5 from 2.5.3 if bug_prt: print 'set py_ver:', py_ver except: print r'Warning: init_psspy() had trouble determining python version number.' cont = False for i in range(len(psse_py)): if py_ver == psse_py[i][1]: cont = True if not cont: check_result = [ -1, 'Python version ' + str(py_ver) + ' not compatible. ' ] if bug_prt: print check_result if bug_prt: print 'py_ver', py_ver # Find PSS/e installations if cont: # pti_path folder exists? if bug_prt: print 'Checking pti_path:', pti_path if not os.path.isdir(pti_path): check_result = [ -3, r'Unable to find PSS/e installation folder "' + pti_path + '" on this computer. ' ] if bug_prt: print check_result print check_result cont = False # Find PSS/e folder(s) if cont: try: psse_paths = os.listdir( pti_path) # get all psse installation paths if bug_prt: print 'Found', len( psse_paths), r'PSS/e install paths: ', psse_paths except: check_result = [ -4, r'Unable to find PSS/e installation folder on this computer. ' ] if bug_prt: print check_result cont = False # Get installed PSS/e version numbers from path # (e.g. path, 'C:\Program Files (x86)\PTI\PSSE32.2.2') if cont: psse_vers = [] psse_path = '' for i in range( len(psse_paths)): # check each path for psse_ver_req if bug_prt: print 'path', psse_paths[i] x = str(psse_paths[i])[4:6] if bug_prt: print 'path ver:', x, '; psse_ver_req:', str( psse_ver_req) try: x = int(x) except: x = 0 if 31 <= x <= 34 and str(psse_ver_req) == str(x): psse_path = psse_paths[ i] # used later to load psspy library if bug_prt: print 'Found psse_path:', psse_path else: if bug_prt: print 'Did not find a psse_path in psse_paths:', psse_paths, 'where version = ', x if psse_path == '': check_result = [ -5, r'Unable to find PSS/e installation folder on this computer. ' ] if bug_prt: print check_result cont = False # is psse / py version pair in compatibility list. cont = False if bug_prt: print 'Checking psse and python version against compatibility list.' for i in range(len(psse_py)): if bug_prt: print ' ', psse_py[i][0], psse_ver_req, py_ver, psse_py[i][1] if psse_py[i][0] == psse_ver_req and py_ver == psse_py[i][1]: cont = True if bug_prt: print ' Winner - psse and python versions are compatible!' break if not cont: check_result=[-6,'Python version ' + str(py_ver) \ + r' not compatible with PSS/e version ' \ + str(psse_ver_req) + '. Compatibility list. '] # + str(psse_py)<-compaibility list # ----- Done: Check user PSSE and PY versions for compatibility) ----- # ----- Start: Initialize python to interact with PSSE ----- if bug_prt: print ' Starting: Initialize python to interact with PSSE' if check_result[0] < 1: if bug_prt: print r'Python - PSS/e compatibility check: ', check_result else: #compatibility check passed or was skipped check_result = [ -7, 'Unexpected error initializing libraries (sys, psspy and redirect). ' ] try: import sys check_result = [ -8, 'Imported sys library. Failed to import psspy and redirect. ' ] s = pti_path + '\\' + psse_path + "\PSSBIN" sys.path.append(s) if bug_prt: print r'attempting to add to sys.path:', s if bug_prt: print r'sys.path:', sys.path if bug_prt: print r'attempting to load psspy.' import psspy check_result = [4, 'Imported sys and psspy libraries. '] if control_psse: if bug_prt: print r'attempting to load redirect.' check_result = [ -9, 'Imported sys and psspy libraries. Failed to import redirect. ' ] import redirect if bug_prt: print r'attempting to execute: redirect.psse2py()' redirect.psse2py() check_result = [ 5, r'Successfully configured Python to control PSS/e. ' ] if bug_prt: print check_result if bug_prt: print 'init_psspy() completed successfully. ', check_result except: if bug_prt: print 'init_psspy() failed, Code:', check_result if psse_ver_req == 0: print r'init_psspy() failed. For more info, run w/PSSE version like: init_psspy(32)' if not bug_prt: print 'Consider setting bug_prt=False for verbose debugging comments.' print r'If that doesn\'t solve your problem, check your PSSE and Pyton installations.' print r'Check out this onenote article for more information:' help_page = r'onenote:///\\corp\shares\TransmissionServices\TSD,%20Shared%20Interest\OneNote%20Notebooks\Software%20Development\Python.one#PSS/E%20library%20for%20Toad§ion-id={A3CDFF46-74C6-4A36-B5F7-805ECC3539D9}&page-id={185CE924-9A62-4B5D-9921-1D2E4A30F244}&end' print help_page import urllib urllib.urlopen(help_page) return check_result # ----- Done: Initialize python to interact with PSSE ----- def _rollback_import(message): log.error(message) # Now disable exception logging to avoid an annoying error in the # exception logger before we raise the import error: _teardown_log() # Roll back any psyops sub-modules that have been imported thus # far for key in list(sys.modules): if key.startswith('psyops.'): del sys.modules[key] raise ImportError('psyops') if sys.version_info[0] >= 3 and is_psyops_source_dir: _rollback_import( "You appear to be trying to import psyops from within a source " "checkout. This is currently not possible using Python 3 due to " "the reliance of 2to3 to convert some of psyops's subpackages " "for Python 3 compatibility.") try: from .utils import _compiler except ImportError: if is_psyops_source_dir: _rollback_import( 'You appear to be trying to import psyops from within a ' 'source checkout; please run `./setup.py develop` or ' '`./setup.py build_ext --inplace` first so that extension ' 'modules can be compiled and made importable.') else: # Outright broken installation; don't be nice. raise # add these here so we only need to cleanup the namespace at the end config_dir = None config_dir = os.path.dirname(__file__) try: config.configuration.update_default_config(__package__, config_dir) except config.configuration.ConfigurationDefaultMissingError as e: wmsg = (e.args[0] + " Cannot install default profile. If you are " "importing from source, this is expected.") warn(config.configuration.ConfigurationDefaultMissingWarning(wmsg))
# add PSS/E path to python import pssepath pssepath.add_pssepath() # import all psspy functions from psspy import * # redirect PSS/E alerts/messages to python command line import redirect redirect.psse2py() # declare 'with mute:' block to silent PSS/E alerts import os from contextlib2 import redirect_stdout mute = redirect_stdout(open(os.devnull, 'w')) class PssError(BaseException): pass ############################################################################# # Bus class Bus: def __init__(self, id): if id is int:
for app_dir in reversed([APP_DIR, ADMIN_DIR, UTILS_DIR, META_DIR, LIB_DIR]): #BOTTLE_TEMPLATE_DIR, STATIC_DIR, add_to_syspath(app_dir) if 'Windows' in platform.platform(): import pssepath pssepath.ignore_python_mismatch = True # ==== sqlite3 options detect_types_arg = sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES # ==== db options SLURP_DB = os.path.join(APP_DIR, 'admin', 'slurp.db') COMPARE_DB = os.path.join(APP_DIR, 'admin', 'compare.db') JOB_TABLE = 'jobs' MSG_TABLE = 'msg' # ==== Psse options: PREF_PSSE_VER = None # this adds pssbin to system path. System path is global for all modules so # there is no need to run this in any files that import app_settings, just run # import psspy USE_CASPY = True if 'Windows' in platform.platform(): pssepath.add_pssepath(PREF_PSSE_VER) # python exec required for the selected psse. PYTHON_EXEC = pssepath.req_python_exec else: # If not windows, define this as just the currently running python. PYTHON_EXEC = sys.executable
def _initialize_psyops(): from . import config import os import sys from warnings import warn # If this __init__.py file is in ./psyops/ then import is within a source dir is_psyops_source_dir = (os.path.abspath(os.path.dirname(__file__)) == os.path.abspath('psyops') and os.path.exists('setup.py')) # try to import pssepath and pssypy try: import pssepath pssepath.add_pssepath() import psspy except: ret = _alt_init_psspy() print print 'init_psspy result:', ret def _alt_init_psspy(psse_ver_req=0, control_psse=True \ , pti_path='C:\\Program Files (x86)\\PTI' \ , bug_prt=False): ''' # _alt_init_psspy is an alternative psse/python initializer in case pssepath # is not available. # alternatively, you can use just the commented out lines of code directly # below, but it is less robust than pssepath. # for PSSE 32 and Python 2.5 #import sys #sys.path.append(r'C:\Program Files (x86)\PTI\PSSE32.2.2\PSSBIN') # dbl-check path #import psspy #import redirect #redirect.psse2py() # for PSSE 34 and Python 2.7 #import sys #sys.path.append(r'C:\Program Files (x86)\PTI\PSSE34\PSSBIN') # dbl-check path #import psspy #import redirect #redirect.psse2py() # init_psspy() # 1. Confirms user has required PSS/e version installed. # 2. Confirms user is running version of Python # required # 3. Initializes Python for PSSE interaction. # Returns list of [code, remark] #code: # + value = success # - value = error #remark: informational remark such as failure reason. # Parameters (inputs) # psse_ver_req: PSSE version required for this # script to function properly. # valid values are integers: 31, 32, 33, 34. # control_psse: # True: issue command: redirect.redirect.psse2py(). # False: do not issue the psse2py() command. ''' import sys import os errs=[] # run compatibility check? check_result=[1,'PSS//e and Python versions are compatible. '] # check passed until proven to failed cont=True if psse_ver_req==0: check_result=[2,'Compatibility check declined. '] cont=False # skip compatibility check # ----- Start: Check user PSSE and PY versions for compatibility) ----- # initialize variables psse_py = [[31,2.5],[32,2.5],[33,2.7],[34,2.7]] # psse/py compatibility # validate psse_ver_req parameter: is it a number if cont: try: psse_ver_req=int(float(psse_ver_req)) type(psse_ver_req) except: cont=False check_result=[-1,'psse_ver_req must be a version number from 31 to 34. '] if bug_prt: print check_result # validate psse_ver_req parameter: is it in the psse_py compatability list if cont: cont=False # don't cont compatibility check for i in range(len(psse_py)): if psse_py[i][0]==psse_ver_req: cont=True if not cont: check_result=[-1,'psse_ver_req must be a version number from 31 to 34. '] if bug_prt: print check_result py_ver=0 # get version number for python instance running now (sys.version command) if cont: try: py_ver = str(sys.version).split(' ')[0].split('.') #extract version from beginning of string py_ver = float(str(py_ver[0])+'.'+str(py_ver[1])) # keep only 1 level of subversioning, e.g., keep 2.5 from 2.5.3 if bug_prt: print 'set py_ver:', py_ver except: print r'Warning: init_psspy() had trouble determining python version number.' cont = False for i in range(len(psse_py)): if py_ver==psse_py[i][1]: cont=True if not cont: check_result=[-1,'Python version ' + str(py_ver) +' not compatible. '] if bug_prt: print check_result if bug_prt: print 'py_ver', py_ver # Find PSS/e installations if cont: # pti_path folder exists? if bug_prt: print 'Checking pti_path:', pti_path if not os.path.isdir(pti_path): check_result=[-3,r'Unable to find PSS/e installation folder "' + pti_path + '" on this computer. '] if bug_prt: print check_result print check_result cont = False # Find PSS/e folder(s) if cont: try: psse_paths = os.listdir(pti_path) # get all psse installation paths if bug_prt: print 'Found', len(psse_paths), r'PSS/e install paths: ', psse_paths except: check_result=[-4,r'Unable to find PSS/e installation folder on this computer. '] if bug_prt: print check_result cont = False # Get installed PSS/e version numbers from path # (e.g. path, 'C:\Program Files (x86)\PTI\PSSE32.2.2') if cont: psse_vers=[] psse_path='' for i in range(len(psse_paths)): # check each path for psse_ver_req if bug_prt: print 'path',psse_paths[i] x=str(psse_paths[i])[4:6] if bug_prt: print 'path ver:', x,'; psse_ver_req:',str(psse_ver_req) try: x=int(x) except: x=0 if 31<=x<=34 and str(psse_ver_req)==str(x): psse_path=psse_paths[i] # used later to load psspy library if bug_prt: print 'Found psse_path:',psse_path else: if bug_prt: print 'Did not find a psse_path in psse_paths:',psse_paths, 'where version = ',x if psse_path=='': check_result=[-5,r'Unable to find PSS/e installation folder on this computer. '] if bug_prt: print check_result cont = False # is psse / py version pair in compatibility list. cont = False if bug_prt: print 'Checking psse and python version against compatibility list.' for i in range(len(psse_py)): if bug_prt: print ' ', psse_py[i][0], psse_ver_req, py_ver, psse_py[i][1] if psse_py[i][0]==psse_ver_req and py_ver==psse_py[i][1]: cont = True if bug_prt: print ' Winner - psse and python versions are compatible!' break if not cont: check_result=[-6,'Python version ' + str(py_ver) \ + r' not compatible with PSS/e version ' \ + str(psse_ver_req) + '. Compatibility list. '] # + str(psse_py)<-compaibility list # ----- Done: Check user PSSE and PY versions for compatibility) ----- # ----- Start: Initialize python to interact with PSSE ----- if bug_prt: print ' Starting: Initialize python to interact with PSSE' if check_result[0]<1: if bug_prt: print r'Python - PSS/e compatibility check: ', check_result else: #compatibility check passed or was skipped check_result=[-7,'Unexpected error initializing libraries (sys, psspy and redirect). '] try: import sys check_result=[-8,'Imported sys library. Failed to import psspy and redirect. '] s= pti_path+'\\'+psse_path+"\PSSBIN" sys.path.append(s) if bug_prt: print r'attempting to add to sys.path:', s if bug_prt: print r'sys.path:',sys.path if bug_prt: print r'attempting to load psspy.' import psspy check_result=[4,'Imported sys and psspy libraries. '] if control_psse: if bug_prt: print r'attempting to load redirect.' check_result=[-9,'Imported sys and psspy libraries. Failed to import redirect. '] import redirect if bug_prt: print r'attempting to execute: redirect.psse2py()' redirect.psse2py() check_result=[5,r'Successfully configured Python to control PSS/e. '] if bug_prt: print check_result if bug_prt: print 'init_psspy() completed successfully. ', check_result except: if bug_prt: print 'init_psspy() failed, Code:', check_result if psse_ver_req==0: print r'init_psspy() failed. For more info, run w/PSSE version like: init_psspy(32)' if not bug_prt: print 'Consider setting bug_prt=False for verbose debugging comments.' print r'If that doesn\'t solve your problem, check your PSSE and Pyton installations.' print r'Check out this onenote article for more information:' help_page = r'onenote:///\\corp\shares\TransmissionServices\TSD,%20Shared%20Interest\OneNote%20Notebooks\Software%20Development\Python.one#PSS/E%20library%20for%20Toad§ion-id={A3CDFF46-74C6-4A36-B5F7-805ECC3539D9}&page-id={185CE924-9A62-4B5D-9921-1D2E4A30F244}&end' print help_page import urllib urllib.urlopen(help_page) return check_result # ----- Done: Initialize python to interact with PSSE ----- def _rollback_import(message): log.error(message) # Now disable exception logging to avoid an annoying error in the # exception logger before we raise the import error: _teardown_log() # Roll back any psyops sub-modules that have been imported thus # far for key in list(sys.modules): if key.startswith('psyops.'): del sys.modules[key] raise ImportError('psyops') if sys.version_info[0] >= 3 and is_psyops_source_dir: _rollback_import( "You appear to be trying to import psyops from within a source " "checkout. This is currently not possible using Python 3 due to " "the reliance of 2to3 to convert some of psyops's subpackages " "for Python 3 compatibility.") try: from .utils import _compiler except ImportError: if is_psyops_source_dir: _rollback_import( 'You appear to be trying to import psyops from within a ' 'source checkout; please run `./setup.py develop` or ' '`./setup.py build_ext --inplace` first so that extension ' 'modules can be compiled and made importable.') else: # Outright broken installation; don't be nice. raise
# File:"C:\Python27\Lib\site-packages\psyops\psse_compare.py", generated on TUE, APR 26 2016 14:20, release 32.02.02 ################################################################## # Initialize ################################################################## import pssepath pssepath.add_pssepath() import psspy import os compare_opt = \ {'bus identifiers':1 ,'bus type codes':2, \ 'machine status':3, 'generator MW':4, \ 'generator MW or MVAR':5, 'bus loads':6, \ 'bus shunts':7, 'switched shunts':8, \ 'voltage':9, 'voltage and angle':10, \ 'Mbase and Zsorce':11, 'Mbase and Zpos':12, \ 'Mbase and Zneg':13, 'Mbase and Zzero':14, \ 'negative sequence bus shunts':15, 'zero sequence bus shunts':16, \ 'branch status':17, "line R:'X:'B":18, \ 'line shunts':19, 'line ratings':20, \ 'metered end':21, 'transformers':22, \ 'flow MW or MVAR (from bus)':23, 'flow MW or MVAR (from & to)':24, \ 'line MW or MVAR losses':25, "zero sequence R:'X:'B":26, \ 'zero sequence line shunts':27, 'connection codes':28, \ 'zero sequence mutuals':29, 'multi-section lines':30, \ 'multi-section metered end':31, 'load status':32, \ 'line lengths':33, 'generator MVAR':34, \ 'flow MW (from bus)':35, 'flow MVAR (from bus)':36, \ 'flow MW (from and to)':37, 'flow MVAR (from and to)':38, \ 'line MW losses':39, 'line MVAR losses':40, \