及时对位置的时间序列重新采样 [英] Resample time-series of position evenly in time

查看:94
本文介绍了及时对位置的时间序列重新采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如地球科学中经常发生的那样,我有一个时间序列(lon,lat).时间序列的时间间隔不均匀.时间采样如下:

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, ... ]

我与每个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.

位置不遵循单调函数,因此无法使用scipy常用的重新采样和插值函数. 位置随时间变化

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?

推荐答案

一种方法是分别对经度和纬度进行插值.这是一个包含一些模拟数据的示例.

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

假设我们有100个经度(lon),纬度(lat)和时间戳(t).时间不规律:

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:

我们使用scipy的interp1d分别线性插值纬度和经度:

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)

然后,我们制作一系列常规时间戳记[1, 2, 3, ..., 100],并重新采样纬度和经度:

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)

下图显示了按规则间隔np.arange(0, 99, 5)进行插值的结果.这是一个比您想要的间隔更粗糙的间隔,因为如果使用更精细的间隔,很难看到实际上每个绘图中都有两个函数.

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.

这篇关于及时对位置的时间序列重新采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