[SciPy-User] faster interpolations (interp1d)
josef.pktd@gmai...
josef.pktd@gmai...
Wed Mar 2 09:13:28 CST 2011
On Wed, Mar 2, 2011 at 9:34 AM, James McCormac <jmccormac01@qub.ac.uk> wrote:
>
> Hi Josef,
> Do you mean, create the spectra then resample it afterwards?
that's kind of the idea
(I never went through all the numerical details, and I still haven't
gone through 10 ways to estimate the spectral density.)
you can look at the source of scipy.signal.signaltools which looks
faster to me than interpolation in time domain. And if you want to end
up with the fft anyway, maybe you can skip the final ifft.
But image processing libraries might have the interpolation out of the box.
Cheers,
Josef
> I can have a
> look at ndimage.iterpolation.
>
> Cheers
> James
>
>
>
> On Wed, March 2, 2011 1:56 pm, josef.pktd@gmail.com wrote:
>> On Tue, Mar 1, 2011 at 9:03 AM, eat <e.antero.tammi@gmail.com> wrote:
>>
>>> Hi,
>>>
>>>
>>> On Tue, Mar 1, 2011 at 1:01 PM, James McCormac <jmccormac01@qub.ac.uk>
>>> wrote:
>>>
>>>>
>>>> Hi eat,
>>>> Yes this code works fine, its not actually that bad on a 2x500 arrays
>>>> ~5
>>>> but the 500 length arrays are the shortest I can run with. I am
>>>> analyzing CCD images which can go up 2000x2000 in length and breadth,
>>>> meaning 2x2000 1d arrays after collapsing the spectra. This takes >20
>>>> sec per image which is much too long. Ideally the id like it to run as
>>>> fast as possible (depending on how much accuracy I can maintain).
>>>> Yes the code works fine its just a little slow, I've put timers in and
>>>> 98%
>>>> of the time is taken up by the interpolation. Any improvement in
>>>> performance would be great. I've slimmed down the rest of the body
>>>> as much as possible already.
>>>
>>> Can you provide a minimal working code example, which demonstrates the
>>> problem? At least you'll get better idea how it performs on some other
>>> machine.
>>>
>>> Regards,
>>> eat
>>>>
>>>> Cheers
>>>> James
>>>>
>>>>
>>>> On 1 Mar 2011, at 07:31, eat wrote:
>>>>
>>>>
>>>> Hi James,
>>>>
>>>>
>>>> On Mon, Feb 28, 2011 at 5:25 PM, James McCormac
>>>> <jmccormac01@qub.ac.uk>
>>>> wrote:
>>>>
>>>>>
>>>>> Hi eat,
>>>>> you sent me a suggestion for faster 1d interpolations using matrices
>>>>> a few weeks back but I cannot find the email anywhere when I looked
>>>>> for it today.
>>>>>
>>>>> Here is a better explanation of what I am trying to do. For example
>>>>> I
>>>>> have a 1d array of 500 elements. I want to interpolate them
>>>>> quadratically so each array becomes 10 values, 50,000 in total.
>>>>>
>>>>> I have 500x500 pixels and I want to get 0.01 pixel resolution.
>>>>>
>>>>>
>>>>> code snipet: # collapse an image in the x direction
>>>>> ref_xproj=np.sum(refarray,axis=0)
>>>>>
>>>>> # make an array for the 1d spectra
>>>>> x = np.linspace(0, (x_2-x_1), (x_2-x_1))
>>>>>
>>>>> # interpolation
>>>>> f2_xr = interp1d(x, ref_xproj, kind='quadratic')
>>>>>
>>>>> # new x array for interpolated data
>>>>> xnew = np.linspace(0, (x_2-x_1), (x_2-x_1)*100)
>>>>>
>>>>> # FFT of interpolated spectra
>>>>> F_ref_xproj = fftpack.fft(f2_xr(xnew))
>>>>>
>>>>>
>>>>> Can I do this type of interpolation faster using the method you
>>>>> described before?
>>>>
>>>> I'll misinterpreted your original question and the method I suggested
>>>> there is not applicable. To better understand your situation, few
>>>> questions:
>>>> - what you described above; it does work for you in technical sense?
>>>> - if so, then the problem is with the execution performance?
>>>> - what are your current timings?
>>>> - how much you'll need to enhance them?
>>>> Regards,
>>>> eat
>>>>>
>>>>> Cheers
>>>>> James
>>>>>
>>
>> Just a thought since I don't know the details:
>>
>>
>> using fft interpolation might be faster, e.g. signal.resample
>>
>>>>> t = np.linspace(0,10,25) x = np.sin(t) t2 = np.linspace(0,10,50) x2 =
>>>>> signal.resample(x,50)
>>
>> scipy.ndimage.interpolation should also be faster, if there is something
>> that does what you want.
>>
>> Josef
>>
>>
>>
>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> SciPy-User mailing list
>>>>> SciPy-User@scipy.org
>>>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>>>
>>>>
>>>> _______________________________________________
>>>> SciPy-User mailing list
>>>> SciPy-User@scipy.org
>>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>>
>>>>
>>>> -------------------------------------------------
>>>> James McCormac
>>>> jmccormac01@qub.ac.uk Astrophysics Research Centre
>>>> School of Mathematics & Physics
>>>> Queens University Belfast
>>>> University Road,
>>>> Belfast, U.K
>>>> BT7 1NN,
>>>> TEL: 028 90973509
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> SciPy-User mailing list
>>>> SciPy-User@scipy.org
>>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>>
>>>>
>>>
>>>
>>> _______________________________________________
>>> SciPy-User mailing list
>>> SciPy-User@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>
>>>
>>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
More information about the SciPy-User
mailing list