waveformindex/home/perette/Projects/Skeezball/TestUtilities/waveform.py

This module provides a waveform class, which is used for vibrator control.

Modules

abc json math random

Classes

abc.ABC(builtins.object)
Waveform
SawtoothWave
SineWave
SquareWave

class SawtoothWave(Waveform)

SawtoothWave(period: float, *, portion: float = 1.0, offset: float = 0.0, rates: list[int] | None = None, minimum: int = 1, maximum: int = 100, name: str = 'unnamed')

A waveform that is a symetrical sawtooth wave.

Method resolution order:
SawtoothWave
Waveform
abc.ABC
builtins.object

Methods defined here:
magnitudeAtTime(self, t: float) -> int

Calculate the waveform level at time.
t: The time at which to calculate the amplitude.
Return value: The level, in the range 0 to 100.


Data and other attributes defined here:
__abstractmethods__ = frozenset()
__annotations__ = {}

Methods inherited from Waveform:
__init__(self, period: float, *, portion: float = 1.0, offset: float = 0.0, rates: list[int] | None = None, minimum: int = 1, maximum: int = 100, name: str = 'unnamed')

Create a new waveform.


period: The length of one cycle of the waveform, in seconds.
portion: Specifies portion of one cycle of wave to use; 1.0=whole wave.
offset: The phase shift, as a portion of one cycle of wave (0-1.0).
minimum: Used to set a baseline for wave intensity. (imagine the DC bias of the wave.)
maximum: Along with minimum, sets the amplitude of the wave. (maximum - minimum sets AC portion of the wave)
rates: is a list of intensities. These are scaled by minimum and maximum. Each value represents period / len(rates) seconds. If rates are omitted, a linear rising-then-falling from minimum to maximum and back over the period is used.

__repr__(self) -> str

Return repr(self).

areaUnderCurve(self, duration: float) -> float

Estimate area under the curve for a duration.

copyWith(self, *, period: float | None = None, portion: float | None = None, offset: float | None = None, rates: list[int] | None = None, minimum: int | None = None, maximum: int | None = None)

Make a new waveform based on the existing one. Parameters are as in __init__. Present values are used for any not specified.


Class methods inherited from Waveform:
byName(name: str) from abc.ABCMeta

Return a waveform by name.

initialize(data_dir: str) from abc.ABCMeta

Initialize the waveform library.

loadLibrary(data) -> None from abc.ABCMeta

Load multiple waveforms from configuration data.
data: The configuration data with the waveforms.

random(intensity: str | None = None) from abc.ABCMeta

Return a random waveform.
intensity: If specified, specifies a library collection from which to return a waveform.
Return value: A waveform from the library, or (if intensity is not specified or is not in the library) a waveform constructed with random parameters.


Static methods inherited from Waveform:
fromConfig(data)

Construct a wave from configuration data.
data: The configuration data specifying wave parameters.
Return value: A waveform in accordance with the provided spec.


Data descriptors inherited from Waveform:
__dict__

dictionary for instance variables (if defined)

__weakref__

list of weak references to the object (if defined)


Data and other attributes inherited from Waveform:
NONE = SquareWave<period=1, minimum=1, rates=[0]>

class SineWave(Waveform)

SineWave(period: float, *, portion: float = 1.0, offset: float = 0.75, minimum: int = 1, maximum: int = 100, name: str = 'unnamed', rates: list[int] | None = None)

A waveform that is a sine wave.

Method resolution order:
SineWave
Waveform
abc.ABC
builtins.object

Methods defined here:
__init__(self, period: float, *, portion: float = 1.0, offset: float = 0.75, minimum: int = 1, maximum: int = 100, name: str = 'unnamed', rates: list[int] | None = None)

Create a new waveform.


