Model

The Model class define a data type for use with a Block.

For a usage-focused overview of how models are used within the PyRogue tree, see Model API.

class pyrogue.Model(bitSize, binPoint=0)[source]

Extensible base class which describes how a data type is represented and accessed using the Rogue Variables and Blocks

Parameters:
  • bitSize (int) – Number of bits being represented.

  • binPoint (int, default: 0) – Binary point position.

  • args (Any)

  • kwargs (Any)

Variables:
  • name (str) – String representation of the Model type

  • fstring (str) – Not sure what this is, Where is it used?

  • encoding (str) – Encoding type for converting between string and byte arrays. i.e. UTF-8

  • pytype (int) – Python type class.

  • defaultdisp (str) – Default display formatting string. May be overriden by the Variable disp parameter.

  • signed (bool) – Flag indicating if value is signed. Default=False

  • endianness (str) – Endianness indicator. ‘little’ or ‘big’. Default=’little’

  • bitReverse (bool) – Bit reversal flag.

  • modelId (int) – Block processing ID. See Block Process Types

  • isBigEndian (bool) – True if endianness = ‘big’

  • ndType (np.dtype) – numpy type value (bool, int32, int64, uint32, uin64, float32, float64)

Return type:

Any

property isBigEndian: bool

Return True if the model is big endian.

toBytes(value)[source]

Convert the python value to byte array. Implement this method in a subclass to define the conversion.

Parameters:

value (Any) – Python value to convert.

Return type:

Any

fromBytes(ba)[source]

Convert a byte array to a python value. Implement this method in a subclass to define the conversion.

Parameters:

ba (bytearray) – Byte array to extract value from.

Return type:

Any

fromString(string)[source]

Convert a string to a python value. Implement this method in a subclass to define the conversion.

Parameters:

string (str) – String representation of the value.

Return type:

Any

minValue()[source]

Return the minimum value for the Model type. Implement this method in a subclass to define the minimum value.

Return type:

Any

maxValue()[source]

Return the maximum value for the Model type. Implement this method in a subclass to define the maximum value.

Return type:

Any

Standard Models

The following are pre-defined models for various data types.

UInt

class pyrogue.UInt(bitSize)[source]

Model class for unsigned integers.

Parameters:
  • bitSize (int) – Number of bits being represented.

  • args (Any)

  • kwargs (Any)

Return type:

Any

pytype

alias of int

toBytes(value)[source]
Parameters:

value (int) – Python value to convert.

Returns:

Byte array representation of the value.

Return type:

bytes

fromBytes(ba)[source]
Parameters:

ba (bytes) – Byte array to extract value from.

Returns:

Python value.

Return type:

int

fromString(string)[source]
Parameters:

string (str) – String representation of the value.

Returns:

Python value.

Return type:

int

minValue()[source]

Return the minimum unisgned int (0).

Return type:

int

maxValue()[source]

Return the maximum unsigned int (2**bitSize-1).

Return type:

int

UIntBE

class pyrogue.UIntBE(bitSize)[source]

Model class for big endian unsigned integers. Inherits from UInt.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

UIntReversed

class pyrogue.UIntReversed(bitSize)[source]

Model class for unsigned integers, stored in reverse bit order.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

toBytes(value)[source]

Convert a python int value to a byte array.

Parameters:

value (int) – Python int value to convert.

Returns:

Byte array representation of the value.

Return type:

bytes

fromBytes(ba)[source]

Convert a byte array to a python int value.

Parameters:

ba (bytes) – Byte array to extract value from.

Returns:

Python value.

Return type:

int

Int

class pyrogue.Int(bitSize)[source]

Model class for signed integers.

Parameters:
  • bitSize (int) – Number of bits being represented.

  • args (Any)

  • kwargs (Any)

Return type:

Any

toBytes(value)[source]

Convert a python int value to a byte array.

Parameters:

value (int) – Python int value to convert.

Returns:

Byte array representation of the value.

Return type:

bytes

fromBytes(ba)[source]

Convert a byte array to a python int value.

Parameters:

ba (bytes) – Byte array to extract value from.

Returns:

Python value.

Return type:

int

fromString(string)[source]

Convert a string to a python int value.

Parameters:

string (str) – String representation of the value.

Returns:

Python value.

Return type:

int

minValue()[source]

