PyMU package¶
aggPhasor¶
client¶
-
class
Client
(theDestIp, theDestPort, proto='TCP', sockType='INET')[source]¶ Bases:
object
Client class that creates a client and provides simple functions for connecting to PMUs or PDCs without needing to directly use Python’s socket library. Supports INET and UNIX sockets
Parameters: - theDestIp (str) – IP address to connect to. If using unix socket this is the file name to connect to
- theDestPort (int) – Port to connect to
- proto (str) – Protocol to use. Accepts TCP or UDP
- sockType (str) – Type of socket to create. INET or UNIX
-
readSample
(bytesToRead)[source]¶ Read a sample from the socket
Parameters: bytesToRead (int) – Number of bytes to read from socket Returns: Byte array of data read from socket
-
sendData
(bytesToSend)[source]¶ Send bytes to destination
Parameters: bytesToSend (int) – Number of bytes to send
pmuCommandFrame¶
-
class
CommandFrame
(commandStr, pmuIdInt, debug=False)[source]¶ Bases:
pymu.pmuFrame.PMUFrame
Class for creating a Command Frame based on C37.118-2005
Parameters: - commandStr (str) – Command to send
- pmuIdInt (int) – Frame ID of PMU
- debug (bool) – Print debug statements
-
genFracsec
()[source]¶ Generate fraction of seconds based on current time
Returns: FRACSEC field bytes as hex str
pmuConfigFrame¶
Class for parsing Config Frame 1 or 2
-
class
Anunit
(anunitHexStr, debug=False)[source]¶ Bases:
object
Class for conversion factor for analog channels
Parameters: anunitHexStr (str) – Conversion factor for analog channels field in hex str format
-
class
ConfigFrame
(frameInHexStr, debug=False)[source]¶ Bases:
pymu.pmuFrame.PMUFrame
Parses Config Frame (1 or 2)
Parameters: - frameInHexStr (str) – Config frame as byte array in hex str format
- debug (bool) – Print debug statements
-
class
Digunit
(digunitHexStr, debug=False)[source]¶ Bases:
object
Class for mask of digital status words
Parameters: digunitHexStr (str) – Conversion factor for digital status channels field in hex str format
-
class
Phunit
(phunitHexStr, debug=False)[source]¶ Bases:
object
Class for conversion factor for phasor channels
Parameters: phunitHexStr (str) – Conversion factor field in hex str format
pmuDataFrame¶
-
class
DataFrame
(frameInHexStr, theConfigFrame, debug=False)[source]¶ Bases:
pymu.pmuFrame.PMUFrame
Class for creating a Data Frame based on C37.118-2011
Parameters: - frameInHexStr (str) – Data frame bytes as hex str
- theConfigFrame (ConfigFrame) – Config frame describing the data frame
- debug (bool) – Print debug statements
-
class
PMU
(pmuHexStr, theStationFrame, debug=False)[source]¶ Bases:
object
Class for a PMU in a data frame
Parameters: - pmuHexStr (str) – Bytes of PMU fields in hex str format
- theStationFrame (Station) – Station fields from config frame describing PMU data
- debug (bool) – Print debug statements
-
class
Phasor
(thePhsrValHex, theStationFrame, theName, debug=False)[source]¶ Bases:
object
Class for holding phasor information
Parameters: - thePhsrValHex (str) – Phasor values in hex str format
- theStationFrame (Station) – Station frame which describe data format
- theName (str) – Name of phasor channel
- debug (bool) – Print debug statements
pmuEnum¶
File containing all the enums used for PyMU. For detailed explanations please look at C37.118-2005 standard
pmuFrame¶
-
class
PMUFrame
(frameInHexStr, debug=False)[source]¶ Bases:
object
Super class for all C37.118-2005/C37.118-2011 frames
Parameters: - frameInHexStr – Bytes from frame (any time) in hex str format
- debug (bool) – Print debug statements
pmuLib¶
Commonly used functions for parsing PMU Frames
-
bytesToFloat
(b)[source]¶ Converts byte array to double
Parameters: b (byte-array) – Byte array to convert Returns: Float value
-
bytesToHexStr
(bytesInput)[source]¶ Converts byte array to hex str
Parameters: bytesInput (byte-array) – byte array to convert Returns: Hex string representing bytesInput
-
doubleToBytes
(f)[source]¶ Converts double to byte array
Parameters: f (double) – Double value to convert Returns: Byte array representation of double value
-
doubleToHex
(f)[source]¶ Converts double to hex
Parameters: f (double) – Double value to convert Returns: Hex representation of double value
-
doubleToHexStr
(f)[source]¶ Converts double to hex str
Parameters: f (double) – Double value to convert Returns: Hex string representation of double value
-
hexToBin
(hexStr, numOfBits)[source]¶ Converts hex string to binary
Parameters: - hexStr (str) – Hex value in string format
- numOfBits (int) – Number of bits to convert
Returns: bits representing the hex values
server¶
-
class
Server
(thePort, proto='TCP', printInfo=False)[source]¶ Bases:
object
Server class that creates a server and provides simple functions for incoming connections/data from PMUs or PDCs without needing to directly use Python’s socket library. Supports INET sockets only (will eventually be updated).
Parameters: - thePort (int) – Local port to listen on
- proto (str) – Protocol to use. Accepts TCP or UDP
- printInfo (bool) – Specifies whether or not to print debug statements
-
readSample
(length)[source]¶ Will read exactly exactly as many bytes as specified by length and return them as an int
-
setTimeout
(numOfSecs)[source]¶ Set socket timeout
Parameters: numOfSecs (int) – Time to wait for socket action to complete before throwing timeout exception
tools¶
Tools for common functions relayed to commanding, reading, and parsing PMU data
-
createAggPhasors
(configFrame)[source]¶ Creates an array of aggregate phasors for data collection
Parameters: configFrame (ConfigFrame) – ConfigFrame containing stations Returns: List containing all the station AggPhasor objects
-
getDataSample
(rcvr, debug=False)[source]¶ Get a data sample regardless of TCP or UDP connection
Parameters: - rcvr (
Client
/Server
) – Object used for receiving data frames - debug (bool) – Print debug statements
Returns: Data frame in hex string format
- rcvr (
-
getStations
(configFrame)[source]¶ Returns all station names from the config frame
Parameters: configFrame (ConfigFrame) – ConfigFrame containing stations Returns: List containing all the station names
-
parseSamples
(data, configFrame, pmus)[source]¶ Takes in an array of dataFrames and inserts the data into an array of aggregate phasors
Parameters: - data (List) – List containing all the data samples
- configFrame (ConfigFrame) – ConfigFrame containing stations
- pmus (List) – List of phasor values
Returns: List containing all the phasor values
-
readConfigFrame2
(cli, debug=False)[source]¶ Retrieve and return config frame 2 from PMU or PDC
Parameters: - cli (Client) – Client connection to data source
- debug (bool) – Print debug statements
Returns: Populated ConfigFrame
-
requestConfigFrame2
(cli, idcode)[source]¶ Send command to request config frame 2
Parameters: - cli (Client) – Client connection to data source
- idcode (int) – Frame ID of data source
-
startDataCapture
(idcode, ip, port=4712, tcpUdp='TCP', debug=False)[source]¶ Connect to data source, request config frame, send data start command
Parameters: - idcode (int) – Frame ID of PMU
- ip (str) – IP address of data source
- port (int) – Command port on data source
- tcpUdp (str) – Use TCP or UDP
- debug (bool) – Print debug statements
Returns: Populated
pymu.pmuConfigFrame.ConfigFrame
object
transferFrame¶
-
class
PhasorField
(phasor, idNum, theUnits)[source]¶ Bases:
object
Class to hold simplified phasor fields
Parameters: - phasor (Phasor) – Phasor containing measurements
- idNum (int) – Frame ID to use
- theUnits (str) – Volts or Amps
-
class
TransferFrame
(inputDataFrame)[source]¶ Bases:
object
Custom class meant to create a message that can be passed to a socket connection. Only contains timestamp, phasor values, and ID for each phasor
Parameters: inputDataFrame (pmuDataFrame) – Populated data frame containing measurement values