0

I want to find that x,y co-ordinates of all the local maxima of a 3D surface B-Spline made using bisplrep.

splder, and sproot are used with splrep to find for single variate B-Spline. How is bisplrep maxima and minima found?

My code is given below.

tck = interpolate.bisplrep(X, Y, sensor_counts, s=0)
xnew, ynew = np.mgrid[ min(grid_x):max(grid_x):100j, min(grid_y):max(grid_y):100j]
znew = interpolate.bisplev(xnew[:,0], ynew[0,:], tck, dx=0, dy=1)
print xnew
print ynew
fig = plt.figure()
ax = fig.gca(projection='3d')
print tck
surf = ax.plot_surface(xnew, ynew, znew, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=0, antialiased=False)
cset = ax.contour(xnew, ynew, znew, zdir='z', offset=5100, cmap=cm.coolwarm)
Ayan Banerjee
  • 121
  • 2
  • 12

1 Answers1

0

We can use scipy.optimize library of python.

I used scipy.optimize.fmin_tnc in the following way.

def neg_bspline( x ):
global tck
f = -interpolate.bisplev( x[0], x[1], tck, dx=0, dy=0)
g = [-interpolate.bisplev( x[0], x[1], tck, dx=1, dy=0 ), -interpolate.bisplev( x[0], x[1], tck, dx=0, dy=1)]
return f, g

for i in sensor_array:
    x0 = i.get_coordinate()
    print x0
    bounds = [(0,200) , (0,200)]
    x0 = fmin_tnc(neg_bspline, x0=x0, bounds=bounds)
    print x0
    solutions.append( x0[0] )
result_plot( solutions )
Ayan Banerjee
  • 121
  • 2
  • 12