[SciPy-user] Fwd: interpolation question
John Travers
jtravs@gmail....
Wed Oct 24 08:02:49 CDT 2007
Hi Micheal,
On 23/10/2007, Michael Hearne <mhearne@usgs.gov> wrote:
> Haven't heard any discussion on this issue since I posted last week - are
> these in fact bugs or am I not using the module correctly?
I do want to look at and solve these issues, but I'm extremely busy at
the moment finishing off my thesis, so haven't got too much time to
spend on it!
> I do have one more question - when I use the code with a non-square grid, I
> get an error saying that my x data does not match the x dimension of my z
> data.
>
> In looking at the following code, it seems like x is being compared with the
> number of rows of Z data, and y being compared with the number of columns:
[snip]
> Isn't numpy row-major like Matlab? I.e, The first dimension is that of
> rows, the second is that of columns?
numpy is generally row-major I think. However a lot of scipy is
written in fortran and so the implementation may leak through. I think
this is the case with these functions.
However, I'm not quite sure I understand your problem. If you have a
2d array of data with m rows and n columns (i.e. m in first index, n
in second) then I would expect to call a procedure like
RectBivariateSpline with 1d arrays of length m and n, in that order.
Does this not make sense? What is referred to as x and y is arbitrary
right? In this case x just refers to the first dimension rather than
fastest changing dimension.
Anyway, the underlying code is in fortran and from a quick look at the
source of fitpack2 I don't see any special treatment of x,y axes in
any of the bivariate spline procedures so I suspect that the fortran
convention is reflected directly in (this part) of scipy. Have you
checked the other 2d spline functions like SmoothBivariateSpline etc?
> I also found that if I modify the code in fitpack2.py (see below) to compare
> dimension[0] with Y and dimension[1] with X, I still get back interpolated
> results whose dimensions are opposite of what was specified (rows =>
> columns, columns=> rows).
This is because the actual interpolation is performed in the base
class of all of the bivariate spline procedures, see the __call__
method of BivariateSpline for this. As I noted above this convention
will be across all of the bivariate spline methods. Is it not also
reflected in interp2d?
Maybe I will understand your problem better if you give me a short
code example which shows the issue. I'll then discuss it with other
scipy developers and see if a consensus can be agreed upon about
whether this is a bug that should be fixed or simply a convention to
be observed. There is a slight problem in that this code is now 4
years in use (though RectBivariateSpline only about a year) and so
changing it now may not be possible due to backards compatibility.
I'll try and consider this in more detail when I get more time!
Best regards,
John
More information about the SciPy-user
mailing list