cis_interface.interface package

Submodules

cis_interface.interface.PsiInterface module

class cis_interface.interface.PsiInterface.PsiAsciiFileInput(name, src_type=1, matlab=False)[source]

Bases: object

Class for generic ASCII input from either a file or message queue.

Parameters:
  • name (str) – Path to the local file that input should be read from (if src_type == 0) or the name of the input message queue that input should be received from.
  • src_type (int, optional) – If 0, input is read from a local file. Otherwise input is received from a message queue. Defauts to 1.
recv_line()[source]

Receive a single line of ASCII input.

Returns:
Success or failure of receiving a line and the
line received (including the newline character).
Return type:tuple(bool, str)
class cis_interface.interface.PsiInterface.PsiAsciiFileOutput(name, dst_type=1, matlab=False)[source]

Bases: object

Class for generic ASCII output to either a local file or message queue.

Parameters:
  • name (str) – Path to the local file where output should be written (if dst_type == 0) or the name of the message queue where output should be sent.
  • dst_type (int, optional) – If 0, output is written to a local file. Otherwise, output is sent to a message queue. Defaults to 1.
send_eof()[source]

Send an end-of-file message to the message queue.

send_line(line)[source]

Output a single ASCII line.

Parameters:line (str) – Line to output (including newline character).
Returns:Success or failure of sending the line.
Return type:bool
class cis_interface.interface.PsiInterface.PsiAsciiTableInput(name, src_type=1, matlab=False)[source]

Bases: object

Class for handling table-like formatted input.

Parameters:
  • name (str) – The path to the local file to read input from (if src_type == 0) or the name of the message queue input should be received from.
  • src_type (int, optional) – If 0, input is read from a local file. Otherwise, the input is received from a message queue. Defaults to 1.
recv_array()[source]

Receive an entire array of table data.

Returns:
Success or failure of receiving the row
and the array of table data.
Return type:tuple(bool, np.ndarray)
recv_row()[source]

Receive a single row of variables from the input.

Returns:
Success or failure of receiving the row and
the variables recovered from the row.
Return type:tuple(bool, tuple)
class cis_interface.interface.PsiInterface.PsiAsciiTableOutput(name, fmt, dst_type=1, matlab=False)[source]

Bases: object

Class for handling table-like formatted output.

Parameters:
  • name (str) – The path to the local file where output should be saved (if dst_type == 0) or the name of the message queue where the output should be sent.
  • fmt (str) – A C style format string specifying how each ‘row’ of output should be formated. This should include the newline character.
  • dst_type (int, optional) – If 0, output is sent to a local file. Otherwise, the output is sent to a message queue. Defaults to 1.
send_array(arr)[source]

Output an array of table data to either a local file or message sueue.

Parameters:arr (numpy.ndarray) – Array of table data. The first dimension is assumed to be table rows and the second dimension is assumed to be table columns.
Returns:Success or failure of outputing the array.
Return type:bool
send_eof()[source]

Send an end-of-file message to the message queue.

send_row(*args)[source]

Output arguments as a formated row to either a local file or message queue.

Parameters:*args – All arguments are formated to create a table ‘row’.
Returns:Success or failure of outputing the row.
Return type:bool
class cis_interface.interface.PsiInterface.PsiInput(name, matlab=False)[source]

Bases: object

Class for handling input from a message queue.

Parameters:name (str) – The name of the message queue. Combined with the suffix ‘_INT’, it should match an environment variable containing a message queue key.
name

str – The name of the message queue.

qname

str – The name of the message queue combined with the suffix ‘_IN’.

q

sysv_ipc.MessageQueue – Message queue.

name = None
q = None
qName = None
recv()[source]

Receive a message smaller than PSI_MSG_MAX. The process will sleep until there is a message in the queue to receive.

Returns:
The success or failure of receiving a message
and the message received.
Return type:tuple (bool, str)
recv_nolimit()[source]

Receive a message larger than PSI_MSG_MAX that is sent in multiple parts.

Returns:
The success or failure of receiving a message
and the complete message received.
Return type:tuple (bool, str)
cis_interface.interface.PsiInterface.PsiMatlab(_type, args)[source]

Short interface to identify functions called by Matlab.

Parameters:
  • _type (str) – Name of class that should be returned.
  • args (list) – Additional arguments that should be passed to class initializer.
Returns:

An instance of the requested class.

Return type:

obj

class cis_interface.interface.PsiInterface.PsiOutput(name, matlab=False)[source]

Class for handling output to a message queue.

Parameters:name (str) – The name of the message queue. Combined with the suffix ‘_OUT’, it should match an environment variable containing a message queue key.
name

