Python numpy.fft.rfftfreq() Examples

The following are code examples for showing how to use numpy.fft.rfftfreq(). 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: mpiFFT4py   Author: spectralDNS   File: line.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def get_local_wavenumbermesh(self, scaled=True, broadcast=False,
                                 eliminate_highest_freq=False):
        kx = fftfreq(self.N[0], 1./self.N[0])
        ky = rfftfreq(self.N[1], 1./self.N[1])
        if eliminate_highest_freq:
            for i, k in enumerate((kx, ky)):
                if self.N[i] % 2 == 0:
                    k[self.N[i]//2] = 0

        Ks = np.meshgrid(kx, ky[self.rank*self.Np[1]//2:(self.rank*self.Np[1]//2+self.Npf)], indexing='ij', sparse=True)
        if scaled is True:
            Lp = 2*np.pi/self.L
            Ks[0] *= Lp[0]
            Ks[1] *= Lp[1]
        K = Ks
        if broadcast is True:
            K = [np.broadcast_to(k, self.complex_shape()) for k in Ks]
        return K 
Example 2
Project: LaserTOF   Author: kyleuckert   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 3
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 4
Project: recruit   Author: Frank-qlu   File: test_helper.py    Apache License 2.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 5
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_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 6
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 7
Project: MARRtino-2.0   Author: DaniAffCH   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 8
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 9
Project: vnpy_crypto   Author: birforce   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 10
Project: ble5-nrf52-mac   Author: tomasero   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 11
Project: Computable   Author: ktraunmueller   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 12
Project: poker   Author: surgebiswas   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 13
Project: P3_image_processing   Author: latedude2   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 14
Project: pystella   Author: zachjweiner   File: dft.py    MIT License 5 votes vote down vote up
def __init__(self, decomp, context, queue, grid_shape, dtype):
        """
        :arg decomp: A :class:`pystella.DomainDecomposition`.

        :arg context: A :class:`pyopencl.Context`.

        :arg queue: A :class:`pyopencl.CommandQueue`.

        :arg grid_shape: A 3-:class:`tuple` specifying the shape of position-space
            arrays to be transformed.

        :arg dtype: The datatype of real arrays to be transformed. The complex
            datatype is chosen to have the same precision.
        """

        self.decomp = decomp
        self.grid_shape = grid_shape
        self.dtype = dtype
        cdtype = _c_dtype_mapping[dtype]
        self.cdtype = cdtype

        self.fx = cla.zeros(queue, grid_shape, dtype)
        self.fk = cla.zeros(queue, self.shape(True), cdtype)
        from gpyfft import FFT
        self.forward = FFT(context, queue, self.fx, out_array=self.fk, real=True,
                           scale_forward=1, scale_backward=1)
        self.backward = FFT(context, queue, self.fk, out_array=self.fx, real=True,
                            scale_forward=1, scale_backward=1)

        from numpy.fft import fftfreq, rfftfreq
        names = ('momenta_x', 'momenta_y', 'momenta_z')

        slc = ((), (), (),)
        k = [fftfreq(n, 1/n).astype(dtype) for n in grid_shape]
        self.sub_k_c = {direction: cla.to_device(queue, k_i[s_i])
                        for direction, k_i, s_i in zip(names, k, slc)}

        k[-1] = rfftfreq(grid_shape[-1], 1/grid_shape[-1]).astype(dtype)
        self.sub_k = {direction: cla.to_device(queue, k_i[s_i])
                      for direction, k_i, s_i in zip(names, k, slc)} 
Example 15
Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 16
Project: 3dprinteros-client   Author: panasevychol   File: test_helper.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 17
Project: 3dprinteros-client   Author: panasevychol   File: test_helper.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 18
Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_helper.py    Apache License 2.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 19
Project: fund   Author: Frank-qlu   File: test_helper.py    Apache License 2.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 20
Project: pySINDy   Author: luckystarufo   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 21
Project: Programming-for-Non-Technical-Roles-   Author: PacktPublishing   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 22
Project: linear_neuron   Author: uglyboxer   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 23
Project: facethin   Author: ParkerGod   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 24
Project: islam-buddy   Author: hamir   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 25
Project: mxnet-lambda   Author: awslabs   File: test_helper.py    Apache License 2.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 26
Project: Deribit_funding_rate_indicator   Author: Dimasik007   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 27
Project: psychrometric-chart-makeover   Author: buds-lab   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 28
Project: wine-ml-on-aws-lambda   Author: pierreant   File: test_helper.py    Apache License 2.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 29
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_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 30
Project: SignLanguage_ML   Author: mareep-raljodid   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 31
Project: ImageFusion   Author: pfchai   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 32
Project: sarah   Author: ChonchoFronto   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 33
Project: honours_project   Author: JFriel   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 34
Project: honours_project   Author: JFriel   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 35
Project: Blackjack-Tracker   Author: martinabeleda   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 36
Project: PYPIC   Author: max614   File: test_helper.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 37
Project: PYPIC   Author: max614   File: test_helper.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 38
Project: PYPIC   Author: max614   File: test_helper.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 39
Project: pyem   Author: asarnow   File: sort.py    GNU General Public License v3.0 5 votes vote down vote up
def main(args):
    pyfftw.interfaces.cache.enable()

    refmap = mrc.read(args.key, compat="relion")
    df = star.parse_star(args.input, keep_index=False)
    star.augment_star_ucsf(df)
    refmap_ft = vop.vol_ft(refmap, threads=args.threads)

    apix = star.calculate_apix(df)
    sz = refmap_ft.shape[0] // 2 - 1
    sx, sy = np.meshgrid(rfftfreq(sz), fftfreq(sz))
    s = np.sqrt(sx ** 2 + sy ** 2)
    r = s * sz
    r = np.round(r).astype(np.int64)
    r[r > sz // 2] = sz // 2 + 1
    a = np.arctan2(sy, sx)

    def1 = df["rlnDefocusU"].values
    def2 = df["rlnDefocusV"].values
    angast = df["rlnDefocusAngle"].values
    phase = df["rlnPhaseShift"].values
    kv = df["rlnVoltage"].values
    ac = df["rlnAmplitudeContrast"].values
    cs = df["rlnSphericalAberration"].values
    xshift = df["rlnOriginX"].values
    yshift = df["rlnOriginY"].values

    score = np.zeros(df.shape[0])

    # TODO parallelize
    for i, row in df.iterrows():
        xcor = particle_xcorr(row, refmap_ft)

    if args.top is None:
        args.top = df.shape[0]

    top = df.iloc[np.argsort(score)][:args.top]
    star.simplify_star_ucsf(top)
    star.write_star(args.output, top)
    return 0 
Example 40
Project: offlow   Author: satwikkansal   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 41
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_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 42
Project: elasticintel   Author: securityclippy   File: test_helper.py    GNU General Public License v3.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 43
Project: cnidaria   Author: sauloal   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 44
Project: AutoDraw   Author: yemi-Jump   File: test_helper.py    MIT License 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 45
Project: mpiFFT4py   Author: spectralDNS   File: pencil.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def complex_local_wavenumbers(self):
        s = self.complex_local_slice()
        return (fftfreq(self.N[0], 1./self.N[0]).astype(int)[s[0]],
                fftfreq(self.N[1], 1./self.N[1]).astype(int),
                rfftfreq(self.N[2], 1./self.N[2]).astype(int)[s[2]]) 
Example 46
Project: mpiFFT4py   Author: spectralDNS   File: pencil.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def get_local_wavenumbermesh(self, scaled=False, broadcast=False,
                                 eliminate_highest_freq=False):
        """Returns (scaled) local decomposed wavenumbermesh

        If scaled is True, then the wavenumbermesh is scaled with physical mesh
        size. This takes care of mapping the physical domain to a computational
        cube of size (2pi)**3


        """
        s = self.complex_local_slice()
        kx = fftfreq(self.N[0], 1./self.N[0]).astype(int)
        ky = fftfreq(self.N[1], 1./self.N[1]).astype(int)
        kz = rfftfreq(self.N[2], 1./self.N[2]).astype(int)
        if eliminate_highest_freq:
            for i, k in enumerate((kx, ky, kz)):
                if self.N[i] % 2 == 0:
                    k[self.N[i]//2] = 0
        kx = kx[s[0]]
        kz = kz[s[2]]
        Ks = np.meshgrid(kx, ky, kz, indexing='ij', sparse=True)
        if scaled is True:
            Lp = 2*np.pi/self.L
            for i in range(3):
                Ks[i] = (Ks[i]*Lp[i]).astype(self.float)
        K = Ks
        if broadcast is True:
            K = [np.broadcast_to(k, self.complex_shape()) for k in Ks]
        return K 
Example 47
Project: fund-rank-dashboard   Author: 1pani   File: test_helper.py    Apache License 2.0 5 votes vote down vote up
def test_definition(self):
        x = [0, 1, 2, 3, 4]
        assert_array_almost_equal(9*fft.rfftfreq(9), x)
        assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x)
        x = [0, 1, 2, 3, 4, 5]
        assert_array_almost_equal(10*fft.rfftfreq(10), x)
        assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) 
Example 48
Project: pystella   Author: zachjweiner   File: dft.py    MIT License 4 votes vote down vote up
def __init__(self, decomp, queue, grid_shape, proc_shape, dtype, **kwargs):
        """
        :arg decomp: A :class:`pystella.DomainDecomposition`.

        :arg queue: A :class:`pyopencl.CommandQueue`.

        :arg grid_shape: A 3-:class:`tuple` specifying the shape of position-space
            arrays to be transformed.

        :arg proc_shape: A 3-:class:`tuple` specifying the shape of the MPI
            processor grid.

        :arg dtype: The datatype of real arrays to be transformed. The complex
            datatype is chosen to have the same precision.

        Any keyword arguments are passed to :meth:`mpi4py_fft.PFFT.__init__()`.
        """

        self.decomp = decomp
        self.grid_shape = grid_shape
        self.proc_shape = proc_shape
        self.dtype = dtype
        cdtype = _c_dtype_mapping[dtype]
        self.cdtype = cdtype

        if proc_shape[0] > 1 and proc_shape[1] == 1:
            slab = True
        else:
            slab = False

        from mpi4py_fft.pencil import Subcomm
        default_kwargs = dict(
            # FIXME: this is weird
            axes=([0], [1], [2]), threads=16, backend='fftw', collapse=True,
            )
        default_kwargs.update(kwargs)
        comm = decomp.comm if slab else Subcomm(decomp.comm, proc_shape)

        from mpi4py_fft import PFFT
        self.fft = PFFT(comm, grid_shape, dtype=dtype, slab=slab, **default_kwargs)

        for transform in self.fft.xfftn:
            transform.M = 1  # ensure normalization is not applied

        self.fx = self.fft.forward.input_array
        self.fk = self.fft.forward.output_array

        from numpy.fft import fftfreq
        k = [fftfreq(n, 1/n).astype(dtype) for n in grid_shape]

        if dtype in ('float32', 'float64', np.float32, np.float64):
            from numpy.fft import rfftfreq
            k[-1] = rfftfreq(grid_shape[-1], 1/grid_shape[-1]).astype(dtype)

        slc = self.fft.local_slice(True)
        names = ('momenta_x', 'momenta_y', 'momenta_z')
        self.sub_k = {direction: cla.to_device(queue, k_i[s_i])
                      for direction, k_i, s_i in zip(names, k, slc)} 
Example 49
Project: pyMUSIC   Author: amjadsaadeh   File: pyMUSIC.py    MIT License 4 votes vote down vote up
def IFBMUSICSpectrum(data, micPositions, nfft, amountOfSources=1, angleStepsNum=720,\
                     searchInterval=(0, 2 * np.pi), samplingRate=16000, bins=None):
    """
    Returns an IFB MUSIC spectrum. The narrowband spectrums are merged by geometric mean.

    @param data sampled data (real part of the signal)
    @param nfft window size of for the STFT in samples
    @param amountOfSources assumed number of sources
    @param angleStepsNum amount of angle to analyze
    @param searchInterval tuple with the first element as starting angle and the second element is end angle
    @param rate the data are sampled
    @param bins array or range determining the frequency bins to use
    @return IFB MUSIC spectrum
    """

    narrowBandEst = MUSICEst(antennaPositions=micPositions, angleStepsNum=angleStepsNum,\
                             searchInterval=searchInterval)

    # STFT for all microphones (format: [microphone, frequency bins, time])
    stft = np.empty((data.shape[0], nfft // 2 + 1, data.shape[1] // nfft), dtype=np.complex)
    for i in range(data.shape[0]):
        stft[i, :, :] = STFT(np.asarray(data)[i, :], nfft)

    # Physical frequencies for the MUSIC algorithm
    freqs = rfftfreq(nfft, 1 / samplingRate)

    mergedSpectrums = np.ones(angleStepsNum)
    if bins == None:
        bins = range(nfft // 2 + 1)

    # Calculate narrowband spectrums and merging them with geometric mean
    for binIdx in bins:
        crossSpectrum = np.matrix(np.zeros((stft.shape[0], stft.shape[0]), dtype=np.complex))
        for j in range(stft.shape[2]):
            curDFT = np.matrix(stft[:, binIdx, j]).transpose()
            crossSpectrum += curDFT * curDFT.transpose().conjugate()
        crossSpectrum /= stft.shape[2]
        noiseMat = narrowBandEst.getNoiseMat(crossSpectrum, amountOfSources)
        spectrum, angleBins = narrowBandEst.getSpectrum(noiseMat, freqs[binIdx], noiseMatMode='spec')
        mergedSpectrums *= spectrum

    mergedSpectrums = mergedSpectrums ** (1 / len(bins))

    return mergedSpectrums, angleBins