Difference between splines in Lumerical and Python


There is a built-in spline function in Lumerical that allows you to create smooth contours. This function is different from those written in other programs, such as Python and Matlab. Below, the graph shows that the splines do not match.

For comparison, splines were created mat files in Matlab and Lumerical:

I also used various interpolation methods,(https://docs.scipy.org/doc/scipy/reference/interpolate.html) but I could not get the same results that the spline gives in Lumerical.

Can you provide code for the spline that is used in lumerical? We model the geometry in Lumerical using a spline, and to create a structure in KLayout we use a spline from Python.

Thank you in advance.


Hi @krutov13,
I briefly looked at your files and the main difference seems to be that you are interpolating slightly different vectors. In the Lumerical script, you use the vector

w_original = [w1,w2,w3,w4,w5,w6,w7,w8,w9,w10,w11,w12,w13];

while in Matlab, you use the vector

w_original = [w1,w2,w3,w4,*w4*,w6,w7,w8,w9,w10,w11,w12,w13];

Notice the duplicated “w4” in Matlab vs. “w5” in Lumerical script.

Using the same data already leads to very similar plots for me:

However, if you look carefully, you can still observe slight differences at the endpoints. This is due to the fact that cubic spline interpolation is not uniquely defined at the endpoints. In the case of Lumerical script, we implement clamped splines which assumes that the slope at the endpoints is 0. Matlab also supports this (as described here https://www.mathworks.com/help/matlab/ref/spline.html), by using

w = spline(x_original, [0 w_original 0], x);

With the same data and the “clamped endpoint” option in Matlab, I obtain essentially identical results:

I hope this helps.


Hi @jniegemann,

Thank you for looking at my code, and prompted where the error is. Information regarding the slight differences between splines is also very useful.

Thank you very much.


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.