str – The name of the message queue.

qname

str – The name of the message queue combined with the suffix ‘_OUT’.

q

sysv_ipc.MessageQueue – Message queue.

send(payload)[source]

Send a message smaller than PSI_MSG_MAX.

Parameters:payload (str) – Message to send.
Returns:Success or failure of sending the message.
Return type:bool
send_nolimit(payload)[source]

Send a message larger than PSI_MSG_MAX in multiple parts.

Parameters:payload (str) – Message to send.
Returns:Success or failure of sending the message.
Return type:bool
class cis_interface.interface.PsiInterface.PsiPickleInput(name, src_type=1, matlab=False)[source]

Bases: object

Class for handling pickled input.

Parameters:
  • name (str) – The path to the local file to read input from (if src_type == 0) or the name of the message queue input should be received from.
  • src_type (int, optional) – If 0, input is read from a local file. Otherwise, the input is received from a message queue. Defaults to 1.
recv()[source]

Receive a single pickled object.

Returns:
Success or failure of receiving a pickled
object and the unpickled object that was received.
Return type:tuple(bool, object)
class cis_interface.interface.PsiInterface.PsiPickleOutput(name, dst_type=1, matlab=False)[source]

Bases: object

Class for handling pickled output.

Parameters:
  • name (str) – The path to the local file where output should be saved (if dst_type == 0) or the name of the message queue where the output should be sent.
  • fmt (str) – A C style format string specifying how each ‘row’ of output should be formated. This should include the newline character.
  • dst_type (int, optional) – If 0, output is sent to a local file. Otherwise, the output is sent to a message queue. Defaults to 1.
send(obj)[source]

Output an object as a pickled string to either a local file or message queue.

Parameters:obj (object) – Any python object that can be pickled.
Returns:Success or failure of outputing the pickled object.
Return type:bool
class cis_interface.interface.PsiInterface.PsiRpc(outname, outfmt, inname, infmt, matlab=False)[source]

Bases: object

Class for sending a message and then receiving a response.

Parameters:
  • outname (str) – The name of the output message queue.
  • outfmt (str) – Format string used to format variables in a message sent to the output message queue.
  • inname (str) – The name of the input message queue.
  • infmt (str) – Format string used to recover variables from messages received from the input message queue.
rpcCall(*args)[source]

Send arguments using the output format string to format a message and then receive values back by parsing the response message with the input format string.

Parameters:*args – All arguments are formatted using the output format string to create the message.
Returns:
Success or failure of receiving a message and
the tuple of arguments retreived by parsing the message using the input format string.
Return type:tuple (bool, tuple)
rpcRecv()[source]

Receive a message and get arguments by parsing the recieved message using the input format string.

Returns:
Success or failure of receiving a message and
the tuple of arguments retreived by parsing the message using the input format string.
Return type:tuple (bool, tuple)
rpcSend(*args)[source]

Send arguments as a message created using the output format string.

Parameters:*args – All arguments are formatted using the output format string to create the message.
Returns:Success or failure of sending the message.
Return type:bool
class cis_interface.interface.PsiInterface.PsiRpcClient(name, outfmt, infmt, matlab=False)[source]

Bases: cis_interface.interface.PsiInterface.PsiRpc

Class for handling requests and response to an RPC Server from a client.

Parameters:
  • name (str) – The name of the server queues.
  • outfmt (str) – Format string used to format variables in a message sent to the request queue.
  • infmt (str) – Format string used to recover variables from messages received from the response queue.
class cis_interface.interface.PsiInterface.PsiRpcServer(name, infmt, outfmt, matlab=False)[source]

Bases: cis_interface.interface.PsiInterface.PsiRpc

Class for handling requests and response for an RPC Server.

Parameters:
  • name (str) – The name of the server queues.
  • infmt (str) – Format string used to recover variables from messages received from the request queue.
  • outfmt (str) – Format string used to format variables in a message sent to the response queue.

cis_interface.interface.scanf module

Small scanf implementation.

Python has powerful regular expressions but sometimes they are totally overkill when you just want to parse a simple-formatted string. C programmers use the scanf-function for these tasks (see link below).

This implementation of scanf translates the simple scanf-format into regular expressions. Unlike C you can be sure that there are no buffer overflows possible.

For more information see
Original code from:
http://code.activestate.com/recipes/502213-simple-scanf-implementation/

Modified original to make the %f more robust, as well as added %* modifier to skip fields.

Version: 1.3.3

Releases:
1.0
2010-10-11
  • Initial release