period: The length of one cycle of the waveform, in seconds.
portion: Specifies portion of one cycle of wave to use; 1.0=whole wave.
offset: The phase shift, as a portion of one cycle of wave (0-1.0).
minimum: Used to set a baseline for wave intensity. (imagine the DC bias of the wave.)
maximum: Along with minimum, sets the amplitude of the wave. (maximum - minimum sets AC portion of the wave)
rates: is a list of intensities. These are scaled by minimum and maximum. Each value represents period / len(rates) seconds. If rates are omitted, a linear rising-then-falling from minimum to maximum and back over the period is used.

magnitudeAtTime(self, t: float) -> int

Calculate the waveform level at time.
t: The time at which to calculate the amplitude.
Return value: The level, in the range 0 to 100.


Data and other attributes defined here:
__abstractmethods__ = frozenset()
__annotations__ = {}

Methods inherited from Waveform:
__repr__(self) -> str

Return repr(self).

areaUnderCurve(self, duration: float) -> float

Estimate area under the curve for a duration.

copyWith(self, *, period: float | None = None, portion: float | None = None, offset: float | None = None, rates: list[int] | None = None, minimum: int | None = None, maximum: int | None = None)

Make a new waveform based on the existing one. Parameters are as in __init__. Present values are used for any not specified.


Class methods inherited from Waveform:
byName(name: str) from abc.ABCMeta

Return a waveform by name.

initialize(data_dir: str) from abc.ABCMeta

Initialize the waveform library.

loadLibrary(data) -> None from abc.ABCMeta

Load multiple waveforms from configuration data.
data: The configuration data with the waveforms.

random(intensity: str | None = None) from abc.ABCMeta

Return a random waveform.
intensity: If specified, specifies a library collection from which to return a waveform.
Return value: A waveform from the library, or (if intensity is not specified or is not in the library) a waveform constructed with random parameters.


Static methods inherited from Waveform:
fromConfig(data)

Construct a wave from configuration data.
data: The configuration data specifying wave parameters.
Return value: A waveform in accordance with the provided spec.


Data descriptors inherited from Waveform:
__dict__

dictionary for instance variables (if defined)

__weakref__

list of weak references to the object (if defined)


Data and other attributes inherited from Waveform:
NONE = SquareWave<period=1, minimum=1, rates=[0]>

class SquareWave(Waveform)

SquareWave(period: float, *, portion: float = 1.0, offset: float = 0.0, rates: list[int] | None = None, minimum: int = 1, maximum: int = 100, name: str = 'unnamed')

A waveform that is a series of fixed intensities. "SteppedWave" might be a better name.

Method resolution order:
SquareWave
Waveform
abc.ABC
builtins.object

Methods defined here:
magnitudeAtTime(self, t: float) -> int

Calculate the waveform level at time.
t: The time at which to calculate the amplitude.
Return value: The level, in the range 0 to 100.


Data and other attributes defined here:
__abstractmethods__ = frozenset()
__annotations__ = {}

Methods inherited from Waveform:
__init__(self, period: float, *, portion: float = 1.0, offset: float = 0.0, rates: list[int] | None = None, minimum: int = 1, maximum: int = 100, name: str = 'unnamed')

Create a new waveform.


period: The length of one cycle of the waveform, in seconds.
portion: Specifies portion of one cycle of wave to use; 1.0=whole wave.
offset: The phase shift, as a portion of one cycle of wave (0-1.0).
minimum: Used to set a baseline for wave intensity. (imagine the DC bias of the wave.)
maximum: Along with minimum, sets the amplitude of the wave. (maximum - minimum sets AC portion of the wave)
rates: is a list of intensities. These are scaled by minimum and maximum. Each value represents period / len(rates) seconds. If rates are omitted, a linear rising-then-falling from minimum to maximum and back over the period is used.

__repr__(self) -> str

Return repr(self).

areaUnderCurve(self, duration: float) -> float

Estimate area under the curve for a duration.

copyWith(self, *, period: float | None = None, portion: float | None = None, offset: float | None = None, rates: list[int] | None = None, minimum: int | None = None, maximum: int | None = None)

Make a new waveform based on the existing one. Parameters are as in __init__. Present values are used for any not specified.


