Interpolation allows you to create data points inside of a defined range. It interpolates the data points, the interpolate_table function reassigns the independent variable to a user defined list and interpolates all the other values in data, returning a data table with the same format. It should be noted that this does not extrapolate, so if the new range is outside the old range it will fail.
from pyMez import *
from pyMez.Code.Analysis.Interpolation import *
# first we define a table where the independent x-axis is the first column
x_data=np.linspace(-10,10,10).tolist()
data_table=[[x,2.1*x,1.25*x**2] for x in x_data]
column_names=["x","line","second_order"]
data_table=AsciiDataTable(data=data_table,
column_names=column_names,
header=["A test of the data table"],
column_types=["float","float","float"])
print(data_table)
# now we want a lot of data points in between the defined range
interpolated_table=interpolate_table(table=data_table,independent_variable_list=np.linspace(-5,5,50))
print(interpolated_table)
%matplotlib inline
# for demonstation we can now plot to compare them
plt.plot(data_table["x"],data_table["line"],label="original")
plt.plot(interpolated_table["x"],interpolated_table["line"],label="interpolated")
plt.legend()
# The second order
plt.plot(data_table["x"],data_table["second_order"],label="original")
plt.plot(interpolated_table["x"],interpolated_table["second_order"],label="interpolated")
plt.legend()