Exemplo n.º 1
0
class FFTTests(unittest.TestCase):
    def setUp(self):
        """
        Create an trial *Signal* object
        """

        fd = 50.0E3  # digitization frequency
        f0 = 5.00E3  # signal frequency
        nt = 512  # number of signal points

        self.dt = dt = 1 / fd
        t = dt * np.arange(nt)
        s = 1.0 * np.sin(2 * np.pi * f0 * t)

        self.s = Signal('.FFTTests_1.h5')
        self.s.load_nparray(s, "x", "nm", dt)
        self.s.time_mask_binarate("middle")
        self.s.time_window_cyclicize(10 * dt)
        self.s.fft()
        self.s.freq_filter_Hilbert_complex()

    def testfft_1(self):
        """FFT: test that the resulting data is complex"""

        first_point = self.s.f['workup/freq/FT'][0]
        self.assertEqual(isinstance(first_point, complex), True)

    def testfft_2(self):
        """FFT: test that the complex Hilbert transform filter is real"""

        first_point = self.s.f['workup/freq/filter/Hc'][0]
        self.assertEqual(isinstance(first_point, complex), False)

    def testfft_3(self):
        """FFT: test the complex Hilbert transform filter near freq = 0"""

        freq = self.s.f['workup/freq/freq'][:]
        index = np.roll(freq == 0, -1) + np.roll(freq == 0, 0) + np.roll(
            freq == 0, 1)
        filt = self.s.f['workup/freq/filter/Hc'][index]

        self.assertTrue(np.allclose(filt, np.array([0, 1, 2])))

    def test_phase_fit_rounding(self):
        self.s.ifft()
        # T_chunk_goal set to cause problem due to incorrect rounding
        T_chunk_goal = self.dt * 26
        self.s.fit_phase(T_chunk_goal)

    def tearDown(self):
        """Close the h5 files before the next iteration."""
        try:
            self.s.f.close()
        except:
            pass
Exemplo n.º 2
0
class FFTTests(unittest.TestCase):
    
    def setUp(self):
        """
        Create an trial *Signal* object
        """
        
        fd = 50.0E3    # digitization frequency
        f0 = 5.00E3    # signal frequency
        nt = 512     # number of signal points    

        self.dt = dt = 1/fd
        t = dt*np.arange(nt)
        s = 1.0*np.sin(2*np.pi*f0*t) 

        self.s = Signal('.FFTTests_1.h5')
        self.s.load_nparray(s,"x","nm",dt)
        self.s.time_mask_binarate("middle")
        self.s.time_window_cyclicize(10*dt)
        self.s.fft()
        self.s.freq_filter_Hilbert_complex()
        
    def testfft_1(self):
        """FFT: test that the resulting data is complex"""
        
        first_point = self.s.f['workup/freq/FT'][0]
        self.assertEqual(isinstance(first_point, complex),True)
        
    def testfft_2(self):
        """FFT: test that the complex Hilbert transform filter is real"""
        
        first_point = self.s.f['workup/freq/filter/Hc'][0]
        self.assertEqual(isinstance(first_point, complex),False)
        
    def testfft_3(self):
        """FFT: test the complex Hilbert transform filter near freq = 0"""
        
        freq = self.s.f['workup/freq/freq'][:]
        index = np.roll(freq == 0,-1) + np.roll(freq == 0,0) + np.roll(freq == 0,1)
        filt = self.s.f['workup/freq/filter/Hc'][index]
        
        self.assertTrue(np.allclose(filt,np.array([0, 1, 2])))

    def test_phase_fit_rounding(self):
        self.s.ifft()
        # T_chunk_goal set to cause problem due to incorrect rounding
        T_chunk_goal = self.dt*26
        self.s.fit_phase(T_chunk_goal)
                           
    def tearDown(self):
        """Close the h5 files before the next iteration."""
        try:
            self.s.f.close()
        except:
            pass                
Exemplo n.º 3
0
class MaskTests(unittest.TestCase):
    def setUp(self):
        """
        Create a trial *Signal* object
        """

        self.s = Signal('.InitLoadSaveTests_1.h5')
        self.s.load_nparray(np.arange(60000), "x", "nm", 10E-6)

    def test_binarate_1(self):
        """Binarate mask middle; test length is 2^n"""

        self.s.time_mask_binarate("middle")
        m = self.s.f['workup/time/mask/binarate']

        self.assertEqual(np.count_nonzero(m), 32 * 1024)

    def test_binarate_2(self):
        """Binarate mask start; test length is 2^n"""

        self.s.time_mask_binarate("start")
        m = self.s.f['workup/time/mask/binarate']

        self.assertEqual(np.count_nonzero(m), 32 * 1024)

    def test_binarate_3(self):
        """Binarate mask end test length is 2^n"""

        self.s.time_mask_binarate("end")
        m = self.s.f['workup/time/mask/binarate']

        self.assertEqual(np.count_nonzero(m), 32 * 1024)

    def test_binarate_4(self):
        """If we have not called binarate, then workup/time/mask/binarate does not exist"""

        self.assertEqual(self.s.f.__contains__('workup/time/mask/binarate'),
                         False)

    def test_binarate_5(self):
        """If we have called binarate, then workup/time/mask/binarate does exist"""

        self.s.time_mask_binarate("middle")
        self.assertEqual(self.s.f.__contains__('workup/time/mask/binarate'),
                         True)

    def tearDown(self):
        """Close the h5 files before the next iteration."""
        try:
            self.s.f.close()
        except:
            pass
Exemplo n.º 4
0
class MaskTests(unittest.TestCase):
    
    def setUp(self):
        """
        Create a trial *Signal* object
        """
        
        self.s = Signal('.InitLoadSaveTests_1.h5')
        self.s.load_nparray(np.arange(60000),"x","nm",10E-6)    
        
    def test_binarate_1(self):
        """Binarate mask middle; test length is 2^n"""
        
        self.s.time_mask_binarate("middle")
        m = self.s.f['workup/time/mask/binarate']

        self.assertEqual(np.count_nonzero(m),32*1024)    
        
    def test_binarate_2(self):
        """Binarate mask start; test length is 2^n"""
        
        self.s.time_mask_binarate("start")
        m = self.s.f['workup/time/mask/binarate']

        self.assertEqual(np.count_nonzero(m),32*1024)   
        
    def test_binarate_3(self):
        """Binarate mask end test length is 2^n"""
        
        self.s.time_mask_binarate("end")
        m = self.s.f['workup/time/mask/binarate']

        self.assertEqual(np.count_nonzero(m),32*1024)   
 
    def test_binarate_4(self):
        """If we have not called binarate, then workup/time/mask/binarate does not exist"""
        
        self.assertEqual(self.s.f.__contains__('workup/time/mask/binarate'),False)

    def test_binarate_5(self):
        """If we have called binarate, then workup/time/mask/binarate does exist"""
        
        self.s.time_mask_binarate("middle")
        self.assertEqual(self.s.f.__contains__('workup/time/mask/binarate'),True)  
   
    def tearDown(self):
        """Close the h5 files before the next iteration."""
        try:
            self.s.f.close()
        except:
            pass