In [1]:
import escape as esc
esc.require("0.9.8")
import numpy as np
Loading material database from C:\dev\escape-core\python\src\escape\scattering\..\data\mdb\materials.db
Linear interpolation functor¶
ESCAPE provides piecewise linear interpolation as a functor, so it can be used inside expressions, models, or other functors (e.g. calibration curves, lookup tables, or empirical corrections). Behaviour matches numpy.interp: given arrays xp (x-coordinates) and yp (y-values), esc.linterp(X, xp, yp) evaluates at arbitrary X.
Important: The x-coordinates xp must be strictly increasing. There is no internal sorting; if xp is not increasing, the returned values are meaningless.
In [2]:
X = esc.var("X")
xp = np.linspace(0, 2 * np.pi, 10)
yp = np.sin(xp)
yinterp = esc.linterp(X, xp, yp)
yinterp.show(coordinates=np.linspace(0, 2 * np.pi, 100)).config(
xlabel="X", ylabel="Y", title="Linear interpolation sin(X)"
)
Out[2]:
In [ ]: