'Fixing Knots for scipy.interpolate.bisplrep

I have a 6x6 matrix of data(values_master) for a 6x6 set of data points:

master_x,master_y=mgrid[950:1450:6j,550:1050:6j]

I then try and interpolate the data using bisplrep:

master_tck = bisplrep(master_x,master_y,values_master,kx=2,ky=2,task=-1,tx=[950,1050,1150,1250,1350,1450],ty=[550,650,750,850,950,1050],s=0)

However, when I output the co-ordinates of the knots to check that they have been read in correctly, I get the following:

tx=[950.950.950.1450.1450.1450.]
ty=[550.550.550.1050.1050.1050.]

Which do not appear to match my input for tx and ty at all. What is the explanation for this?



Solution 1:[1]

A bit late but I ran into the same problem. The issue seems to be related to the required multiplicity of the end knots. Quoting from the B-spline wiki page:

One distinguishes internal knots and end points. Internal knots cover the x-domain one is interested in. Since a single B-spline already extends over 1 + n knots, it follows that the internal knots need to be extended with n ? 1 endpoints on each side, to give full support to the first and last B-spline, which affect the internal knot intervals. The values of the endpoints do not matter, usually the first or last internal knot is just repeated.

So apparently, since the algorithm need thos repeated endpoints, it modifies the list accordingly if required. In fact, if you put in

master_tck = bisplrep(master_x,master_y,values_master,kx=2,ky=2,task=-1,
                      tx=[950,950,950,1200,1450,1450,1450],
                      ty=[550,550,550,850,1050,1050,1050])

you get the desired ticks

master_tck[0] = array([ 950.,  950.,  950., 1200., 1450., 1450., 1450.])
master_tck[1] = array([ 550.,  550.,  550.,  850., 1050., 1050., 1050.])

Unfortunatley, when you put in more than one intermediat point in each direction you get a ValueError: Invalid inputs and I couldn't figure out why this is. Quoting again form said wiki page:

A B-spline of order nis a piecewise polynomial function of degree n ? 1 in a variable x. It is defined over 1 + n locations t_j, called knots or breakpoints

hints at an expected number of knots but that given number doesn't quite fit with my observation here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1