ripyl.util package

Submodules

ripyl.util.bitops module

Bit-wise operations

ripyl.util.bitops.join_bits(bits)

Convert an array of bits (MSB first) to an integer word

Parameters:bits (sequence of ints) – The bits to be merged into an integer
Returns:An int representing the bits contained in the bits parameter.
ripyl.util.bitops.split_bits(n, num_bits)

Convert integer to a list of bits (MSB-first)

Parameters:
  • n (int) – The number to convert to bits.
  • num_bits (int) – The number of bits in the result.
Returns:

A list of ints representing each bit in n.

ripyl.util.color module

Color formatting

ripyl.util.color.colorize(t, code)
ripyl.util.color.error(t)
ripyl.util.color.note(t)
ripyl.util.color.stdout_redirected()
ripyl.util.color.success(t)
ripyl.util.color.warn(t)

ripyl.util.eng module

Engineering unit string formatting

class ripyl.util.eng.Eng(f, frac_digits=3)

Bases: object

Base class for engineering unit string formatting

__init__(f, frac_digits=3)
Parameters:
  • f (number) – The number to represent in engineering units.
  • frac_digits (int) – The number of fractional digits to display in a string.
class ripyl.util.eng.EngSI(f, units='', frac_digits=3, unit_sep=' ')

Bases: ripyl.util.eng.Eng

Class for engineering unit string formatting with SI units

__init__(f, units='', frac_digits=3, unit_sep=' ')
Parameters:
  • f (number) – The number to represent in engineering units.
  • units (string) – The units that the number represents.
  • frac_digits (int) – The number of fractional digits to display in a string.
  • unit_sep (string) – The separator between the number and the units string
class ripyl.util.eng.EngUSI(f, units='', frac_digits=3, unit_sep=' ')

Bases: ripyl.util.eng.EngSI

Class for engineering unit string formatting with SI units with unicode characters

__init__(f, units='', frac_digits=3, unit_sep=' ')
ripyl.util.eng.eng(f, frac_digits=3)

Create engineering formatted string

ripyl.util.eng.eng_si(f, units='', frac_digits=3, unit_sep=' ')

Create engineering formatted string with SI units

ripyl.util.eng.eng_usi(f, units='', frac_digits=3, unit_sep=' ')

Create engineering formatted string with unicode SI units

ripyl.util.enum module

Enumeration support

class ripyl.util.enum.Enum

Bases: object

Base class for enumeration classes

This provides a name() class method that will return the string attribute name for an encoded enumeration value.

e.g.

>>> class Colors(Enum):
...     blue = 1
...     red = 2
...     green = 3
:param  :
>>> Colors.name(Colors.red)
'red'
>>> Colors.name(1, full_name=True)
'Colors.blue'

“Instantiating” the Enum sub-class calls the name() method as well:

>>> Colors(3, full_name=False)
'green'

If necesssary you can use non-integers as the values as long as they are hashable:

>>> class MathConst(Enum):
...     pi = 3.2     # in certain US states :)
...     e = 2.71828
:param  :
>>> MathConst.pi
3.2
classmethod name(value, full_name=False)

Lookup the enumeration name with the provided value

Parameters:
  • value (hashable) – A hashable Enum value (typically int) to find a name for.
  • full_name (bool) – Include full name of Enum object in result
Returns:

A string for the enum attribute associated with value.

ripyl.util.equality module

Ripyl protocol decode library Equality functions

ripyl.util.equality.min_relative_epsilon(a, b)

Compute the minimum epsilon value for relatively_equal()

Parameters:
  • a (float) – First number to compare
  • b (float) – Second number to compare
Returns:

A float representing the minimum epsilon.

ripyl.util.equality.relatively_equal(a, b, epsilon)

Evaluate the relative equality of two floats

The epsilon parameter controls how close the relatve magnitudes need to be for equality to be determined.

Adapted from: http://floating-point-gui.de/errors/comparison/

Parameters:
  • a (float) – First number to compare
  • b (float) – Second number to compare
  • epsilon (float) – Relative epsilon for comparison
Returns:

True when a and b are nearly equal

ripyl.util.plot module

Annotated protocol plotting

class ripyl.util.plot.AnnotationStyle(color, alpha)

Bases: object

Set styling for plot annotation boxes

__init__(color, alpha)
class ripyl.util.plot.LabelStyle(color='black', angle=0.0, size='large', italic=False, bold=False)

Bases: object

Set styling for annotation labels

__init__(color='black', angle=0.0, size='large', italic=False, bold=False)
class ripyl.util.plot.Plotter

Bases: object

Manage annotated waveform plotting

__init__()
plot(channels, annotations=None, title='', label_format=5, show_names=False, ylim=None, xlim=None)

Plot annotated waveform data

Parameters:
  • channels (dict of string:sample stream) – A dict of waveform sample data keyed by the string label used for each channel’s vertical axis.
  • annotations (sequence of StreamRecord or None) – The annotation data produced by a protocol decoder
  • title (string) – Title for the plot
  • label_format (AnnotationFormat) – data format to apply for annotation records with a data_format attribute equal to AnnotationFormat.General
  • show_names (bool) – Show the field names for each annotation value
  • ylim (pair of float or None) – Set lower and upper bound for the y-axes
  • xlim (pair of float or None) – Set lower and upper bound for the x-axis
save_plot(fname, figsize=None)

Save the result of plot() to a file

Parameters:
  • fname (string) – Name of the file to save a plot image to
  • figsize ((number,number)) – The (x,y) dimensions of the image in inches. Matplotlib uses 100DPI.
show()

Show the result of plot() in an interactive window

waveform_bounds(raw_samples)

Retrieve the y-axis boundaries for annotation elements

ripyl.util.stats module

Statistical operations

Module contents

Ripyl utility functions