Ejemplo n.º 1
0
    def test_fft_phases(self):
        spectrum_reference = np.zeros((128,), dtype=np.complex128)
        spectrum_reference[65] = np.sqrt(2*np.pi)
        spectrum_reference[69] = 2*np.sqrt(2*np.pi)

        x = np.linspace(0, 2*np.pi, 128, endpoint=False)
        if sys.version_info.major == 3 and sys.version_info.minor < 5:
            y = np.exp(1.j*x) + 2.*np.exp(5.j*x)
        else:
            y = ne.evaluate('exp(1.j*x) + 2.*exp(5.j*x)')
        y = dh.Field(y, axes=[dh.Axis(grid=x)])
        yf = y.fft()

        # this is passed already with the old code
        self.assertAllClose(spectrum_reference, yf, atol=1e-10)

        x = np.linspace(0, 2*np.pi, 128, endpoint=False) + 3*np.pi/4
        if sys.version_info.major == 3 and sys.version_info.minor < 5:
            y = np.exp(1.j*x) + 2.*np.exp(5.j*x)
        else:
            y = ne.evaluate('exp(1.j*x) + 2.*exp(5.j*x)')
        y = dh.Field(y, axes=[dh.Axis(grid=x)])
        yf = y.fft()

        # this is passed only with the new implementation
        self.assertAllClose(spectrum_reference, yf, atol=1e-10)
Ejemplo n.º 2
0
 def setUp(self):
     self.fempty = dh.Field([])
     self.f0d = dh.Field([42])
     m = np.reshape(np.arange(10), 10)
     self.f1d = dh.Field(m)
     m = np.reshape(np.arange(20), (4, 5))
     self.f2d = dh.Field(m)
     m = np.reshape(np.arange(60), (4, 5, 3))
     self.f3d = dh.Field(m)
Ejemplo n.º 3
0
    def setUp(self):
        self.fempty = dh.Field([])
        self.f0d = dh.Field([42.])
        m = np.reshape(np.arange(10).astype('d'), 10)
        self.f1d = dh.Field(m)
        self.f1dnl = dh.Field(m, axes=[dh.Axis(grid=m**2)])
        m = np.reshape(np.arange(20).astype('d'), (4, 5))
        self.f2d = dh.Field(m)
        m = np.reshape(np.arange(60).astype('d'), (4, 5, 3))
        self.f3d = dh.Field(m)

        x, y = helper.meshgrid(np.linspace(0,2*np.pi,100), np.linspace(0,2*np.pi,100), indexing='ij', sparse=True)
        self.f2d_fine = dh.Field(np.sin(x)*np.cos(y))