Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bounded circular interpolation in python

My question is something similar to the question here. In simple term I have a time series angle data which is bounded between [0, 360]. I need to compute an iterpolation between measurements. Currently, I am using scipy.interpolate.interp1d. To make my question clear here is an example,

import numpy as np
from scipy import interpolate
data = np.array([[0, 2, 4], [1, 359, 1]]) # first row time index, second row angle measurements
f = interpolate.interp1d(data[0, :], data[1, :], kind='linear', bounds_error=False, fill_value=None)
f([1, 3])

this will result in [ 180., 180.]. However between time 2 and time 4 the angle changed from 359 to 1, that is only a 2 degree change and the interpolated value at 3 should have been 0. The angles are changing in CCW direction through time.

Finally, my question is this,

Is there any standard module that I can use to achieve this?

Just because I want to avoid custom method as much as possible!

like image 790
hashmuke Avatar asked Dec 04 '14 13:12

hashmuke


1 Answers

As of version 1.10.0, numpy.interp takes a period keyword: http://docs.scipy.org/doc/numpy/reference/generated/numpy.interp.html

like image 141
S E Clark Avatar answered Oct 27 '22 18:10

S E Clark