You are on page 1of 82

Python

In Powerflow & Short-circuit Analysis Tool

User Manual

A product of

Powertech Labs Inc.


Surrey, British Columbia
Canada
www.powertechlabs.com
www.DSATools.com

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.
PSAT Python User Manual

DISCLAIMER OF WARRANTIES AND LIMITATION OF LIABILITIES

THIS SOFTWARE AND ITS DOCUMENTATION WERE PREPARED BY POWERTECH LABS, INC.
(PLI). NEITHER PLI, ANY COSPONSOR, NOR ANY PERSON ACTING ON BEHALF OF ANY OF
THEM:

(A) MAKES ANY WARRANTY OR REPRESENTATION WHATSOEVER, EXPRESS OR IMPLIED,


(I) WITH RESPECT TO THE USE OF ANY INFORMATION, APPARATUS, METHOD,
PROCESS, OR SIMILAR ITEM DISCLOSED IN THIS DOCUMENT, INCLUDING
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, OR (II) THAT SUCH
USE DOES NOT INFRINGE ON OR INTERFERE WITH PRIVATELY OWNED RIGHTS,
INCLUDING ANY PARTY'S INTELLECTUAL PROPERTY, OR (III) THAT THIS DOCUMENT IS
SUITABLE TO ANY PARTICULAR USER'S CIRCUMSTANCE; OR

(B) ASSUMES RESPONSIBILITY FOR ANY DAMAGES OR OTHER LIABILITY WHATSOEVER


(INCLUDING ANY CONSEQUENTIAL DAMAGES, EVEN IF PLI OR ANY PLI
REPRESENTATIVE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES)
RESULTING FROM YOUR SELECTION OR USE OF THIS DOCUMENT OR ANY
INFORMATION, APPARATUS, METHOD, PROCESS, OR SIMILAR ITEM DISCLOSED IN THIS
DOCUMENT.

PSAT PYTHON program and its documentation are confidential property of Powertech Labs Inc. This
Program is protected under the copyright laws and by application of international treaties. All Rights
Reserved under the Copyright Laws.

Except as expressly provided by the terms and conditions set forth in the License, the LICENSEE
shall not:
(a) distribute or disclose the Program, Documentation or Derivative Work thereof to others;
or
(b) disclose the Proprietary Information associated with or embodied in the Program and
Documentation in any form whatsoever;
Without prior written consent of Powertech Labs Inc.

The LICENSEE shall not use the program except as expressly provided by the conditions of
LICENSE TYPE in the License.

Copyright Powertech Labs Inc. 2002−2020

Last modified – April 2020

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. i


PSAT Python User Manual

CONTENTS Page
1. Introduction .......................................................................................................................1
2. Imported Modules .............................................................................................................1
3. Error Argument ................................................................................................................1
4. Data Structures..................................................................................................................2
4.1 PSAT Component Data Structures ...............................................................................2
4.2 PSAT Component ID Structure ....................................................................................2
5. Get and Set Bus Data.........................................................................................................4
6. Get and Set Generator Data..............................................................................................6
7. Get and Set Load Data ......................................................................................................8
8. Get and Set Load Model Data ......................................................................................... 10
9. Get and Set Fixed Shunt Data ......................................................................................... 11
10. Get and Set Switchable Shunt Data ................................................................................ 12
11. Get and Set Line Data ..................................................................................................... 14
12. Get and Set Fixed Transformer Data ............................................................................. 16
13. Get and Set Adjustable Transformer Data .................................................................... 19
14. Get and Set Impedance Correction Table Data ............................................................. 22
15. Get and Set 3-Winding Transformer Data ..................................................................... 23
16. Get and Set Fixed Series Compensator Data.................................................................. 27
17. Get and Set Adjustable Series Compensator Data ......................................................... 30
18. Get and Set Static Tap Changer / Phase Regulator Data .............................................. 32
19. Get and Set DC Bus Data ................................................................................................ 35
20. Get and Set DC Converter Data ..................................................................................... 36
21. Get and Set Voltage Source Converter Data .................................................................. 38
22. Get and Set DC Line Data ............................................................................................... 41
23. Get and Set DC Breaker Data ......................................................................................... 43
24. Get and Set Area Data..................................................................................................... 44
25. Get and Set Zone Data .................................................................................................... 45
26. Get and Set Owner Data ................................................................................................. 46
27. Get and Set Node Data .................................................................................................... 47
28. Get and Set Zero Sequence Coupling Data .................................................................... 48
29. Get and Set Node Breaker Station .................................................................................. 49
30. Get and Set Node Breaker Busbar .................................................................................. 50
31. Get and Set Node Breaker Node ..................................................................................... 51
32. Get and Set Node Breaker Connector ............................................................................ 52
33. Get and Set Component’s Node Data ............................................................................. 54
34. Get and Set Case Data ..................................................................................................... 55
35. Get Short Circuit Data .................................................................................................... 57
36. Get WSCR Data .............................................................................................................. 58
37. Get and Set Criteria File ................................................................................................. 59
38. Get and Set Properties .................................................................................................... 59
39. Add and Delete Components........................................................................................... 62
40. Add and Delete Sectional Branches ................................................................................ 64
41. Counting Sections of a Branch ........................................................................................ 65
42. Get a Section of a Branch ................................................................................................ 65
43. Get Solution Status .......................................................................................................... 66
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. ii


PSAT Python User Manual

44. Set Solution Failure Option............................................................................................. 66


45. Disable Engine Messages ................................................................................................. 67
46. Subsystems ....................................................................................................................... 67
46.1 Subsystem Definition.................................................................................................. 67
46.2 Subsystem Deletion .................................................................................................... 67
46.3 Subsystem Include and Exclude ................................................................................. 68
46.4 Iteration on Subsystem Components ........................................................................... 70
46.5 Subsystem Count ........................................................................................................ 71
47. Equipment Name Commands ......................................................................................... 71
48. Executing PSAT Commands ........................................................................................... 74
49. Executing PSAT Print Messages ..................................................................................... 74
50. Executing PSAT Read Input ........................................................................................... 76
51. User Written Functions ................................................................................................... 77
52. Debugging Python Functions Within PSAT ................................................................... 78

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. iii


PSAT Python User Manual

1. Introduction
PSAT supports the use of Python programs. Python is a powerful and popular programming language,
which can be freely downloaded from http://www.python.org. This site provides valuable information on
Python and includes tutorials to help you become familiar with this tool.

For use in PSAT, you need to download the latest version of Python 2.7, Python 3.4 or Python 3.8 from
http://www.python.org and install it on your computer. While installing a new version of python
remember to make a new environmental variable namde “Python[XX]_64_DIR” pointing to the location
of the python in you system, where [XX] designates the Python version supported (27, 34 or 38). You
must specify which python version to use from the Scripts menu in PSAT.

Python modules named psat_python[XX] are provided with PSAT, where [XX] designates the Python
version supported (27, 34 or 38). These modules include the functions that you can call from a Python
program to obtain powerflow data, change powerflow data, solve powerflow, etc. You write a Python
program, using these PSAT functions and any other Python feature, and you run it within PSAT.

Running PSAT Python programs in PSAT is similar to running PSAT Macros from file. You must first
save the program in a Python file (with extension .py) and use the Run Python File option from the
Scripts menu to run the saved file.

2. Imported Modules
When you invoke Python within PSAT, modules sys and psat_python[XX] (where [XX] is the Python
version) are automatically “imported”, so you don’t need to “import” these in every PSAT Python
program. The following sections describe the data structures and functions provided in psat_python.
The functions in this module can be called, for example, as:

_psat_python[XX].subsys_clear ()
or
subsys_clear ()

The _psat_python[XX]. prefix is not necessary, unless you may want to import other modules that
might have functions with similar names as psat_python functions.

You can write your own Python functions and call them from other scripts as described in section 51

3. Error Argument
Most PSAT Python functions have a psat_error class argument that returns an error in two attributes:

error.code: is an integer error code (0: no error, >0: error number)


error.msg: is a string error message
You may create this object for use as an argument for psat_python functions by the following statement:

error = psat_error()
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 1


PSAT Python User Manual

4. Data Structures

4.1 PSAT Component Data Structures

The set_*_dat and add_comp functions described below require an argument that is a PSAT Component
Data Structure (psat_*_dat) class. This argument specifies the values for the attributes of the object that
will be set (modified) or added by these functions. These objects can be created by assigning a PSAT
Data Structure. For example, a bus object is created by:

busdat = psat_bus_dat()

Note that this assignment does not accept arguments. It sets defaults for all attributes (described below)
of busdat object. You need to assign a proper value to each attribute (e.g., busdat.number, busdat.name,
etc.) before giving it to the set_bus_dat or add_comp functions.

These objects are also created by calling the get_*_dat functions, as in:

busdat = get_bus_dat(“ABC”, error)

In this case, busdat gets the attributes of bus “ABC”. You can then change some of the attributes and give
busdat to the set_bus_dat (to change the attributes of the existing bus) or add_comp (to add a new bus).

The same applies to other objects, e.g., load, line, etc.

All PSAT Component Data Structures (psat_*_dat) have a function called comp_id() that returns a
psat_comp_id that can represent the component in other PSAT python function that take a psat_comp_id
structure. For more details on the psat_comp_id structure refer to section 4.2.

4.2 PSAT Component ID Structure

Many PSAT python functions (get/set_*_dat, get/set_*_prop, get_next_comp, etc.) take or return a
psat_comp_id structure. This structure is used to uniquely identify an individual component (AC Bus,
Line, Generator, etc.) in the powerflow. It only contains identifying component attributes (such as
component type, bus connections, id, etc.) and does not contain any specific property attributes (such as
voltage levels, flows, limits, etc).

The attributes of the psat_comp_id structure are described below:

psat_comp_id Note that there are two groups of attributes for AC and DC component
“types”. The DC attributes are ignored for AC components and vice versa
(except for “bus” and “bus2”, which are required to identify Converters and
VSCs).

type component type (string), which is one of:


bus or bs
generator or gen
load or ld
fixed_shunt or fxsh
switchable_shunt or swsh
line or ln
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 2


PSAT Python User Manual

fixed_transformer or fxtr
adjustable_transformer or ultc
three_winding_transformer or twtr
fixed_series_compensator or fxsc
adjustable_series_compensator or vrsc
static_tap_changer_phase_regulator or stcpr
dc_bus or dcbs
dc_converter or cnvrtr
voltage_source_converter or vsc
dc_line or dcln
dc_breaker or dcbrkr
area or ar
zone or zn
owner or own
node or nd
z_seq_coupling or zseq
nb_station or nbst
nb_busbar or nbbb
nb_node or nbnd
nb_connector or nbcn

Alternatively, compid.type can be specified as an integer for example:


ctype.bus, ctype.gen, etc., described in more detail below.
(computation is faster using the integer ctype.* values)

bus bus number of the AC component, or first-bus number for multi-bus


AC components (Also used to specify Area, Zone, and Owner number,
as well as Z-Seq Couplings Line1 To-bus)
bus2 second-bus number of the AC component for multi-bus components
(Also used to specify Z-Seq Couplings Line1 From-bus)
bus3 third-bus number of 3- or 4-bus AC components, or AC bus of DC
converters (Also used to specify Z-Seq Couplings Line2 To-bus)
bus4 forth-bus number of 4-bus AC components, or the second AC bus of
voltage source converters(Also used to specify Z-Seq Couplings Line2
From-bus)
(bus, bus2, bus3 and bus4 must be specified in the correct order)
id ID of AC component (string)
eqname component equipment name (required for get/set_node_dat functions)
secno section number when the component is a sectional branch

dcbus1 DC bus name of the component, or first-DC-bus name for multi-bus


DC components (Also used to specify Z-Seq Couplings Line1 ID)
dcbus2 second-DC-bus name for multi-bus DC components(Also used to
specify Z-Seq Couplings Line2 ID)
dcid ID of DC component (int)

nodes (struct) 1. nd1 - Node of the component


2. nd2 - Node of the component
3. nd3 - Node of the component
4. ndRemote1 - Remote Node of the component

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 3


PSAT Python User Manual

5. ndRemote2 - Remote Node of the component


6. ndRemote3 - Remote Node of the component
This struct can be modified using “Get and Set Component’s Node
Data” functions

The psat_comp_id structure can be initialized for the various component types by passing in the required
properties to uniquely identify that component. For example to initialize for AC Bus number 123:

acbus_id = psat_comp_id(ctype.bus,123)

Or for example to initialize for an AC line between buses 1 and 8 with an ID of ‘1’:

acline_id = psat_comp_id(“line”, 1, 8, ‘1’)

The component type can be specified as either a string or integer (ctype.*) value, all AC buses must be
specified by their bus number (integer) and DC buses by name (string).

Currently the psat_comp_id equipment name attribute ‘eqname’ is only used in searching for node
components, for all other components it is only a return value set by PSAT.

For specific situations the psat_comp_id structure can be initialized with a ‘type’ value only, as is
required by some functions like the subsystem function ‘get_next_comp’.

5. Get and Set Bus Data


The following function returns the data of a bus in the powerflow data.

get_bus_dat (busid, error)

Where

busid Is the number (integer) or name (string) or psat_comp_id (structure) of the


bus.
error Is the returned error (psat_error class).
If busid exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg: 1, ’Bus is not found.’

Returned values Data of bus busid, in psat_bus_dat structure, with the following attributes:
number bus number
name bus name
eqname bus equipment name
basekv base kV
type bus type 1: load bus, 2: gen bus, 3: swing bus, 4: out of service bus
vmag voltage magnitude in pu
vang voltage angle in degree

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 4


PSAT Python User Manual

vreal real part of complex voltage in pu (=vmag*cos(vang))


vimag imaginary part of complex voltage in pu (=vmag*sin(vang))
area area number
zone zone number
owner owner number
userdata any miscellaneous user defined data

For example,

error = psat_error()
busno = 123
busdat = get_bus_dat (busno, error)

Returns:

busdat.number: 123
busdat.name: ’ABCD 110.’
busdat.basekv: 110.
. . . etc.
error.code: 0

But if bus 123 doesn’t exist, the returned busdat is unknown and error.code is 1.

The following function sets (changes) the data of a bus in the powerflow data.

set_bus_dat (busid, busdat, error)

Where

busid Is the number (integer) or name (string) or psat_comp_id (structure) of the


bus.
busdat Is the new data for bus busid, in psat_bus_dat structure (as above).
If busdat.number (or busdat.name) is different from busid, the bus is re-
numbered (or renamed) to the new busdat.number (or busdat.name).
busdat.vreal and busdat.vimag values are ignored (voltage is set by
busdat.vmag and busdat.vang)
error Is the returned error (psat_error class).
If the powerflow data is set to busdat,
error.code, error.msg: 0, ’’
If busid doesn’t exists,
error.code, error.msg: 1, ’Bus is not found.’
If busdat.number is different from busid and another bus with this number
already exists in the powerflow data,
error.code, error.msg: 2, ’New bus number already exists.’
If busdat.area doesn’t exists,
error.code, error.msg: 3, ’Area is not found.’
If busdat.zone doesn’t exists,
error.code, error.msg: 4, ’Zone is not found.’
If busdat.owner doesn’t exists,
error.code, error.msg: 5, ’Owner is not found.’
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 5


PSAT Python User Manual

If busdat has invalid (unacceptable) values,


error.code, error.msg: 6, ’New bus data is invalid.’

Returned values None

For example,
error = psat_error()
busno = 123
busdat = get_bus_dat (busno, error)

busdat.type = 1
busdat.vmag = 1.0
busdat.vang = 0.0
busdat.area = 5
busdat.zone = 51
set_bus_dat (busno, busdat, error)

changes the type of bus 123 to “load bus”, its voltage to (1.0, 0.0) and its area and zone to 5 and 51
(powerflow data must have area 5 and zone 51 for this bus data to be acceptable).

6. Get and Set Generator Data


The following functions return the data of a generator in the powerflow data.

get_gen_dat (busid, genid, error)

get_gen_dat (gen_compid, error)

Where

busid Is the number (integer) or name (string) of the generator bus.


genid Is the generator ID (string).
gen_compid Is the psat_comp_id (structure) of a generator
error Is the returned error (psat_error class).
If generator genid at bus busid exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg: 1, ’Generator is not found.’

Returned values Data of the generator, in psat_gen_dat structure, with the following
attributes:
bus generator bus number
id generator id
eqname generator equipment name
status generator status (1: in service, 0: out of service)
basemva generator base MVA
mw MW output
mwmax maximum MW

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 6


PSAT Python User Manual

mwmin minimum MW
mvar MVAr output
mvarmax maximum MVAr
mvarmin minimum MVAr
openvar open MVAr limit (1: Yes, 0: No)
vhi upper limit of terminal voltage in pu
vlo lower limit of terminal voltage in pu
rembus remote controlled bus number (0: no remote bus)
vrem scheduled voltage of remote controlled bus
varshare share of the generator for control of the remote bus
rgen generator internal resistance in pu of generator base MVA
xgen generator internal reactance in pu of generator base MVA
rtrnsf step-up transformer resistance in pu of generator base MVA
xtrnsf step-up transformer reactance in pu of generator base MVA
taptransf step-up transformer tap ratio in pu
wmcm wind machine MVAr control mode
0:N/A,1:QT&QB,2:MW&GWPF,3:Fixed
wmpf wind machine power factor
govbl governor base load 0: No, 1: Yes
owner(0:3) generator owners 1 to 4
ownfrac(0:3) generator owner fractions 1 to 4
inr N-seq resistance
inx N-seq reactance
izr Z-seq resistance
izx Z-seq reactance
ipr pos-seq resistance
ipx pos-seq reactance
igr grounding resistance
igx grounding reactance

