0

IDL to Python: All is OK except for the spline interpolation section, where I'm not sure what IDL is doing. Here's a section with the bit I want to convert:

; slice of IDL code
x=[6.0 5.0 4.0 3.0 2.0]
x1 = [1.0]
xi1 = x1[0]
x2 = [1.15,1.81984,2.1,2.27015,2.7]
x3 = [3.5,3.9,4.0,4.1,4.2]
xi3 = X3[N_ELEMENTS(X3)-1]
a1v = 0.574 *x1^1.61
a1d = 0.574*1.61*xi1^0.61
a2v = 1 + 0.17699*(x2-1.82) - 0.50447*(x2-1.82)^2 $
- 0.02427*(x2-1.82)^3 + 0.72085*(x2-1.82)^4 $
+ 0.01979*(x2-1.82)^5 - 0.77530*(x2-1.82)^6 $
+ 0.32999*(x2-1.82)^7 + [0.0,0.0,-0.011,0.0, 0.0]
a3v = 1.752 - 0.316*x3 - 0.104/ (( x3-4.67)*( x3-4.67) $
+ 0.341) + [0.442,0.341,0.130,0.020,0.000]
a3d = -0.316 + 0.104*2*(xi3-4.67)/((xi3-4.67)*(xi3-4.67) + 0.341)^2
; these are the two lines I need to convert to python
as = SPL_INIT([x1,x2,x3], [a1v,a2v,a3v], YP0=a1d, YPN_1=a3d)
av = REVERSE(SPL_INTERP([x1,x2,x3], [a1v,a2v,a3v], as, REVERSE(x)))

TIA.

Jim Lewis
  • 43,505
  • 7
  • 82
  • 96
dcnicholls
  • 391
  • 1
  • 5
  • 15

1 Answers1

0

I'm not sure about SPL_INTERP() because I don't believe they (Exelis) provide the source code for that. However, they do provide another cubic-spline routine simply called SPLINE() which they provide as .pro code that you can take a look at like so:

IDL> .edit spline

You may look at the implementation there to see if that will give you the results you need.

That said, you may also want to try SciPy, which has this functionality:
http://docs.scipy.org/doc/scipy-0.14.0/reference/tutorial/interpolate.html#spline-interpolation

Hope this helps.

spacemanjosh
  • 641
  • 1
  • 5
  • 14