def __init__(self, x, y, post_eng_to_phys=unit_function, pre_phys_to_eng=unit_function):
""" PChip interpolation for converting between physics and engineering units.
Args:
x(list): A list of points on the x axis. These must be in increasing order
for the interpolation to work. Otherwise, a ValueError is raised.
y(list): A list of points on the y axis. These must be in increasing or
decreasing order. Otherwise, a ValueError is raised.
Raises:
ValueError: An error occured when the given y coefficients are neither in
increasing or decreasing order.
"""
super(self.__class__, self).__init__(post_eng_to_phys, pre_phys_to_eng)
self.x = x
self.y = y
self.pp = PchipInterpolator(x, y)
diff = numpy.diff(y)
if not ((numpy.all(diff > 0)) or (numpy.all((diff < 0)))):
raise ValueError("Given coefficients must be monotonically"
"decreasing.")
评论列表
文章目录