[SciPy-User] 1-d Interpolation of unevenly spaced data
Dybbroe Adam
Adam.Dybbroe at smhi.se
Tue Feb 1 18:23:08 EST 2011
Thanks.
Ok, I have stored my data in an npz-file (attached).
You should be able to run the following code (with the npz file in the
same directory from where you run):
import numpy as np
outfile = './ipol_test_arrays.npz'
from scipy.interpolate import splrep, splev
# Load data and try do the spline interpolation:
npzfile = np.load(outfile)
wvl = npzfile['wvl']
resp = npzfile['resp']
xspl = np.linspace(wvl[0], wvl[-1], 300)
tck = splrep(wvl, resp)
resp_ipol = splev(xspl, tck)
Here is what I get:
In [1]: run scipy_ipol_test_ext.py
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/local_disk/laptop/NowcastingSaf/radiationStuff/test/scipy_ipol_test_ext.py
in <module>()
14 xspl = np.linspace(wvl[0], wvl[-1], 300)
15
---> 16 tck = splrep(wvl, resp)
17 resp_ipol = splev(xspl, tck)
18
/home/a000680/usr/lib64/python2.5/site-packages/scipy/interpolate/fitpack.pyc
in splrep(x, y, w, xb, xe, k, task, s, t, full_output, per, quiet)
416 else:
417 try:
--> 418 raise _iermess[ier][1],_iermess[ier][0]
419 except KeyError:
420 raise _iermess['unknown'][1],_iermess['unknown'][0]
ValueError: Error on input data
WARNING: Failure executing file: <scipy_ipol_test_ext.py>
:-(
-Adam
On 2011-02-01 15:12, Christian K. wrote:
> Am 01.02.11 14:40, schrieb Dybbroe Adam:
>
>> # Mask out part of the response curve:
>> maskidx = np.logical_and(np.greater_equal(w_ch, start),
>> np.less_equal(w_ch, end))
>> wvl = np.repeat(w_ch, maskidx)
>> resp = np.repeat(resp_ch, maskidx)
>>
> I do not unterstand what those lines are for. As long as the
> interpolation range is within the data range everything is ok.
>
> Thus it is really suffienct to do
>
> tck = splrep(yourdata_x, yourdata_y)
> resp_ipol = splev(linspace(yourdata_x[0],yourdata_x[-1],200), tck)
>
> Maybe you could post a running script including your data.
>
> Regards, Christian
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110202/0a3536b2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ipol_test_arrays.npz
Type: application/octet-stream
Size: 3868 bytes
Desc: ipol_test_arrays.npz
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110202/0a3536b2/attachment.obj>
More information about the SciPy-User
mailing list