First, I want to thank John Hunter and Jouni Seppanen for their very useful help with my xticklabel problems. I have little experience with python, and am a total newbie wrt. matplotlib (- which is very impressive...).
Few days ago I was looking for a method to interpolate 12hourly data, and was not happy with the python alternatives I found. I wanted something in native python, not wrappers to C or Fortran programs
(in this case speed is not a big issue). It so happened that few weeks ago a coworker gave me a faint photocopy of a photocopy from an article published 26 years ago with an interpolation method I had not seen before.
The main point of the method was that it did not generate spline like excursions. The claim was that the method was "consistantly well behaved".
So, I wrote it up in Python (well, I translated my Matlab code). It seems to work as the author claimed. The interpolation method needs x,y and y' (the slope of y(x)) as input, but the article also provided a simple algorithm to estimate the slope. I am including these functions in an attachment. To use them is very simple:
Example where y' is known
x = seq(0,2*pi,10); y = sin(x); yp = cos(x)
xi = seq(0,2*pi,40);
yi = StinemanInterp(x,y,yp,xi);
plot(x,y,'o',xi,yi)
Example where y' is calculated using slopes()
x = seq(0,2*pi,10); y = sin(x);
yp = slopes(x,y)
xi = seq(0,2*pi,40);
yi = StinemanInterp(x,y,yp,xi);
plot(x,y,'o',xi,yi)
I make no claim that the method is fast, nor that my coding is optimal. - I am sure it can be sped up, but it is fast enough for my uses.
Nor do I claim that this is the best interpolation algorithm, - I have no interest in taking part in a religous debate on the merits of different interpolation methods.
For me this is simply a consise method that works resonably well. The slope y' can be calculated using other methods than slopes(),- using divided differences to get the derivative of a quadratic through any three points is straightforward (but not implemented here). Also if yp is simply the linear slope the method yields linear interpolation.
As I said, I have not seen this method before, but it may well be that it is known under a different guise....My coworker got it from a Swiss glaciologist....
Sincerely,
Halldór
niceinterp.py (4.38 KB)
···
--
Halldor Bjornsson
Bustadavegur 9 IS150 Reykjavik Iceland.
e: halldor()vedur.is tel:+354-522600