Resample Time-series Of Position Evenly In Time
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_posit
Solution 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 importinterp1df_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.
Post a Comment for "Resample Time-series Of Position Evenly In Time"