Esempio n. 1
0
 def __init__(self, methodName='runTest'):
     data, _ = hlp.read_two_column_stuff('./files/two_column_data_example.txt')
     data[:, 0] *= 10
     data[:, 1] *= 100
     prof = Vs_Profile(data)
     self.prof = prof
     super(Test_Class_Vs_Profile, self).__init__(methodName=methodName)
    def test_find_f0(self):
        data, _ = hlp.read_two_column_stuff(_join(f_dir, 'two_column_data_example.txt'))
        f0 = sr.find_f0(data)
        f0_benchmark = 0.5
        self.assertAlmostEqual(f0, f0_benchmark)

        f0_incr = sr.find_f0(np.array([[0.1, 0.2, 0.3], [1, 2, 3]]).T)
        f0_decr = sr.find_f0(np.array([[0.1, 0.2, 0.3], [3, 2, 1]]).T)

        self.assertAlmostEqual(f0_incr, 0.3)  # monotonically increasing
        self.assertAlmostEqual(f0_decr, 0.1)  # monotonically decreasing
    def test_load_data(self):

        txt_filename = _join(f_dir, 'two_column_data_example.txt')

        fs_bench, df_bench = hlp.read_two_column_stuff(txt_filename)
        fs = FS(txt_filename, fmin=0.1, fmax=2.5, n_pts=20, log_scale=False)

        self.assertAlmostEqual(fs.raw_df, df_bench)
        self.assertTrue(np.allclose(fs.raw_data, fs_bench))
        self.assertAlmostEqual(fs.spectrum[0], 1)
        self.assertAlmostEqual(fs.spectrum[-1], 7)
Esempio n. 4
0
    def test_read_two_column_stuff(self):
        # Load from file
        data, dt = hlp.read_two_column_stuff('./files/two_column_data_example.txt')
        benchmark = np.array([[.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.0,
                               1.1, 1.2, 1.3, 1.4, 1.5],
                              [1, 2, 3, 4, 5, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7]]).T
        self.assertTrue(np.allclose(data, benchmark))
        self.assertAlmostEqual(dt, benchmark[1, 0] - benchmark[0, 0])

        # Load from 1D numpy array
        data_1col = np.array([1, 2, 3, 4, 5, 2, 3, 4, 5, 6, 3, 4, 5, 6, 7])
        dt = 0.1
        data_, dt_ = hlp.read_two_column_stuff(data, dt)
        self.assertTrue(np.allclose(data_1col, data_[:, 1]))
        self.assertAlmostEqual(dt, dt_)

        # Load from 2D numpy array
        data__, dt__ \
            = hlp.read_two_column_stuff(benchmark,
                                         benchmark[1, 0] - benchmark[0, 0])
        self.assertTrue(np.allclose(data__, benchmark))
        self.assertAlmostEqual(dt__, benchmark[1, 0] - benchmark[0, 0])
Esempio n. 5
0
    def test_fourier_transform(self):
        accel, _ = hlp.read_two_column_stuff(
            _join(f_dir, 'two_column_data_example.txt'))
        freq, FS = sig.fourier_transform(accel, real_val=False).T

        freq_bench = [
            0.6667, 1.3333, 2.0000, 2.6667, 3.3333, 4.0000, 4.6667, 5.3333
        ]
        FS_bench = [
            60.0000 + 0.0000j, -1.5000 + 7.0569j, -1.5000 + 3.3691j,
            -7.5000 + 10.3229j, -1.5000 + 1.3506j, -1.5000 + 0.8660j,
            -7.5000 + 2.4369j, -1.5000 + 0.1577j
        ]

        self.assertTrue(np.allclose(freq, freq_bench, atol=0.0001, rtol=0.0))
        self.assertTrue(np.allclose(FS, FS_bench, atol=0.0001, rtol=0.0))
    def test_response_spectra(self):
        accel, _ = hlp.read_two_column_stuff(_join(f_dir, 'two_column_data_example.txt'))

        T_min = 0.01
        T_max = 10
        n_pts = 50
        Tn, SA = sr.response_spectra(accel, T_min=T_min, T_max=T_max,
                                     n_pts=n_pts, parallel=False)[:2]

        Tn_bench = np.logspace(np.log10(T_min), np.log10(T_max), n_pts)
        SA_bench = np.array([7.0000, 7.0000, 7.0000, 7.0000, 7.0001, 7.0002,
                             6.9995, 7.0007, 7.0024, 6.9941, 7.0176, 6.9908,
                             6.9930, 6.9615, 7.0031, 7.1326, 6.9622, 7.0992,
                             6.5499, 7.3710, 7.3458, 6.8662, 8.3708, 8.5229,
                             7.9719, 7.5457, 8.9573, 10.6608, 10.5915, 9.4506,
                             8.1594, 6.9023, 7.1242, 6.5462, 6.3940, 6.3472,
                             6.7302, 7.0554, 7.2901, 7.6946, 7.6408, 7.1073,
                             6.3034, 5.3997, 4.5102, 3.6991, 2.9946, 2.4023,
                             1.9156, 1.5218])

        self.assertTrue(np.allclose(Tn, Tn_bench))
        self.assertTrue(np.allclose(SA, SA_bench, rtol=0.0001, atol=0.0))
    def test_num_int(self):
        accel, _ = hlp.read_two_column_stuff(_join(f_dir, 'two_column_data_example.txt'))
        v, u = sr.num_int(accel)

        v_bench = np.array([[0.1000, 0.1000],
                            [0.2000, 0.3000],
                            [0.3000, 0.6000],
                            [0.4000, 1.0000],
                            [0.5000, 1.5000],
                            [0.6000, 1.7000],
                            [0.7000, 2.0000],
                            [0.8000, 2.4000],
                            [0.9000, 2.9000],
                            [1.0000, 3.5000],
                            [1.1000, 3.8000],
                            [1.2000, 4.2000],
                            [1.3000, 4.7000],
                            [1.4000, 5.3000],
                            [1.5000, 6.0000]])
        u_bench = np.array([[0.1000, 0.0100],
                            [0.2000, 0.0400],
                            [0.3000, 0.1000],
                            [0.4000, 0.2000],
                            [0.5000, 0.3500],
                            [0.6000, 0.5200],
                            [0.7000, 0.7200],
                            [0.8000, 0.9600],
                            [0.9000, 1.2500],
                            [1.0000, 1.6000],
                            [1.1000, 1.9800],
                            [1.2000, 2.4000],
                            [1.3000, 2.8700],
                            [1.4000, 3.4000],
                            [1.5000, 4.0000]])

        self.assertTrue(np.allclose(v, v_bench))
        self.assertTrue(np.allclose(u, u_bench))