[Scipy-tickets] [SciPy] #1522: derivatives() method is missing in BivariateSpline

SciPy Trac scipy-tickets@scipy....
Sat Nov 12 10:29:39 CST 2011

```#1522: derivatives() method is missing in BivariateSpline
----------------------------------------------------+-----------------------
Reporter:  nils                                    |       Owner:  somebody
Type:  enhancement                             |      Status:  new
Priority:  normal                                  |   Milestone:  Unscheduled
Component:  scipy.interpolate                       |     Version:  devel
Keywords:  bivariate spline, derivatives() method  |
----------------------------------------------------+-----------------------

Comment(by mrkwjc):

> {{{
> Looks like BivariateSpline forgot to grow a derivatives() method,
> UnivariateSpline does have one. This would be a useful addition.
> }}}

I use modified BivariateSpline:

from scipy.interpolate import BivariateSpline, bisplev

class BivariateSpline2(BivariateSpline):
def __call__(self, x, y, dx=0, dy=0, mth='array'):
""" Evaluate spline at positions x,y."""
x = np.asarray(x)
y = np.asarray(y)
# empty input yields empty output
if (x.size == 0) and (y.size == 0):
return array([])

if mth=='array':
z = bisplev(x, y, self.tck + self.degrees, dx=dx, dy=dy)
if len(np.asarray(z).shape) == 0: z = z.reshape((1,1))
if len(np.asarray(z).shape) == 1: z = z.reshape((1, len(z)))
return z
raise NotImplementedError('unknown method mth=%s' % mth)

Now you can call for example:
b = BivariateSpline2(x,y,z)
dxdy = b(xi, yi, dx=1, dy=1)

--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1522#comment:2>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
```