Пример #1
0
 def test_integrate(self):
     """
     """
     x_tgt, x_vel, _ = read_cor(os.path.join(DATA_DIR, '004339xa.cor'))
     y_tgt, y_vel, _ = read_cor(os.path.join(DATA_DIR, '004339ya.cor'))
     z_tgt, z_vel, _ = read_cor(os.path.join(DATA_DIR, '004339za.cor'))
     vel = Recording({'X': x_vel, 'Y': y_vel, 'Z': z_vel})
     tgt = Recording({'X': x_tgt, 'Y': y_tgt, 'Z': z_tgt})
     cal = vel.integrate()
     fs = os.path.join(
         OUTPUT_DIR, 'recordings.recording.integrate.png')
     plot_recordings([tgt, cal], labels=['tgt', 'cal'], colors=['r', 'b'],
         widths=[3, 1], title='differentiate', filespec=fs)
Пример #2
0
class TestRecording(unittest.TestCase):
    """
    """

    x = read_cor(os.path.join(DATA_DIR, '004339xa.cor'))[-1]
    y = read_cor(os.path.join(DATA_DIR, '004339ya.cor'))[-1]
    z = read_cor(os.path.join(DATA_DIR, '004339za.cor'))[-1]
    r = Recording({'X': x, 'Y': y, 'Z': z})

    def test_get_component(self):
        """
        """
        self.assertEqual(self.r.get_component('X'), self.x)
        self.assertEqual(self.r.get_component('Y'), self.y)
        self.assertEqual(self.r.get_component('Z'), self.z)

    def test_differentiate(self):
        """
        """
        _, x_vel, x_tgt = read_cor(os.path.join(DATA_DIR, '004339xa.cor'))
        _, y_vel, y_tgt = read_cor(os.path.join(DATA_DIR, '004339ya.cor'))
        _, z_vel, z_tgt = read_cor(os.path.join(DATA_DIR, '004339za.cor'))
        vel = Recording({'X': x_vel, 'Y': y_vel, 'Z': z_vel})
        tgt = Recording({'X': x_tgt, 'Y': y_tgt, 'Z': z_tgt})
        cal = vel.differentiate()
        fs = os.path.join(
            OUTPUT_DIR, 'recordings.recording.differentiate.png')
        plot_recordings([tgt, cal], labels=['tgt', 'cal'], colors=['r', 'b'],
            widths=[3, 1], title='differentiate', filespec=fs)

    def test_integrate(self):
        """
        """
        x_tgt, x_vel, _ = read_cor(os.path.join(DATA_DIR, '004339xa.cor'))
        y_tgt, y_vel, _ = read_cor(os.path.join(DATA_DIR, '004339ya.cor'))
        z_tgt, z_vel, _ = read_cor(os.path.join(DATA_DIR, '004339za.cor'))
        vel = Recording({'X': x_vel, 'Y': y_vel, 'Z': z_vel})
        tgt = Recording({'X': x_tgt, 'Y': y_tgt, 'Z': z_tgt})
        cal = vel.integrate()
        fs = os.path.join(
            OUTPUT_DIR, 'recordings.recording.integrate.png')
        plot_recordings([tgt, cal], labels=['tgt', 'cal'], colors=['r', 'b'],
            widths=[3, 1], title='differentiate', filespec=fs)

    def test_plot(self):
        """
        """
        fs = os.path.join(OUTPUT_DIR, 'recordings.recording.plot.png')
        self.r.plot(filespec=fs)
Пример #3
0
 def test_get_seismogram(self):
     """
     """
     acc = read_cor(os.path.join(DATA_DIR, '004676xa.cor'))[-1]
     dft = acc.get_dft()
     cal_acc = dft.get_seismogram(acc.time_delta)
     cal_acc = list(np.round(cal_acc.amplitudes, 12))
     tgt_acc = list(np.round(acc.amplitudes, 12))
     self.assertListEqual(cal_acc[::20], tgt_acc[::20])
Пример #4
0
 def test_inverse(self):
     """
     """
     acc = read_cor(os.path.join(DATA_DIR, '004676xa.cor'))[-1]
     dft = acc.get_dft()
     cal_acc = dft.inverse(acc.time_delta)
     tgt_acc = acc.amplitudes
     for cal, tgt in zip(cal_acc[::20], tgt_acc[::20]):
         self.assertTrue(abs(cal - tgt) < 10**-PRECISION)
Пример #5
0
 def test_integrate(self):
     """
     """
     tgt, vel, _ = read_cor(os.path.join(DATA_DIR, '004339za.cor'))
     cal = vel.integrate()
     fs = os.path.join(
         OUTPUT_DIR, 'recordings.seismogram.integrate.png')
     plot_seismograms([[tgt, cal]], labels=[['tgt', 'cal']],
         colors=[['r', 'b']], widths=[[3, 1]], title='integrate',
         size=(15, 10), filespec=fs)
