vectorinterpolators#
This modules provides interpolator objects to find interpolated values in lists. - x generally describes the index value lists - y descreibes the corresponding values
Example usage#
# import this module
import themachinethatgoesping.tools.vectorinterpolators as vip
# create value lists
timestamps = [100, 150, 300, 400, 950, 1000]
values = [10, 50, 30, 500, -30,-20]
# create interpolator object (here a linear interpolator)
linear = vip.LinearInterpolator(X=timestamps, Y=values)
# find interpolated y value for a given x value (e.g. a random timestamp)
y_value = lip(target_x=125)
print(y_value) #<< 30.0
# find extrapolated y value for value outside timestamps boundary
y_value = linear(target_x=50)
print(y_value) #<< -30.0
Types#
- class t_extr_mode#
extrapolation mode type.
Members:
extrapolate
nearest
fail
- property name#
- str(self: t_extr_mode) str #
Class: AkimaInterpolator#
- class AkimaInterpolator#
Interpolator class to perform a (modified) akima interpolation. Uses boost makima interpolator. Note: this interpolator acts as linear interpolator if less than 4 values are stored.
- __init__(self: themachinethatgoesping.tools_cppy.vectorinterpolators.AkimaInterpolator, X: List[float] = [], Y: List[float] = [], extrapolation_mode: themachinethatgoesping.tools_cppy.vectorinterpolators.t_extr_mode = <t_extr_mode.extrapolate: 0>) None #
Construct a new Interpolator object from a vector of pairs usage: interpolated_y_value = interpolator.interpolate(x_value)
- Parameter
X
: X vector; must be unique and sorted in ascending order. same size as Y!
- Parameter
Y
: Y vector; must be unique and sorted in ascending order. same size as X!
- Parameter
extrapolation_mode
: t_extr_mode
object that describes the extrapolation mode
- Parameter
- __call__(*args, **kwargs)#
Overloaded function.
__call__(self: themachinethatgoesping.tools_cppy.vectorinterpolators.AkimaInterpolator, target_x: float) -> float
get the interpolated y value for given x target
- Parameter
target_x
: find the corresponding y value for this x value
- Returns:
corresponding y value
__call__(self: themachinethatgoesping.tools_cppy.vectorinterpolators.AkimaInterpolator, targets_x: List[float]) -> List[float]
get nearest y values for given x targets (vectorized call)
- Parameter
targets_x
: vector of x values. For each of these values find the corrsponding y value
- Returns:
corresponding y value
- set_data_XY(self: AkimaInterpolator, X: List[float], Y: List[float]) None #
change the input data to these X and Y vectors
- Parameter
X:
: x vector (must be same size, must be sorted in ascending order)
- Parameter
Y:
: y vector (must be same size)
- Parameter
- append(self: AkimaInterpolator, x: float, y: float) None #
append an x- and the corresponding y value to the interpolator data. Exception: raises domain error, strong exception guarantee
- Parameter
x
: value, must be > than all existing x values
- Parameter
y
: corresponding y value
- Parameter
- extend(self: AkimaInterpolator, X: List[float], Y: List[float]) None #
append x and y value lists to the interpolator data (vectorized call) Exception: raises domain error, strong exception guarantee
- Parameter
X
: list of x values. Must be sorted in ascending order. All x values must be larger than the largest x value in the interpolator data.
- Parameter
Y
: list of corresponding Y values. Must be same size as X
- Parameter
- set_extrapolation_mode(self: AkimaInterpolator, extrapolation_mode: t_extr_mode) None #
Set the extrapolation mode
- Parameter
extrapolation_mode
: t_extr_mode
object (enumerator) that describes the extrapolation mode
- Parameter
- get_extrapolation_mode(self: AkimaInterpolator) t_extr_mode #
Get the currently set extrapolation mode
- Returns:
py:class:t_extr_mode <themachinethatgoesping.tools.vectorinterpolators.t_extr_mode> object (enumerator) that describes the extrapolation mode
- get_data_X(self: AkimaInterpolator) List[float] #
return the x component of the internal data vector
- Returns:
std::vector<double>
- get_data_Y(self: AkimaInterpolator) List[float] #
return the y component of the internal data vector
- Returns:
std::vector<YType>
- copy(self: AkimaInterpolator) AkimaInterpolator #
return a copy using the c++ default copy constructor
- to_binary(self: AkimaInterpolator, resize_buffer: bool = True) bytes #
convert object to bytearray
- static from_binary(buffer: bytes, check_buffer_is_read_completely: bool = True) AkimaInterpolator #
create T_CLASS object from bytearray
- info_string(self: AkimaInterpolator, float_precision: int = 2) str #
Return object information as string
- print(self: AkimaInterpolator, float_precision: int = 2) None #
Print object information
Class: LinearInterpolator#
- class LinearInterpolator#
Find linear interpolated values within vector data
- __init__(self: themachinethatgoesping.tools_cppy.vectorinterpolators.LinearInterpolator, X: List[float] = [], Y: List[float] = [], extrapolation_mode: themachinethatgoesping.tools_cppy.vectorinterpolators.t_extr_mode = <t_extr_mode.extrapolate: 0>) None #
Construct a new Interpolator object from a vector of pairs usage: interpolated_y_value = interpolator.interpolate(x_value)
- Parameter
X
: X vector; must be unique and sorted in ascending order. same size as Y!
- Parameter
Y
: Y vector; must be unique and sorted in ascending order. same size as X!
- Parameter
extrapolation_mode
: t_extr_mode
object that describes the extrapolation mode
- Parameter
- __call__(*args, **kwargs)#
Overloaded function.
__call__(self: themachinethatgoesping.tools_cppy.vectorinterpolators.LinearInterpolator, target_x: float) -> float
get the interpolated y value for given x target
- Parameter
target_x
: find the corresponding y value for this x value
- Returns:
corresponding y value
__call__(self: themachinethatgoesping.tools_cppy.vectorinterpolators.LinearInterpolator, targets_x: List[float]) -> List[float]
get nearest y values for given x targets (vectorized call)
- Parameter
targets_x
: vector of x values. For each of these values find the corrsponding y value
- Returns:
corresponding y value
- set_data_XY(self: LinearInterpolator, X: List[float], Y: List[float]) None #
change the input data to these X and Y vectors
- Parameter
X:
: x vector (must be same size, must be sorted in ascending order)
- Parameter
Y:
: y vector (must be same size)
- Parameter
- append(self: LinearInterpolator, x: float, y: float) None #
append an x- and the corresponding y value to the interpolator data. Exception: raises domain error, strong exception guarantee
- Parameter
x
: value, must be > than all existing x values
- Parameter
y
: corresponding y value
- Parameter
- extend(self: LinearInterpolator, X: List[float], Y: List[float]) None #
append x and y value lists to the interpolator data (vectorized call) Exception: raises domain error, strong exception guarantee
- Parameter
X
: list of x values. Must be sorted in ascending order. All x values must be larger than the largest x value in the interpolator data.
- Parameter
Y
: list of corresponding Y values. Must be same size as X
- Parameter
- set_extrapolation_mode(self: LinearInterpolator, extrapolation_mode: t_extr_mode) None #
Set the extrapolation mode
- Parameter
extrapolation_mode
: t_extr_mode
object (enumerator) that describes the extrapolation mode
- Parameter
- get_extrapolation_mode(self: LinearInterpolator) t_extr_mode #
Get the currently set extrapolation mode
- Returns:
py:class:t_extr_mode <themachinethatgoesping.tools.vectorinterpolators.t_extr_mode> object (enumerator) that describes the extrapolation mode
- get_data_X(self: LinearInterpolator) List[float] #
return the x component of the internal data vector
- Returns:
std::vector<double>
- get_data_Y(self: LinearInterpolator) List[float] #
return the y component of the internal data vector
- Returns:
std::vector<YType>
- copy(self: LinearInterpolator) LinearInterpolator #
return a copy using the c++ default copy constructor
- to_binary(self: LinearInterpolator, resize_buffer: bool = True) bytes #
convert object to bytearray
- static from_binary(buffer: bytes, check_buffer_is_read_completely: bool = True) LinearInterpolator #
create T_CLASS object from bytearray
- info_string(self: LinearInterpolator, float_precision: int = 2) str #
Return object information as string
- print(self: LinearInterpolator, float_precision: int = 2) None #
Print object information
Class: NearestInterpolator#
- class NearestInterpolator#
Interpolator class to find nearest neighbors within vector data
- __init__(self: themachinethatgoesping.tools_cppy.vectorinterpolators.NearestInterpolator, X: List[float] = [], Y: List[float] = [], extrapolation_mode: themachinethatgoesping.tools_cppy.vectorinterpolators.t_extr_mode = <t_extr_mode.extrapolate: 0>) None #
Construct a new Interpolator object from a vector of pairs usage: interpolated_y_value = interpolator.interpolate(x_value)
- Parameter
X
: X vector; must be unique and sorted in ascending order. same size as Y!
- Parameter
Y
: Y vector; must be unique and sorted in ascending order. same size as X!
- Parameter
extrapolation_mode
: t_extr_mode
object that describes the extrapolation mode
- Parameter
- __call__(*args, **kwargs)#
Overloaded function.
__call__(self: themachinethatgoesping.tools_cppy.vectorinterpolators.NearestInterpolator, target_x: float) -> float
get the interpolated y value for given x target
- Parameter
target_x
: find the corresponding y value for this x value
- Returns:
corresponding y value
__call__(self: themachinethatgoesping.tools_cppy.vectorinterpolators.NearestInterpolator, targets_x: List[float]) -> List[float]
get nearest y values for given x targets (vectorized call)
- Parameter
targets_x
: vector of x values. For each of these values find the corrsponding y value
- Returns:
corresponding y value
- set_data_XY(self: NearestInterpolator, X: List[float], Y: List[float]) None #
change the input data to these X and Y vectors
- Parameter
X:
: x vector (must be same size, must be sorted in ascending order)
- Parameter
Y:
: y vector (must be same size)
- Parameter
- append(self: NearestInterpolator, x: float, y: float) None #
append an x- and the corresponding y value to the interpolator data. Exception: raises domain error, strong exception guarantee
- Parameter
x
: value, must be > than all existing x values
- Parameter
y
: corresponding y value
- Parameter
- extend(self: NearestInterpolator, X: List[float], Y: List[float]) None #
append x and y value lists to the interpolator data (vectorized call) Exception: raises domain error, strong exception guarantee
- Parameter
X
: list of x values. Must be sorted in ascending order. All x values must be larger than the largest x value in the interpolator data.
- Parameter
Y
: list of corresponding Y values. Must be same size as X
- Parameter
- set_extrapolation_mode(self: NearestInterpolator, extrapolation_mode: t_extr_mode) None #
Set the extrapolation mode
- Parameter
extrapolation_mode
: t_extr_mode
object (enumerator) that describes the extrapolation mode
- Parameter
- get_extrapolation_mode(self: NearestInterpolator) t_extr_mode #
Get the currently set extrapolation mode
- Returns:
py:class:t_extr_mode <themachinethatgoesping.tools.vectorinterpolators.t_extr_mode> object (enumerator) that describes the extrapolation mode
- get_data_X(self: NearestInterpolator) List[float] #
return the x component of the internal data vector
- Returns:
std::vector<double>
- get_data_Y(self: NearestInterpolator) List[float] #
return the y component of the internal data vector
- Returns:
std::vector<YType>
- copy(self: NearestInterpolator) NearestInterpolator #
return a copy using the c++ default copy constructor
- to_binary(self: NearestInterpolator, resize_buffer: bool = True) bytes #
convert object to bytearray
- static from_binary(buffer: bytes, check_buffer_is_read_completely: bool = True) NearestInterpolator #
create T_CLASS object from bytearray
- info_string(self: NearestInterpolator, float_precision: int = 2) str #
Return object information as string
- print(self: NearestInterpolator, float_precision: int = 2) None #
Print object information
Class: SlerpInterpolator#
Example usage#
# import this module
import themachinethatgoesping.tools.vectorinterpolators as vip
# create value lists
timestamps = [100, 150, 1000] #x list, must be sorted, no duplicates
yaw = [10, 50, -20] #yaw values (degrees)
pitch = [10, 50, -20] #yaw values (degrees)
roll = [10, 50, -20] #yaw values (degrees)
# create interpolator object (here a linear interpolator)
slerp = vip.SlerpInterpolator(X=timestamps, Yaw=yaw, Pitch = pitch, Roll = roll)
# find interpolated y value for a given x value (e.g. a random timestamp)
ypr_value = slerp(target_x=125)
print(ypr_value) #<< [23.65708869335217, 32.74209962001251, 23.657088693352158]
# find extrapolated y value for value outside timestamps boundary
ypr_value = slerp(target_x=50)
print(ypr_value) #<< [355.97195450327666, -40.17949250447276, -4.0280454967233394]
Class#
- class SlerpInterpolator#
Class that implements a slerp interpolation for vectors. Data is internally represented in quaternions using lib eigen. Interfaces to represent the data in yaw, pitch, roll angles are provided. the __call__ equivalent to get interpolated yaw pitch roll is the ypr function
- __init__(self: themachinethatgoesping.tools_cppy.vectorinterpolators.SlerpInterpolator, X: List[float] = [], Yaw: List[float] = [], Pitch: List[float] = [], Roll: List[float] = [], input_in_degrees: bool = True, extrapolation_mode: themachinethatgoesping.tools_cppy.vectorinterpolators.t_extr_mode = <t_extr_mode.extrapolate: 0>) None #
Construct a new Slerp Interpolator object using vectors of x, yaw, pitch and roll
- Parameter
X
: vector; must be unique and sorted in ascending order
- Parameter
yaw
: vector with yaw data (rotation around z axis). Must be same size as X!
- Parameter
pitch
: vector with pitch data (rotation around y axis). Must be same size as X!
- Parameter
roll
: vector with roll data (rotation around x axis). Must be same size as X!
- Parameter
input_in_degrees
: if true (default) yaw,pitch and roll are in °, otherwise [rad]
- Parameter
extrapolation_mode
: t_extr_mode
object that describes the extrapolation mode
- Parameter
- __call__(*args, **kwargs)#
Overloaded function.
__call__(self: themachinethatgoesping.tools_cppy.vectorinterpolators.SlerpInterpolator, target_x: float, output_in_degrees: bool = True) -> Annotated[List[float], FixedSize(3)]
get the interpolated yaw, pitch and roll values for given x target
- Parameter
target_x
: find the corresponding y value for this x value
- Parameter
output_in_degrees
: if true, yaw pitch and roll input values are in ° otherwise rad
- Returns:
corresponding y value
__call__(self: themachinethatgoesping.tools_cppy.vectorinterpolators.SlerpInterpolator, targets_x: List[float], output_in_degrees: bool = True) -> List[Annotated[List[float], FixedSize(3)]]
get the interpolated yaw, pitch and roll values for given x target (vectorized call)
- Parameter
targets_x
: vector of x values. For each of these values find the corrsponding yaw, pitch and roll value
- Parameter
output_in_degrees
: if true, yaw pitch and roll input values are in ° otherwise rad
- Returns:
corresponding y value
- set_data_XYPR(*args, **kwargs)#
Overloaded function.
set_data_XYPR(self: themachinethatgoesping.tools_cppy.vectorinterpolators.SlerpInterpolator, X: List[float], Yaw: List[float], Pitch: List[float], Roll: List[float], input_in_degrees: bool = True) -> None
change the input data to these X, yaw, pitch, roll vectors (will be converted to quaternion)
- Parameter
X
: vector; must be unique and sorted in ascending order
- Parameter
yaw
: vector with yaw data (rotation around z axis). Must be same size as X!
- Parameter
pitch
: vector with pitch data (rotation around y axis). Must be same size as X!
- Parameter
roll
: vector with roll data (rotation around x axis). Must be same size as X!
- Parameter
input_in_degrees
: if true, yaw pitch and roll input values are in ° otherwise rad
set_data_XYPR(self: themachinethatgoesping.tools_cppy.vectorinterpolators.SlerpInterpolator, X: List[float], YPR: List[Annotated[List[float], FixedSize(3)]], input_in_degrees: bool = True) -> None
change the input data to these X, yaw, pitch, roll vectors (will be converted to quaternion)
- Parameter
X
: vector; must be unique and sorted in ascending order
- Parameter
yaw
: vector with yaw data (rotation around z axis). Must be same size as X!
- Parameter
pitch
: vector with pitch data (rotation around y axis). Must be same size as X!
- Parameter
roll
: vector with roll data (rotation around x axis). Must be same size as X!
- Parameter
input_in_degrees
: if true, yaw pitch and roll input values are in ° otherwise rad
- append(*args, **kwargs)#
Overloaded function.
append(self: themachinethatgoesping.tools_cppy.vectorinterpolators.SlerpInterpolator, x: float, yaw: float, pitch: float, roll: float, input_in_degrees: bool = True) -> None
append an x, yaw, pitch, roll data point
- Parameter
X
: must be larger than all internal data points
- Parameter
yaw
: rotation around z axis
- Parameter
pitch
: rotation around y axis
- Parameter
roll
: rotation around x axis
- Parameter
input_in_degrees
: if true, yaw pitch and roll input values are in ° otherwise rad
append(self: themachinethatgoesping.tools_cppy.vectorinterpolators.SlerpInterpolator, x: float, ypr: Annotated[List[float], FixedSize(3)], input_in_degrees: bool = True) -> None
append an x, yaw, pitch, roll data point
- Parameter
X
: must be larger than all internal data points
- Parameter
ypr
: array with one yaw, pitch and roll data point
- Parameter
input_in_degrees
: if true, yaw pitch and roll input values are in ° otherwise rad
- extend(*args, **kwargs)#
Overloaded function.
extend(self: themachinethatgoesping.tools_cppy.vectorinterpolators.SlerpInterpolator, X: List[float], Yaw: List[float], Pitch: List[float], Roll: List[float], input_in_degrees: bool = True) -> None
append data with lists of x, yaw, pitch, roll data (vectorized call)
- Parameter
X
: vector; must be unique and sorted in ascending order
- Parameter
yaw
: vector with yaw data (rotation around z axis). Must be same size as X!
- Parameter
pitch
: vector with pitch data (rotation around y axis). Must be same size as X!
- Parameter
roll
: vector with roll data (rotation around x axis). Must be same size as X!
- Parameter
input_in_degrees
: if true, yaw pitch and roll input values are in ° otherwise rad
extend(self: themachinethatgoesping.tools_cppy.vectorinterpolators.SlerpInterpolator, X: List[float], YPR: List[Annotated[List[float], FixedSize(3)]], input_in_degrees: bool = True) -> None
append data with list of x, yaw, pitch, roll data (vectorized call)
- Parameter
X
: vector; must be unique and sorted in ascending order
- Parameter
ypr
: vector with yaw, pitch and roll data points. Must be same size as X!
- Parameter
input_in_degrees
: if true, yaw pitch and roll input values are in ° otherwise rad
- set_extrapolation_mode(self: SlerpInterpolator, extrapolation_mode: t_extr_mode) None #
Set the extrapolation mode
- Parameter
extrapolation_mode
: t_extr_mode
object (enumerator) that describes the extrapolation mode
- Parameter
- get_extrapolation_mode(self: SlerpInterpolator) t_extr_mode #
Get the currently set extrapolation mode
- Returns:
py:class:t_extr_mode <themachinethatgoesping.tools.vectorinterpolators.t_extr_mode> object (enumerator) that describes the extrapolation mode
- get_data_X(self: SlerpInterpolator) List[float] #
return the x component of the internal data vector
- Returns:
std::vector<double>
- get_data_YPR(self: SlerpInterpolator, output_in_degrees: bool = True) List[Annotated[List[float], FixedSize(3)]] #
return the internal yrp data vector
- Parameter
output_in_degrees
: convert yaw, pitch and roll to degrees (default = True)
- Returns:
std::vector<std::array<3, double>> YPR
- Parameter
- copy(self: SlerpInterpolator) SlerpInterpolator #
return a copy using the c++ default copy constructor
- to_binary(self: SlerpInterpolator, resize_buffer: bool = True) bytes #
convert object to bytearray
- static from_binary(buffer: bytes, check_buffer_is_read_completely: bool = True) SlerpInterpolator #
create T_CLASS object from bytearray
- info_string(self: SlerpInterpolator, float_precision: int = 2) str #
Return object information as string
- print(self: SlerpInterpolator, float_precision: int = 2) None #
Print object information