Python numpy.fft.irfft() Examples

The following are code examples for showing how to use numpy.fft.irfft(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: parSpectral   Author: JoyMonteiro   File: pSpectral.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def ChebY(self,field):

        N = self.yn - 1;
        z = cos(arange(0, N+1)*pi/N) /self.lengthY;
        mf = arange(0, N+1);
        m = mf[:, newaxis];
        ans = zeros((N+1, self.xn));

        newField = vstack((field, field[N-1:0:-1]));

        temp = rfft(newField, axis=0); 

        multiplier = 1j*m;
        mtemp = multiplier* temp;

        out = irfft(mtemp, axis=0);

        ans[1:N,:] = -out[1:N,:]/ (1- self.cby[1:N, np.newaxis]**2)**0.5; 

        ans[0,:] = sum(m**2 * temp[mf,:], axis=0)/N + 0.5*N*temp[N,:];

        ans[N,:] = sum( (-1)**(m+1) * m**2 * temp[mf,:], axis=0)/N + 0.5*(-1**(N+1))* N * temp[N];

        return ans; 
Example 2
Project: pybold   Author: hcherkaoui   File: convolution.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def spectral_convolve(k, x):
    """ Return k.conv(x).

    Parameters:
    -----------
    k : 1d np.ndarray,
        kernel.
    x : 1d np.ndarray,
        signal.

    Results:
    --------
    k_conv_x : 1d np.ndarray,
        the convolved signal.
    """
    x, p = custom_padd(x)
    N = len(x)
    fft_k = rfft(k, n=N, norm=None)
    padded_h_conv_x = irfft(fft_k * rfft(x,  n=N, norm=None), norm=None)
    k_conv_x = unpadd(padded_h_conv_x, p)

    return k_conv_x 
Example 3
Project: pybold   Author: hcherkaoui   File: convolution.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def spectral_retro_convolve(k, x):
    """ Return k_t.conv(x).

    Parameters:
    -----------
    k : 1d np.ndarray,
        kernel.
    x : 1d np.ndarray,
        signal.

    Results:
    --------
    k_conv_x : 1d np.ndarray,
        the convolved signal.
    """
    x, p = custom_padd(x)
    N = len(x)
    fft_k = rfft(k, n=N, norm=None).conj()
    padded_k_conv_x = irfft(fft_k * rfft(x,  n=N, norm=None), norm=None)
    k_conv_x = unpadd(padded_k_conv_x, p)

    return k_conv_x 
Example 4
Project: pybold   Author: hcherkaoui   File: convolution.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def spectral_deconvolve(k, x):
    """ Return k.conv(x).

    Parameters:
    -----------
    k : 1d np.ndarray,
        kernel.
    x : 1d np.ndarray,
        signal.

    Results:
    --------
    k_conv_x : 1d np.ndarray,
        the convolved signal.
    """
    x, p = custom_padd(x)
    N = len(x)
    fft_k = 1.0 / rfft(k, n=N, norm=None)
    padded_h_conv_x = irfft(fft_k * rfft(x,  n=N, norm=None), norm=None)
    k_conv_x = unpadd(padded_h_conv_x, p)

    return k_conv_x 
Example 5
Project: pybold   Author: hcherkaoui   File: convolution.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def spectral_retro_deconvolve(k, x):
    """ Return k.conv(x).

    Parameters:
    -----------
    k : 1d np.ndarray,
        kernel.
    x : 1d np.ndarray,
        signal.

    Results:
    --------
    k_conv_x : 1d np.ndarray,
        the convolved signal.
    """
    x, p = custom_padd(x)
    N = len(x)
    fft_k = (1.0 / rfft(k, n=N, norm=None)).conj()
    padded_h_conv_x = irfft(fft_k * rfft(x,  n=N, norm=None), norm=None)
    k_conv_x = unpadd(padded_h_conv_x, p)

    return k_conv_x 
Example 6
Project: acoustics-hardware   Author: AppliedAcousticsChalmers   File: generators.py    MIT License 5 votes vote down vote up
def _fft_noise(self):
        normal = np.random.normal(size=self.device.framesize)
        shaped = ifft(self._spectral_coefficients * fft(normal))
        return shaped 
Example 7
Project: LaserTOF   Author: kyleuckert   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_gaussian_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_gaussian(a, [5.0, 2.5],
                                                       shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1) 
Example 8
Project: LaserTOF   Author: kyleuckert   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_uniform_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_uniform(a, [5.0, 2.5],
                                                      shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0) 
Example 9
Project: LaserTOF   Author: kyleuckert   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_shift_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for dtype in [numpy.float32, numpy.float64]:
                expected = numpy.arange(shape[0] * shape[1], dtype=dtype)
                expected.shape = shape
                a = fft.rfft(expected, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_shift(a, [1, 1], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_array_almost_equal(a[1:, 1:], expected[:-1, :-1])
                assert_array_almost_equal(a.imag, numpy.zeros(shape)) 
Example 10
Project: LaserTOF   Author: kyleuckert   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_ellipsoid_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_ellipsoid(a, [5.0, 2.5],
                                              shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0) 
Example 11
Project: pyMatrixProfile   Author: ZiyaoWei   File: util.py    MIT License 5 votes vote down vote up
def mass(query, ts):
    """
    >>> np.round(mass(np.array([0.0, 1.0, -1.0, 0.0]), np.array([-1, 1, 0, 0, -1, 1])), 3)
    array([ 2.   ,  2.828,  2.   ])
    """
    query = zNormalize(query)
    m = len(query)
    n = len(ts)

    stdv = movstd(ts, m)
    query = query[::-1]
    query = np.pad(query, (0, n - m), 'constant')
    dots = fft.irfft(fft.rfft(ts) * fft.rfft(query))
    return np.sqrt(2 * (m - (dots[m - 1 :] / stdv))) 
Example 12
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: bench_basic.py    GNU General Public License v3.0 5 votes vote down vote up
def bench_random(self):
        from numpy.fft import irfft as numpy_irfft

        print()
        print('Inverse Fast Fourier Transform (real data)')
        print('==================================')
        print(' size |  scipy  |  numpy  ')
        print('----------------------------------')
        for size,repeat in [(100,7000),(1000,2000),
                            (256,10000),
                            (512,10000),
                            (1024,1000),
                            (2048,1000),
                            (2048*2,500),
                            (2048*4,500),
                            ]:
            print('%5s' % size, end=' ')
            sys.stdout.flush()

            x = random([size]).astype(double)
            x1 = zeros(size/2+1,dtype=cdouble)
            x1[0] = x[0]
            for i in range(1,size/2):
                x1[i] = x[2*i-1] + 1j * x[2*i]
            if not size % 2:
                x1[-1] = x[-1]
            y = irfft(x)

            print('|%8.2f' % measure('irfft(x)',repeat), end=' ')
            sys.stdout.flush()

            assert_array_almost_equal(numpy_irfft(x1,size),y)
            print('|%8.2f' % measure('numpy_irfft(x1,size)',repeat), end=' ')
            sys.stdout.flush()

            print(' (secs for %s calls)' % (repeat))

        sys.stdout.flush() 
Example 13
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_ndimage.py    GNU General Public License v3.0 5 votes vote down vote up
def test_fourier_gaussian_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_gaussian(a, [5.0, 2.5],
                                                       shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1) 
Example 14
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_ndimage.py    GNU General Public License v3.0 5 votes vote down vote up
def test_fourier_uniform_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_uniform(a, [5.0, 2.5],
                                                      shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0) 
Example 15
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_ndimage.py    GNU General Public License v3.0 5 votes vote down vote up
def test_fourier_shift_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for dtype in [numpy.float32, numpy.float64]:
                expected = numpy.arange(shape[0] * shape[1], dtype=dtype)
                expected.shape = shape
                a = fft.rfft(expected, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_shift(a, [1, 1], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_array_almost_equal(a[1:, 1:], expected[:-1, :-1])
                assert_array_almost_equal(a.imag, numpy.zeros(shape)) 
Example 16
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_ndimage.py    GNU General Public License v3.0 5 votes vote down vote up
def test_fourier_ellipsoid_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_ellipsoid(a, [5.0, 2.5],
                                              shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0) 
Example 17
Project: ocelot   Author: ocelot-collab   File: reswake.py    GNU General Public License v3.0 5 votes vote down vote up
def impedance2wake(f, y):
    """
    Fourier transform with exp(-iwt)
                f -    Hz
                y -    Om
                s    - Meter
                w -    V/C
    """
    df = f[1] - f[0]
    n = len(f)
    s = 1./df*np.arange(n)/n*speed_of_light
    w = n*df*irfft(y, n)
    return s, w 
Example 18
Project: ble5-nrf52-mac   Author: tomasero   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_gaussian_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type_, dec in zip([numpy.float32, numpy.float64], [6, 14]):
                a = numpy.zeros(shape, type_)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_gaussian(a, [5.0, 2.5], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1, decimal=dec) 
Example 19
Project: ble5-nrf52-mac   Author: tomasero   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_uniform_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type_, dec in zip([numpy.float32, numpy.float64], [6, 14]):
                a = numpy.zeros(shape, type_)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_uniform(a, [5.0, 2.5], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0, decimal=dec) 
Example 20
Project: ble5-nrf52-mac   Author: tomasero   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_shift_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type_, dec in zip([numpy.float32, numpy.float64], [4, 11]):
                expected = numpy.arange(shape[0] * shape[1], dtype=type_)
                expected.shape = shape
                a = fft.rfft(expected, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_shift(a, [1, 1], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_array_almost_equal(a[1:, 1:], expected[:-1, :-1],
                                          decimal=dec)
                assert_array_almost_equal(a.imag, numpy.zeros(shape),
                                          decimal=dec) 
Example 21
Project: ble5-nrf52-mac   Author: tomasero   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_ellipsoid_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type_, dec in zip([numpy.float32, numpy.float64], [5, 14]):
                a = numpy.zeros(shape, type_)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_ellipsoid(a, [5.0, 2.5],
                                              shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0, decimal=dec) 
Example 22
Project: Computable   Author: ktraunmueller   File: bench_basic.py    MIT License 5 votes vote down vote up
def bench_random(self):
        from numpy.fft import irfft as numpy_irfft

        print()
        print('Inverse Fast Fourier Transform (real data)')
        print('==================================')
        print(' size |  scipy  |  numpy  ')
        print('----------------------------------')
        for size,repeat in [(100,7000),(1000,2000),
                            (256,10000),
                            (512,10000),
                            (1024,1000),
                            (2048,1000),
                            (2048*2,500),
                            (2048*4,500),
                            ]:
            print('%5s' % size, end=' ')
            sys.stdout.flush()

            x = random([size]).astype(double)
            x1 = zeros(size/2+1,dtype=cdouble)
            x1[0] = x[0]
            for i in range(1,size/2):
                x1[i] = x[2*i-1] + 1j * x[2*i]
            if not size % 2:
                x1[-1] = x[-1]
            y = irfft(x)

            print('|%8.2f' % measure('irfft(x)',repeat), end=' ')
            sys.stdout.flush()

            assert_array_almost_equal(numpy_irfft(x1,size),y)
            print('|%8.2f' % measure('numpy_irfft(x1,size)',repeat), end=' ')
            sys.stdout.flush()

            print(' (secs for %s calls)' % (repeat))

        sys.stdout.flush() 
Example 23
Project: Computable   Author: ktraunmueller   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_gaussian_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_gaussian(a, [5.0, 2.5],
                                                       shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1) 
Example 24
Project: Computable   Author: ktraunmueller   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_uniform_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_uniform(a, [5.0, 2.5],
                                                      shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0) 
Example 25
Project: Computable   Author: ktraunmueller   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_shift_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for dtype in [numpy.float32, numpy.float64]:
                expected = numpy.arange(shape[0] * shape[1], dtype=dtype)
                expected.shape = shape
                a = fft.rfft(expected, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_shift(a, [1, 1], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_array_almost_equal(a[1:, 1:], expected[:-1, :-1])
                assert_array_almost_equal(a.imag, numpy.zeros(shape)) 
Example 26
Project: Computable   Author: ktraunmueller   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_ellipsoid_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_ellipsoid(a, [5.0, 2.5],
                                              shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0) 
Example 27
Project: poker   Author: surgebiswas   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_gaussian_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_gaussian(a, [5.0, 2.5],
                                                       shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1) 
Example 28
Project: poker   Author: surgebiswas   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_uniform_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_uniform(a, [5.0, 2.5],
                                                      shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0) 
Example 29
Project: poker   Author: surgebiswas   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_shift_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for dtype in [numpy.float32, numpy.float64]:
                expected = numpy.arange(shape[0] * shape[1], dtype=dtype)
                expected.shape = shape
                a = fft.rfft(expected, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_shift(a, [1, 1], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_array_almost_equal(a[1:, 1:], expected[:-1, :-1])
                assert_array_almost_equal(a.imag, numpy.zeros(shape)) 
Example 30
Project: poker   Author: surgebiswas   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_ellipsoid_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_ellipsoid(a, [5.0, 2.5],
                                              shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0) 
Example 31
Project: P3_image_processing   Author: latedude2   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_gaussian_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type_, dec in zip([numpy.float32, numpy.float64], [6, 14]):
                a = numpy.zeros(shape, type_)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_gaussian(a, [5.0, 2.5], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1, decimal=dec) 
Example 32
Project: P3_image_processing   Author: latedude2   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_uniform_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type_, dec in zip([numpy.float32, numpy.float64], [6, 14]):
                a = numpy.zeros(shape, type_)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_uniform(a, [5.0, 2.5], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0, decimal=dec) 
Example 33
Project: P3_image_processing   Author: latedude2   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_shift_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type_, dec in zip([numpy.float32, numpy.float64], [4, 11]):
                expected = numpy.arange(shape[0] * shape[1], dtype=type_)
                expected.shape = shape
                a = fft.rfft(expected, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_shift(a, [1, 1], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_array_almost_equal(a[1:, 1:], expected[:-1, :-1],
                                          decimal=dec)
                assert_array_almost_equal(a.imag, numpy.zeros(shape),
                                          decimal=dec) 
Example 34
Project: P3_image_processing   Author: latedude2   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_ellipsoid_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type_, dec in zip([numpy.float32, numpy.float64], [5, 14]):
                a = numpy.zeros(shape, type_)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_ellipsoid(a, [5.0, 2.5],
                                              shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0, decimal=dec) 
Example 35
Project: SimpleMC   Author: ja-vazquez   File: cosmich.py    GNU General Public License v2.0 5 votes vote down vote up
def smline(x, y, mnmx):

    # first lets.pad
    y = log(y+1e-30)
    N = len(y)
    y = array([y[0]]*N+list(y)+[y[-1]]*N)
    rft = fft.rfft(y)
    Nx = len(rft)
    k = linspace(0, 1, Nx)
    rft *= exp(-k*k/(2*0.2**2))
    y = fft.irfft(rft)
    y = y[N:2*N]
    y = exp(y)
    return x, y 
Example 36
Project: SimpleMC   Author: ja-vazquez   File: cosmich.py    GNU General Public License v2.0 5 votes vote down vote up
def smline(x, y, mnmx):

    # first lets.pad
    y = log(y+1e-30)
    N = len(y)
    y = array([y[0]]*N+list(y)+[y[-1]]*N)
    rft = fft.rfft(y)
    Nx = len(rft)
    k = linspace(0, 1, Nx)
    rft *= exp(-k*k/(2*0.2**2))
    y = fft.irfft(rft)
    y = y[N:2*N]
    y = exp(y)
    return x, y 
Example 37
Project: SimpleMC   Author: ja-vazquez   File: cosmich.py    GNU General Public License v2.0 5 votes vote down vote up
def smline(x, y, mnmx):

    # first lets.pad
    y = log(y+1e-30)
    N = len(y)
    y = array([y[0]]*N+list(y)+[y[-1]]*N)
    rft = fft.rfft(y)
    Nx = len(rft)
    k = linspace(0, 1, Nx)
    rft *= exp(-k*k/(2*0.2**2))
    y = fft.irfft(rft)
    y = y[N:2*N]
    y = exp(y)
    return x, y 
Example 38
Project: alona   Author: oscar-franzen   File: irlb.py    GNU General Public License v3.0 5 votes vote down vote up
def multS(s, v, L, TP=False):

    N = s.shape[0]
    vp = prepare_v(v, N, L, TP=TP)
    p = irfft(rfft(vp) * rfft(s))
    if not TP:
        return p[:L]
    return p[L - 1:] 
Example 39
Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_gaussian_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type_, dec in zip([numpy.float32, numpy.float64], [6, 14]):
                a = numpy.zeros(shape, type_)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_gaussian(a, [5.0, 2.5], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1, decimal=dec) 
Example 40
Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_uniform_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type_, dec in zip([numpy.float32, numpy.float64], [6, 14]):
                a = numpy.zeros(shape, type_)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_uniform(a, [5.0, 2.5], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0, decimal=dec) 
Example 41
Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_shift_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type_, dec in zip([numpy.float32, numpy.float64], [4, 11]):
                expected = numpy.arange(shape[0] * shape[1], dtype=type_)
                expected.shape = shape
                a = fft.rfft(expected, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_shift(a, [1, 1], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_array_almost_equal(a[1:, 1:], expected[:-1, :-1],
                                          decimal=dec)
                assert_array_almost_equal(a.imag, numpy.zeros(shape),
                                          decimal=dec) 
Example 42
Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_ndimage.py    MIT License 5 votes vote down vote up
def test_fourier_ellipsoid_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type_, dec in zip([numpy.float32, numpy.float64], [5, 14]):
                a = numpy.zeros(shape, type_)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_ellipsoid(a, [5.0, 2.5],
                                              shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0, decimal=dec) 
Example 43
Project: inference-tools   Author: C-bowman   File: mcmc.py    MIT License 5 votes vote down vote up
def ESS(x):
    # get the autocorrelation
    f = irfft(abs(rfft(x - mean(x)))**2)
    # remove reflected 2nd half
    f = f[:len(f)//2]
    # check that the first value is not negative
    if f[0] < 0.: raise ValueError('First element of the autocorrelation is negative')
    # cut to first negative value
    f = f[:argmax(f<0.)]
    # sum and normalise
    thin_factor = f.sum() / f[0]
    return int(len(x) / thin_factor) 
Example 44
Project: aces   Author: vanceeasleaf   File: vdos.py    GNU General Public License v2.0 5 votes vote down vote up
def acf(self, a):
        length = len(a)
        a = rfft(a, axis=0)
        c = irfft(a * a.conjugate(), axis=0) / length
        return c 
Example 45
Project: aces   Author: vanceeasleaf   File: __init__.py    GNU General Public License v2.0 5 votes vote down vote up
def acf(a):
    length = len(a)
    print("start fourier transform of correlation")
    a = rfft(a, axis=0)
    print("start inverse fourier transform of correlation")
    c = irfft(a * a.conjugate(), axis=0) / length
    return c 
Example 46
Project: mnnpy   Author: chriscainx   File: irlb.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def multS(s, v, L, TP=False):

    N = s.shape[0]
    vp = prepare_v(v, N, L, TP=TP)
    p = irfft(rfft(vp) * rfft(s))
    if not TP:
        return p[:L]
    return p[L - 1:] 
Example 47
Project: wine-ml-on-aws-lambda   Author: pierreant   File: test_ndimage.py    Apache License 2.0 5 votes vote down vote up
def test_fourier_gaussian_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_gaussian(a, [5.0, 2.5],
                                                       shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1) 
Example 48
Project: wine-ml-on-aws-lambda   Author: pierreant   File: test_ndimage.py    Apache License 2.0 5 votes vote down vote up
def test_fourier_uniform_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_uniform(a, [5.0, 2.5],
                                                      shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0) 
Example 49
Project: wine-ml-on-aws-lambda   Author: pierreant   File: test_ndimage.py    Apache License 2.0 5 votes vote down vote up
def test_fourier_shift_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for dtype in [numpy.float32, numpy.float64]:
                expected = numpy.arange(shape[0] * shape[1], dtype=dtype)
                expected.shape = shape
                a = fft.rfft(expected, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_shift(a, [1, 1], shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_array_almost_equal(a[1:, 1:], expected[:-1, :-1])
                assert_array_almost_equal(a.imag, numpy.zeros(shape)) 
Example 50
Project: wine-ml-on-aws-lambda   Author: pierreant   File: test_ndimage.py    Apache License 2.0 5 votes vote down vote up
def test_fourier_ellipsoid_real01(self):
        for shape in [(32, 16), (31, 15)]:
            for type in [numpy.float32, numpy.float64]:
                a = numpy.zeros(shape, type)
                a[0, 0] = 1.0
                a = fft.rfft(a, shape[0], 0)
                a = fft.fft(a, shape[1], 1)
                a = ndimage.fourier_ellipsoid(a, [5.0, 2.5],
                                              shape[0], 0)
                a = fft.ifft(a, shape[1], 1)
                a = fft.irfft(a, shape[0], 0)
                assert_almost_equal(ndimage.sum(a), 1.0)