Пример #6
0
    def test_read_cor(self):
        """
        """
        dis, vel, acc = read_cor(os.path.join(DATA_DIR, '004676xa.cor'))

        time_delta = 0.005
        dis_f_amplitudes = [
            +0.00000E+00, -8.04332E-09, -1.60866E-08, -2.41300E-08,
            -3.21733E-08, -4.02166E-08, -4.82599E-08, -5.63033E-08,
            -6.43466E-08, -7.23899E-08, -8.04333E-08, -8.84766E-08,
            -9.65200E-08, -1.04563E-07, -1.12607E-07, -1.20650E-07,
        ]
        dis_l_amplitudes = [
            -9.72654E-08, -8.77383E-08, -7.86358E-08, -6.99553E-08,
            -6.16943E-08, -5.38502E-08, -4.64206E-08, -3.94030E-08,
            -3.27948E-08, -2.65934E-08, -2.07964E-08, -1.54012E-08,
            -1.04053E-08, -5.80606E-09, -1.60096E-09,  2.21252E-09,
        ]
        vel_f_amplitudes = [
            -1.60866E-06, -1.60866E-06, -1.60866E-06, -1.60866E-06,
            -1.60867E-06, -1.60867E-06, -1.60867E-06, -1.60867E-06,
            -1.60867E-06, -1.60867E-06, -1.60867E-06, -1.60867E-06,
            -1.60867E-06, -1.60867E-06, -1.60867E-06, -1.60867E-06,
        ]
        vel_l_amplitudes = [
            +1.94801E-06, +1.86284E-06, +1.77817E-06, +1.69402E-06,
            +1.61039E-06, +1.52724E-06, +1.44460E-06, +1.36246E-06,
            +1.28084E-06, +1.19972E-06, +1.11909E-06, +1.03898E-06,
            +9.59383E-07, +8.80308E-07, +8.01735E-07, +7.23655E-07,
        ]
        acc_f_amplitudes = [
            -9.90240E-11, -9.91940E-11, -9.93590E-11, -9.95200E-11,
            -9.96760E-11, -9.98280E-11, -9.99760E-11, -1.00120E-10,
            -1.00260E-10, -1.00390E-10, -1.00520E-10, -1.00640E-10,
            -1.00760E-10, -1.00880E-10, -1.00990E-10, -1.01090E-10,
        ]
        acc_l_amplitudes = [
            -1.70820E-05, -1.69850E-05, -1.68840E-05, -1.67770E-05,
            -1.66760E-05, -1.65810E-05, -1.64780E-05, -1.63760E-05,
            -1.62730E-05, -1.61760E-05, -1.60740E-05, -1.59710E-05,
            -1.58670E-05, -1.57630E-05, -1.56660E-05, -1.55660E-05,
        ]

        self.assertEqual(dis.time_delta, time_delta)
        self.assertEqual(vel.time_delta, time_delta)
        self.assertEqual(acc.time_delta, time_delta)
        self.assertListEqual(list(dis.amplitudes[:+16]), dis_f_amplitudes)
        self.assertListEqual(list(dis.amplitudes[-16:]), dis_l_amplitudes)
        self.assertListEqual(list(vel.amplitudes[:+16]), vel_f_amplitudes)
        self.assertListEqual(list(vel.amplitudes[-16:]), vel_l_amplitudes)
        self.assertListEqual(list(acc.amplitudes[:+16]), acc_f_amplitudes)
        self.assertListEqual(list(acc.amplitudes[-16:]), acc_l_amplitudes)
        self.assertEqual(dis.unit, UNITS['dis'])
        self.assertEqual(vel.unit, UNITS['vel'])
        self.assertEqual(acc.unit, UNITS['acc'])
