Degitization

[1]:
# Import auxiliary libraries for demonstration

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

plt.rcParams[ "figure.figsize" ] = [ 5, 4 ]
plt.style.use( "default" )

plt.rcParams[ "figure.dpi" ] = 80
plt.rcParams[ "font.family" ] = "Times New Roman"
plt.rcParams[ "font.size" ] = '14'

Sequence digitization

Function sequenceDigitization can digitize a sequence with specific resolution.

Function help

[2]:
from ffpack.utils import sequenceDigitization
help( sequenceDigitization )
Help on function sequenceDigitization in module ffpack.utils.generalUtils:

sequenceDigitization(data, resolution=1.0)
    Digitize the sequence data to a specific resolution

    The sequence data are digitized by the round method.

    Parameters
    ----------
    data: 1d array
        Sequence data to digitize.

    resolution: bool, optional
        The desired resolution to round the data points.

    Returns
    -------
    rst: 1d array
        A list contains the digitized data.

    Raises
    ------
    ValueError
        If the data dimension is not 1.
        If the data length is less than 2 with keedEnds == False
        If the data length is less than 3 with keedEnds == True

    Notes
    -----
    The default round function will round half to even: 1.5, 2.5 => 2.0:

    Examples
    --------
    >>> from ffpack.utils import sequenceDigitization
    >>> data = [ -1.0, 2.3, 1.8, 0.6, -0.4, 0.8, -1.6, -2.5, 3.4, 0.3, 0.1 ]
    >>> rst = sequenceDigitization( data )

Example with default values

[3]:
dstrSequenceData = [ -1.0, 2.3, 1.8, 0.6, -0.4, 0.8, -1.6, -2.5, 3.4, 0.3, 0.1 ]

dstrResults = sequenceDigitization( dstrSequenceData, resolution=1.0 )
[4]:
print( dstrResults )
[-1.0, 2.0, 2.0, 1.0, -0.0, 1.0, -2.0, -2.0, 3.0, 0.0, 0.0]
[5]:
fig, ( ax1, ax2 ) = plt.subplots( 1, 2, figsize=( 10, 4 ) )

ax1.plot( dstrSequenceData, 'o-' )

ax1.tick_params( axis='x', direction="in", length=5 )
ax1.tick_params( axis='y', direction="in", length=5 )
ax1.set_ylabel( "Load units" )
ax1.set_xlabel( "Data points" )
ax1.set_title( "Sequence data" )
ax1.grid( axis='y', color="0.7" )

ax2.plot( dstrResults, 'o-' )

ax2.tick_params(axis='x', direction="in", length=5)
ax2.tick_params(axis='y', direction="in", length=5)
ax2.set_ylabel( "Load units" )
ax2.set_xlabel( "Data points" )
ax2.set_title( "Digitize sequence to resolution data" )
ax2.grid( axis='y', color="0.7" )

plt.tight_layout()
plt.show()
../_images/moduleCookbook_utilsDigitization_9_0.png