Steps tendency - #184
Conversation
890edb1 to
bba2e43
Compare
maarten-ic
left a comment
There was a problem hiding this comment.
Some highlevel comments, let's agree on those first
| Just like the :ref:`Constant Tendency <constant-value-types>`, the ``value`` list may contain numbers or strings: | ||
| * ``duration``, ``end``: See :ref:`Common Time Parameters <available-tendencies>`. | ||
| Either may be used to specify when the last step ends. | ||
| If both are omitted, the tendency simply stops at the last point in the ``time`` list. |
There was a problem hiding this comment.
This is a bit misleading, since we'll do constant extrapolation at the end of the tendency regardless right?
|
|
||
| - {type: steps, time: [0, 2, 4], value: [1, 3, 5], end: 6} | ||
|
|
||
| The same tendency can equivalently be written using ``duration`` instead of ``end``: |
There was a problem hiding this comment.
But only because the first time value is 0?
| from waveform_editor.tendencies.util import validate_time_array | ||
|
|
||
|
|
||
| class PiecewiseLinearTendency(BaseTendency): |
There was a problem hiding this comment.
Would it make sense to make a single superclass for this one and the steps tendency?
The main difference is the interpolation strategy between points. Perhaps we want a "closest" interpolation strategy in the future or "pspline" or ...
The superclass could take care of most of the logic, then the concrete subclasses just provide the interpolation and derivative logic.
See maybe: https://docs.scipy.org/doc/scipy/tutorial/interpolate/1D.html#tutorial-interpolate-interp1d-replacements
| def merge_value_types(types): | ||
| """Determine a single value type from a collection of value types. Mixing | ||
| ``int`` and ``float`` is allowed and results in ``float``, any other mix of | ||
| distinct types is not allowed. | ||
|
|
||
| Args: | ||
| types: An iterable of ``int``, ``float``, and/or ``str`` types. | ||
|
|
||
| Returns: | ||
| The merged type, or None if the types cannot be merged. | ||
| """ | ||
| types = set(types) | ||
| if types <= {int, float}: | ||
| return float if float in types else int | ||
| if len(types) == 1: | ||
| return types.pop() | ||
| return None |
There was a problem hiding this comment.
Could we just follow numpy behaviour for stepwise tendencies?
>>> numpy.array([1, 2, 3])
array([1, 2, 3])
>>> numpy.array([1, 2, 3.])
array([1., 2., 3.])
>>> numpy.array([1, 2, 'x'])
array(['1', '2', 'x'], dtype='<U21')obviously you cannot use the last one with linear interpolation, but I'd be fine casting everything to strings if you have a string value
Introduces a new tendency type, the
stepstendency. This is basically a shorthand way to write a sequence of constant tendencies.