f0uriest / interpax

Interpolation and function approximation with JAX
MIT License
137 stars 11 forks source link

`interp1d` with periodic data not working as expected #33

Closed dpanici closed 5 months ago

dpanici commented 5 months ago

When using interp1d with period given, the expected result is an interpolation assuming the signal is periodic. However in 0.3.2 it seems that this is not what is returned.

MWE:

from interpax import interp1d
import jax.numpy as jnp

xq = jnp.linspace(0,2*jnp.pi,endpoint=True)
x = jnp.linspace(0,2*jnp.pi,4,endpoint=False)
f = jnp.array([12,10,8,10])

fq= interp1d(xq, x, f, period=2*jnp.pi,method="cubic",derivative=0)

print(fq)

import matplotlib.pyplot as plt
plt.figure()
plt.plot(xq,fq)
plt.scatter(x,f)

import interpax
plt.title(f"interpax version {interpax.__version__}")

image

image

The change in 0.3.2 seems to be that the _make_periodic function no longer pads the x points to enforce periodicity (i.e. does not make the x and f arrays first and last points be the same). The above snippet works fine in 0.3.2 with linear as the interpolation method, but not with cubic or cubic2 (I have not tried the others)

f0uriest commented 5 months ago

This should be resolved by #34. I've pulled v0.3.2 and released a new v0.3.3 that undoes this change.