1.1
2010-10-13
  • Changed regex from ‘match’ (only matches at beginning of line) to ‘search’ (matches anywhere in line)
  • Bugfix - ignore cast for skipped fields
1.2
2013-05-30
  • Added ‘collapseWhitespace’ flag (defaults to True) to take the search string and replace all whitespace with regex string to match repeated whitespace. This enables better matching in log files where the data has been formatted for easier reading. These cases have variable amounts of whitespace between the columns, depending on the number of characters in the data itself.
1.3
2016-01-18
  • Add ‘extractdata’ function.
1.3.1
2016-06-23
  • Release to PyPi, now including README.md
cis_interface.interface.scanf.scanf(format, s=None, collapseWhitespace=True)[source]
scanf supports the following formats:
%c One character %5c 5 characters %d, %i int value %7d, %7i int value with length 7 %f float value %o octal value %X, %x hex value %s string terminated by whitespace

Examples: >>> scanf(“%s - %d errors, %d warnings”, “/usr/sbin/sendmail - 0 errors, 4 warnings”) (‘/usr/sbin/sendmail’, 0, 4) >>> scanf(“%o %x %d”, “0123 0x123 123”) (66, 291, 123)

If the parameter s is a file-like object, s.readline is called. If s is not specified, stdin is assumed.

The function returns a tuple of found values or None if the format does not match.

cis_interface.interface.scanf.scanf_compile(format, collapseWhitespace=True)[source]

Translate the format into a regular expression

For example: >>> format_re, casts = _scanf_compile(‘%s - %d errors, %d warnings’) >>> print format_re.pattern (S+) - ([+-]?d+) errors, ([+-]?d+) warnings

Translated formats are cached for faster reuse

Module contents

Routines for interfacing with framework from Python/C/C++/Matlab.

class cis_interface.interface.PsiInput(name, matlab=False)[source]

Bases: object

Class for handling input from a message queue.

Parameters:name (str) – The name of the message queue. Combined with the suffix ‘_INT’, it should match an environment variable containing a message queue key.
name

str – The name of the message queue.

qname

str – The name of the message queue combined with the suffix ‘_IN’.

q

sysv_ipc.MessageQueue – Message queue.

name = None
q = None
qName = None
recv()[source]

Receive a message smaller than PSI_MSG_MAX. The process will sleep until there is a message in the queue to receive.

Returns:
The success or failure of receiving a message
and the message received.
Return type:tuple (bool, str)
recv_nolimit()[source]

Receive a message larger than PSI_MSG_MAX that is sent in multiple parts.

Returns:
The success or failure of receiving a message
and the complete message received.
Return type:tuple (bool, str)
class cis_interface.interface.PsiOutput(name, matlab=False)[source]

Class for handling output to a message queue.

Parameters:name (str) – The name of the message queue. Combined with the suffix ‘_OUT’, it should match an environment variable containing a message queue key.
name

str – The name of the message queue.

qname

str – The name of the message queue combined with the suffix ‘_OUT’.

q

sysv_ipc.MessageQueue – Message queue.

send(payload)[source]

Send a message smaller than PSI_MSG_MAX.

Parameters:payload (str) – Message to send.
Returns:Success or failure of sending the message.
Return type:bool
send_nolimit(payload)[source]

Send a message larger than PSI_MSG_MAX in multiple parts.

Parameters:payload (str) – Message to send.
Returns:Success or failure of sending the message.
Return type:bool
class cis_interface.interface.PsiRpc(outname, outfmt, inname, infmt, matlab=False)[source]

Bases: object

Class for sending a message and then receiving a response.

Parameters:
  • outname (str) – The name of the output message queue.
  • outfmt (str) – Format string used to format variables in a message sent to the output message queue.
  • inname (str) – The name of the input message queue.
  • infmt (str) – Format string used to recover variables from messages received from the input message queue.
rpcCall(*args)[source]

Send arguments using the output format string to format a message and then receive values back by parsing the response message with the input format string.

Parameters:*args – All arguments are formatted using the output format string to create the message.
Returns:
Success or failure of receiving a message and
the tuple of arguments retreived by parsing the message using the input format string.
Return type:tuple (bool, tuple)
rpcRecv()[source]

Receive a message and get arguments by parsing the recieved message using the input format string.

Returns:
Success or failure of receiving a message and
the tuple of arguments retreived by parsing the message using the input format string.
Return type:tuple (bool, tuple)
rpcSend(*args)[source]

Send arguments as a message created using the output format string.

Parameters:*args – All arguments are formatted using the output format string to create the message.
Returns:Success or failure of sending the message.
Return type:bool