Interpolation to evenly space trajectory data for different curves

五迷三道 提交于 2021-02-20 02:28:16

问题


I am using the following code (adapted from Resample or normalize trajectory data so points are evenly spaced) to interpolate 2D X & Y positional data (with no time index) so that the points are evenly spaced. From my understanding, the answer for that question assumed that the x values follow a certain curve or pattern (e.g. exponential curve) but that isn't the case for all my trajectories.

I believe I need to interpolate X and Y separately. However, this code does not seem to produce evenly spaced output and I'm not sure how to solve this. The arrays are already 1000 points before interpolation and vary in 'shape'. Thus I don't know how to define x & x_new:

# Interpolation for X values 
from scipy.interpolate import interp1d
y = df['X']
x = np.linspace(y.min(),y.max(),1000)
# define interpolation function:
f = interp1d(x,y)
# create new df with desired x vals, generate y with interp function:
x_new = np.linspace(y.min(),y.max(),1000)
y_new = f(x_new)
X_interp = pd.DataFrame(np.array([y_new]).T, columns=["x_interp"])


# Interpolation for Y values 
from scipy.interpolate import interp1d
y = df['Y']
x = np.linspace(y.min(),y.max(),1000)
# define interpolation function:
f = interp1d(x,y)
# create new df with desired x vals, generate y with interp function:
x_new = np.linspace(y.min(),y.max(),1000)
y_new = f(x_new)
Y_interp = pd.DataFrame(np.array([y_new]).T, columns=["y_interp"])

But it doesnt change the data in any way.

As an example, the 2D data (X & Y positions with no time index) for one of the trajectories looks like this when plotted as a scatterplot:

# Note the interpolation doesnt change the data so it looks the same whether I plot using:
plt.scatter(X_interp['x_interp'], Y_interp['y_interp']) 
# or the original data
plt.scatter(df['X'], df['Y']))

来源:https://stackoverflow.com/questions/66221994/interpolation-to-evenly-space-trajectory-data-for-different-curves

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!