Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
documented LUT class
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto-escobar committed Jan 27, 2024
1 parent 664b47f commit e09a58d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions controller/common/lut.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@


class LUT:
"""
Class for performing look-up table interpolation.
Methods:
__init__: Initializes the LUT object with lookup table data and interpolation method.
__call__: Calls the interpolation method with the given input.
"""

def __init__(self, lookup_table: list, interpolation_method: str = "linear"):
"""
Initializes the LUT object.
Args:
lookup_table (list): A list of tuples or lists containing x-y data points for
interpolation. Format is [[x-values],[y-values]]
interpolation_method (str): Interpolation method to use. Default is "linear".
Raises:
ValueError: If the specified interpolation method is unknown.
"""
self.__table = np.array(lookup_table)
self.__interpolation = interpolation_method

Expand All @@ -16,6 +35,16 @@ def __init__(self, lookup_table: list, interpolation_method: str = "linear"):
raise ValueError(self.__interpolation + " is an unknown interpolation method!")

def __call__(self, x: float) -> float:
"""
Calls the interpolation method with the given input.
Args:
x (float): The input value to interpolate.
Returns:
float: The interpolated value using the interpolation method defined when LUT instance
creation.
"""
return self.__method(x)

def __linearInterpolation(self, x: float) -> float:
Expand Down

0 comments on commit e09a58d

Please sign in to comment.