Пример #7
0
    def test_read_cor(self):
        """
        """
        dis, vel, acc = read_cor(os.path.join(DATA_DIR, '004676xa.cor'))

        time_delta = 0.005
        dis_f_amplitudes = [
            +0.00000E+00, -8.04332E-09, -1.60866E-08, -2.41300E-08,
            -3.21733E-08, -4.02166E-08, -4.82599E-08, -5.63033E-08,
            -6.43466E-08, -7.23899E-08, -8.04333E-08, -8.84766E-08,
            -9.65200E-08, -1.04563E-07, -1.12607E-07, -1.20650E-07,
        ]
        dis_l_amplitudes = [
            -9.72654E-08, -8.77383E-08, -7.86358E-08, -6.99553E-08,
            -6.16943E-08, -5.38502E-08, -4.64206E-08, -3.94030E-08,
            -3.27948E-08, -2.65934E-08, -2.07964E-08, -1.54012E-08,
            -1.04053E-08, -5.80606E-09, -1.60096E-09,  2.21252E-09,
        ]
        vel_f_amplitudes = [
            -1.60866E-06, -1.60866E-06, -1.60866E-06, -1.60866E-06,
            -1.60867E-06, -1.60867E-06, -1.60867E-06, -1.60867E-06,
            -1.60867E-06, -1.60867E-06, -1.60867E-06, -1.60867E-06,
            -1.60867E-06, -1.60867E-06, -1.60867E-06, -1.60867E-06,
        ]
        vel_l_amplitudes = [
            +1.94801E-06, +1.86284E-06, +1.77817E-06, +1.69402E-06,
            +1.61039E-06, +1.52724E-06, +1.44460E-06, +1.36246E-06,
            +1.28084E-06, +1.19972E-06, +1.11909E-06, +1.03898E-06,
            +9.59383E-07, +8.80308E-07, +8.01735E-07, +7.23655E-07,
        ]
        acc_f_amplitudes = [
            -9.90240E-11, -9.91940E-11, -9.93590E-11, -9.95200E-11,
            -9.96760E-11, -9.98280E-11, -9.99760E-11, -1.00120E-10,
            -1.00260E-10, -1.00390E-10, -1.00520E-10, -1.00640E-10,
            -1.00760E-10, -1.00880E-10, -1.00990E-10, -1.01090E-10,
        ]
        acc_l_amplitudes = [
            -1.70820E-05, -1.69850E-05, -1.68840E-05, -1.67770E-05,
            -1.66760E-05, -1.65810E-05, -1.64780E-05, -1.63760E-05,
            -1.62730E-05, -1.61760E-05, -1.60740E-05, -1.59710E-05,
            -1.58670E-05, -1.57630E-05, -1.56660E-05, -1.55660E-05,
        ]

        self.assertEqual(dis.time_delta, time_delta)
        self.assertEqual(vel.time_delta, time_delta)
        self.assertEqual(acc.time_delta, time_delta)
        self.assertListEqual(list(dis.amplitudes[:+16]), dis_f_amplitudes)
        self.assertListEqual(list(dis.amplitudes[-16:]), dis_l_amplitudes)
        self.assertListEqual(list(vel.amplitudes[:+16]), vel_f_amplitudes)
        self.assertListEqual(list(vel.amplitudes[-16:]), vel_l_amplitudes)
        self.assertListEqual(list(acc.amplitudes[:+16]), acc_f_amplitudes)
        self.assertListEqual(list(acc.amplitudes[-16:]), acc_l_amplitudes)
        self.assertEqual(dis.unit, UNITS['dis'])
        self.assertEqual(vel.unit, UNITS['vel'])
        self.assertEqual(acc.unit, UNITS['acc'])
Пример #8
0
 def test_get_response_spectrum(self):
     """
     """
     acc = read_cor(os.path.join(DATA_DIR, '004676xa.cor'))[-1]
     acc = Accelerogram.from_seismogram(acc)
     periods = np.logspace(-2, 2, 200)
     cal_rdis_rs = acc.get_response_spectrum(periods, damping=0.05, gmt='dis')
     cal_rvel_rs = acc.get_response_spectrum(periods, damping=0.05, gmt='vel')
     cal_aacc_rs = acc.get_response_spectrum(periods, damping=0.05, gmt='acc')
     cal_pvel_rs = ResponseSpectrum(periods,
         cal_rdis_rs.responses * (2*np.pi/periods), unit='m/s', damping=0.05)
     tgt_rss = read_spc(os.path.join(DATA_DIR, '004676xa.spc'))[2]
     tgt_rdis_rs, tgt_rvel_rs, tgt_aacc_rs, tgt_pvel_rs = tgt_rss
     fs1 = os.path.join(FIG_DIR, 'response_spectrum_rdis.png')
     fs2 = os.path.join(FIG_DIR, 'response_spectrum_rvel.png')
     fs3 = os.path.join(FIG_DIR, 'response_spectrum_aacc.png')
     fs4 = os.path.join(FIG_DIR, 'response_spectrum_pvel.png')
     plot.response_spectra([tgt_rdis_rs, cal_rdis_rs], png_filespec=fs1)
     plot.response_spectra([tgt_rvel_rs, cal_rvel_rs], png_filespec=fs2)
     plot.response_spectra([tgt_aacc_rs, cal_aacc_rs], png_filespec=fs3)
     plot.response_spectra([tgt_pvel_rs, cal_pvel_rs], png_filespec=fs4)