Class methods inherited from Waveform:
byName(name: str) from abc.ABCMeta

Return a waveform by name.

initialize(data_dir: str) from abc.ABCMeta

Initialize the waveform library.

loadLibrary(data) -> None from abc.ABCMeta

Load multiple waveforms from configuration data.
data: The configuration data with the waveforms.

random(intensity: str | None = None) from abc.ABCMeta

Return a random waveform.
intensity: If specified, specifies a library collection from which to return a waveform.
Return value: A waveform from the library, or (if intensity is not specified or is not in the library) a waveform constructed with random parameters.


Static methods inherited from Waveform:
fromConfig(data)

Construct a wave from configuration data.
data: The configuration data specifying wave parameters.
Return value: A waveform in accordance with the provided spec.


Data descriptors inherited from Waveform:
__dict__

dictionary for instance variables (if defined)

__weakref__

list of weak references to the object (if defined)


Data and other attributes inherited from Waveform:
NONE = SquareWave<period=1, minimum=1, rates=[0]>

class Waveform(abc.ABC)

Waveform(period: float, *, portion: float = 1.0, offset: float = 0.0, rates: list[int] | None = None, minimum: int = 1, maximum: int = 100, name: str = 'unnamed')

Method resolution order:
Waveform
abc.ABC
builtins.object

Methods defined here:
__init__(self, period: float, *, portion: float = 1.0, offset: float = 0.0, rates: list[int] | None = None, minimum: int = 1, maximum: int = 100, name: str = 'unnamed')

Create a new waveform.


period: The length of one cycle of the waveform, in seconds.
portion: Specifies portion of one cycle of wave to use; 1.0=whole wave.
offset: The phase shift, as a portion of one cycle of wave (0-1.0).
minimum: Used to set a baseline for wave intensity. (imagine the DC bias of the wave.)
maximum: Along with minimum, sets the amplitude of the wave. (maximum - minimum sets AC portion of the wave)
rates: is a list of intensities. These are scaled by minimum and maximum. Each value represents period / len(rates) seconds. If rates are omitted, a linear rising-then-falling from minimum to maximum and back over the period is used.

__repr__(self) -> str

Return repr(self).

areaUnderCurve(self, duration: float) -> float

Estimate area under the curve for a duration.

copyWith(self, *, period: float | None = None, portion: float | None = None, offset: float | None = None, rates: list[int] | None = None, minimum: int | None = None, maximum: int | None = None)

Make a new waveform based on the existing one. Parameters are as in __init__. Present values are used for any not specified.

magnitudeAtTime(self, t: float) -> int

Calculate the waveform level at time.
t: The time at which to calculate the amplitude.
Return value: The level, in the range 0 to 100.


Class methods defined here:
byName(name: str) from abc.ABCMeta

Return a waveform by name.

initialize(data_dir: str) from abc.ABCMeta

Initialize the waveform library.

loadLibrary(data) -> None from abc.ABCMeta

Load multiple waveforms from configuration data.
data: The configuration data with the waveforms.

random(intensity: str | None = None) from abc.ABCMeta

Return a random waveform.
intensity: If specified, specifies a library collection from which to return a waveform.
Return value: A waveform from the library, or (if intensity is not specified or is not in the library) a waveform constructed with random parameters.


Static methods defined here:
fromConfig(data)

Construct a wave from configuration data.
data: The configuration data specifying wave parameters.
Return value: A waveform in accordance with the provided spec.


Data descriptors defined here:
__dict__

dictionary for instance variables (if defined)

__weakref__

list of weak references to the object (if defined)


Data and other attributes defined here:
NONE = SquareWave<period=1, minimum=1, rates=[0]>
__abstractmethods__ = frozenset({'magnitudeAtTime'})
__annotations__ = {'NONE': typing.Any, '_waveforms': list[typing.Any], '_waveforms_by_intensity': dict[str, list[typing.Any]], '_waveforms_by_name': dict[str, list[typing.Any]]}

Data

Any = typing.Any