Resample time-series of position evenly in time

你。 提交于 2019-12-11 03:56:41

问题


As often happens in Earth sciences, I have a time series of positions (lon,lat). The time series is not evenly spaced in time. The time sampling looks like :

    t_diff_every_position = [3.99, 1.00, 3.00, 4.00, 3.98, 3.99, ... ]

And I have associated position with every t :

   lat = [77.0591,  77.0547,  77.0537, 74.6766,  74.6693,  74.6725, ... ]
   lon = [-135.2876, -135.2825, -135.2776, -143.7432, -143.7994,
   -143.8582, ... ]

I want to re-sample the positions to have a dataset evenly spaced in time. So I want the time vector to look like :

    t_resampled = [4.00, 4.00, 4.00, 4.00, 4.00, 4.00, ... ]

and have the associated position from an interpolation.

The positions do not follow a monotonic function, so I can't use the usual re-sampling and interpolation functions from scipy. Positions with time

Does anyone have an idea about how this could be achieved?


回答1:


One approach is to interpolate the longitudes and latitudes separately. Here's an example with some simulated data.

Suppose we have 100 longitudes (lon), latitudes (lat), and timestamps (t). The time is irregular:

>>> t
array([ 0.        ,  1.09511126,  1.99576514,  2.65742629,  3.35929893,
        4.1379694 ,  5.55703942,  6.52892196,  7.64924527,  8.60496239])

And the path drawn by these coordinates looks something like:

We use scipy's interp1d to linearly interpolate the latitude and the longitude separately:

from scipy.interpolate import interp1d
f_lon = interp1d(t, lon)
f_lat = interp1d(t, lat)

Then we make an array of regular timestamps, [1, 2, 3, ..., 100], and resample our latitudes and longitudes:

reg_t = np.arange(0, 99)
reg_lon = f_lon(reg_t)
reg_lat = f_lat(reg_t)

The plots below show the result for interpolating on the regular interval np.arange(0, 99, 5). This is a coarser interval than what you'd like, since it is quite difficult to see that there are in fact two functions in each plot if a finer interval is used.



来源:https://stackoverflow.com/questions/33808554/resample-time-series-of-position-evenly-in-time

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