Return the minimum signed int (-2**(bitSize-1)).

Return type:

int

maxValue()[source]

Return the maximum signed int (2**(bitSize-1)-1).

Return type:

int

IntBE

class pyrogue.IntBE(bitSize)[source]

Model class for big endian integers. Inherits from Int.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

Bool

class pyrogue.Bool(bitSize)[source]

Model class for booleans.

Parameters:
  • bitSize (int) – Number of bits being represented. Must be 1.

  • args (Any)

  • kwargs (Any)

Return type:

Any

pytype

alias of bool

toBytes(value)[source]

Convert a python bool value to a byte array.

Parameters:

value (bool) – Python bool value to convert.

Returns:

Byte array representation of the value.

Return type:

bytes

fromBytes(ba)[source]

Convert a byte array to a python bool value.

Parameters:

ba (bytes) – Byte array to extract value from.

Returns:

Python value.

Return type:

bool

fromString(string)[source]

Convert a string to a python bool value.

Parameters:
  • string (str) – String representation of the value.

  • string

Returns:

Python value.

Return type:

bool

minValue()[source]

Return the minimum bool (0).

Return type:

int

maxValue()[source]

Return the maximum bool (1).

Return type:

int

String

class pyrogue.String(bitSize)[source]

Model class for strings.

Parameters:
  • bitSize (int) – Number of bits being represented.

  • args (Any)

  • kwargs (Any)

Return type:

Any

pytype

alias of str

toBytes(value)[source]

Convert a python string value to a byte array.

Parameters:

value (str) – Python string value to convert.

Returns:

Byte array representation of the value.

Return type:

bytearray

fromBytes(ba)[source]

Convert a byte array to a python string value.

Parameters:

ba (bytearray) – Byte array to extract value from.

Returns:

Python value.

Return type:

str

fromString(string)[source]

Convert a string to a python string value.

Parameters:

string (str) – String representation of the value.

Returns:

Python string value.

Return type:

str

Float

class pyrogue.Float(bitSize)[source]

Model class for 32-bit floating point numbers.

Parameters:
  • bitSize (int) – Number of bits being represented. Must be 32.

  • args (Any)

  • kwargs (Any)

Return type:

Any

pytype

alias of float

toBytes(value)[source]

Convert a python float value to a byte array.

Parameters:

value (float) – Python float value to convert.

Returns:

Byte array representation of the value.

Return type:

bytearray

fromBytes(ba)[source]

Convert a byte array to a python float value.

Parameters:

ba (bytes) – Byte array to extract value from.

Returns:

Python value.

Return type:

float

fromString(string)[source]

Convert a string to a python float value.

Parameters:

string (str) – String representation of the value.

Returns:

Python value.

Return type:

float

minValue()[source]

Return the minimum 32-bit float (-3.4e38).

Return type:

float

maxValue()[source]

Return the maximum 32-bit float (3.4e38).

Return type:

float

FloatBE

class pyrogue.FloatBE(bitSize)[source]

Model class for 32-bit floats stored as big endian

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

Double

class pyrogue.Double(bitSize)[source]

Model class for 64-bit floats.

Parameters:
  • bitSize (int) – Number of bits being represented. Must be 64.

  • args (Any)

  • kwargs (Any)

Return type:

Any

minValue()[source]

Return the minimum 64-bit float (-1.80e308).

Return type:

float

maxValue()[source]

Return the maximum 64-bit float (1.80e308).

Return type:

float

DoubleBE

class pyrogue.DoubleBE(bitSize)[source]

Model class for 64-bit floats stored as big endian

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

Fixed

class pyrogue.Fixed(bitSize, binPoint)[source]

Model class for fixed point signed integers

Parameters:
  • bitSize (int) – Specifies the total number of bits, including the binary point bit width.

  • binPoint (int) – Specifies the bit location of the binary point, where bit zero is the least significant bit.

  • args (Any)

  • kwargs (Any)

Return type:

Any

pytype

alias of float

UFixed

class pyrogue.UFixed(bitSize, binPoint)[source]

Model class for fixed point unsigned integers

Parameters:
  • bitSize (int) – Specifies the total number of bits, including the binary point bit width.

  • binPoint (int) – Specifies the bit location of the binary point, where bit zero is the least significant bit.

  • args (Any)

  • kwargs (Any)

Return type:

Any

pytype

alias of float