Exemple #1
0
 def test_angle1(self):
     """
     """
     v1 = Vector(1, 0, 0)
     v2 = Vector(0, 1, 0)
     self.assertEqual(round_to_significant(v1.angle(v2), 5), 90)
     v1 = Vector(1, 0, 0)
     v2 = Vector(2, 0, 0)
     self.assertEqual(v1.angle(v2), 0)
     v1 = Vector(1, 0, 0)
     v2 = Vector(1, 1, 0)
     self.assertEqual(round_to_significant(v1.angle(v2), 5), 45)
Exemple #2
0
 def test_round_to_significant(self):
     """
     """
     x = 12.345
     self.assertEqual(round_to_significant(x, 1), 10)
     self.assertEqual(round_to_significant(x, 2), 12)
     self.assertEqual(round_to_significant(x, 3), 12.3)
     self.assertEqual(round_to_significant(x, 4), 12.34)
     self.assertEqual(round_to_significant(x, 5), 12.345)
     self.assertEqual(type(round_to_significant(x, 1)), int)
     self.assertEqual(type(round_to_significant(x, 2)), int)
     self.assertEqual(type(round_to_significant(x, 3)), float)
     self.assertEqual(type(round_to_significant(x, 4)), float)
     self.assertEqual(type(round_to_significant(x, 5)), float)
Exemple #3
0
 def test_mw_to_m0(self):
     """
     """
     mws = [9.03]
     m0s = [3.9 * 10 ** 22]
     for mw, m0 in zip(mws, m0s):
         self.assertEqual(round_to_significant(mw_to_m0(mw), 2), m0)
Exemple #4
0
 def test_m0_to_mw(self):
     """
     """
     m0s = [3.9 * 10 ** 22]
     mws = [9.03]
     for m0, mw in zip(m0s, mws):
         self.assertEqual(round_to_significant(m0_to_mw(m0), 3), mw)
Exemple #5
0
    def test_angles(self):
        """
        """
        xs = np.array([1, 0, 0, 1])
        ys = np.array([0, 1, 0, 1])
        zs = np.array([0, 0, 1, 0])
        vs = VectorSpace(xs, ys, zs)

        angles = vs.angles((1, 0, 0))
        self.assertEqual(angles[0], 00.)
        self.assertEqual(angles[1], 90.)
        self.assertEqual(angles[2], 90.)
        self.assertEqual(round_to_significant(angles[3], 2), 45.)

        angles = vs.angles((1, 1, 1))
        self.assertEqual(np.round(angles[3], 14), np.round(np.degrees(np.arcsin(1/np.sqrt(3))), 14))
Exemple #6
0
    def test(self):
        """
        """
        tgt_fas = read_fas_model(os.path.join(DATA_DIR, 'ab06_bc.m7.50r0030.0_fs.col'))[0]

        frequencies = tgt_fas.frequencies

        mag = 7.5
        sd = 250 * 10**5  ## magnitude independent stress drop (Pa)
        rp = 0.55  ## radiation patttern
        pf = 1 / np.sqrt(2)  ## partition factor
        fsf = 2  ## free surface factor
        rho = 2800  ## density (kg/m3)
        vel = 3700  ## shear wave velocity (m/s)

        source_model = OmegaSquareSourceModel(mag, sd, rp, pf, fsf, rho, vel)
        source_model_fas = source_model.get_fas(frequencies)

        gs_segments = [
            (1, -1.3),
            (70, 0.2),
            (140, -0.5)
            ]

        gs_model = GeometricalSpreadingModel(gs_segments)

        qr1 = 1000
        ft1 = 0.2
        fr1 = 0.02
        s1 = 0.0
        qr2 = 1272
        ft2 = 1.4242
        fr2 = 3.02
        s2 = 0.32

        q_model = QModel(fr1, qr1, s1, ft1, ft2, fr2, qr2, s2)

        c_q = 3.7
        kappa = 0.02  ## fm is zero and kappa is magnitude independent

        att_model = AttenuationModel(q_model, c_q, kappa)

        distance = 30

        se = np.array([
            (0.0001, 1.000),
            (0.1014, 1.073),
            (0.2402, 1.145),
            (0.4468, 1.237),
            (0.7865, 1.394),
            (1.3840, 1.672),
            (1.9260, 1.884),
            (2.8530, 2.079),
            (4.0260, 2.202),
            (6.3410, 2.313),
            (12.540, 2.411),
            (21.230, 2.452),
            (33.390, 2.474),
            (82.000, 2.497),
            ])
 
        site = Site(se)

        cal_fas = source_model_fas * gs_model(distance) * att_model(distance, frequencies) * site(frequencies)

        unit = 'm'
        self.assertListEqual(
            [round_to_significant(float(x), 2) for x in tgt_fas.get_amplitudes(unit=unit)],
            [round_to_significant(float(x), 2) for x in cal_fas.get_amplitudes(unit=unit)])
Exemple #7
0
 def test_properties(self):
     """
     """
     self.assertEqual(round_to_significant(self.source_model.seismic_moment, 4), 1.995E+27 / 10**7)
     self.assertEqual(round_to_significant(self.source_model.corner_frequency, 4), 9.083E-02)