The following functions set (change) the data of a generator in the powerflow data.

set_gen_dat (busid, genid, gendat, error)

set_gen_dat (gen_compid, gendat, error)

Where

busid Is the number (integer) or name (string) of the generator bus.


genid Is the generator ID (string).
gen_compid Is the psat_comp_id (structure) of a generator
gendat Is the new data for the generator, in psat_gen_dat structure (as above).
If gendat.bus is different from busid, the generator is moved from busid to
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 7


PSAT Python User Manual

gendat.bus.
If gendat.id is different from genid, the ID of generator is set to the new
gendat.id.
error Is the returned error (psat_error class).
If the powerflow data is changed to gendat,
error.code, error.msg: 0, ’’
If the generator genid at busid doesn’t exist in the powerflow data,
error.code, error.msg: 1, ’Generator is not found.’
If gendat.bus doesn’t exist in the powerflow data,
error.code, error.msg: 2, ’New generator bus is not found.’
If gendat has invalid (unacceptable) values,
error.code, error.msg: 3, ’New generator data is invalid.’
If gendat has invalid node,

Returned values None

7. Get and Set Load Data


The following functions return the data of a load in the powerflow data.

get_load_dat (busid, loadid, error)

get_load_dat (load_compid, error)

Where

busid Is the number (integer) or name (string) of the load bus.


loadid Is the load ID (string).
load_compid Is the psat_comp_id (structure) of a load
error Is the returned error (psat_error class).
If load loadid at bus busid exists in the powerflow data,
error.code, error.msg : 0, ’’
Otherwise,
error.code, error.msg : 1, ’Load is not found.’

Returned values Data of the load, in psat_load_dat structure, with the following attributes:
bus load bus number
id load id
name load name
eqname load equipment name
status load status 0: out, 1: in
owner load owner
area load area
zone load zone
refmw reference MW load

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 8


PSAT Python User Manual

refmvar reference MVAr load


nommw nominal MW load (at 1 pu voltage)
nommvar nominal MVAr load
mw actual MW load (at current voltage)
mvar actual MVAr load
cp[0:4] real part of load components 1 to 5
cq[0:4] reactive part of load components 1 to 5
cm[0:4] model number of load components 1 to 5
0: out (no load)
1: constant power
2 :constant current
3: constant impedance
k: exponential model number k (k>0)

nsg n-seq conductance


nsx n-seq suseptance
zsg z-seq conductance
zsx z-seq suseptance
scalable scalable flag. 1: ‘yes’, 2: ‘no’

The following functions set (change) the data of a load in the powerflow data.

set_load_dat (busid, loadid, loaddat, error)

set_load_dat (load_compid, loaddat, error)

Where

busid Is the number (integer) or name (string) of the load bus.


loadid Is the load ID (string).
load_compid Is the psat_comp_id (structure) of a load
loaddat Is the new data for the load, in psat_load_dat structure (as above).
If loaddat.bus is different from busid, the load is moved from busid to
loaddat.bus.
If loaddat.id is different from loadid, the ID of load is set to the new
loaddat.id.
The nommw, nommvar, mw and mvar attributes of loaddat are ignored
(since these are calculated form the load component data).
error Is the returned error (psat_error class).
If the powerflow data is changed to loaddat,
error.code, error.msg: 0, ’’
If the load loadid at busid doesn’t exist in the powerflow data,
error.code, error.msg: 1, ’Load is not found.’
If loaddat.bus doesn’t exist in the powerflow data,
error.code, error.msg: 2, ’New load bus is not found.’
If loaddat has invalid (unacceptable) values,
error.code, error.msg: 3, ’New load data is invalid.’

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 9


PSAT Python User Manual

Returned values None

8. Get and Set Load Model Data


The following function returns the data of a load model in the powerflow data.

get_load_model_dat (ldmdl, error)

Where

ldmdl Is the number (integer) of the load model.


error Is the returned error (psat_error class).
If load model ldmdl exists in the powerflow data,
error.code, error.msg : 0, ’’
Otherwise,
error.code, error.msg : 1, ’Load model is not found.’

Returned values Data of the load model, in psat_load_model_dat structure, with the
following attributes:
number load model number
pc(0:2) P coefficients 1 to 3
pe(0:2) P exponents 1 to 3
qc(0:2) Q coefficients 1 to 3
qe(0:2) Q exponents 1 to 3

The following function sets (changes) the data of a load model in the powerflow data.

set_load_model_dat (ldmdl, ldmdldat, error)

Where

ldmdl Is the number (integer) of load model.


ldmdldat Is the new data for the load model, in
psat_load_model_dat structure (as above).
Note: ldmdldat.number and ldmdl must be the same.
error Is the returned error (psat_error class).
If the powerflow data is changed to ldmdldat,
error.code, error.msg: 0, ’’
If the load model ldmdl doesn’t exist in the powerflow data,
error.code, error.msg: 1, ’Load model is not found.’
If ldmdldat.number is different from ldmdl,
error.code, error.msg: 2, ’Load model number can’t be changed.’
If ldmdldat has invalid (unacceptable) values,
error.code, error.msg: 3, ’New load model data is invalid.’

Returned values None

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 10


PSAT Python User Manual

9. Get and Set Fixed Shunt Data


The following functions return the data of a fixed shunt in the powerflow data.

get_fx_shunt_dat (busid, shuntid, error)

get_fx_shunt_dat (shunt_compid, error)

Where

busid Is the number (integer) or name (string) of the fixed shunt bus.
shuntid Is the fixed shunt ID (string).
shunt_compid Is the psat_comp_id (structure) of a fixed shunt
error Is the returned error (psat_error class).
If fixed shunt shuntid at bus busid exists in the powerflow data,
error.code, error.msg : 0, ’’
Otherwise,
error.code, error.msg : 1, ’Fixed shunt is not found.’

Returned values Data of the fixed shunt, in psat_fx_shunt_dat structure,


with the following attributes:
bus fixed shunt bus number
id fixed shunt id
name fixed shunt name
eqname fixed shunt equipment name
status fixed shunt status 0: out, 1: in
owner fixed shunt owner
nommw nominal MW shunt (at 1 pu voltage)
nommvar nominal MVAr shunt
mw actual MW shunt (at current voltage)
mvar actual MVAr shunt
nsg n-seq conductance
nsx n-seq suseptance
zsg z-seq conductance
zsx z-seq suseptance
rsvdctr remote SVD control status 0: disabled, 1: enabled
rsvd remote SVD bus number
rsvdid remote SVD id
uporder remote SVD control up order
dnorder remote SVD control down order

The following functions set (change) the data of a fixed shunt in the powerflow data.

set_fx_shunt_dat (busid, shuntid, fx_shuntdat, error)

set_fx_shunt_dat (shunt_compid, fx_shuntdat, error)

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 11


PSAT Python User Manual

Where

busid Is the number (integer) or name (string) of the fixed shunt bus.
shuntid Is the fixed shunt ID (string).
shunt_compid Is the psat_comp_id (structure) of a fixed shunt
fx_shuntdat Is the new data for the fixed shunt , in
psat_fx_shunt_dat structure (as above).
If fx_shuntdat.bus is different from busid, the fixed shunt is moved from
busid to fx_shuntdat.bus.
If fx_shuntdat.id is different from shuntid, the ID of fixed shunt is set to the
new fx_shuntdat.id.
The mw and mvar attributes of fx_shuntdat are ignored (since these are
calculated form the nominal values).
error Is the returned error (psat_error class).
If the powerflow data is changed to fx_shuntdat,
error.code, error.msg: 0, ’’
If the fixed shunt shuntid at busid doesn’t exist in the powerflow data,
error.code, error.msg: 1, ’Fixed shunt is not found.’
If fx_shuntdat.bus doesn’t exist in the powerflow data,
error.code, error.msg: 2, ’New fixed shunt bus is not found.’
If fx_shuntdat has invalid (unacceptable) values,
error.code, error.msg: 3, ’New fixed shunt data is invalid.’
If fx_shuntdat has invalid node,

Returned values None

10. Get and Set Switchable Shunt Data


The following functions return the data of a switchable shunt in the powerflow data.

get_sw_shunt_dat (busid, shuntid, error)

get_sw_shunt_dat (shunt_compid, error)

Where

busid Is the number (integer) or name (string) of the switchable shunt bus.
shuntid Is the switchable shunt ID (string).
shunt_compid Is the psat_comp_id (structure) of a switchable shunt
error Is the returned error (psat_error class).
If switchable shunt shuntid at bus busid exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg: 1, ’Switchable shunt is not found.’

Returned values Data of the switchable shunt, in psat_sw_shunt_dat structure, with the
following attributes:
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 12


PSAT Python User Manual

bus switchable shunt bus number


id switchable shunt id
name switchable shunt name
eqname switchable shunt equipment name
status status (1: in service, 0: out of service)
control control mode:
0: frozen
1: discrete
2: continuous
3: SVC
4: STATCOM
5: Plant MVAr control
nommw nominal MW shunt that is “on” (at 1 pu voltage)
nommvar nominal MVAr shunt that is “on” (at 1 pu voltage)
mw actual MW shunt that is “on” (at current voltage)
mvar actual MVAr shunt that is “on”
vhi upper limit of terminal voltage in pu
vlo lower limit of terminal voltage in pu
imax Imax
rembus remote controlled bus number (0: no remote bus)
rvhi remote controlled bus upper limit
rvlo remote controlled bus lower limit
vrem scheduled voltage of remote controlled bus
varshare share of the switchable shunt for control of the remote bus
nb[0:7] number of steps (banks) in blocks 1 to 8
bb[0:7] nominal MVAr of each step in blocks 1 to 8
owner switchable shunt owner
rsvdbhi remote shunt switching band low limit
rsvdblo remote shunt switching band high limit

The following functions set (change) the data of a switchable shunt in the powerflow data.

set_sw_shunt_dat (busid, shuntid, sw_shuntdat, error)

set_sw_shunt_dat (shunt_compid, sw_shuntdat, error)

Where

busid Is the number (integer) or name (string) of the switchable shunt bus.
shuntid Is the switchable shunt ID (string).
shunt_compid Is the psat_comp_id (structure) of a switchable shunt
sw_shuntdat Is the new data for the switchable shunt, in psat_sw_shunt_dat structure
(as above).
If sw_shuntdat.bus is different from busid, the switchable shunt is moved
from busid to sw_shuntdat.bus.
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 13


PSAT Python User Manual

If sw_shuntdat.id is different from shuntid, the ID of switchable shunt is set


to the new sw_shuntdat.id.
error Is the returned error (psat_error class).
If the powerflow data is changed to sw_shuntdat,
error.code, error.msg: 0, ’’
If the switchable shunt shuntid at busid doesn’t exist in the powerflow data,
error.code, error.msg: 1, ’Switchable shunt is not found.’
If sw_shuntdat.bus doesn’t exist in the powerflow data,
error.code, error.msg: 2, ’New switchable shunt bus is not found.’
If sw_shuntdat has invalid (unacceptable) values,
error.code, error.msg: 3, ’New switchable shunt data is invalid.’
If sw_shuntdat has invalid node,

Returned values None

11. Get and Set Line Data


The following functions return the data of an AC line in the powerflow data.

get_line_dat (bus1id, bus2id, lineid, secno, error)

