Python numpy.fft.irfftn() Examples

The following are code examples for showing how to use numpy.fft.irfftn(). 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: pyDNAbinding   Author: nboley   File: signal.py    GNU General Public License v2.0 6 votes vote down vote up
def cross_correlation(seqs):
    # deal with the shape, and upcast to the next reasonable shape
    shape = np.array(seqs.shape[1:]) + np.array(seqs.shape[1:]) - 1
    fshape = [next_good_fshape(x) for x in shape]
    fslice = tuple([slice(0, int(sz)) for sz in shape])
    flipped_seqs_fft = np.zeros([seqs.shape[0],] + fshape[:-1] + [fshape[-1]//2+1,], dtype='complex')
    for i in xrange(seqs.shape[0]):
        rev_slice = tuple([i,] + [slice(None, None, -1) for sz in shape])
        flipped_seqs_fft[i] = rfftn(seqs[rev_slice], fshape)
    rv = np.zeros((seqs.shape[0], seqs.shape[0]), dtype='float32')
    for i in xrange(seqs.shape[0]):
        fft_seq = rfftn(seqs[i], fshape)
        for j in xrange(i+1, seqs.shape[0]):
            rv[i,j] = irfftn(fft_seq*flipped_seqs_fft[j], fshape)[fslice].max()
            #print rv[i,j], correlate(seqs[i], seqs[j]).max()
    return rv 
Example 2
Project: LaserTOF   Author: kyleuckert   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 3
Project: qfit-3.0   Author: ExcitedStates   File: transformer.py    MIT License 5 votes vote down vote up
def __call__(self, nyquist=2):

        h, k, l = self.hkl.T

        naive_voxelspacing = self._resolution / (2 * nyquist)
        naive_shape = np.ceil(self.unit_cell.abc / naive_voxelspacing)
        naive_shape = naive_shape[::-1].astype(int)
        shape = naive_shape
        # TODO make grid of unit cell a multiple of small primes
        #efficient_multiples = [2, 3, 5, 7, 11, 13]
        #shape = [closest_upper_multiple(x, efficient_multiples) for x in naive_shape]
        fft_grid = np.zeros(shape, dtype=np.complex128)

        start_sf = self._f_phi_to_complex(self.f, self.phi)
        symops = self.space_group.symop_list[:self.space_group.num_primitive_sym_equiv]
        two_pi = 2 * np.pi
        hsym = np.zeros_like(h)
        ksym = np.zeros_like(k)
        lsym = np.zeros_like(l)
        for symop in symops:
            for n, msym in enumerate((hsym, ksym, lsym)):
                msym.fill(0)
                rot = np.asarray(symop.R.T)[n]
                for r, m in zip(rot, (h, k, l)):
                    if r != 0:
                        msym += int(r) * m
            if np.allclose(symop.t, 0):
                sf = start_sf
            else:
                delta_phi = np.rad2deg(np.inner((-two_pi * symop.t), self.hkl))
                delta_phi = np.asarray(delta_phi).ravel()
                sf = self._f_phi_to_complex(self.f, self.phi + delta_phi)
            fft_grid[lsym, ksym, hsym] = sf
            fft_grid[-lsym, -ksym, -hsym] = sf.conj()
        #grid = np.fft.ifftn(fft_grid)
        nx = shape[-1]
        grid = np.fft.irfftn(fft_grid[:, :, :nx // 2 + 1])
        grid -= grid.mean()
        grid /= grid.std()
        return grid 
Example 4
Project: qfit-3.0   Author: ExcitedStates   File: transformer.py    MIT License 5 votes vote down vote up
def density(self):

        self._transformer.density()
        fft_grid = rfftn(self.xmap.array)
        fft_grid[self._fft_mask] = 0
        grid = irfftn(fft_grid)
        if self.b_add is not None:
            pass
        self.xmap.array[:] = grid.real 
Example 5
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 6
Project: recruit   Author: Frank-qlu   File: test_helper.py    Apache License 2.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 7
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 8
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 9
Project: MARRtino-2.0   Author: DaniAffCH   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 10
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 11
Project: vnpy_crypto   Author: birforce   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 12
Project: ble5-nrf52-mac   Author: tomasero   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 13
Project: Computable   Author: ktraunmueller   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 14
Project: poker   Author: surgebiswas   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 15
Project: P3_image_processing   Author: latedude2   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 16
Project: hawc_hal   Author: threeML   File: psf_convolutor.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def extended_source_image(self, ideal_image):

        # Convolve

        assert np.alltrue(ideal_image.shape == self._expected_shape), "Shape of image to be convolved is not correct."

        ret = irfftn(rfftn(ideal_image, self._fshape) * self._psf_fft, self._fshape)[self._fslice].copy()

        conv = _centered(ret, self._expected_shape)

        return conv 
Example 17
Project: hawc_hal   Author: threeML   File: fast_convolution.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __call__(self, image):

        assert alltrue(image.shape == self._expected_shape), "Shape of image to be convolved is not correct. Re-run setup."

        ret = irfftn(rfftn(image, self._fshape) * self._psf_fft, self._fshape)[self._fslice].copy()

        return _centered(ret, self._expected_shape) 
Example 18
Project: pyDNAbinding   Author: nboley   File: signal.py    GNU General Public License v2.0 5 votes vote down vote up
def _transformed_fft_convolve(freq_h, freq_x):
    return irfftn(freq_x*freq_h) 
Example 19
Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 20
Project: 3dprinteros-client   Author: panasevychol   File: test_helper.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 21
Project: 3dprinteros-client   Author: panasevychol   File: test_helper.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 22
Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_helper.py    Apache License 2.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 23
Project: fund   Author: Frank-qlu   File: test_helper.py    Apache License 2.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 24
Project: pySINDy   Author: luckystarufo   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 25
Project: Programming-for-Non-Technical-Roles-   Author: PacktPublishing   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 26
Project: linear_neuron   Author: uglyboxer   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 27
Project: facethin   Author: ParkerGod   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 28
Project: islam-buddy   Author: hamir   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 29
Project: mxnet-lambda   Author: awslabs   File: test_helper.py    Apache License 2.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 30
Project: Deribit_funding_rate_indicator   Author: Dimasik007   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 31
Project: psychrometric-chart-makeover   Author: buds-lab   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 32
Project: wine-ml-on-aws-lambda   Author: pierreant   File: test_helper.py    Apache License 2.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 33
Project: linux-cross-gcc   Author: nmercier   File: test_helper.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 34
Project: thunder-registration   Author: thunder-project   File: transforms.py    MIT License 5 votes vote down vote up
def compute(a, b):
        """
        Compute an optimal displacement between two ndarrays.

        Finds the displacement between two ndimensional arrays. Arrays must be
        of the same size. Algorithm uses a cross correlation, computed efficiently
        through an n-dimensional fft.

        Parameters
        ----------
        a : ndarray
            The first array

        b : ndarray
            The second array
        """
        from numpy.fft import rfftn, irfftn
        from numpy import unravel_index, argmax

        # compute real-valued cross-correlation in fourier domain
        s = a.shape
        f = rfftn(a)
        f *= rfftn(b).conjugate()
        c = abs(irfftn(f, s))

        # find location of maximum
        inds = unravel_index(argmax(c), s)

        # fix displacements that are greater than half the total size
        pairs = zip(inds, a.shape)
        # cast to basic python int for serialization
        adjusted = [int(d - n) if d > n // 2 else int(d) for (d, n) in pairs]

        return Displacement(adjusted) 
Example 35
Project: SignLanguage_ML   Author: mareep-raljodid   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 36
Project: ImageFusion   Author: pfchai   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 37
Project: sarah   Author: ChonchoFronto   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 38
Project: deconv3d   Author: irap-omp   File: convolution.py    MIT License 5 votes vote down vote up
def convolve_1d(data, psf, compute_fourier=True, axis=0):
    """
    Convolve data with PSF only along one dimension specified by axis
    (default: 0).
    PSF can be the PSF data or its Fourier transform.
    if compute_fourier then compute the fft transform of the PSF.
    if False then assumes that the fft is given.
    """

    axis = np.array([axis])

    # Compute needed padding
    cubep, boxcube = padding(data, axes=axis)

    # Get the size of the axis
    size = np.array(np.shape(cubep)[slice(axis, axis + 1)])

    if compute_fourier:
        psfp, boxpsf = padding(psf, axes=axis)
        fftpsf = np.fft.rfftn(psfp, s=size, axes=axis)
    else:
        fftpsf = psf

    fftimg = np.fft.rfftn(cubep, s=size, axes=axis)

    # Convolution
    fft = np.fft.fftshift(np.fft.irfftn(fftimg * fftpsf, s=size, axes=axis), axes=axis).real

    # Truncate padding
    cube_conv = fft[boxcube]

    return cube_conv, fftpsf 
Example 39
Project: honours_project   Author: JFriel   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 40
Project: honours_project   Author: JFriel   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 41
Project: Blackjack-Tracker   Author: martinabeleda   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 42
Project: DiffractionMicroscopy   Author: davidwhogg   File: pharet.py    MIT License 5 votes vote down vote up
def get_real_image(self):
        if self.image is None:
            self.image = irfftn(self.ft, self.imageshape)
        return self.image 
Example 43
Project: PYPIC   Author: max614   File: test_helper.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 44
Project: PYPIC   Author: max614   File: test_helper.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 45
Project: PYPIC   Author: max614   File: test_helper.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 46
Project: Generic-Sweepscript   Author: benschneider   File: covfunc.py    GNU General Public License v2.0 5 votes vote down vote up
def get_g2(P1, P2, lags=20):
    ''' Returns the Top part of the G2 equation (<P1P2> - <P1><P2>)'''
    lags = int(lags)
    P1 = np.asarray(P1)
    P2 = np.asarray(P2)
    # G2 = np.zeros([lags*2-1])

    start = len(P1*2-1)-lags
    stop = len(P1*2-1)-1+lags

    # assume I1 Q1 have the same shape
    sP1 = np.array(P1.shape)
    complex_result = np.issubdtype(P1.dtype, np.complex)
    shape = sP1 - 1

    # Speed up FFT by padding to optimal size for FFTPACK
    fshape = [_next_regular(int(d)) for d in shape]
    fslice = tuple([slice(0, int(sz)) for sz in shape])
    if not complex_result and _rfft_lock.acquire(False):
        try:
            fftP1 = rfftn(P1, fshape)
            rfftP2 = rfftn(P2[::-1], fshape)
            G2 = irfftn((fftP1*rfftP2))[fslice].copy()[start:stop]/len(fftP1)
            return

        finally:
            _rfft_lock.release()

    else:
        # If we're here, it's either because we need a complex result, or we
        # failed to acquire _rfft_lock (meaning rfftn isn't threadsafe and
        # is already in use by another thread).  In either case, use the
        # (threadsafe but slower) SciPy complex-FFT routines instead.
        # ret = ifftn(fftn(in1, fshape) * fftn(in2, fshape))[fslice].copy()
        print 'Abort, reason:complex input or Multithreaded FFT not available'

        if not complex_result:
            pass  # ret = ret.real

    P12var = np.var(P1)*np.var(P2)
    return G2-P12var 
Example 47
Project: offlow   Author: satwikkansal   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 48
Project: lambda-tensorflow-object-detection   Author: mikylucky   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 49
Project: elasticintel   Author: securityclippy   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes) 
Example 50
Project: cnidaria   Author: sauloal   File: test_helper.py    MIT License 5 votes vote down vote up
def test_not_last_axis_success(self):
        ar, ai = np.random.random((2, 16, 8, 32))
        a = ar + 1j*ai

        axes = (-2,)

        # Should not raise error
        fft.irfftn(a, axes=axes)