2019-07-11 08:14:36 -0500
| answered a question | how to export ANSI values to txt Here is some code I use, hopefully you can leverage portions of it to save yourself some time. def __ANSI(self, out_file_identifier, out_file_path, subsystem):
ierr, busarray = self.psspy.abusint(subsystem, 1, 'NUMBER')
if ierr: return ierr
busarray = busarray[0]
# skip rerun
if not os.path.isfile(os.path.join(out_file_path, '%d_ANSI_rawData_tot.txt' % out_file_identifier)):
ierr = self.psspy.report_output(2, os.path.join(out_file_path,
'%d_ANSI_rawData_tot.txt' % out_file_identifier))
if ierr: return ierr
vltary = [1.05 for x in busarray if x]
cptary = [0.033 for x in busarray if x]
# total current
ierr = self.psspy.ansi_2([0, 0, 0, 5, 0], [40, 80, 40, 80], len(busarray), busarray, vltary, cptary, '')
if ierr > 0:
self.log('ERROR PERFORMING ANSI %s - Error code %s' % (out_file_identifier, ierr), 'error')
ierr = self.psspy.report_output(2, os.path.join(out_file_path,
'%d_ANSI_rawData_sym.txt' % out_file_identifier))
if ierr: return ierr
vltary = [1.05 for x in busarray if x]
cptary = [0.033 for x in busarray if x]
# symmetric current
ierr = self.psspy.ansi_2([0, 0, 0, 5, 1], [40, 80, 40, 80], len(busarray), busarray, vltary, cptary, '')
if ierr > 0:
self.log('ERROR PERFORMING ANSI %s - Error code %s' % (out_file_identifier, ierr), 'error')
else:
self.log('skipping %d_ANSI_rawData_tot.txt' % out_file_identifier)
def RunANSI_study(self):
self.log('Beginning ANSI portion of study...')
# trim tp specific to those in study
TP_specific_areas = list(set(int(x.area) for x in self.ansi_param))
# create a default subsystem
self.createSubsystemOfAreas(self.areas, sid=0)
# find all buses in default subsystem
study_buses = self.returnBusesInSubsystem(sid=0, in_service_only=False, bus_property='Number')
# make list of buses manageable size for PSS/E report window
self.log(' Segmenting %d study buses.' % len(study_buses))
study_buses = self.splitter(study_buses, chunk=100)
# loop thru lists of buses, create subsystems, and perform ANSI on them
self.log(' Created %d segments of size %d.' % (len(study_buses), len(study_buses[0])))
for i, segment_of_study_buses in enumerate(study_buses, 1):
self.createSubsystemOfBuses(segment_of_study_buses, 0)
self.log(' Running default ANSI for segment %d' % i)
self.__ANSI(i, self.report_dir, 0)
self.log('ANSI study complete.')
def processANSIresults(self, workbook, folder):
"""
:param workbook: Workbook to add results.
:param folder: Location of psse reports.
:return: Workbook with results included.
"""
if not hasattr(self, 'psspy'):
#self.init_psse()
self.init_psse()
#self.PSSEService.init_psse()
self.openCase(self.model_path)
ansi_results_sym, ansi_results_tot, ansi_tpspec = self.__compileANSIresults(folder)
workbook = self.__writeANSIresults(workbook, ansi_results_sym, 'Default-ANSI-Symm Curr Basis')
workbook = self.__writeANSIresults(workbook, ansi_results_tot, 'Default-ANSI-Total Curr Basis')
if ansi_tpspec:
workbook = self.__writeANSIresults(workbook, ansi_tpspec, 'TP-Criteria ANSI')
return workbook
def __compileANSIresults(self, folder):
""" Parses a folder and build ANSI results from PSSE ANSI report txt files."""
# get list of report filepaths
list_of_ansi_reports = glob.glob(os.path.join(folder, '*ANSI_rawData*.txt'))
self.log('Read in %d ANSI report files.' % len(list_of_ansi_reports))
list_of_ansi_reports_sym = [x for x in list_of_ansi_reports if 'sym' in os.path.basename(x)]
list_of_ansi_reports_tot = [x for x in list_of_ansi_reports if 'tot' in os.path.basename(x)]
list_of_ansi_reports_tp = [x for x in list_of_ansi_reports if 'TPSPEC' in os.path.basename(x)]
# file in memory
data = []
for report in list_of_ansi_reports_sym:
data_file = open(report, 'rU')
data.extend(data_file.readlines())
# parse ... (more) |
2018-12-08 19:31:38 -0500
| commented answer | How do I get the short circuit current with the ASCC_3 API? If you look in the api documentation, the ascc_currents command does not have an ierr in front of it like most of the other api calls.
You're probably looping thru an empty array named "current" |
2018-12-08 18:16:36 -0500
| answered a question | How to I get the contribution of neighboring buses, after the ascc_currents api runs? I generate a report when I run my ASCC analysis, the report always has the contributions listed for me. Are you running these manually or through the API? If you're using the API this may help you find a way to implement it: def __ASCC(self, out_file_identifier, out_file_path, subsystem, gen_scfiles=False):
"""
:param out_file_identifier: increments file names
:param out_file_path: gives folder to place reports in
:param subsystem: specifies subsystem id for psspy.ascc api
:param gen_scfiles: option flag for scfile output of psspy.ascc api
:return:
"""
if not os.path.isfile(os.path.join(out_file_path, '%d_ASCC_rawData.txt' % out_file_identifier)):
self.log('Running ASCC for segment %d' % out_file_identifier)
ierr = self.psspy.report_output(2, os.path.join(out_file_path, '%d_ASCC_rawData.txt' % out_file_identifier))
if ierr: self.log('Error on ASCC reporting for segment %s ierr %s' % (out_file_identifier, ierr), 'error')
# class fault analysis conditions
# ierr = self.psspy.flat_2([1, 1, 1, 2, 1, 2, 1, 3], [1, 1])
if gen_scfiles:
if not os.path.exists(os.path.join(out_file_path, 'scfiles')):
os.makedirs(os.path.join(out_file_path, 'scfiles'))
scfile_path = os.path.join(out_file_path, 'scfiles', '%d_scfile.sc' % out_file_identifier)
else:
scfile_path = ""
# this flats the case and stuff
ierr = self.psspy.ascc_3(subsystem, 0, [1, 1, 0, 1, 0, 2, 0, 1, 0, 1, 1, 0, 0, 2, 2, 1, 1], [1],
'', '', scfile_path)
if ierr: self.log('Error on ASCC segment %s ierr %s', 'error')
else:
self.log('skipping %d_ASCC_rawData.txt' % out_file_identifier)
|
2018-11-08 10:11:27 -0500
| answered a question | How do I get the short circuit current with the ASCC_3 API? ASCC_CURRENTS should return an array you can parse. Do you have the code you tried to use to implement that? |
2018-04-15 22:40:31 -0500
| received badge | ● Teacher
(source)
|
2018-01-17 10:52:30 -0500
| commented answer | Automated Simulation for System Losses numpy.arange([start, ]stop, [step, ]dtype=None)
in your case nump.arange(0,25,0.1)
looks like this returns an array, you'd loop thru the values in the array
for load in array:
run the recorded stuff and store losses
np.savetxt('test.csv', first_layer_output, delimiter=',', fmt='%s') |
2017-12-21 17:46:18 -0500
| answered a question | Storing PSSE data in python variables I think you can use ierr = report_output(islct, filarg, options) |
2017-12-13 11:42:31 -0500
| answered a question | No module named psspy with psse33 Does this work? def init_psse(self, vsn=32):
"""
Inits PSSE to version of parent service.
"""
# PSSE initialization routine.
self.PSSE_VERSION == 33
if self.PSSE_VERSION == 32:
# this loops takes into account both the 32 and 64 bit registries, fixing an issue, where trying to run python code through certain IDEs wouldn't work.
try:
pssepath, regtype = _winreg.QueryValueEx(
_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\PTI\\PSS\xaeE 32\\Product Paths", 0,
_winreg.KEY_READ), "PsseInstallPath")
except WindowsError:
pssepath, regtype = _winreg.QueryValueEx(
_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\\Wow6432Node\\PTI\\PSS\xaeE 32\\Product Paths", 0,
_winreg.KEY_READ), "PsseInstallPath")
elif self.PSSE_VERSION == 33:
try:
pssepath, regtype = _winreg.QueryValueEx(
_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\PTI\\PSSE 33\\Product Paths", 0, _winreg.KEY_READ),
"PsseInstallPath")
except WindowsError:
pssepath, regtype = _winreg.QueryValueEx(
_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\\Wow6432Node\\PTI\\PSSE 33\\Product Paths", 0,
_winreg.KEY_READ), "PsseInstallPath")
sys.path.append(os.path.join(pssepath, 'PSSBIN'))
sys.path.append(os.path.join(pssepath, 'PSSLIB'))
os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSBIN')
os.environ['PATH'] += ';' + os.path.join(pssepath, 'PSSLIB')
if "PTI\PSSE" not in pssepath:
self.log("ERROR: Cannot find PSS(R)E Version %i." % self.PSSE_VERSION, 'error')
sys.exit()
import psspy
import redirect
|
2017-12-13 11:31:39 -0500
| answered a question | Storing Short Circuit Analysis Data Approximation of how I do this: Running Short circuit and building lots of text files: def splitter(self, inputlist, chunk=100):
""" Breaks inputlist into a list of lists with size chunk."""
chunks = [inputlist[x:x + chunk] for x in range(0, len(inputlist), chunk)]
return chunks
def RunASCC_study(self, options):
ascc_results = []
# create subsystem of areas in user input
self.createSubsystemOfAreas(options['Areas'])
# find all buses in study areas
study_buses = self.returnBusesInSubsystem(sid=0, in_service_only=False, bus_property='Number')
# make list of buses manageable size for PSS/E report window
self.log('Segmenting %d study buses.' % len(study_buses))
study_buses = self.splitter(study_buses, chunk=100)
# loop thru lists of buses, create subsystems, and perform ASCC on them
self.log('Created %d segments of size %d.\nPerforming ASCC portion of study.' % (
len(study_buses), len(study_buses[0])))
for i, segment_of_study_buses in enumerate(study_buses, 1):
self.createSubsystemOfBuses(segment_of_study_buses, sid=0)
self.log('Running ASCC for segment %d' % i)
self.__ASCC(i, self.report_directory, 0)
def __ASCC(self, out_file_identifier, out_file_path, subsystem, gen_scfiles=False):
"""
:param out_file_identifier: increments file names
:param out_file_path: gives folder to place reports in
:param subsystem: specifies subsystem id for psspy.ascc api
:param gen_scfiles: option flag for scfile output of psspy.ascc api
:return:
"""
ierr = self.psspy.report_output(2, os.path.join(out_file_path, '%d_ASCC_rawData.txt' % out_file_identifier))
if ierr: self.log('Error on ASCC segment %s ier %s' % (out_file_identifier, ierr), 'error')
# class fault analysis conditions
# ierr = self.psspy.flat_2([1, 1, 1, 2, 1, 2, 1, 3], [1, 1])
if gen_scfiles:
if not os.path.exists(os.path.join(out_file_path, 'scfiles')):
os.makedirs(os.path.join(out_file_path, 'scfiles'))
scfile_path = os.path.join(out_file_path, 'scfiles', '%d_scfile.sc' % out_file_identifier)
else:
scfile_path = ""
ierr = self.psspy.ascc_3(subsystem, 0, [1, 1, 0, 1, 0, 2, 0, 1, 0, 1, 1, 0, 0, 2, 2, 1, 1], [1],
'', '', scfile_path)
if ierr: self.log('Error on ASCC segment %s' % out_file_identifier, 'error')
Parsing text files: def __compileASCCresults(self, folder):
"""
Parses a folder and build ASCC results from PSSE ASCC report txt files.
:param folder: Directory of containing psse reports.
:return: List of result objects.
"""
# get list of report filepaths
list_of_ascc_reports = []
for txtfile in os.listdir(folder):
if txtfile.endswith("ASCC_rawData.txt"):
list_of_ascc_reports.append(os.path.join(folder, txtfile))
# file in memory
data = []
for report in list_of_ascc_reports:
data_file = open(report, 'rU')
data.extend(data_file.readlines())
# parse file
list_of_result_objects = []
options = []
while data:
line = data.pop(0)
line = line.rstrip().rstrip('\r\n')
# build options
if line.upper().startswith('OPTIONS USED'):
# only need options once because its the same
if not options:
options.append(line)
line = data.pop(0).rstrip().rstrip('\r\n')
while line:
options.append(line.split('-', 1)[1])
line = data.pop(0).rstrip().rstrip('\r\n')
else:
pass
# build fault result objects
temp_list = []
if line.startswith('AT BUS'):
while line != "-----------------------------------------------------------------------------------------------------------------------------------------------":
temp_list.append(line)
line = data.pop(0).rstrip().rstrip('\r\n')
list_of_result_objects.append(self.ASCCfaultResult(temp_list, options, self.log))
self.log('Read in %d ASCC data files.' % len(list_of_ascc_reports))
return list_of_result_objects
class ASCCfaultResult():
""" Creates an object from a list of text lines ... (more) |
2017-08-21 12:42:40 -0500
| commented answer | Python win32com http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32
One of these:
pywin32‑221‑cp27‑cp27m‑win32.whl
pywin32‑221‑cp27‑cp27m‑win_amd64.whl
Depending on if you have 32 or 64 bit windows. |
2017-08-21 08:08:42 -0500
| answered a question | Python win32com win32com.client is a part of pywin32 You can download pywin32 from here |
2017-08-03 12:55:11 -0500
| commented answer | How to do dynamic simulation to test the transient stability of power system? |
2017-07-25 12:57:39 -0500
| answered a question | How to get three-winding transformer power flow Have you considered WNDDAT. It can return percent current or MVA loading of 3 winding transformer. |
2017-07-21 10:40:38 -0500
| answered a question | Bus number too long, workaround I tried to create some 7 digit numbers, looks like you're limited to 6 digits. You can use commenting to make a "memo" field in raw files to preserve a lookup to your original 7 digit numbers if you want to do that. Here's an example of what I do: 1234 'bus name ' 138.00 1 1 1 1 1.0247 2.435 /* [bus name ] */
|
2017-07-20 10:03:39 -0500
| commented answer | AttributeError: 'module' object has no attribute 'workbook' year,busnum,busname,change,tla,location = row[0:760] would need to be something like this
year, busnum = row[0:20], row[21:29] |
2017-07-19 13:57:56 -0500
| commented answer | AttributeError: 'module' object has no attribute 'workbook' You would need to open an existing file. I would expect to see something like this.
xlsfile = r'C:\Desktop\data.xls'
testxls = excelpy.workbook(xlsfile, mode='r') |
2017-07-19 13:14:07 -0500
| answered a question | AttributeError: 'module' object has no attribute 'workbook' Where do you assign a value to xlsfile? To elaborate: 'r' is specifying read on an existing file. From the documentation: (1) When used to create new Excel files or add worksheets to existing Excel files:
testxls = excelpy.workbook()
testxls = excelpy.workbook(r"c:\working dir\ex1.xls")
testxls = excelpy.workbook(r"c:\working dir\ex1.xls", "MySheet") or
testxls = excelpy.workbook(r"c:\working dir\ex1.xls", "MySheet", False) or
testxls = excelpy.workbook(r"c:\working dir\ex1.xls", "MySheet", False, 'w') or
testxls = excelpy.workbook(xlsfile=r"c:\working dir\ex1.xls", sheet="MySheet",
overwritesheet=False, mode='w')
(2) When used to read existing Excel files:
testxls = excelpy.workbook(r"c:\working dir\ex1.xls", mode='r')
|
2017-06-29 15:32:45 -0500
| answered a question | PSS/E 32 Script Incompatible with v33 |
2017-06-27 08:25:07 -0500
| commented answer | how to convert sld ver.33 to ver.32 I think he's recommending saving the model in another version and recreating the slider. |
2017-06-19 09:37:12 -0500
| answered a question | Graphical display Short Circuit Analysis I received some answers from PTI, summary below. Manual display of the ASCC fault analysis requires changing the diagram to display the ASCC fault analysis results. There is a toolbar button titled "Display ASCC fault analysis results." Screenshot showing location : https://ptisupport.ptd.siemens.com/fi...Customer/Schermerhorn/417451/ascctoolbar_shortcut.PNG API wise for scripts, this can be accomplished by using setdiagresascc_3() and setdiagrestypeascc() via the psspy module to display your results. See Chapter 6 of the API manual for further documentation. |
2017-06-15 09:25:32 -0500
| received badge | ● Enthusiast
|
2017-06-14 12:24:04 -0500
| answered a question | Why psse turn off every time I try to run dynamic simulation !..? What version of windows and PSSE. |
2017-06-01 09:23:05 -0500
| answered a question | How much of a 200 hour license does a typical study consume This depends greatly on the study. I have done short circuit studies which take 4 hours, and powerflow and dynamic studies which take 1000+ and require automation across multiple licenses. |
2017-06-01 09:21:44 -0500
| received badge | ● Editor
(source)
|
2017-06-01 09:21:25 -0500
| answered a question | How do I export short circuit data(.sc) to an excel file using pss/e and python? I don't have an example for this portion but you would use the command ASCC_SCFILE, this imports your scfile. I do have an example for running Short Circuit itself and exporting this data with the ASCCCURRENTS command.
The parameters would be set according to your situation.
rlst = pssarrays.ascccurrents(subsystem, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 2, 2, 1, 1, 1, '', '', '') This returns an object which you can access such as:
print rlst.fltbus[0]
print rlst.thevzpu[0].z1
print rlst.fltlg[0].ia
print rlst.flt3ph[0].ia2 Hopefully this gives you a starting point. |
2017-05-28 19:56:53 -0500
| received badge | ● Popular Question
(source)
|
2017-05-28 19:56:53 -0500
| received badge | ● Famous Question
(source)
|
2017-05-28 19:56:53 -0500
| received badge | ● Notable Question
(source)
|
2017-05-26 09:52:46 -0500
| asked a question | Graphical display Short Circuit Analysis The PSSE API documentation says that the command ASCC3 has a parameter SCFILE, which creates the ASCC3 results file. The command ASCC_SCFILE then says that "This API reads ASCC short circuit results from SCFILE and produces same ASCC output report that was generated when SCFILE was created. SCFILE is read into PSS®E memory to enable displaying ASCC results onto slider diagrams." When I manually or via python apply ASCC faults I don't see any change to the slider diagram. When I create and reopen SC files I don't see any changes made to the slider. I am unsure how to make these results appear in the slider. |
2017-05-25 16:04:28 -0500
| answered a question | PSSE manual |
2017-05-25 15:52:51 -0500
| commented answer | How to estimate the maximum asymmetric short circuit current? Jervis, have you attempted to generate any graphical results from an ASCC routine?
The PSSE api doc shows command ASCC has a parameter scfile which creates scfile. The PSSE api doc then shows command ASCC_SCFILE can read this file into memory to enable displaying ASCC results onto slider diagrams. |