get_line_dat (line_compid, error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
line.
bus2id Is the number (integer) or name (string) of the other terminal bus of the
line.
lineid Is the line ID (string).
line_compid Is the psat_comp_id (structure) of an AC line
secno Is the section number.
If the line is not part of a sectional branch, secno is ignored
Otherwise, secno must be the correct section number for this line.
error Is the returned error (psat_error class).
If line lineid, section secno, between bus1id and bus2id exists in the
powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg: 1, ’Line is not found.’

Returned values Data of the line, in psat_line_dat structure, with the following attributes:
frbus from-bus number
tobus to-bus number (order of frbus and tobus is significant)
id line ID
eqname Line equipment name
sec section number (ignored if the line is not part of a sectional branch)

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 14


PSAT Python User Manual

status status (1: in service, 0: out of service)


meter metered end (F: from-bus, T: to-bus)
rsr series resistance
xsr series reactance
gch charging conductance
bch charging susceptance
gfr from-bus shunt conductance
bfr from-bus shunt susceptance
gto to-bus shunt conductance
bto to-bus shunt susceptance
pfr MW flow at from bus side
qfr MVAr flow at from bus side
ifr Current (in Amps) at from bus side
pto MW flow at to bus side
qto MVAr flow at to bus side
ito Current (in Amps) at to bus side
rat1 MVA rating 1
rat2 MVA rating 2
rat3 MVA rating 3
rat4 MVA rating 4
rat5 MVA rating 5
rat6 MVA rating 6
ratgr rating group number
length line length
owner(0:3) line owners 1 to 4
ownfrac(0:3) line owner fractions 1 to 4
izr Z-seq resistance
izx Z-seq reactance
czg Z-seq charging conductance
czx Z-seq charging suseptance
fzg Z-seq from conductance
fzx Z-seq from suseptance
tzg Z-seq to conductance
tzx Z-seq to suseptance

The following functions set (change) the data of an AC line in the powerflow data.

set_line_dat (bus1id, bus2id, lineid, secno, linedat, error)

set_line_dat (line_compid, linedat, error)

Where

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 15


PSAT Python User Manual

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
line.
bus2id Is the number (integer) or name (string) of the other terminal bus of the
line.
lineid Is the line ID (string).
line_compid Is the psat_comp_id (structure) of an AC line
secno Is the section number.
If the line is not part of a sectional branch, secno must be 0. Otherwise,
secno must be the correct section number for this line.
linedat Is the new data for the line, in psat_line_dat structure (as above).
If linedat.frbus is different from the “from-bus” of the line in the powerflow
data, the “from-bus” is changed to linedat.frbus.
If linedat.tobus is different from the “to-bus” of the line in the powerflow
data, the “to-bus” is changed to linedat.tobus (the order of from-bus and to-
bus is important).
If linedat.id is different from lineid, the ID of line is changed to the new
linedat.id.
secno and linedat.sec must be equal (to change the sections, see Add and
Delete Sectional Branches below).
linedat.pfr/qfr/ifr/pto/qto/ito values are ignored (flows are not set to
specified values).
error Is the returned error (psat_error class).
If the powerflow data is changed to linedat,
error.code, error.msg: 0, ’’
If the line lineid, section secno, between bus1id and bus2id doesn’t exist in
the powerflow data,
error.code, error.msg: 1, ’Line is not found.’
If linedat.frbus or linedat.tobus doesn’t exist in the powerflow data,
error.code, error.msg: 2, ’New line from/to bus is not found.’
If from-bus, to-bus or ID is changed to new linedat.frbus, linedat.tobus or
linedat.id and another branch with these new from-bus, to-bus and ID
already exists,
error.code, error.msg: 3, ’Another branch with the same from-bus, to-
bus and ID already exists.’
If linedat has invalid (unacceptable) values,
error.code, error.msg: 4, ’New line data is invalid.’
If linedat has invalid node,

Returned values None

Note that changing the from-bus, to-bus, ID or status of one section of a sectional branch results in similar
changes for all sections of that branch.

12. Get and Set Fixed Transformer Data


The following functions return the data of a fixed transformer in the powerflow data.

get_fx_trans_dat (bus1id, bus2id, transid, secno, error)

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 16


PSAT Python User Manual

get_fx_trans_dat (trans_compid, error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
fixed transformer.
bus2id Is the number (integer) or name (string) of the other terminal bus of the
fixed transformer.
transid Is the fixed transformer ID (string).
trans_compid Is the psat_comp_id (structure) of a fixed transformer
secno Is the section number.
If the fixed transformer is not part of a sectional branch, secno is ignored
Otherwise, secno must be the correct section number for this fixed
transformer.
error Is the returned error (psat_error class).
If fixed transformer transid, section secno, between bus1id and bus2id
exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg: 1, ’Fixed transformer is not found.’

Returned values Data of the fixed transformer, in psat_fx_trans_dat structure, with the
following attributes:
frbus from-bus number
tobus to-bus number (order of frbus and tobus is significant)
id fixed transformer ID
name fixed transformer name
eqname fixed transformer equipment name
sec section number (ignored if the fixed transformer is not part of a
sectional branch)
status status (1: in service, 0: out of service)
basmva transformer base MVA
meter metered end (F: from-bus, T: to-bus)
ratio off-nominal turns ratio in pu.
phsh phase shift angle in degree
rsr series resistance
xsr series reactance
gfr from-bus magnetizing conductance
bfr from-bus magnetizing susceptance
gto to-bus magnetizing conductance
bto to-bus magnetizing susceptance
gch charging conductance
bch charging susceptance
pfr MW flow at from bus side
qfr MVAr flow at from bus side
ifr Current (in Amps) at from bus side
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 17


PSAT Python User Manual

pto MW flow at to bus side


qto MVAr flow at to bus side
ito Current (in Amps) at to bus side
rat1:rat6 MVA ratings 1 to 6
ratgr rating group number
owner(0:3) transformer owners 1 to 4
ownfrac(0:3) transformer owner fractions 1 to 4
izr Z-seq resistance
izx Z-seq reactance
pgr primary grounding resistance
pgx primary grounding reactance
sgr secondary grounding resistance
sgx secondary grounding reactance
wndcon winding connection (integer)

The following functions set (change) the data of a fixed transformer in the powerflow data.

set_fx_trans_dat (bus1id, bus2id, transid, secno, fx_transdat, error)

set_fx_trans_dat (trans_compid, fx_transdat, error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
fixed transformer.
bus2id Is the number (integer) or name (string) of the other terminal bus of the
fixed transformer.
transid Is the fixed transformer ID (string).
trans_compid Is the psat_comp_id (structure) of a fixed transformer
secno Is the section number.
If the fixed transformer is not part of a sectional branch, secno must be 0.
Otherwise, secno must be the correct section number for this fixed
transformer.
fx_transdat Is the new data for the fixed transformer, in psat_fx_trans_dat structure
(as above).
If fx_transdat.frbus is different from the “from-bus” of the fixed
transformer in the powerflow data, the “from-bus” is changed to
fx_transdat.frbus.
If fx_transdat.tobus is different from the “to-bus” of the fixed transformer
in the powerflow data, the “to-bus” is changed to fx_transdat.tobus (order
of from-bus and to-bus is important).
If fx_transdat.id is different from transid, the ID of fixed transformer is
changed to the new fx_transdat.id.
secno and fx_transdat.sec must be equal.
fx_transdat.pfr/qfr/ifr/pto/qto/ito values are ignored (flows are not set to
specified values).
error Is the returned error (psat_error class).

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 18


PSAT Python User Manual

If the powerflow data is changed to fx_transdat,


error.code, error.msg: 0, ’’
If the fixed transformer transid, section secno, between bus1id and bus2id
doesn’t exist in the powerflow data,
error.code, error.msg: 1, ’Fixed transformer is not found.’
If fx_transdat.frbus or fx_transdat.tobus doesn’t exist in the powerflow
data,
error.code, error.msg: 2, ’New fixed transformer from/to bus is not
found.’
If from-bus, to-bus or ID is changed to new fx_transdat.frbus,
fx_transdat.tobus or fx_transdat.id and another branch with these new
from-bus, to-bus and ID already exists,
error.code, error.msg: 3, ’Another branch with the same from-bus, to-
bus and ID already exists.’
If fx_transdat has invalid (unacceptable) values,
error.code, error.msg: 4, ’New fixed transformer data is invalid.’
If fx_transdat has invalid node,

Returned values None

Note that changing the from-bus, to-bus, ID or status of one section of a sectional branch results in similar
changes for all sections of that branch.

13. Get and Set Adjustable Transformer Data


The following functions return the data of an adjustable transformer (2-winding) in the powerflow data.

get_2w_trans_dat (bus1id, bus2id, transid, secno, error)

get_2w_trans_dat (trans_compid, error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
adjustable transformer.
bus2id Is the number (integer) or name (string) of the other terminal bus of the
adjustable transformer.
transid Is the adjustable transformer ID (string).
trans_compid Is the psat_comp_id (structure) of an adjustable transformer
secno Is the section number.
If the adjustable transformer is not part of a sectional branch, secno is
ignored.
Otherwise, secno must be the correct section number for this adjustable
transformer.
error Is the returned error (psat_error class).
If adjustable transformer transid, section secno, between bus1id and bus2id
exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ’Adjustable transformer is not found.’
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 19


PSAT Python User Manual

Returned values Data of the adjustable transformer, in psat_2w_trans_dat structure, with the
following attributes:
frbus from-bus number
tobus to-bus number (order of frbus and tobus is significant)
id adjustable transformer ID
name adjustable transformer name
eqname adjustable transformer equipment name
sec section number (ignored if the adjustable transformer is not part of a
sectional branch)
status status (1: in service, 0: out of service)
basmva transformer base MVA
meter metered end (F: from-bus, T: to-bus)
fsratio from-side off-nominal turns ratio in pu.
tsratio to-side off-nominal turns ratio in pu.
maxratio from-side maximum turns ratio in pu.
minratio from-side minimum turns ratio in pu.
stepratio step size of from-side turns ratio in pu.
phsh phase shift angle in degree
maxphsh maximum phase shift angle in degree
minphsh minimum phase shift angle in degree
rsr series resistance
xsr series reactance
zct impedance correction table number
gfr from-bus magnetizing conductance
bfr from-bus magnetizing susceptance
gto to-bus magnetizing conductance
bto to-bus magnetizing susceptance
gch charging conductance
bch charging susceptance
ctl control flag (1: enabled, 0: disabled)
ctlvar control type (V: voltage, Q: MVAr flow, P: MW flow)
ctlside control side (F: from-side, T: to-side)
ctlbus controlled bus number
vhi upper limit for controlled bus voltage in pu
vlo lower limit for controlled bus voltage in pu
qhi upper limit for controlled MVAr flow
qlo lower limit for controlled MVAr flow
phi upper limit for controlled MW flow
plo lower limit for controlled MW flow
pfr MW flow at from bus side
qfr MVAr flow at from bus side

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 20


PSAT Python User Manual

ifr Current (in Amps) at from bus side


pto MW flow at to bus side
qto MVAr flow at to bus side
ito Current (in Amps) at to bus side
rat1:rat6 MVA ratings 1 to 6
ratgr rating group number
owner(0:3) transformer owners 1 to 4
ownfrac(0:3) transformer owner fractions 1 to 4
izr Z-seq resistance
izx Z-seq reactance
pgr primary grounding resistance
pgx primary grounding reactance
sgr secondary grounding resistance
sgx secondary grounding reactance
wndcon winding connection (integer)
nv1 nominal voltage of From-Side
nv2 nominal voltage of To-Side
cw configuration option for turns ratios
cz configuration option for impedance data
cm configuration option for magnetizing impedance
mgl primary magnetizing conductance/loss
mxc primary magnetizing susceptance/current

The following functions set (change) the data of an adjustable transformer in the powerflow data.

set_2w_trans_dat (bus1id, bus2id, transid, secno, 2w_transdat, [test_data_entry], error)

set_2w_trans_dat (trans_compid, 2w_transdat, [test_data_entry], error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
adjustable transformer.
bus2id Is the number (integer) or name (string) of the other terminal bus of the
adjustable transformer.
Transid Is the adjustable transformer ID (string).
trans_compid Is the psat_comp_id (structure) of an adjustable transformer
Secno Is the section number.
If the adjustable transformer is not part of a sectional branch, secno must be
0. Otherwise, secno must be the correct section number for this adjustable
transformer.
2w_transdat Is the new data for the adjustable transformer, in psat_2w_trans_dat
structure (as above).
If 2w_transdat.frbus is different from the “from-bus” of the adjustable
transformer in the powerflow data, the “from-bus” is changed to

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 21


PSAT Python User Manual

2w_transdat.frbus.
If 2w_transdat.tobus is different from the “to-bus” of the adjustable
transformer in the powerflow data, the “to-bus” is changed to
2w_transdat.tobus (order of from-bus and to-bus is important).
If 2w_transdat.id is different from transid, the ID of adjustable transformer
is changed to the new 2w_transdat.id.
secno and 2w_transdat.sec must be equal.
2w_transdat.pfr/qfr/ifr/pto/qto/ito values are ignored (flows are not set to
specified values).
test_data_entry Is an optional boolean value (True or False). When ‘True’, it specifies that
the test data entry fields (mgl,mxc) of the 2w_transdat parameter are used
instead of the PSAT default Admittance fields (gfr,bfr,gto,bto,gch,bch)
Error Is the returned error (psat_error class).
If the powerflow data is changed to 2w_transdat,
error.code, error.msg: 0, ’’
If the adjustable transformer transid, section secno, between bus1id and
bus2id doesn’t exist in the powerflow data,
error.code, error.msg: 1, ’Adjustable transformer is not found.’
If 2w_transdat.frbus or 2w_transdat.tobus doesn’t exist in the powerflow
data,
error.code, error.msg: 2, ’New adjustable transformer from/to bus is
not found.’
If from-bus, to-bus or ID is changed to new 2w_transdat.frbus,
2w_transdat.tobus or 2w_transdat.id and another branch with these new
from-bus, to-bus and ID already exists,
error.code, error.msg: 3, ’Another branch with the same from-bus, to-
bus and ID already exists.’
If 2w_transdat has invalid (unacceptable) values,
error.code, error.msg: 4, ’New adjustable transformer data is invalid.’
If 2w_transdat has invalid node,

Returned values None

Note that changing the from-bus, to-bus, ID or status of one section of a sectional branch results in similar
changes for all sections of that branch.

14. Get and Set Impedance Correction Table Data


The following function returns the data of an Impedance Correction Table in the powerflow data.

get_zct_dat (zctno, error)

Where

zctno Is the Impedance Correction Table number (integer).


error Is the returned error (psat_error class).
If the Impedance Correction Table exists in the powerflow data,
error.code, error.msg : 0, ’’
Otherwise,
error.code, error.msg: 1, ’Impedance Correction Table is not found.’
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 22


PSAT Python User Manual

Returned values Data of the Impedance Correction Table, in psat_zct_dat structure, with the
following attributes:
tno table number
trps(0:10) turns ratio (in pu) or phase shift angle (in degrees) of 11 points in the
table
fctr(0:10) correction factors for the above 11 points

The following function sets (changes) the data of an Impedance Correction Table in the powerflow data.

set_zct_dat (zctno, zctdat, error)

Where

zctno Is the Impedance Correction Table number (integer).


zctdat Is the new data for the Impedance Correction Table, in psat_zct_dat
structure (as above).
If zctdat.tno is different from zctno, the table number is changed to
zctdat.tno.
error Is the returned error (psat_error class).
If the powerflow data is changed to zctdat,
error.code, error.msg: 0, ’’
If the Impedance Correction Table number zctno doesn’t exist in the
powerflow data,
error.code, error.msg : 1, ’Impedance Correction Table is not found.’
If zctdat.tno is different from zctno and another table with this number
already exists,
error.code, error.msg : 2, ’Another Impedance Correction Table with
the same number already exists.’
If zctdat has invalid (unacceptable) values,
error.code, error.msg : 3, ’New Impedance Correction Table data is
invalid.’

Returned values None

15. Get and Set 3-Winding Transformer Data


The following functions return the data of a 3-winding transformer in the powerflow data.

get_3w_trans_dat (bus1id, bus2id, bus3id, transid, error)

get_3w_trans_dat (trans_compid, error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
3-winding transformer.
bus2id Is the number (integer) or name (string) of the other terminal bus of the 3-
winding transformer.
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 23


PSAT Python User Manual

bus3id Is the number (integer) or name (string) of the third terminal bus of the 3-
winding transformer.
transid Is the 3-winding transformer ID (string).
trans_compid Is the psat_comp_id (structure) of an 3-winding transformer
error Is the returned error (psat_error class).
If 3-winding transformer transid, between bus1id, bus2id and bus3id exists
in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ’3-winding transformer is not found.’

Returned values Data of the 3-winding transformer, in psat_3w_trans_dat structure, with the
following attributes:
prbus primary-bus number
scbus secondary-bus number
trbus tertiary-bus number (order of prbus, scbus and trbus is significant)
id 3-winding transformer ID
name 3-winding transformer name
eqname 3-winding transformer equipment name
status status:
0: out of service
1: in service
2: secondary winding out of service
3: tertiary winding out of service
4: primary winding out of service

basmva transformer base MVA


nmtrd non-metered end: (P: primary-bus, S: secondary-bus, T: tertiary-bus)
ratiop off-nominal turns ratio (in pu) of P, S and T windings
ratios
ratiot
phshp phase shift angle (in degree) of P, S and T windings
phshs
phsht
prmaxratio maximum of variable turns ratio in pu. of P, S and T windings
scmaxratio
trmaxratio
prminratio minimum of variable turns ratio in pu. of P, S and T windings
scminratio
trminratio
prstepratio step size of variable turns ratio in pu. of P, S and T windings
scstepratio
trstepratio
rsrp series resistance (in pu) of P, S and T windings
rsrs
rsrt
xsrp series reactance (in pu) of P, S and T windings

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 24


PSAT Python User Manual

xsrs
xsrt
gmp magnetizing conductance (in pu) of P, S and T windings
gms
gmt
bmp magnetizing susceptance (in pu) of P, S and T windings
bms
bmt
gcp charging conductance (in pu) of P, S and T windings
gcs
gct
bcp charging susceptance (in pu) of P, S and T windings
bcs
bct
przct impedance correction table number of P, S and T windings
sczct
trzct
prctl control flag of P, S and T windings (0: disabled, 1: voltage, 2: mvar,
scctl 10: mw)
trctl
prctlside control side of P, S and T windings (T: tap-side, I: impedance-side)
scctlside
trctlside
prctlbus controlled bus number of P, S and T windings
scctlbus
trctlbus
prvhi upper limit for controlled bus voltage in pu of P, S and T windings
scvhi
trvhi
prvlo lower limit for controlled bus voltage in pu of P, S and T windings
scvlo
trvlo
ppr MW flow at the P, S and T windings
psc
ptr
qpr MVAr flow at the P, S and T windings
qsc
qtr
ipr Current (in Amps) at the P, S and T windings
isc
itr
ratpr1:ratpr6 primary-winding MVA ratings 1 to 6
ratsc1:ratsc6 secondary-winding MVA ratings 1 to 6
rattr1:rattr6 tertiary-winding MVA ratings 1 to 6
ratgr rating group number
owner(0:3) 3-winding transformer owners 1 to 4

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 25


PSAT Python User Manual

ownfrac(0:3) 3-winding transformer owner fractions 1 to 4


pzr primary Z-seq resistance
pzx primary Z-seq reactance
szr secondary Z-seq resistance
szx secondary Z-seq reactance
tzr tertiary Z-seq resistance
tzx tertiary Z-seq reactance
pgr primary grounding resistance
pgx primary grounding reactance
sgr secondary grounding resistance
sgx secondary grounding reactance
tgr tertiary grounding resistance
tgx tertiary grounding reactance
wndcon winding connection (integer)
s12 base MVA of primary to secondary winding
s23 base MVA of secondary to tertiary winding
s31 base MVA of tertiary to primary winding
nv1 nominal voltage of P, S, and T windings
nv2
nv3
cw configuration option for turns ratios
cz configuration option for impedance data
cm configuration option for magnetizing admittance
r12 primary to secondary resistance
x12 primary to secondary reactance
r23 secondary to tertiary resistance
x23 secondary to tertiary reactance
r31 tertiary to primary resistance
x31 tertiary to primary reactance
ml1 primary magnetizing conductance/loss

The following functions set (change) the data of a 3-winding transformer in the powerflow data.

set_3w_trans_dat (bus1id, bus2id, bus3id, transid, 3w_transdat, [test_data_entry], error)

set_3w_trans_dat (trans_compid, 3w_transdat, [test_data_entry], error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
3-winding transformer.
bus2id Is the number (integer) or name (string) of the other terminal bus of the 3-
winding transformer.
bus3id Is the number (integer) or name (string) of the third terminal bus of the 3-
winding transformer.
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 26


PSAT Python User Manual

transid Is the 3-winding transformer ID (string).


trans_compid Is the psat_comp_id (structure) of an 3-winding transformer
3w_transdat Is the new data for the 3-winding transformer, in psat_3w_trans_dat
structure (as above).
If 3w_transdat.prbus/scbus/trbus is different from the “primary-
bus”/”secondary-bus”/”tertiary-bus” of the 3-winding transformer in the
powerflow data, the “primary-bus”/”secondary-bus”/”tertiary-bus” is
changed to 3w_transdat.prbus/scbus/trbus (order of
primary/secondary/tertiary buses is important).
If 3w_transdat.id is different from transid, the ID of 3-winding transformer
is changed to the new 3w_transdat.id.
3w_transdat.pp/ps/pt/qp/qs/qt/ip/is/it values are ignored (flows are not set
to specified values).
test_data_entry Is an optional boolean value (True or False). When ‘True’, it specifies that
the test data entry fields (r12,x12,r23,x23,r31,x31,ml1,nc1) of the
3w_transdat parameter are used instead of the PSAT default Impedance
and Admittance fields (rsr[pst],xsr[pst],gm[pst],bm[pst],gc[pst],bc[pst])
error Is the returned error (psat_error class).
If the powerflow data is changed to 3w_transdat,
error.code, error.msg: 0, ’’
If the 3-winding transformer transid, between bus1id, bus2id and bus3id
doesn’t exist in the powerflow data,
error.code, error.msg: 1, ’3-winding transformer is not found.’
If the new 3w_transdat.prbus, 3w_transdat.scbus or 3w_transdat.trbus
doesn’t exist in the powerflow data,
error.code, error.msg: 2, ’New 3-winding transformer
primary/secondary/tertiary bus is not found.’
If the primary/secondary/tertiary bus or ID is changed to new values and
another 3w-transformer with these new primary/secondary/tertiary buses
and ID already exists,
error.code, error.msg: 3, ’Another 3w-transformer with the same
primary/secondary/tertiary buses and ID already exists.’
If 3w_transdat has invalid (unacceptable) values,
error.code, error.msg: 4, ’New 3w-transformer data is invalid.’

Returned values None

16. Get and Set Fixed Series Compensator Data


The following functions return the data of a fixed series compensator in the powerflow data.

get_fx_sercomp_dat (bus1id, bus2id, scid, secno, error)

get_fx_sercomp_dat (sc_compid, error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
fixed series compensator.
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 27


PSAT Python User Manual

bus2id Is the number (integer) or name (string) of the other terminal bus of the
fixed series compensator.
scid Is the fixed series compensator ID (string).
sc_compid Is the psat_comp_id (structure) of a fixed series compensator
secno Is the section number.
If the fixed series compensator is not part of a sectional branch, secno is
ignored.
Otherwise, secno must be the correct section number for this fixed series
compensator.
error Is the returned error (psat_error class).
If fixed series compensator scid, section secno, between bus1id and bus2id
exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg: 1, ’Fixed series compensator is not found.’

Returned values Data of the fixed series compensator, in psat_fx_sercomp_dat structure,


with the following attributes:
frbus from-bus number
tobus to-bus number (order of frbus and tobus is significant)
id fixed series compensator ID
name fixed series compensator name
eqname fixed series compensator equipment name
sec section number (ignored if the fixed series compensator is not part of a
sectional branch)
status status (1: in service, 0: out of service)
meter metered end (F: from-bus, T: to-bus)
xsr reactance (in pu) of series compensator
amprat AMP rating
kvrat kV rating
pfr MW flow at from bus side
qfr MVAr flow at from bus side
ifr Current (in Amps) at from bus side
pto MW flow at to bus side
qto MVAr flow at to bus side
ito Current (in Amps) at to bus side
owner fixed series compensator owner

The following functions set (change) the data of a fixed series compensator in the powerflow data.

set_fx_sercomp_dat (bus1id, bus2id, scid, secno, fx_sercompdat, error)

set_fx_sercomp_dat (sc_compid, fx_sercompdat, error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 28


PSAT Python User Manual

fixed series compensator.


bus2id Is the number (integer) or name (string) of the other terminal bus of the
fixed series compensator.
scid Is the fixed series compensator ID (string).
sc_compid Is the psat_comp_id (structure) of a fixed series compensator
secno Is the section number.
If the fixed series compensator is not part of a sectional branch, secno must
be 0. Otherwise, secno must be the correct section number for this fixed
series compensator.
fx_sercompdat Is the new data for the fixed series compensator, in psat_fx_sercomp_dat
structure (as above).
If fx_sercompdat.frbus is different from the “from-bus” of the fixed series
compensator in the powerflow data, the “from-bus” is changed to
fx_sercompdat.frbus.
If fx_sercompdat.tobus is different from the “to-bus” of the fixed series
compensator in the powerflow data, the “to-bus” is changed to
fx_sercompdat.tobus (order of from-bus and to-bus is important).
If fx_sercompdat.id is different from scid, the ID of fixed series
compensator is changed to the new fx_sercompdat.id.
secno and fx_sercompdat.sec must be equal.
fx_sercompdat.pfr/qfr/ifr/pto/qto/ito values are ignored (flows are not set to
specified values).
error Is the returned error (psat_error class).
If the powerflow data is changed to fx_sercompdat,
error.code, error.msg: 0, ’’
If the fixed series compensator scid, section secno, between bus1id and
bus2id doesn’t exist in the powerflow data,
error.code, error.msg : 1, ’Fixed series compensator is not found.’
If fx_sercompdat.frbus or fx_sercompdat.tobus doesn’t exist in the
powerflow data,
error.code, error.msg : 2, ’New fixed series compensator from/to bus
is not found.’
If from-bus, to-bus or ID is changed to new fx_sercompdat.frbus,
fx_sercompdat.tobus or fx_sercompdat.id and another branch with these
new from-bus, to-bus and ID already exists,
error.code, error.msg : 3, ’Another branch with the same from-bus,
to-bus and ID already exists.’
If fx_sercompdat has invalid (unacceptable) values,
error.code, error.msg : 4, ’New fixed series compensator data is
invalid.’
If gendat has invalid node,

Returned values None

Note that changing the from-bus, to-bus, ID or status of one section of a sectional branch results in similar
changes for all sections of that branch.

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 29


PSAT Python User Manual

17. Get and Set Adjustable Series Compensator Data


The following functions return the data of an adjustable series compensator in the powerflow data.

get_aj_sercomp_dat (bus1id, bus2id, scid, secno, error)

get_aj_sercomp_dat (sc_compid, error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
adjustable series compensator.
bus2id Is the number (integer) or name (string) of the other terminal bus of the
adjustable series compensator.
scid Is the adjustable series compensator ID (string).
sc_compid Is the psat_comp_id (structure) of an adjustable series compensator
secno Is the section number.
If the adjustable series compensator is not part of a sectional branch, secno
is ignored.
Otherwise, secno must be the correct section number for this adjustable
series compensator.
error Is the returned error (psat_error class).
If adjustable series compensator scid, section secno, between bus1id and
bus2id exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg: 1, ’Adjustable series compensator is not
found.’

Returned values Data of the adjustable series compensator, in psat_aj_sercomp_dat


structure, with the following attributes:
frbus from-bus number
tobus to-bus number (order of frbus and tobus is significant)
id adjustable series compensator ID
name adjustable series compensator name
eqname adjustable series compensator equipment name
sec section number (ignored if the adjustable series compensator is not part
of a sectional branch)
status status (1: in service, 0: out of service)
meter metered end (F: from-bus, T: to-bus)
ctl control flag (1: enabled, 0: disabled)
xsr reactance (in pu) of series compensator
xmax maximum reactance (in pu)
xmin minimum reactance (in pu)
phi upper limit for controlled MW flow
plo lower limit for controlled MW flow
amprat AMP rating

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 30


PSAT Python User Manual

kvrat kV rating
pfr MW flow at from bus side
qfr MVAr flow at from bus side
ifr Current (in Amps) at from bus side
pto MW flow at to bus side
qto MVAr flow at to bus side
ito Current (in Amps) at to bus side
owner adjustable series compensator owner

The following functions set (change) the data of an adjustable series compensator in the powerflow data.

set_aj_sercomp_dat (bus1id, bus2id, scid, secno, aj_sercompdat, error)

set_aj_sercomp_dat (sc_compid, aj_sercompdat, error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
adjustable series compensator.
bus2id Is the number (integer) or name (string) of the other terminal bus of the
adjustable series compensator.
scid Is the adjustable series compensator ID (string).
sc_compid Is the psat_comp_id (structure) of an adjustable series compensator
secno Is the section number.
If the adjustable series compensator is not part of a sectional branch, secno
must be 0. Otherwise, secno must be the correct section number for this
adjustable series compensator.
aj_sercompdat Is the new data for the adjustable series compensator, in
psat_aj_sercomp_dat structure (as above).
If aj_sercompdat.frbus is different from the “from-bus” of the adjustable
series compensator in the powerflow data, the “from-bus” is changed to
aj_sercompdat.frbus.
If aj_sercompdat.tobus is different from the “to-bus” of the adjustable
series compensator in the powerflow data, the “to-bus” is changed to
aj_sercompdat.tobus (order of from-bus and to-bus is important).
If aj_sercompdat.id is different from scid, the ID of adjustable series
compensator is changed to the new aj_sercompdat.id.
secno and aj_sercompdat.sec must be equal.
aj_sercompdat.pfr/qfr/ifr/pto/qto/ito values are ignored (flows are not set to
specified values).
error Is the returned error (psat_error class).
If the powerflow data is changed to aj_sercompdat,
error.code, error.msg: 0, ’’
If the adjustable series compensator scid, section secno, between bus1id
and bus2id doesn’t exist in the powerflow data,
error.code, error.msg: 1, ’Adjustable series compensator is not
found.’
If aj_sercompdat.frbus or aj_sercompdat.tobus doesn’t exist in the
powerflow data,
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 31


PSAT Python User Manual

error.code, error.msg: 2, ’New adjustable series compensator from/to


bus is not found.’
If from-bus, to-bus or ID is changed to new aj_sercompdat.frbus,
aj_sercompdat.tobus or aj_sercompdat.id and another branch with these
new from-bus, to-bus and ID already exists,
error.code, error.msg: 3, ’Another branch with the same from-bus, to-
bus and ID already exists.’
If aj_sercompdat has invalid (unacceptable) values,
error.code, error.msg: 4, ’New adjustable series compensator data is
invalid.’
If gendat has invalid node,

Returned values None

Note that changing the from-bus, to-bus, ID or status of one section of a sectional branch results in similar
changes for all sections of that branch.

18. Get and Set Static Tap Changer / Phase Regulator Data
The following functions return the data of a Static Tap Changers / Phase Regulators (STCPR) in the
powerflow data.

get_stcpr_dat (bus1id, bus2id, scid, secno, error)

get_stcpr_dat (sc_compid, error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
STCPR.
bus2id Is the number (integer) or name (string) of the other terminal bus of the
STCPR.
scid Is the ID (string).
sc_compid Is the psat_comp_id (structure) of a STCPR
secno Is the section number.
If the STCPR is not part of a sectional branch, secno is ignored.
Otherwise, secno must be the correct section number for this STCPR.
error Is the returned error (psat_error class).
If STCPR scid, section secno, between bus1id and bus2id exists in the
powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ’STCPR is not found.’

Returned values Data of the STCPR, in psat_stcpr_dat structure, with the following
attributes:
frbus from-bus number
tobus to-bus number (order of frbus and tobus is significant)
id ID

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 32


PSAT Python User Manual

name STCPR name


eqname STCPR equipment name
sec section number (ignored if the STCPR is not part of a sectional branch)
status status (1: in service, 0: out of service)
basmva STCPR base MVA
meter metered end (F: from-bus, T: to-bus)
atc tap changer range in pu
xtc tap changer winding position
rtc tap changer ratio in pu
rmaxtc maximum tap changer ratio in pu
rmintc minimum tap changer ratio in pu
apr phase regulator range in pu
xpr phase regulator winding position
rpr phase regulator ratio in pu
rmaxpr maximum phase regulator ratio in pu
rminpr minimum phase regulator ratio in pu
rsr series resistance in pu
xsr series reactance in pu
zcttc impedance correction table number for tap changer
zctpr impedance correction table number for phase regulator
gfr from-bus magnetizing conductance
bfr from-bus magnetizing susceptance
gto to-bus magnetizing conductance
bto to-bus magnetizing susceptance
gch charging conductance
bch charging susceptance
ctl control flag (1: enabled, 0: disabled)
ctlvar control type (V: voltage, Q: MVAr flow, P: MW flow,
PV: voltage and MW flow, PQ: MVAr and MW flows)
ctlside control side (F: from-side, T: to-side)
ctlbus controlled bus number
vhi upper limit for controlled bus voltage in pu
vlo lower limit for controlled bus voltage in pu
qhi upper limit for controlled MVAr flow
qlo lower limit for controlled MVAr flow
phi upper limit for controlled MW flow
plo lower limit for controlled MW flow
pfr MW flow at from bus side
qfr MVAr flow at from bus side
ifr Current (in Amps) at from bus side
pto MW flow at to bus side

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 33


PSAT Python User Manual

qto MVAr flow at to bus side


ito Current (in Amps) at to bus side
rat1:rat6 MVA ratings 1 to 6
ratgr rating group number
owner(0:3) STCPR owners 1 to 4
ownfrac(0:3) STCPR owner fractions 1 to 4

The following functions set (change) the data of an STCPR in the powerflow data.

set_stcpr_dat (bus1id, bus2id, scid, secno, stcprdat, error)

set_stcpr_dat (sc_compid, stcprdat, error)

Where

bus1id Is the number (integer) or name (string) of one of the terminal buses of the
STCPR.
bus2id Is the number (integer) or name (string) of the other terminal bus of the
STCPR.
scid Is the ID (string).
sc_compid Is the psat_comp_id (structure) of a STCPR
secno Is the section number.
If the STCPR is not part of a sectional branch, secno must be 0. Otherwise,
secno must be the correct section number for this STCPR.
stcprdat Is the new data for the STCPR, in psat_stcpr_dat structure (as above).
If stcprdat.frbus is different from the “from-bus” of the STCPR in the
powerflow data, the “from-bus” is changed to stcprdat.frbus.
If stcprdat.tobus is different from the “to-bus” of the STCPR in the
powerflow data, the “to-bus” is changed to stcprdat.tobus (order of from-
bus and to-bus is important).
If stcprdat.id is different from scid, the ID of STCPR is changed to the new
stcprdat.id.
secno and stcprdat.sec must be equal.
stcprdat.pfr/qfr/ifr/pto/qto/ito values are ignored (flows are not set to
specified values).
error Is the returned error (psat_error class).
If the powerflow data is changed to stcprdat,
error.code, error.msg: 0, ’’
If the STCPR scid, section secno, between bus1id and bus2id doesn’t exist
in the powerflow data,
error.code, error.msg : 1, ’STCPR is not found.’
If stcprdat.frbus or stcprdat.tobus doesn’t exist in the powerflow data,
error.code, error.msg : 2, ’New STCPR from/to bus is not found.’
If from-bus, to-bus or ID is changed to new stcprdat.frbus, stcprdat.tobus or
stcprdat.id and another branch with these new from-bus, to-bus and ID
already exists,
error.code, error.msg : 3, ’Another branch with the same from-bus,
to-bus and ID already exists.’
If stcprdat has invalid (unacceptable) values,

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 34


PSAT Python User Manual

error.code, error.msg : 4, ’New STCPR data is invalid.’


If gendat has invalid node,

Returned values None

Note that changing the from-bus, to-bus, ID or status of one section of a sectional branch results in similar
changes for all sections of that branch.

19. Get and Set DC Bus Data


The following functions return the data of a DC bus in the powerflow data.

get_dcbus_dat (dcbnam, error)

get_dcbus_dat (dcbus_compid, error)

Where

dcbnam Is the DC bus name (string).


dcbus_compid Is the psat_comp_id (structure) of a DC bus.
error Is the returned error (psat_error class).
If the DC bus exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ’DC bus is not found.’

Returned values Data of the Dc bus, in psat_dcbus_dat structure, with the following
attributes:
name DC bus name
area area number
zone zone number
vmag DC bus voltage

The following functions set (change) the data of a DC bus in the powerflow data.

set_dcbus_dat (dcbnam, dcbusdat, error)

set_dcbus_dat (dcbus_compid, dcbusdat, error)

Where

dcbnam Is the DC bus name (string).


dcbus_compid Is the psat_comp_id (structure) of a DC bus.
dcbusdat Is the new data for the Dc bus, in psat_dcbus_dat structure (as above).
If dcbusdat.name is different from dcbnam, the DC bus name is changed to
dcbusdat.name.
error Is the returned error (psat_error class).
If the powerflow data is changed to dcbusdat,
error.code, error.msg: 0, ’’
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 35


PSAT Python User Manual

If the DC bus dcbnam doesn’t exist in the powerflow data,


error.code, error.msg : 1, ’DC bus is not found.’
If dcbusdat.name is different from dcbnam and another bus with this name
already exists,
error.code, error.msg : 2, ’Another DC bus with the same name
already exists.’
If dcbusdat has invalid (unacceptable) values,
error.code, error.msg : 3, ’New DC bus data is invalid.’

Returned values None

20. Get and Set DC Converter Data


The following functions return the data of a DC converter in the powerflow data.

get_converter_dat (dcbnm1, dcbnm2, acbusid, cnvid, error)

get_converter_dat (cnv_compid, error)

Where

dcbnm1 Is the name (string) of the first DC terminal bus of the converter.
dcbnm2 Is the name (string) of the second DC terminal bus of the converter.
acbusid Is the number (integer)/name (string) of the AC-side (primary) terminal bus
of the converter transformer.
cnvid Is the converter circuit number (integer).
cnv_compid Is the psat_comp_id (structure) of a DC converter.
error Is the returned error (psat_error class).
If the converter exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ’Converter is not found.’

Returned values Data of the Converter, in psat_converter_dat structure, with the following
attributes:
dcb1 name of first DC bus (8 character long).
dcb2 name of second DC bus (8 character long).
acbus number of AC bus (primary terminal) of converter transformer.
id circuit number (ID) of the converters (integer).
type converter type (R: Rectifier, I: Inverter )
xc commutating reactance, either in ohms per bridge when transformer
MVA is zero, or in pu based on transformer MVA rating.
rcomp voltage compounding resistance in Ohms.
nbr number of series bridges in this converter.
basmva transformer MVA rating (zero when Xc is in ohms/bridge).
baskv base voltage of transformer primary side in kV.

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 36


PSAT Python User Manual

nratio transformer nominal ratio (DC side base voltage / AC side base
voltage).
maxratio maximum off-nominal turns ratio of the transformer in pu.
minratio minimum off-nominal turns ratio of the transformer in pu.
stepratio transformer step size in pu.
ctl1 first control variable (VD, ID, etc.) described in PSAT manual.
sp1 set point of the first control variable in the units specified in PSAT
manual.
ctl2 second control variable (VD, ID, etc.) described in PSAT manual.
sp2 set point of the second control variable in the units specified in PSAT
manual.
almax maximum alpha in degrees.
almin minimum alpha in degrees.
gamin minimum gamma in degrees.
pmax maximum real power in MW.
pmin minimum real power in MW.
qmax maximum reactive power in MVAr.
qmin minimum reactive power in MVAr.
imax maximum DC current in Amps.
vdc DC Voltage (kV)
idc DC Current (A)
alpha Alpha (Deg)
gamma Gamma (Deg)
ratio Transformer Ratio
pac AC Power (MW)
qac AC Power (MVAr)
iac AC Current (A)

The following functions set (change) the data of a Converter in the powerflow data.

set_converter_dat (dcbnm1, dcbnm2, acbusid, cnvid, convdat, error)

set_converter_dat (cnv_compid, convdat, error)

Where

dcbnm1 Is the name (string) of the first DC terminal bus of the converter.
dcbnm2 Is the name (string) of the second DC terminal bus of the converter.
acbusid Is the number (integer) / name (string) of the AC-side (primary) terminal
bus of the converter transformer.
cnvid Is the converter circuit number (integer).
cnv_compid Is the psat_comp_id (structure) of a DC converter.
convdat Is the new data for the converter, in psat_converter_dat structure (as above)
If convdat.dcb1 (or .dcb2 or .acbus or .id) is different from dcbnm1 (or

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 37


PSAT Python User Manual

dcbnm2 or acbusno or cnvid), the first DC bus (or second DC bus, or AC


bus or circuit number) of the converter is changed to convdat.dcb1 (or
.dcb2 or .acbus or .id).
convdat.vdc/idc/alpha/gamma/ratio/pac/qac/iac values are ignored (these
are not set to specified values).
error Is the returned error (psat_error class).
If the powerflow data is changed to convdat,
error.code, error.msg : 0, ’’
If the converter cnvid, connected between dcbnm1, dcbnm2 and acbusno
doesn’t exist in the powerflow data,
error.code, error.msg : 1, ’Converter is not found.’
If convdat.dcb1 (or convdat.dcb2) is different from dcbnam1 (or dcbnam2)
and there is no DC bus with this name in the powerflow data,
error.code, error.msg : 2, ’New converter DC bus 1/2 is not found.’
If convdat.acbus is different from acbusno and there is no bus with this
number in the powerflow data,
error.code, error.msg : 3, ’New converter AC bus is not found.’
If convdat.id is different from cnvid and there is another converter between
the same buses with the same ID,
error.code, error.msg : 4, ’Another Converter with the same ID
already exists.’
If convdat has invalid (unacceptable) values,
error.code, error.msg : 5, ’New converter data is invalid.’
If gendat has invalid node,

Returned values None

21. Get and Set Voltage Source Converter Data


The following functions return the data of a Voltage Source Converter (VSC) in the powerflow data.

get_vsc_dat (dcbnm1, dcbnm2, acbusid1, acbusid2, vscid, error)

get_vsc_dat (vsc_compid, error)

Where

dcbnm1 Is the name (string) of the first DC terminal bus of the VSC.
dcbnm2 Is the name (string) of the second DC terminal bus of the VSC.
acbusid1 Is the number (integer) / name (string) of the first AC terminal bus of the
VSC.
acbusid2 Is the number (integer) / name (string) of the second AC terminal bus of the
VSC.
vscid Is the VSC circuit number (integer).
vsc_compid Is the psat_comp_id (structure) of a Voltage Source Converter (VSC).
error Is the returned error (psat_error class).
If the VSC exists in the powerflow data,

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 38


PSAT Python User Manual

error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ’Voltage Source Converter is not found.’

Returned values Data of the VSC, in psat_vsc_dat structure, with the following attributes:
dcb1 name of first DC bus (8 character long).
dcb2 name of second DC bus (8 character long).
acb1 number of first AC bus (integer).
acb2 number of second AC bus (integer).
id circuit number (ID) of the VSC (integer).
type VSC type (R: Rectifier, I: Inverter )
xt transformer reactance, either in ohms per bridge when transformer
MVA is zero, or in pu based on transformer MVA rating.
xl line reactance, either in ohms if transformer MVA is zero, or in pu
based on transformer MVA rating. This is the reactance of line in series
with the transformer between the two AC buses.
nbr number of series bridges in this VSC.
kc code for the DC-to-AC gain (i.e. Vl-1/Vd), which can be one of the
following (integer):
0 - gain is 1
1 - SQRT(6)/4 for linear sinusoidal PWM
2 - SQRT(6)/ for square-wave pulse switching
3 - 0.727 for 5th and 7th harmonic elimination switching

basmva transformer MVA rating (zero when xt is in ohms/bridge).


baskv base voltage of transformer primary side in kV.
nratio transformer nominal ratio (DC side base voltage / AC side base
voltage).
maxratio maximum off-nominal turns ratio of the transformer in pu.
minratio minimum off-nominal turns ratio of the transformer in pu.
stepratio transformer step size in pu.
ctl1 first control variable (VD, ID, etc.) described in PSAT manual.
sp1 set point of the first control variable in the units specified in PSAT
manual.
ctl2 second control variable (VD, ID, etc.) described in PSAT manual.
sp2 set point of the second control variable in the units specified in PSAT
manual.
ctl3 third control variable (VD, ID, etc.) described in PSAT manual.
sp3 set point of the third control variable in the units specified in PSAT
manual.
pamax maximum power angle in degrees.
pamin minimum power angle in degrees.
mrmax maximum modulation ratio.
mrmin minimum modulation ratio.
imax maximum AC current in Amps.
vte estimated UPFC terminal voltage (the voltage expected to be kept

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 39


PSAT Python User Manual

constant by the shunt converter of UPFC) in pu.


vtmax upper limit of the voltage of first AC bus in pu.
vtmin lower limit of the voltage of first AC bus in pu.
The last three items are specified for the series VSC of a UPFC model.
smax converter MVA rating.
pwf power weighting factor.
qmin controlled MVAr lower limit.
qmax controlled MVAr upper limit.
rembus remote controlled bus number.
varshare % VAr sharing.
losscoa converter loss coefficient A.
losscob converter loss coefficient B.
lossmin converter loss minimum.
linkconv linked converter name.
vdc DC Voltage (kV)
idc DC Current (A)
pang Power Angle (Deg)
modr Modulation Ratio
ratio Transformer Ratio
pac ACBus 1 Power (MW)
qac ACBus 1 Power (MVAr)
iac ACBus 1 Current (A)
pinj AC Power Injection (MW)
qinj AC Power Injection (MVAr)
vinj AC Voltage Injection Magnitude
ainj AC Voltage Injection Angle

The following functions set (change) the data of a Voltage Source Converter in the powerflow data.

set_vsc_dat (dcbnm1, dcbnm2, acbusid1, acbusid2, vscid, vscdat, error)

set_vsc_dat (vsc_compid, vscdat, error)

Where

dcbnm1 Is the name (string) of the first DC terminal bus of the VSC.
dcbnm2 Is the name (string) of the second DC terminal bus of the VSC.
acbusid1 Is the number (integer) / name (string) of the first AC bus of the VSC.
acbusid2 Is the number (integer) / name (string) of the second AC bus of the VSC.
vscid Is the VSC circuit number (integer).
vsc_compid Is the psat_comp_id (structure) of a Voltage Source Converter (VSC).
vscdat Is the new data for the VSC, in psat_vsc_dat structure (as above).
If vscdat.dcb1 (or .dcb2 or .acb1 or acb2 or .id) is different from dcbnm1
(or dcbnm2 or acbno1 or acbno2 or vscid), the first DC bus (or second DC

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 40


PSAT Python User Manual

bus, or first AC bus or second AC bus or circuit number) of the VSC is


changed to vscdat.dcb1 (or .dcb2 or .acb1 or acb2 or .id).
vscdat.vdc/idc/pang/modr/ratio/pac/qac/iac/pinj/qinj/vinj/ainj values are
ignored (these are not set to specified values).
error Is the returned error (psat_error class).
If the powerflow data is changed to vscdat,
error.code, error.msg : 0, ’’
If the VSC vscid, connected between dcbnm1, dcbnm2, acbno1 and acbno2
doesn’t exist in the powerflow data,
error.code, error.msg : 1, ’Voltage Source Converter is not found.’
If vscdat.dcb1 (or vscdat.dcb2) is different from dcbnam1 (or dcbnam2)
and there is no DC bus with this name in the powerflow data,
error.code, error.msg : 2, ’New converter DC bus 1/2 is not found.’
If vscdat.acb1 (or vscdat.acb2) is different from acbno1 (or acbno2) and
there is no AC bus with this number in the powerflow data,
error.code, error.msg : 3, ’New converter AC bus 1/2 is not found.’
If vscdat.id is different from vscid and there is another VSC between the
same buses with the same ID,
error.code, error.msg : 4, ’Another Voltage Source Converter with the
same ID already exists.’
If vscdat has invalid (unacceptable) values,
error.code, error.msg : 5, ’New Voltage Source Converter data is
invalid.’

Returned values None

22. Get and Set DC Line Data


The following functions return the data of a DC line in the powerflow data.

get_dcline_dat (dcbnm1, dcbnm2, dclid, error)

get_dcline_dat (dcl_compid, error)

Where

dcbnm1 Is the name (string) of one of the DC terminal buses of the DC line.
dcbnm2 Is the name (string) of the other DC terminal bus of the DC line.
dclid Is the DC line circuit number (integer).
dcl_compid Is the psat_comp_id (structure) of a DC line.
error Is the returned error (psat_error class).
If the DC line exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ’DC line is not found.’

Returned values Data of the DC line, in psat_dcline_dat structure, with the following
attributes:
dcb1 name of first (From) DC bus (8 character long).

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 41


PSAT Python User Manual

dcb2 name of second (To) DC bus (8 character long).


id circuit number (ID) of the DC lines (integer).
meter metered end (F: From-bus, T: To-bus)
rdc line resistance in Ohms.
ldc line inductance in mH.
cdc1 capacitance at From side in microF.
cdc2 capacitance at To side in microF.
imax current rating in Amps.
pfr Bus 1 Power (MW)
ifr Bus 1 Current (Amp)
pto Bus 2 Power (MW)
ito Bus 2 Current (Amp)

The following functions set (change) the data of a DC line in the powerflow data.

set_dcline_dat (dcbnm1, dcbnm2, dclid, dclinedat, error)

set_dcline_dat (dcl_compid, error)

Where

dcbnm1 Is the name (string) of one of the DC terminal buses of the DC line.
dcbnm2 Is the name (string) of the other DC terminal bus of the DC line.
dclid Is the DC line circuit number (integer).
dcl_compid Is the psat_comp_id (structure) of a DC line.
dclinedat Is the new data for the DC line, in psat_dcline_dat structure (as above).
If dclinedat.dcb1 is different from the From-bus of the line in the
powerflow data, the From-bus is changed to dclinedat.dcb1.
If dclinedat.dcb2 is different from the To-bus of the line in the powerflow
data, the To-bus is changed to dclinedat.dcb2 (the order of From-bus and
To-bus is important).
If dclinedat.id is different from dclid, the ID (number) of DC line is
changed to the new dclinedat.id.
dclinedat.pfr/ifr/pto/ito values are ignored (flows are not set to specified
values).
error Is the returned error (psat_error class).
If the powerflow data is changed to dclinedat,
error.code, error.msg : 0, ’’
If the DC line dclid, connected between dcbnm1 and dcbnm2 doesn’t exist
in the powerflow data,
error.code, error.msg : 1, ’DC line is not found.’
If dclinedat.dcb1 (or dclinedat.dcb2) is different from dcbnam1 (or
dcbnam2) and there is no DC bus with this name in the powerflow data,
error.code, error.msg : 2, ’New DC bus 1/2 of DC line is not found.’
If dclinedat.id is different from dclid and there is another DC line between
the same buses with the same ID,
error.code, error.msg : 3, ’Another DC line with the same ID already

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 42


PSAT Python User Manual

exists.’
If dclinedat has invalid (unacceptable) values,
error.code, error.msg : 4, ’New DC line data is invalid.’

Returned values None

23. Get and Set DC Breaker Data


The following functions return the data of a DC breaker in the powerflow data.

get_dcbrkr_dat (dcbnm1, dcbnm2, dcbid, error)

get_dcbrkr_dat (dcb_compid, error)

Where

dcbnm1 Is the name (string) of one of the DC terminal buses of the DC breaker.
dcbnm2 Is the name (string) of the other DC terminal bus of the DC breaker.
dcbid Is the DC breaker circuit number (integer).
dcb_compid Is the psat_comp_id (structure) of a DC breaker.
error Is the returned error (psat_error class).
If the DC breaker exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ’DC breaker is not found.’

Returned values Data of the DC breaker, in psat_dcbrkr_dat structure, with the following
attributes:
dcb1 name of first (From) DC bus (8 character long).
dcb2 name of second (To) DC bus (8 character long).
id circuit number (ID) of the DC breakers (integer).
stat status (C: Closed, O: Open)
pfr Breaker Power (MW)
ifr Breaker Current (Amp)

The following functions set (change) the data of a DC breaker in the powerflow data.

set_dcbrkr_dat (dcbnm1, dcbnm2, dcbid, dcbrkrdat, error)

set_dcbrkr_dat (dcb_compid, dcbrkrdat, error)

Where

dcbnm1 Is the name (string) of one of the DC terminal buses of the DC breaker.
dcbnm2 Is the name (string) of the other DC terminal bus of the DC breaker.
dcbid Is the DC breaker circuit number (integer).

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 43


PSAT Python User Manual

dcb_compid Is the psat_comp_id (structure) of a DC breaker.


dcbrkrdat Is the new data for the DC breaker, in psat_dcbrkr_dat structure (as above).
If dcbrkrdat.dcb1 is different from the From-bus of the breaker in the
powerflow data, the From-bus is changed to dcbrkrdat.dcb1.
If dcbrkrdat.dcb2 is different from the To-bus of the breaker in the
powerflow data, the To-bus is changed to dcbrkrdat.dcb2 (the order of
From-bus and To-bus is important).
If dcbrkrdat.id is different from dcbid, the ID (number) of DC breaker is
changed to the new dcbrkrdat.id.
dcbrkrdat.pfr/ifr values are ignored (flows are not set to specified values).
error Is the returned error (psat_error class).
If the powerflow data is changed to dcbrkrdat,
error.code, error.msg : 0, ’’
If the DC breaker dcbid, connected between dcbnm1 and dcbnm2 doesn’t
exist in the powerflow data,
error.code, error.msg : 1, ’DC breaker is not found.’
If dcbrkrdat.dcb1 (or dcbrkrdat.dcb2) is different from dcbnam1 (or
dcbnam2) and there is no DC bus with this name in the powerflow data,
error.code, error.msg : 2, ’New DC bus 1/2 of DC breaker is not
found.’
If dcbrkrdat.id is different from dcbid and there is another DC breaker
between the same buses with the same ID,
error.code, error.msg : 3, ’Another DC breaker with the same ID
already exists.’
If dcbrkrdat has invalid (unacceptable) values,
error.code, error.msg : 4, ’New DC breaker data is invalid.’

Returned values None

24. Get and Set Area Data


The following function returns the data of an Area in the powerflow data.

get_area_dat (arid, error)

Where

arid Is the number (integer) or name (string) or psat_comp_id (structure) of the


area.
error Is the returned error (psat_error class).
If the area exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ’Area is not found.’

Returned values Data of the area arid, in psat_area_dat structure, with the following
attributes:
number area number

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 44


PSAT Python User Manual

name area name


slbus slack-bus number of the area (integer)
cntl area interchange control flag (1: Enabled, 0: Disabled)
lmtsl slack generation limit flag for interchange control
1: keep slack generation within its limit,
0: ignore slack generation limits
pex desired real power export from the area, in MW (real)
ptol tolerance for desired export, in MW (real)

The following function sets (changes) the data of an Area in the powerflow data.

set_area_dat (arid, areadat, error)

Where

arid Is the number (integer) or name (string) or psat_comp_id (structure) of the


area.
areadat Is the new data for the area, in psat_area_dat structure (as above).
If areadat.number (or areadat.name) is different from arid, the area is re-
numbered (or renamed) to the new areadat.number (or areadat.name).
error Is the returned error (psat_error class).
If the powerflow data is changed to areadat,
error.code, error.msg : 0, ’’
If the area arid doesn’t exist in the powerflow data,
error.code, error.msg : 1, ’Area is not found.’
If areadat.number is different from arid and another area with this number
already exists in the powerflow data,
error.code, error.msg : 2, ’New area number already exists.’
If areadat.slbus doesn’t exist in the powerflow data,
error.code, error.msg : 3, ’New slack bus is not found.’
If areadat has invalid (unacceptable) values,
error.code, error.msg : 4, ’New area data is invalid.’

Returned values None

25. Get and Set Zone Data


The following function returns the data of a Zone in the powerflow data.

get_zone_dat (znid, error)

Where

znid Is the number (integer) or name (string) or psat_comp_id (structure) of the


zone.
error Is the returned error (psat_error class).
If the zone exists in the powerflow data,
error.code, error.msg: 0, ’’

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 45


PSAT Python User Manual

Otherwise,
error.code, error.msg : 1, ’Zone is not found.’

Returned values Data of the zone znid, in psat_zone_dat structure, with the following
attributes:
number zone number
name zone name

The following function sets (changes) the data of a Zone in the powerflow data.

set_zone_dat (znid, zonedat, error)

Where

znid Is the number (integer) or name (string) or psat_comp_id (structure) of the


zone.
zonedat Is the new data for the zone, in psat_zone_dat structure (as above).
If zonedat.number (or zonedat.name) is different from znid, the zone is re-
numbered (or renamed) to the new zonedat.number (or zonedat.name).
error Is the returned error (psat_error class).
If the powerflow data is changed to zonedat,
error.code, error.msg : 0, ’’
If the zone znid doesn’t exist in the powerflow data,
error.code, error.msg : 1, ’Zone is not found.’
If zonedat.number is different from znid and another zone with this number
already exists in the powerflow data,
error.code, error.msg : 2, ’New zone number already exists.’

Returned values None

26. Get and Set Owner Data


The following function returns the data of an Owner in the powerflow data.

get_owner_dat (owid, error)

Where

owid Is the number (integer) or name (string) or psat_comp_id (structure) of the


owner.
error Is the returned error (psat_error class).
If the owner exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ’Owner is not found.’

Returned values Data of the owner owid, in psat_owner_dat structure, with the following
attributes:
number owner number

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 46


PSAT Python User Manual

name owner name

The following function sets (changes) the data of an Owner in the powerflow data.

set_owner_dat (owid, ownerdat, error)

Where

owid Is the number (integer) or name (string) or psat_comp_id (structure) of the


owner.
ownerdat Is the new data for the owner, in psat_owner_dat structure (as above).
If ownerdat.number (or ownerdat.name) is different from owid, the owner
is re-numbered (or renamed) to the new ownerdat.number (or
ownerdat.name).
error Is the returned error (psat_error class).
If the powerflow data is changed to ownerdat,
error.code, error.msg : 0, ’’
If the owner owid doesn’t exist in the powerflow data,
error.code, error.msg : 1, ’Owner is not found.’
If ownerdat.number is different from owid and another owner with this
number already exists in the powerflow data,
error.code, error.msg : 2, ’New owner number already exists.’

Returned values None

27. Get and Set Node Data


The following function returns the data of a Node in the powerflow data.

get_node_dat (nodeid, error)

Where

nodeid Is equipment name (string) or psat_comp_id (structure) of the node.


error Is the returned error (psat_error class).
If the node exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ’Node is not found.’

Returned values Data of the node nodeid, in psat_node_dat structure, with the following
attributes:
number node bus number
eqname node equipment name

The following function sets (changes) the data of a Node in the powerflow data.

set_node_dat (nodeid, nodedat, error)

Where
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 47


PSAT Python User Manual

nodeid Is the equipment name (string) or psat_comp_id (structure) of the node.


nodedat Is the new data for the node, in psat_node_dat structure (as above).
If nodedat.eqname is different from nodeid, the node is renamed to the new
nodedat.eqname.
If nodedat.number is different from the “node bus” of the node in the
powerflow data, the “node-bus” is changed to nodedat.number.
error Is the returned error (psat_error class).
If the powerflow data is changed to nodedat,
error.code, error.msg : 0, ’’
If the node nodeid doesn’t exist in the powerflow data,
error.code, error.msg : 1, ’Node is not found.’

Returned values None

28. Get and Set Zero Sequence Coupling Data


The following functions return the data of a Zero Sequence Coupling item in the powerflow data.

get_z_seq_coupling_dat (line1fr, line1to, line1id, line2fr, line2to, line2id, error)

get_z_seq_coupling_dat (zseq_compid, error)

Where

line1fr Is the number (integer) of the from-bus end of the first zseq coupling line
line1to Is the number (integer) of the to-bus end of the first zseq coupling line
line1id Is the ID (string) of the first zseq coupling line.
line2fr Is the number (integer) of the from-bus end of the second zseq coupling
line
line2to Is the number (integer) of the to-bus end of the second zseq coupling line
line2id Is the ID (string) of the second zseq coupling line.
zseq_compid Is the psat_comp_id (structure) of a Zero Sequence Coupling item
error Is the returned error (psat_error class).
If the node exists in the powerflow data,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ’Node is not found.’

Returned values Data for the zseq coupling item, in psat_z_seq_coupling_dat structure, with
the following attributes:
line1eq Z-Seq coupling line1 equipment name
line1fr Z-Seq coupling line1 from-bus number
line1to Z-Seq coupling line1 to-bus number
line1id Z-Seq coupling line1 ID
line2eq Z-Seq coupling line2 equipment name
line2fr Z-Seq coupling line2 from-bus number
line2to Z-Seq coupling line2 to-bus number
line2id Z-Seq coupling line2 ID
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 48


PSAT Python User Manual

sr line-to-line resistance
sx line-to-line reactance
line1cf line1 coupling factor
line2cf line2 coupling factor
line1md line1 metered end direction
line2md line2 metered end direction

The following function sets (changes) the data of a Zero Sequence Coupling item in the powerflow data.

set_z_seq_coupling_dat (line1fr, line1to, line1id, line2fr, line2to, line2id, zseqdat, error)

set_z_seq_coupling_dat (zseq_compid, zseqdat, error)

Where

line1fr Is the number (integer) of the from-bus end of the zseq coupling line1
line1to Is the number (integer) of the to-bus end of the zseq coupling line1
line1id Is the ID (string) of the zseq coupling line1.
line2fr Is the number (integer) of the from-bus end of the zseq coupling line2
line2to Is the number (integer) of the to-bus end of the zseq coupling line2
line2id Is the ID (string) of the zseq coupling line2.
zseq_compid Is the psat_comp_id (structure) of a Zero Sequence Coupling
zseqdat Is the new data for the zseq coupling item, in psat_z_seq_coupling_dat
structure (as above).
If zseqdat line equipment names or line bus numbers are different from the
specified zseq coupling item, the zseq coupling is changed to the new
zseqdat values.
error Is the returned error (psat_error class).
If the powerflow data is changed to zseqdat,
error.code, error.msg : 0, ’’
If the specified zseq coupling item doesn’t exist in the powerflow data,
error.code, error.msg : 1, ’Z-Seq Coupling item is not found.’

Returned values None

29. Get and Set Node Breaker Station


The following function returns the data of a NB Station in the the powerflow data.

get_nb_station_dat(stnid, error)

Where

stnid Is the name (string) or psat_comp_id (structure) of the station.


error Is the returned error (psat_error class).
If the function is successful,
error.code, error.msg: 0, ’’
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 49


PSAT Python User Manual

Otherwise,
error.code, error.msg : 1, ‘Station is not found.’
Returned values Data of station stnid, in psat_nb_station_dat structure, with following
attributes:
number station number
name station name
type station type. 1: Generic 2:Substation 3:Thermal 4:Hydro 5:Wind 6:Solar
7:Diesel 8:Gas 9:Nuclear 10:Biomass 11:Geothermal
kv station kv
gps_lat location lattitude
gps_long location longitude
sgr station sgr

The following function sets (changes) the data of a Station in powerflow data.

set_nb_station_dat(stnid, stndat, error)

Where

stnid Is the name (string) or psat_comp_id (structure) of the station.


stndat Is the data for the station, in psat_nb_station_dat (as above).
error Is the returned error (psat_error class).
If the function is successful,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ‘Station is not found.’
error.code, error.msg : 2, ‘New Node Breaker Station type is invalid.’

Returned values None

30. Get and Set Node Breaker Busbar


The following function returns the data of a NB Station in the the powerflow data.

get_nb_busbar_dat(bbid, error)

Where

bbid Is the name (string) or psat_comp_id (structure) of the busbar.


error Is the returned error (psat_error class).
If the function is successful,
error.code, error.msg: 0, ’’
Otherwise,

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 50


PSAT Python User Manual

error.code, error.msg : 1, ‘Busbar is not found.’


Returned values Data of busbar bbid, in psat_nb_busbar_dat structure, with following
attributes:
number busbar number
name busbar name
stName busbar’s station name
stNum busabr’s station number
busNum bus number
busName bus name
busEQName bus equipment name
kv busbar kv
vPU busbar voltage PU
vang busbar voltage Angular

The following function sets (changes) the data of a Busbar in powerflow data.

set_nb_busbar_dat(bbid, bbdat, error)

Where

bbid Is the name (string) or psat_comp_id (structure) of the busbar.


bbdat Is the data for the busbar, in psat_nb_busbar_dat (as above).
If bbdat.name (or bb.number or bb.stName) is different from bbid, the
busbar is renamed (or renumbered) to new bbdat.name (or bbdat.number or
bbdat.stName). Everything else is ignored.
error Is the returned error (psat_error class).
If the function is successful,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ‘Busbar is not found.’

Returned values None

31. Get and Set Node Breaker Node


The following function returns the data of a NB Station in the the powerflow data.

get_nb_node_dat(ndid, error)

Where

ndid Is the name (string) or psat_comp_id (structure) of the node breaker node.
error Is the returned error (psat_error class).
If the function is successful,
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 51


PSAT Python User Manual

error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ‘No Node found with the equipment name
"****"’
Returned values Data of node ndid, in psat_nb_node_dat structure, with following attributes:
number node number
name node name
stNum station number
stName station name
bbNum busbar number
bbName busbar name
pfBus preferred bus

The following function sets (changes) the data of a Node in powerflow data.

set_nb_node_dat(ndid, nddat, error)

Where

ndid Is the name (string) or psat_comp_id (structure) of the node.


nddat Is the data for the station, in psat_nb_node_dat (as above).
If nddat.name,number,stName,bbName,pfBus is different from ndid then
they will renamed or renumbered. Everything else will be ignored.
error Is the returned error (psat_error class).
If the function is successful,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ‘No Node found with the equipment name
"****"’

Returned values None

32. Get and Set Node Breaker Connector


The following function returns the data of a NB Connector in the the powerflow data.

get_nb_conn_dat(connid, error)

Where

connid Is the name (string) or psat_comp_id (structure) of the node breaker


connector.
error Is the returned error (psat_error class).
If the function is successful,

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 52


PSAT Python User Manual

error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ‘Connector is not found.’
Returned values Data of conenctor connid, in psat_nb_conn_dat structure, with following
attributes:
number connector number
name connector name
stNum station number
stName station name
status connector status 0:Opem 1:Closed
norStatus connector norma status 0:Open 1:Closed
type connector type 1:Circuit Breaker 2:Switch
frNode from node
toNode to node
rat1 Rating 1
rat2 Rating 2
rat3 Rating 3
react connector Reactance

The following function sets (changes) the data of a Station in powerflow data.

set_nb_conn_dat(ndid, nddat, error)

Where

connid Is the name (string) or psat_comp_id (structure) of the station.


conndat Is the data for the station, in psat_nb_station_dat (as above).
If nddat.name,number,stName,bbName,pfBus is different from ndid then
they will renamed or renumbered. Everything else will be ignored.
error Is the returned error (psat_error class).
If the function is successful,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ‘Connector is not found.’
error.code, error.msg : 2, ‘New Node Breaker Connector type is
invalid.’
error.code, error.msg : 3, ‘New Node Breaker Connector Status is
invalid.’
error.code, error.msg : 4, ‘New Node Breaker Connector Normal Status
is invalid.’

Returned values None

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 53


PSAT Python User Manual

33. Get and Set Component’s Node Data


The following function returns the data of a Nodes of component specified in the the powerflow data. It
also updates the “nodes” struct of fot the compid.

get_comp_node_dat(compid, error)

Where

compid Is the psat_comp_id (structure) of a component that contains node (only if


the component specified is Generator, Load, Fix Shunt, Switchable Shunt,
Line, Fix Transformer, Adjustable Transformer, Fix Series Compresser,
Adjustable Series Compresser, 3 Winding Transformer, STCPR, Converter,
Connector)
error Is the returned error (psat_error class).
If the function is successful,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ‘Component Specified doesn't have node data’
Returned values It also updates the “nodes” struct of fot the compid passed and data of
nodes, in psat_comp_node_dat structure, with following attributes:
nd1 node1 name (populated only if the component specified is Generator, Load,
Fix Shunt, Switchable Shunt, Line, Fix Transformer, Adjustable
Transformer, Fix Series Compresser, Adjustable Series Compresser, 3
Winding Transformer, STCPR, Converter, Connector)
nd2 node2 name (populated only if the component specified is Line, Fix
Transformer, Adjustable Transformer, Fix Series Compresser, Adjustable
Series Compresser, 3 Winding Transformer, STCPR, Connector)
nd3 node3 name (populated only if the component specified is 3 Winding
Transformer)
rnd1 remote node1 name (populated only if the component specified is
Generator, Switchable Shunt, Adjustable Transformer, 3 Winding
Transformer)
rnd2 remote node2 name (populated only if the component specified is 3
Winding Transformer)
rnd3 remote node3 name (populated only if the component specified is 3
Winding Transformer)

The following function sets (changes) the data of a node of the component in powerflow data.

set_comp_node_dat(compid, error)

Where

compid Is the psat_comp_id (structure) of a component that contains node (only if


the component specified is Generator, Load, Fix Shunt, Switchable Shunt,
Line, Fix Transformer, Adjustable Transformer, Fix Series Compresser,
Adjustable Series Compresser, 3 Winding Transformer, STCPR, Converter,

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 54


PSAT Python User Manual

Connector)
error Is the returned error (psat_error class).
If the function is successful,
error.code, error.msg: 0, ’’
Otherwise,
error.code, error.msg : 1, ‘Component Specified doesn't have node data’

Returned values None

eg.
compID = psat_comp_dat(ctype.load, error)
compID.busid = 11
compID.loadid = “1”
compID.nodes.nd1 = “Node11”
set_comp_node_dat (compID,error)

Return: Will update the “Node Name” of load “1” to “Node 11”

OR

loadDat = psat_load_dat()
loadDat.bus = 11
loadDat.id = “1”
compID = loadDat.comp_id()
get_comp_node_dat(compID, error)
compID.nodes.nd1 = “Nodes11”
set_comp_node_dat (compID,error)

Return: Will update the “Node Name” of load “1” to “Node 11”

34. Get and Set Case Data


The following function returns the case settings for the powerflow data.

get_case_dat(error)

Where

error Is the returned error (psat_error class).


If the function is successful,
error.code, error.msg: 0, ’’
Otherwise, error.code is non-zero.

Returned values The case data in psat_case_dat structure, with the following attributes:
projfile Path to project file (259-char)
pffile Path to powerflow file (259-char)
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 55


PSAT Python User Manual

t1 first line of the title (80-char)


t2 second line of the title (80-char)
t3 third line of the title (80-char)
date case date (16-char)
time case time (8-char)
solution_algo solution algorithm. (4 char: "AUTO","XB","NR","BX","XB")
max_iterations maximum number of iterations (integer)
sys_mva_base system MVA base (real)
solution_tol convergence tolerance in terms of maximum MW/MVAR (real)
blow_up_limit blow up limit in terms of max. vol.magnitude deviations (real)
accel_factor acceleration factor when a bus is switched from PQ to PV (real)
zil_threshold zero impedance threshold (real)
voltage_tol used to determine if the voltage controls are satisfied (real)
control_thresh used to initiate the control adjustment (real)
gen_dispatch generator dispatch method (4-char: "SWIN","GOVE","DIST")
start hot or flat start (4-char: "HOT","FLAT")
ait_cflag area interchange control flag (4-char: "ON","LON","OFF")
sws_cflag switchable shunt control flag (boolean)
rsw_vlt_cflag discrete shunt remote voltage control flag
(integer: 0 = Desired Voltage Point, 1 = Within Deadband)
nss_adj_cflag percentage of discrete shunts adjusted per iteration (integer: 1 - 100)
trf_vlt_cflag transformer voltage control flag (boolean)
trf_mvar_cflag transformer MVAR control flag (boolean)
ps_mw_cflag phase shifter MW control flag (boolean)
spr_mw_cflag static phase shifter MW control flag (boolean)
ssc_cflag switchable series capacitor control flag (boolean)
stc_vlt_cflag static tap changers voltage control flag (boolean)
stc_mvar_cflag static tap changers MVAR control flag (boolean)
gen_mvar_cflag limit generator MVAR (boolean)
twt_vlt_cflag *deprecated, ‘trf_vlt_cflag’ controls both 2W and 3W transformers
twt_mvar_cflag *deprecated, ‘trf_mvar_cflag’ controls both 2W and 3W transformers
twt_mw_cflag *deprecated, ‘ps_mw_cflag’ controls both 2W and 3W transformers
itf_mw_cflag interface MW control flag (boolean)
svc_vlt_cflag SVC voltage control flag (boolean)
gen_rc_cflag generator remote voltage control flag (boolean)
gen_gov_cflag generator governor dispatch flag (boolean)
sb_mvar_cflag limit swing bus generator MVAR (boolean)
uvlc_cflag under-voltage load conversion control flag (boolean)
uvlc_thresh under-voltage load conversion threshold for constant power load (real)

The following function sets (changes) the case settings of the powerflow data.

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 56


PSAT Python User Manual

set_case_dat (casedat, error)

Where

casedat Is the new case settings, in psat_case_dat structure (as above).


casedat.projfile/pffile is ignored.
error Is the returned error (psat_error class).
If the function is successful,
error.code, error.msg: 0, ’’
Otherwise, error.code is non-zero.

Returned values None

35. Get Short Circuit Data


The following function can be used to return a list of Short Circuit results based on the Sequence Data
specified.

get_shortcircuit_dat ( [bus_list], [seqfile], [refbus], unit_flag, format_flag, error)

Where
bus_list Is an optional list of bus numbers used to generate short circuit results for
each bus in the list. If this parameter is not specified the short circuit report
will be generated for all buses.
seqfile Is an optional path to the sequence data file to be used in the short circuit
calculations.
refbus Is an optional bus number for the bus that is to be used as the Transfer
Impedance Reference bus.
unit_flag Is an integer flag to indicate the unit of the return values where:
0 = Per-Unit, 1 = kA, 2 = MVA
format_flag Is an integer flag to indicate the format of the return values where:
0 = Cartesian, 1 = Polar
error Is the returned error (psat_error class).
If the function is successful,
error.code, error.msg: 0, ’’
Otherwise, error.code is non-zero.
Returned values A list of SCItem elements (sc_vector list class), one element for each buses
short circuit result. Each SCItem in the list has the following attributes:

number Bus Number


r1 Positive Sequence (R / Magnitude)
x1 Positive Sequence (X / Angle)
r2 Negative Sequence (R / Magnitude)

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 57


PSAT Python User Manual

x2 Negative Sequence (X / Angle)


r0 Zero Sequence (R / Magnitude)
x0 Zero Sequence (X / Angle)
i_fault Fault Currents, has the following attributes:
lll_r LLL Fault Current (Real / Magnitude)
lll_i LLL Fault Current (Imaginary / Angle)
llg_r LLG Fault Current (Real / Magnitude)
llg_i LLG Fault Current (Imaginary / Angle)
ll_r LL Fault Current (Real / Magnitude)
ll_i LL Fault Current (Imaginary / Angle)
lg_r LG Fault Current (Real / Magnitude)
lg_i LG Fault Current (Imaginary / Angle)
y_fault Fault Admittances, has the following attributes:
llg_r LLG Fault Admittance (Real / Magnitude)
llg_i LLG Fault Admittance (Imaginary / Angle)
ll_r LL Fault Admittance (Real / Magnitude)
ll_i LL Fault Admittance (Imaginary / Angle)
lg_r LG Fault Admittance (Real / Magnitude)
lg_i LG Fault Admittance (Imaginary / Angle)

36. Get WSCR Data


The following function returns a list of WSCR results based on the WSCR criteria specified in the current
projects criteria file. To specify a criteria file for the project using python refer to the next scction on how
to Get and Set Criteria file.

get_wscr_dat(error)

Where

error Is the returned error (psat_error class).


If the function is successful,
error.code, error.msg: 0, ’’
Otherwise, error.code is non-zero.

Returned values A list of WSCRItem elements (w_vector list class), one element for each
WSCR criteria group specified in the criteria file. Each WSCRItem in the
list has the following attributes:
name group name of the WSCR criteria (string)
limit WSCR criteria limit as specified in the critera file (real)
value calculated WSCR value (real)

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 58


PSAT Python User Manual

37. Get and Set Criteria File


The following function can be used to get the filename of the criteria file currently specified in the PSAT
project:

get_criteria_file()

Where

Returned value A string value that is the full path to the criteria file specified in the PSAT
project, if no file is specified the string is blank.

The following function can be used to set or change the the criteria file used in the current PSAT project:

set_criteria_file(filename, error)

Where

filename Is the full path to the criteria file to be set to the PSAT project (string)
error Is the returned error (psat_error class).
If the function is successful,
error.code, error.msg: 0, ’’
Otherwise, error.code is non-zero.

Returned values A string value that is the full path to the criteria file that was previously
specified in the PSAT project, if no file was specified the string is blank.

38. Get and Set Properties


The following three functions return an integer property, a real (floating point) property or a string
property, respectively, of a component in the powerflow data.

get_int_prop (compid, propnam, error)


get_real_prop (compid, propnam, error)
get_str_prop (compid, propnam, error)

The following three functions set the value of an integer property, a floating point property or a string
property, respectively, of a component in the powerflow data (they have no Returned value).

set_int_prop (compid, propnam, intval, error)


set_real_prop (compid, propnam, realval, error)
set_str_prop (compid, propnam, strval, error)

Where

compid Is the identifier of the component in psat_comp_id structure. (refer to


section 4.2 for more details on this structure).
propnam Is the property name (string), which is the same as the name of one of the
attributes of the component’s data structure. The attribute names for
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 59


PSAT Python User Manual

psat_bus_dat, psat_gen_dat and other data structures are described for Get
and Set Bus Data, Gen Data and similar functions above. Alternatively,
propnam can be integer prop.number, prop.id, etc., described below
(computation is faster with integer prop.*).
Note that Get and Set Property functions can’t be used for an element of an
array attribute, e.g., they can’t get or set nb(2) of a switchable shunt. Use
Get and Set Data functions above for the array attributes.
intval Is the integer value of the property to be “set”.
realval Is the floating point value of the property to be “set”.
strval Is the string value of the property to be “set”.
error Is the returned error (psat_error class).
If the component and property identified by compid and propnam (or
cmptype and propid described below) exist in the powerflow data and there
is no error,
error.code, error.msg : 0, ’’
If the component does not exist,
error.code, error.msg : 1, ’Component is not found.’
If compid.type (or cmptype) does not have one of the values listed above
for this attribute,
error.code, error.msg : 2, ’Component type is invalid.’
If propnam (propid) is not the name (value) for of one of the attributes of
the corresponding component data structure,
error.code, error.msg : 3, ’Property name (id) is invalid.’
If intval, realval or strval is not an acceptable value to set for the property,
error.code, error.msg : 4, ’New value is invalid.’

The attributes of psat_comp_id structure that do not apply to the component type (e.g., bus2 for generator,
or DC buses for AC components) are ignored.

You may create the compid object for use as an argument for the get and set property functions by the
following statement:

compid = psat_comp_id(type, [bus, [bus2,[bus3,[bus4,]]] [id,][secno,]])

Where

type Is the component type (string), which is one of the values described above
for the type attribute of psat_comp_id structure
bus number (integer) or name (string) of the bus of AC component, or the first-
bus of multi-bus AC components, or
name (string) of the DC bus of DC component, or the first DC bus of multi-
bus DC component
bus2 number (integer) or name (string) of the second AC bus of multi-bus AC
components, or
name (string) of the second DC bus of multi-bus DC component
bus3 number (integer) or name (string) of the third AC bus of multi-bus AC
components, or
number (integer) or name (string) of the first AC bus of DC converters
bus4 number (integer) or name (string) of the forth AC bus of multi-bus AC
components, or

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 60


PSAT Python User Manual

number (integer) or name (string) of the second AC bus of voltage-source


converters
(bus, bus2, bus3 and bus4 must be specified in the correct order)
id ID of AC component (string) or ID of DC component (integer)
secno section number when the component is a sectional branch

The arguments that do not apply to the component type should be omitted (as indicated by “[ ]” in the
above statement). See the examples below on how to specify the components, also refer to section 4.2 for
more details on the psat_comp_id structure.

An alternative form of Get and Set Property functions is:

get_int_prop (cmptype, bus, [bus2,[bus3,[bus4,]]] [id,][secno,] propid,error)


get_real_prop (cmptype, bus, [bus2,[bus3,[bus4,]]] [id,][secno,] propid,error)
get_str_prop (cmptype, bus, [bus2,[bus3,[bus4,]]] [id,][secno,] propid,error)

set_int_prop (cmptype, bus, [bus2,[bus3,[bus4,]]] [id,][secno,] propid, intval, error)


set_real_prop (cmptype, bus, [bus2,[bus3,[bus4,]]] [id,][secno,] propid, realval, error)
set_str_prop (cmptype, bus, [bus2,[bus3,[bus4,]]] [id,][secno,] propid, strval, error)

Where

cmptype Is an integer having one of the following “defined” values:


ctype.bus or ctype.bs
ctype.generator or ctype.gen
ctype.load or ctype.ld
ctype.fixed_shunt or ctype.fxsh
ctype.switchable_shunt or ctype.swsh
ctype.line or ctype.ln
ctype.fixed_transformer or ctype.fxtr
ctype.adjustable_transformer or ctype.ultc
ctype.three_winding_transformer or ctype.twtr
ctype.fixed_series_compensator or ctype.fxsc
ctype.adjustable_series_compensator or ctype.vrsc
ctype.static_tap_changer_phase_regulator or ctype.stcpr
ctype.dc_bus or ctype.dcbs
ctype.dc_converter or ctype.cnvrtr
ctype.voltage_source_converter or ctype.vsc
ctype.dc_line or ctype.dcln
ctype.dc_breaker or ctype.dcbrkr
ctype.area or ctype.ar
ctype.zone or ctype.zn
ctype.owner or ctype.own
ctype.node or ctype.nd
bus, bus2, Are the same as the arguments of compid=psat_comp_id() described
bus3, bus4, above. Note that bus2, bus3, bus4, id or secno should be omitted if they
do not apply to the component type (see the examples below)
id, secno
propid Is an integer having one of the “defined” values prop.xxx, Where xxx is
the same as the name of one of the attributes of the component’s data

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 61


PSAT Python User Manual

structure, similar to propnam string described above (e.g., prop.number,


prop.status, prop.id, etc.)
intval, realval, Are the same as those in the first form of Get and Set Property
strval, error functions described above

Note that although ctype.xxx and prop.xxx are “defined” integer values, you must leave them as
“constants” and do not assign values to them (don’t use them as variables).

For example,

error = psat_error()
comp = psat_comp_id (’gen’,123, ’1’)
# Note that bus2, bus3, bus4 and secno are omitted
p = get_real_prop (comp, ’mw’, error)

If the generator exists, p is the MW output of generator ’1’ at bus 123 and error.code is 0. If the generator
doesn’t exist, the returned value is unknown and error.code is1 and error.msg is ’Component is not
found.’

Another example,

error = psat_error()
set_int_prop (ctype.line, 101, 102, ’1’, 0, prop.status, 0, error)
# Note that bus3 and bus4 are omitted

If the line ’1’ from bus 101 to bus 102 exists, it is put out of service and error.code is 0.

If the line doesn’t exist, or if it is connected from bus 102 to 101 (instead of from bus 101 to bus 102),
error.code is 1 and error.msg is ’Component is not found.’ and no change is made to the powerflow data.

39. Add and Delete Components


The following function adds a new component to the powerflow data and sets its attributes.

add_comp (compdat, error)


add_comp (compid, error)
add_comp (cmptype, bus,[bus2,[bus3,[bus4,]]] [id,][secno,] newcomp, error)

Where

compdat Is the data for the new component in the corresponding psat_*_dat structure
described for the set_*_dat functions above.
When the new component is bus, area, zone or owner, if you set its number
to 0 in compdat, it will change to 1 plus the last existing number in the
powerflow data. If you set its name to ’’ in compdat, it will change to an
automatically assigned name.
For other components, if you set the ID to ’’ in compdat, it will change to a
unique non-blank ID. For example as you add generators to one bus, their
ID is set to ’1’, ’2’, ’3’, etc.
Other attributes of the new component are set to the values specified in
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 62


PSAT Python User Manual

compdat, so you must make sure acceptable values are specified in


compdat.
On return, compdat contains the set values of the attributes (e.g. the
automatically assigned name, ID, etc.)
compid Is the identifier of the component in psat_comp_id structure with the
attributes listed above for the Get and Set Properties functions.
Bus number(s) and ID of the new component will be set to those specified
in compid. Bus number 0 and ID ’’ will change to automatically assigned
values as described for compdat above. Other attributes of the new
component will be set to PSAT default values.
On return, compid contains the automatically assigned bus numbers and ID.
cmptype, Are the identifiers of the component (alternative for compid) similar to
bus, bus2, those for the Get and Set Properties functions described above. The
attributes of the new component will be set the same way as when this
bus3, bus4,
function is called with compid.
id, secno
newcomp Is the returned identifier of the component in psat_comp_id structure,
similar to the returned compid when this function is called with compid.
error Is the returned error (psat_error class).
If the new component is added and its data is set properly,
error.code, error.msg : 0, ’’
If compid.type is not a valid name,
error.code, error.msg : 101, ’Component type is invalid.’
If the component identified by compdat already exists in the powerflow
data,
error.code, error.msg : 102, ’Component already exists.’
For a sectional branch, if the section number in compdat is not valid (as
described in the next section),
error.code, error.msg : 103, ’Section number is invalid.’
If the new component can’t be added,
error.code, error.msg : 104, ’Can not add component’
If the data can’t be set to compdat, retuned error is the same as that returned
by the corresponding set_*_dat function.

Returned values None

The following function deletes a component from the powerflow data.

delete_comp (compdat, error)


delete_comp (compid, error)
delete_comp (cmptype, bus,[bus2,[bus3,[bus4,]]] [id,][secno,]error)

Where

compdat Is the data for the new component in the corresponding psat_*_dat structure
described for the set_*_dat functions above. Only the identifier attributes
(bus numbers and ID) are needed and other attributes (status, etc.) are
ignored.
compid Is the identifier of the component in psat_comp_id structure with the
attributes listed above for the Get and Set Properties functions.

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 63


PSAT Python User Manual

cmptype, Are the identifiers of the component (alternative for compid) similar to
bus, bus2, those for the Get and Set Properties functions described above.
bus3, bus4,
id, secno
error Is the returned error (psat_error class).
If the component is deleted from the powerflow data,
error.code, error.msg : 0, ’’
If compid.type does not have one of the values listed for Get and Set
Properties,
error.code, error.msg : 1, ’Component type is invalid.’
If the component does not exist,
error.code, error.msg : 2, ’Component is not found.’
If the component is a sectional branch and compid.secno does not have an
acceptable value (as described in the next section),
error.code, error.msg: 3, ’Section number is invalid.’

Returned values None

For example, to add generator ’2’ at bus 123 by duplicating the existing generator ’1’,

error = psat_error()
gndt = get_gen_dat (123, ’1’, error)
gndt.id = ‘2’ # or gndt.id = ‘’
add_comp (’gen’, gndt, error)

40. Add and Delete Sectional Branches


For the add_comp and delete_comp functions described above, if the component to be added or deleted is
a non-sectional branch, secno in compdat or compid is ignored. Otherwise the following rules apply.

To add a section to an existing non-sectional branch, in compdat set secno to 2, and set frbus, tobus and id
the same as that of the existing branch. The existing branch becomes section 1. If, instead, you set secno
to 1, the existing branch becomes section 2.

Adding a branch with secno = k, and frbus, tobus and id in compdat the same as an existing sectional
branch that has n sections, places the new section after section k-1 of the existing branch and the existing
sections k:n become sections k+1:n+1. k must be between 1 and n+1.

Deleting a sectional branch when compid.scno is set to 0, deletes all sections of that branch.

To delete only section k of a sectional branch with n sections, set compid.secno to k. The remaining
sections k+1:n become sections k:n-1. k must be between 1 and n.

If the section number specified for adding or deleting a section does not correspond to the above
description, add_comp and delete_comp functions return ’Section number is invalid.’ in the error
message.

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 64


PSAT Python User Manual

41. Counting Sections of a Branch


The following function returns the number of sections in a branch.

get_count_sections (compdat)
get_count_sections (compid)
get_count_sections (bus1,bus2,id)

Where

compdat Is the data for one section of the branch in the corresponding psat_*_dat
structure described for the set_*_dat functions above. Only the identifier
attributes (bus numbers and ID) are needed and other attributes (section
number, impedance, etc.) are ignored.
compid Is the identifier of one section of the branch in psat_comp_id structure with
the attributes listed above for the Get and Set Properties functions.
compid.secno is ignored for this function.
bus, bus2, id Are the identifiers of the branch (alternative for compid) similar to those for
the Get and Set Properties functions described above.

Returned value Number of sections in the sectional branch (integer).


If less than 2, the branch is not sectional.

42. Get a Section of a Branch


The following function returns a section of a branch.

get_section (compid)
get_section (bus1,bus2,id,secno,error)

Where
compid Is the identifier of one section of the branch in psat_comp_id structure with
the attributes listed above for the Get and Set Properties functions. The
compid.type attribute is ignored. This function will return the identifier of
the section that matches compid.secno
bus, bus2, id, secno Are the identifiers of the branch (alternative for compid) similar to those for
the Get and Set Properties functions described above. This function will
return the identifier of the section that matches secno.
error Is the returned error (psat_error class).
If the section identified exists in the powerflow data and there is no error,
error.code, error.msg : 0, ’’
If branch does not exist or is not a sectional branch,
error.code, error.msg : 1, ’Sectional Branch is not found.’
If the branch does not have a section matching secno,
error.code, error.msg : 2, ’Section is not found.’

Returned values Is the identifier of the section, including its type, in psat_comp_id
structure.

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 65


PSAT Python User Manual

43. Get Solution Status


The following function returns the status of the powerflow solution.

get_solution_status()

Returned values An integer code representing the current solution status where:
1 Solved
0 Not solved
-1 Error during solution
-2 Did not converge
-3 Diverged

44. Set Solution Failure Option


The following function sets the default action to take if a solution fails to solve.

set_solution_failure_option (option)

Where
option Is an integer code to define the default action to take if a solution fails to
solve:
0: Prompt user with an option dialog,
1: Restore the pre-solution conditions,
2: Keep the current conditions.

The following optional codes may be added to the default codes (1&2):
8: Do opposite default action if solution status is 'Did not converge'
16: Do opposite default action if solution status is 'Diverged'

For Example: If set_solution_failure_option is set to 9 (1+8) then if PSAT


fails to solve it will 'Restore pre-solution values' unless the
solution status is 'Did not converge' in which case PSAT will
do the pposite and 'Keep solution values'

Note: If an error occurs during solution option 1 will be used in place of


option 2.

Returned values An integer code representing the current solution status where:
0 Failed to set the solution option (specify an option between 0 and 2)
1 Solution failure option set successfully

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 66


PSAT Python User Manual

45. Disable Engine Messages


The following function prevents engine messages from being displayed to the message window. This can
speed up processing speed when performing many operations (like Solutions) that generate messages that
will normally be ignored such as in batch powerflow operations.

disable_engine_messages (bDisable)

Where
bDisable Is an boolean option to disable or re-enable PSAT engine message display.
true: Disable engine messages,
false: Re-enable engine messages.

Returned values An integer code representing the current solution status where:
true If the message state has been modified.
false If the message state has not changed.

46. Subsystems

46.1 Subsystem Definition

This section describes the functions for defining a subsystem of buses, areas, zones, etc., and iterating on
the components in that subsystem.

There is always a main subsystem called “mainsub”. Initially (by default) it is set to <All> (the whole
powerflow data). This can be changed by subsys_inc/exc functions described below.

The following function creates a new empty subsystem.

subsys_define (subname)

Where

subname Name of the subsystem (string).

Several subsystems can be defined, each with a different name. If a subsystem with the same name has
been defined previously, the above function will empty that subsystem (sets it to <None>).

The following function re-initializes the subsystems.

subsys_clear () # reset “mainsub” to <All>


subsys_clear (subname) # reset subsystem subname to <None>

46.2 Subsystem Deletion

The following function deletes a subsystem.

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 67


PSAT Python User Manual

subsys_delete (subname)

Where

subname Subsystem name (string)

46.3 Subsystem Include and Exclude

The following functions add buses, areas, zones and kV levels to the subsystem.

subsys_inc_bus (subname, busid)


subsys_inc_bus (subname, frbus, tobus)
subsys_inc_area (subname, areaid)
subsys_inc_area (subname, frarea, toarea)
subsys_inc_zone (subname, zoneid)
subsys_inc_zone (subname, frzone, tozone)
subsys_inc_kv (subname, kvid)
subsys_inc_kv (subname, frkv, tokv)
subsys_inc_comp(subname, bus1, bus2, bus3, ID)
subsys_inc_vicinity (subname, busid, level)
subsys_inc_vicinity (subname, frbus, tobus, level)
subsys_inc_type (subname, bustype)
subsys_inc_status (subname, status)
subsys_inc_nb_station (subname, stationid)
subsys_inc_nb_station (subname, frstn, tostn)
subsys_inc_owner (subname, ownerid)
subsys_inc_owner (subname, frowner, toowner)

The following functions remove buses, areas, zones and kV levels from the subsystem.

subsys_exc_bus (subname, busid)


subsys_exc_bus (subname, frbus, tobus)
subsys_exc_area (subname, areaid)
subsys_exc_area (subname, frarea, toarea)
subsys_exc_zone (subname, zoneid)
subsys_exc_zone (subname, frzone, tozone)
subsys_exc_kv (subname, kvid)
subsys_exc_kv (subname, frkv, tokv)
subsys_exc_comp(subname, bus1, bus2, bus3, ID)
subsys_exc_vicinity (subname, busid, level)
subsys_exc_vicinity (subname, frbus, tobus, level)
subsys_ exc_type (subname, bustype)
subsys_ exc_status (subname, status)
subsys_ exc_nb_station (subname, stationid)
subsys_ exc_nb_station (subname, frstn, tostn)

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 68


PSAT Python User Manual

subsys_ exc_owner (subname, ownerid)


subsys_ exc_owner (subname, frowner, toowner)

Where

subname Subsystem name (string). If not specified, as in subsys_inc_bus(123), it


refers to the main subsystem (i.e., subname = “mainsub”).
busid is the number (integer) or name (string) of the bus
frbus, tobus are the bus numbers (integers) defining the range of frbus:tobus

areaid is the number (integer) or name (string) of the area


frarea, toarea are the area numbers (integers) defining the range of frarea:toarea

zoneid is the number (integer) or name (string) of the zone


frzone, tozone are the zone numbers (integers) defining the range of frzone:tozone

kvid is the base kV value (real)


frkv, tokv are the base kV values (real) defining the range of frkv:tokv
bus1,bus2,bus3 is the number (integer) or name (string) for a powerflow component
(bus2 and bus3 numbers are optional parameters)
ID is the ID (string) of a component in the powerflow, if omitted the default
value is ‘*’ which matches any ID.
level is the number of levels around the specified bus(s) used to determinte the
vicinity or group of busses included or excluded.
bustype ranges from 1-4 where
1:Load Bus
2:Gen Bus
3:Swing Bus
4:Out
status status:
0: out of service
1: in service
2: secondary winding out of service
3: tertiary winding out of service
4: primary winding out of service
stationid is the number (integer) or name (string) of the station
frstn, tostn are the station numbers (integers) defining the range of frstn:tostn
ownerid is the number (integer) or name (string) of the owner
frowner,toowner are the owner numbers (integers) defining the range of frowner:toowner

Note that, as in the Composite Subsystem definition in PSAT, the final contents of the subsystem depend
on the order in which the above subsys_inc/exc functions are called. Think of the subsystem as a
container that every subsys_inc_* call puts components in it and every subsys_exc_* call removes
components that are previously put in it.

The functions subsys_inc_comp and subsys_exc_comp are capable of including or excluding multiple
components with a single command. By not specifying the ID parameter a wildcard ID (‘*’) is used.
For example:
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 69


PSAT Python User Manual

subsys_inc_comp(123) #This will include bus 123 and all connected components
subsys_inc_comp(10,20) #This will include all components connected to both bus 10 and 20

To omit bus2 or bus3 when specifying buses by name you must specify an empty string (‘’). The
following example will exclude all components with an ID of ‘1’ that are connected to both bus ‘A’ and
‘B’:

subsys_exc_comp(‘A’,’B’,’’,’1’)

46.4 Iteration on Subsystem Components

The first call to the following function after the subsystem is defined or modified by one of the subsys_*
functions above, returns the first component of a specified type in that subsystem.

Subsequent calls to this function return the next component in the subsystem.

get_next_comp (subname, compid, error)

Where

subname Subsystem name (string). If not specified, as in get_next_comp(compid,


error), it refers to the main subsystem (i.e., subname = “mainsub”).
compid Is the identifier of the component in psat_comp_id structure with the
attributes listed above for the Get and Set Properties functions.
compid.type must be set to bus, gen, etc., before the call (otherwise, it is set
to bus by default).
On return, the remaining attributes of compid identify the “next”
component found in the subsystem.
error Is the returned error (psat_error class).
If compid.type is a valid name,
error.code, error.msg : 0, ’’
Otherwise,
error.code, error.msg : 1, ’Component type is invalid.’

Returned value Logical value:


true if the “next” component is found
false if there is no component of the specified type in the subsystem, or
get_next_comp has passed the last component

Note that after any change to the subsystem (call to subsys_inc/exc) the above function returns the first
component in the subsystem. Also, after returning “false” (passed the last component), the next call
returns the first component again.

Without defining the main subsystem, or after calling subsys_clear(), this subsystem is set to <All>, so
the first call without subname argument returns the first component in the powerflow data and the
following calls return the next components until the last component in the powerflow data.

The following function resets the pointer to the first component in the subsystem, so that the following
get_next_comp will return the first component.

reset_next_comp (subname, type, error)


This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 70


PSAT Python User Manual

Where

subname Subsystem name (string). If not specified, as in reset_next_comp(type,


error), it refers to the main subsystem (i.e., subname = “mainsub”).
type Is the component type, which must have one of the values of
psat_comp_id.type (string) or ctype.xxx (integer) as listed above for the Get
and Set Properties functions (“bus”, “gen”, etc., or ctype.bus, ctype.gen,
etc.).
error As in the get_next_comp function.

46.5 Subsystem Count

The following function returns the number of components of a specified type in the subsystem.

get_count_comp (subname, type, error)

Where

subname Subsystem name (string). If not specified, as in get_count_comp (type,


error), it refers to the main subsystem (i.e., subname = “mainsub”).
type Is the component type which must have one of the values of
psat_comp_id.type (string) or ctype.xxx (integer) as listed above for the Get
and Set Properties functions (“bus”, “gen”, etc., or ctype.bus, ctype.gen,
etc.).
error As in the get_next_comp function.

Returned value Number of “type” components in the subsystem (integer).

47. Equipment Name Commands


The following functions can be used to search for and modify PSAT data using component equipment
name based commands. The returned value of each of these functions is the same as the non-equipment
name form.

These functions can be used to get the data of components using equipment name for lookups:

get_bus_dat_eq (eqname, error)


get_gen_dat_eq (eqname, error)
get_load_dat_eq (eqname, error)
get_fx_shunt_dat_eq (eqname, error)
get_sw_shunt_dat_eq (eqname, error)
get_line_dat_eq (eqname, error)
get_fx_trans_dat_eq (eqname, error)
get_2w_trans_dat_eq (eqname, error)

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 71


PSAT Python User Manual

get_3w_trans_dat_eq (eqname, error)


get_fx_sercomp_dat_eq (eqname, error)
get_aj_sercomp_dat_eq (eqname, error)
get_stcpr_dat_eq (eqname, error)
get_z_seq_coupling_dat_eq (line1eqname, line2eqname, error)

Where

eqname Is the equipment name (string) of the component


line1eqname Is the Z-Seq Coupling Line1 equipment name (string)
line2eqname Is the Z-Seq Coupling Line2 equipment name (string)
error Is the returned error (psat_error class).
If a component with eqName exists in the powerflow data,
error.code, error.msg: 0, ’’

Returned values Data structure for the specified component. Refer to the non-equipment
name functions for details on the returned structure.

These functions can be used to set the data of components using equipment name lookups:

set_bus_dat_eq (eqname, busdat, error)


set_gen_dat_eq (eqname, gendat, error)
set_load_dat_eq (eqname, loaddat, error)
set_fx_shunt_dat_eq (eqname, fx_shuntdat, error)
set_sw_shunt_dat_eq (eqname, sw_shuntdat, error)
set_line_dat_eq (eqname, linedat, error)
set_fx_trans_dat_eq (eqname, fx_transdat, error)
set_2w_trans_dat_eq (eqname, transdat, [test_data_entry], error)
set_3w_trans_dat_eq (eqname, transdat, [test_data_entry], error)
set_fx_sercomp_dat_eq (eqname, fx_sercompdat, error)
set_aj_sercomp_dat_eq (eqname, aj_sercompdat, error)
set_stcpr_dat_eq (eqname, stcprdat, error)
set_z_seq_coupling_dat_eq (line1eqname, line2eqname, zseqdat, error)

Where

eqname Is the equipment name (string) of the component


line1eqname Is the Z-Seq Coupling Line1 equipment name (string)
line2eqname Is the Z-Seq Coupling Line2 equipment name (string)
[comp]dat Is the new data for the specified component. Refer to the non-equipment
name functions for details on the component structure.
test_data_entry Is an optional boolean value (True or False). When ‘True’, it specifies that
the test data entry fields of the input data parameter are used instead of the
PSAT default fields. See the non-equipment name functions for
set_2w_trans_dat & set_3w_trans_dat for more details.
This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 72


PSAT Python User Manual

error Is the returned error (psat_error class).


If the powerflow data is set
error.code, error.msg: 0, ’’

Returned values None

These functions can be used to get individual properties of components using equipment name lookups:

get_int_prop_eq (cmptype, eqname, prop, error)


get_real_prop_eq (cmptype, eqname, prop, error)
get_str_prop_eq (cmptype, eqname, prop, error)

The following three functions set the value of an integer property, a floating point property or a string
property, respectively, of a component in the powerflow data (they have no Returned value).

set_int_prop_eq (cmptype, eqname, prop, intval, error)


set_real_prop_eq (cmptype, eqname, prop, realval, error)
set_str_prop_eq (cmptype, eqname, prop, strval, error)

Where

cmptype Is the component type (string) or integer value (ctype). Refer to the
non-equipment name functions for details.
eqname Is the equipment name (string) of the component
prop Is the property name (string), which is the same as the name of one of
the attributes of the components data structure. This may also be an
integer value having one of the “defined” values prop.xxx. ). Refer to
the non-equipment name functions for details
intval, realval, Are the same as those in the first form of the non-equipment Get and
strval, error Set Property functions described above

Returned value Get functions return an integer, real, or string value respectively.
Set functions have no return value.

These functions can be used to include or exclude (wild-card capable) equipment name string filters to the
subsystems:

subsys_inc_eqname (subname, eqname)


subsys_exc_eqname (cmptype, eqname)

Where

subname Is the subsystem name (string). If not specified, as in


subsys_inc_eqname (“Gemini_*”),
it refers to the main subsystem (i.e., subname = “mainsub”).
eqname Is the equipment name (string) of the component (wildcards allowed)

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 73


PSAT Python User Manual

48. Executing PSAT Commands


The following function executes a PSAT macro command.

psat_command (cmnd, error)

Where

cmnd Is a PSAT macro command (string).

error Is the returned error (psat_error class) with error.msg set by the macro
command.

Returned value Logical value:


true if the command has executed successfully
false if the command has failed.

Among the more frequently used PSAT macro commands are:

’OpenPowerflow:"PFB_name"’
Opens a saved PFB (binary powerflow) file. PFB_name (in double quotes) is the name of
the file, e.g., c:\temp\t1.pfb.

’Solve’
Solves the powerflow.

’Import:"powerflow_filename";frmt’
Imports a powerflow data (converts it to PFB). powerflow_filename (in double quotes) is
the name of powerflow data file and frmt (without quotes) is its format, e.g., PTI Rawd
30.

’RunMacroFile:"macro_filename"’
Runs a saved PSAT Macro file named macro_filename.

’SavePowerflow’
Saves the PFB data in the file that has been opened.

’SavePowerflowAs:"new_PFB_name"’
Saves the PFB data in a file named new_PFB_name.

49. Executing PSAT Print Messages


The following function prints a message in PSAT message window.

psat_msg (msgtext)

Where

msgtext Is the message (string) which will appear in the message window.

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 74


PSAT Python User Manual

Returned value None.

The following function pops-up a window to display a message. Pressing the “OK” button will close this
window.

psat_msg_box (msgtext)

Where

msgtext Is the message (string) which will appear in the pop-up window.

Returned value None.

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 75


PSAT Python User Manual

50. Executing PSAT Read Input


The following function pops-up a window to display a prompt and have a box for the user to type in a
string of text or numbers.

psat_read (prompt)

Where

prompt Is the prompt message (string) which will appear in the pop-up window.

Returned value Typed string in the pop-up window.

The following function pops-up a window to display a prompt and have the user click the “Yes” or “No”
button, which will close the window.

psat_read_yn (prompt)

Where

prompt Is the prompt message (string) which will appear in the pop-up window.

Returned value Logical value:


true if the user has clicked “Yes”
false if the user has clicked “No”

The following function pops-up a windows dialog that allows the user to select from a specified list of
choices and returns a list of the users seletions to python.

psat_selection (multi-select, title, choices, selections)

Where

multi-select is a flag (boolean), where true indicates that multiple selections are
allowed, and false indicates only one selection can be made.
title the title (string) which will appear in the pop-up window.
choices is a list of choices (strings) that will be shown to the user, either in a combo
box for single selection, or a list box for multi selection.
selections is a returned list of selections (integers) that is updated with the indexes
into the choices list that reflect the users selections.

Returned value Logical value:


true if the user has clicked “Yes”
false if the user has clicked “No”

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 76


PSAT Python User Manual

The following function pops-up windows file browse dialog that the user can use to browse for a file and
return the location of the selected file to python.

psat_filebrowse (title, filetype, extension)

Where

title is the title (string) which will appear in the pop-up window.

filetype is the file type description (string) which will appear in the file type filter
dropdown box
extension is the file extension (string) that will be used when selecting the specified
file type in the file type filter dropdown box

Returned value The full path to the file opened through the windows file browse dialog, or
an empty string if the user cancels the open file operation.

51. User Written Functions


To write your own functions that you can call from other scripts or functions, you will use a text editor to
write the code according to the Python language rules and save them in Python files with a .py extension,
(e.g., test1.py). If these functions call PSAT Python functions, they must import them from
psat_python[XX] module by the following statement:

from psat_python[XX] import *

Where [XX] is the version of python being used (25,27, etc). This is then followed by the “definition”
statement as in:

def testfunc(arg1, arg2, …):

this is then followed by the rest of the code. For example if you use python 2.7 and wanted to create a
function that taps a line, you write:

from psat_python27 import *

# Specify the line's From-bus, To-bus, ID, percentage from From-bus, and New-bus

def tapline(frbus, tobus, id, xpc, nwbus):


error = psat_error()
psat_msg("Tapping line " + str(frbus)+" "+str (tobus) +" "+ id + " at " + str(xpc))
...

You then save this code in a Python file, e.g., TapLine.py, in the UserScripts folder located under the
PSAT\Bin\Python\ folder.

To call this function from within other scripts, you first import and then call it as in:

from UserScripts.TapLine import tapline


tapline(101, 102, '1', 25.0, 0)

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 77


PSAT Python User Manual

The import statement specifies the folder where the file is located (“UserScripts”) and the filename
(“TapLine”), separated by a “.” . It then specifies the function name defined in this script file (“tapline”)
that you wish to make available to the calling script. You can specify “*” instead of the function name if
you want to load all the functions defined in the script file. Note that the folder, file and function names
are all case-sensitive in the above statements.

52. Debugging Python Functions Within PSAT


To debug your Python code, you need run the Python script ‘RunIdle.py’ within PSAT. The file comes
with your PSAT installation and can be found in the folder ‘..\Psat\bin\python\UserScripts\’.

‘RunIdle.py’ provides the IDLE (Python’s Integrated Development Environment) interface with PSAT
environment embedded. Within the IDLE, the standard module (‘pdb’) can be called to set breadkpoints,
to watch variables, and to evaluate Python codes.

To use the module (‘pdb’), the following statement has to be added to the beginning of your Python script
file:

Import pdb;

The typical usage to break into the debugger from a running script is to insert:

pdb.set_trace();

at the location where you want to break into debugger. You can then check the variables or step through
the codes following this statement. For more information on debugging Python code, please refer to
Python official website: http://www.python.org.

This document contains proprietary information and shall not be reproduced in whole or in part without the prior written perm ission of Powertech.

Powertech Labs Inc. 78

You might also like