Esempio n. 1
0
def par2quakeml(Par_filename,
                QuakeML_filename,
                rotation_axis=[0.0, 1.0, 0.0],
                rotation_angle=-57.5,
                origin_time="2000-01-01 00:00:00.0",
                event_type="other event"):
    # initialise event
    ev = Event()

    # open and read Par file
    fid = open(Par_filename, 'r')

    fid.readline()
    fid.readline()
    fid.readline()
    fid.readline()

    lat_old = 90.0 - float(fid.readline().strip().split()[0])
    lon_old = float(fid.readline().strip().split()[0])
    depth = float(fid.readline().strip().split()[0])

    fid.readline()

    Mtt_old = float(fid.readline().strip().split()[0])
    Mpp_old = float(fid.readline().strip().split()[0])
    Mrr_old = float(fid.readline().strip().split()[0])
    Mtp_old = float(fid.readline().strip().split()[0])
    Mtr_old = float(fid.readline().strip().split()[0])
    Mpr_old = float(fid.readline().strip().split()[0])

    # rotate event into physical domain

    lat, lon = rot.rotate_lat_lon(lat_old, lon_old, rotation_axis,
                                  rotation_angle)
    Mrr, Mtt, Mpp, Mtr, Mpr, Mtp = rot.rotate_moment_tensor(
        Mrr_old, Mtt_old, Mpp_old, Mtr_old, Mpr_old, Mtp_old, lat_old, lon_old,
        rotation_axis, rotation_angle)

    # populate event origin data
    ev.event_type = event_type

    ev_origin = Origin()
    ev_origin.time = UTCDateTime(origin_time)
    ev_origin.latitude = lat
    ev_origin.longitude = lon
    ev_origin.depth = depth
    ev.origins.append(ev_origin)

    # populte event moment tensor

    ev_tensor = Tensor()
    ev_tensor.m_rr = Mrr
    ev_tensor.m_tt = Mtt
    ev_tensor.m_pp = Mpp
    ev_tensor.m_rt = Mtr
    ev_tensor.m_rp = Mpr
    ev_tensor.m_tp = Mtp

    ev_momenttensor = MomentTensor()
    ev_momenttensor.tensor = ev_tensor
    ev_momenttensor.scalar_moment = np.sqrt(Mrr**2 + Mtt**2 + Mpp**2 + Mtr**2 +
                                            Mpr**2 + Mtp**2)

    ev_focalmechanism = FocalMechanism()
    ev_focalmechanism.moment_tensor = ev_momenttensor
    ev_focalmechanism.nodal_planes = NodalPlanes().setdefault(0, 0)

    ev.focal_mechanisms.append(ev_focalmechanism)

    # populate event magnitude
    ev_magnitude = Magnitude()
    ev_magnitude.mag = 0.667 * (np.log10(ev_momenttensor.scalar_moment) - 9.1)
    ev_magnitude.magnitude_type = 'Mw'
    ev.magnitudes.append(ev_magnitude)

    # write QuakeML file
    cat = Catalog()
    cat.append(ev)
    cat.write(QuakeML_filename, format="quakeml")

    # clean up
    fid.close()
Esempio n. 2
0
def par2quakeml(Par_filename, QuakeML_filename, rotation_axis=[0.0, 1.0, 0.0],
                rotation_angle=-57.5, origin_time="2000-01-01 00:00:00.0",
                event_type="other event"):
    # initialise event
    ev = Event()

    # open and read Par file
    fid = open(Par_filename, 'r')

    fid.readline()
    fid.readline()
    fid.readline()
    fid.readline()

    lat_old = 90.0 - float(fid.readline().strip().split()[0])
    lon_old = float(fid.readline().strip().split()[0])
    depth = float(fid.readline().strip().split()[0])

    fid.readline()

    Mtt_old = float(fid.readline().strip().split()[0])
    Mpp_old = float(fid.readline().strip().split()[0])
    Mrr_old = float(fid.readline().strip().split()[0])
    Mtp_old = float(fid.readline().strip().split()[0])
    Mtr_old = float(fid.readline().strip().split()[0])
    Mpr_old = float(fid.readline().strip().split()[0])

    # rotate event into physical domain

    lat, lon = rot.rotate_lat_lon(lat_old, lon_old, rotation_axis,
                                  rotation_angle)
    Mrr, Mtt, Mpp, Mtr, Mpr, Mtp = rot.rotate_moment_tensor(
        Mrr_old, Mtt_old, Mpp_old, Mtr_old, Mpr_old, Mtp_old, lat_old, lon_old,
        rotation_axis, rotation_angle)

    # populate event origin data
    ev.event_type = event_type

    ev_origin = Origin()
    ev_origin.time = UTCDateTime(origin_time)
    ev_origin.latitude = lat
    ev_origin.longitude = lon
    ev_origin.depth = depth
    ev.origins.append(ev_origin)

    # populte event moment tensor

    ev_tensor = Tensor()
    ev_tensor.m_rr = Mrr
    ev_tensor.m_tt = Mtt
    ev_tensor.m_pp = Mpp
    ev_tensor.m_rt = Mtr
    ev_tensor.m_rp = Mpr
    ev_tensor.m_tp = Mtp

    ev_momenttensor = MomentTensor()
    ev_momenttensor.tensor = ev_tensor
    ev_momenttensor.scalar_moment = np.sqrt(Mrr ** 2 + Mtt ** 2 + Mpp ** 2 +
                                            Mtr ** 2 + Mpr ** 2 + Mtp ** 2)

    ev_focalmechanism = FocalMechanism()
    ev_focalmechanism.moment_tensor = ev_momenttensor
    ev_focalmechanism.nodal_planes = NodalPlanes().setdefault(0, 0)

    ev.focal_mechanisms.append(ev_focalmechanism)

    # populate event magnitude
    ev_magnitude = Magnitude()
    ev_magnitude.mag = 0.667 * (np.log10(ev_momenttensor.scalar_moment) - 9.1)
    ev_magnitude.magnitude_type = 'Mw'
    ev.magnitudes.append(ev_magnitude)

    # write QuakeML file
    cat = Catalog()
    cat.append(ev)
    cat.write(QuakeML_filename, format="quakeml")

    # clean up
    fid.close()
Esempio n. 3
0
def test_RotateMomentTensor():
    """
    Tests the moment tensor rotations.
    """
    # A full rotation should not change anything.
    Mrr, Mtt, Mpp, Mrt, Mrp, Mtp = rotations.rotate_moment_tensor(
        1, 2, 3, 4, 5, 6, 7, 8, [9, 10, 11], 360)
    np.testing.assert_almost_equal(Mrr, 1.0, 6)
    np.testing.assert_almost_equal(Mtt, 2.0, 6)
    np.testing.assert_almost_equal(Mpp, 3.0, 6)
    np.testing.assert_almost_equal(Mrt, 4.0, 6)
    np.testing.assert_almost_equal(Mrp, 5.0, 6)
    np.testing.assert_almost_equal(Mtp, 6.0, 6)

    # The following ones are tested against a well proven Matlab script by
    # Andreas Fichtner.
    Mrr, Mtt, Mpp, Mrt, Mrp, Mtp = rotations.rotate_moment_tensor(
        -0.704, 0.071, 0.632, 0.226, -0.611, 3.290, rotations.colat2lat(26.08),
        -21.17, [0, 1, 0], 57.5)
    Mrr_new, Mtt_new, Mpp_new, Mrt_new, Mrp_new, Mtp_new = \
        [-0.70400000, 2.04919171, -1.34619171, 0.02718681, -0.65089007,
         2.83207047]
    np.testing.assert_almost_equal(Mrr, Mrr_new, 6)
    np.testing.assert_almost_equal(Mtt, Mtt_new, 6)
    np.testing.assert_almost_equal(Mpp, Mpp_new, 6)
    np.testing.assert_almost_equal(Mrt, Mrt_new, 6)
    np.testing.assert_almost_equal(Mrp, Mrp_new, 6)
    np.testing.assert_almost_equal(Mtp, Mtp_new, 6)
    # Another example.
    Mrr, Mtt, Mpp, Mrt, Mrp, Mtp = rotations.rotate_moment_tensor(
        -0.818, -1.300, 2.120, 1.720, 2.290, -0.081,
        rotations.colat2lat(53.51), -9.87,
        [np.sqrt(2) / 2, -np.sqrt(2) / 2, 0], -31.34)
    Mrr_new, Mtt_new, Mpp_new, Mrt_new, Mrp_new, Mtp_new = \
        [-0.81800000, -0.69772178, 1.51772178, 2.55423451, 1.29552541,
         1.30522545]
    np.testing.assert_almost_equal(Mrr, Mrr_new, 6)
    np.testing.assert_almost_equal(Mtt, Mtt_new, 6)
    np.testing.assert_almost_equal(Mpp, Mpp_new, 6)
    np.testing.assert_almost_equal(Mrt, Mrt_new, 6)
    np.testing.assert_almost_equal(Mrp, Mrp_new, 6)
    np.testing.assert_almost_equal(Mtp, Mtp_new, 6)
    # The same as before, but with a non-normalized axis. Should work just
    # as well.
    Mrr, Mtt, Mpp, Mrt, Mrp, Mtp = rotations.rotate_moment_tensor(
        -0.818, -1.300, 2.120, 1.720, 2.290, -0.081,
        rotations.colat2lat(53.51), -9.87, [11.12, -11.12, 0], -31.34)
    Mrr_new, Mtt_new, Mpp_new, Mrt_new, Mrp_new, Mtp_new = \
        [-0.81800000, -0.69772178, 1.51772178, 2.55423451, 1.29552541,
         1.30522545]
    np.testing.assert_almost_equal(Mrr, Mrr_new, 6)
    np.testing.assert_almost_equal(Mtt, Mtt_new, 6)
    np.testing.assert_almost_equal(Mpp, Mpp_new, 6)
    np.testing.assert_almost_equal(Mrt, Mrt_new, 6)
    np.testing.assert_almost_equal(Mrp, Mrp_new, 6)
    np.testing.assert_almost_equal(Mtp, Mtp_new, 6)
    # One more.
    Mrr, Mtt, Mpp, Mrt, Mrp, Mtp = rotations.rotate_moment_tensor(
        0.952, -1.030, 0.076, 0.226, -0.040, -0.165,
        rotations.colat2lat(63.34), 55.80,
        [np.sqrt(3) / 3, -np.sqrt(3) / 3, -np.sqrt(3) / 3], 123.45)
    Mrr_new, Mtt_new, Mpp_new, Mrt_new, Mrp_new, Mtp_new = \
        [0.95200000, -0.41458722, -0.53941278, -0.09170855, 0.21039378,
         0.57370606]
    np.testing.assert_almost_equal(Mrr, Mrr_new, 6)
    np.testing.assert_almost_equal(Mtt, Mtt_new, 6)
    np.testing.assert_almost_equal(Mpp, Mpp_new, 6)
    np.testing.assert_almost_equal(Mrt, Mrt_new, 6)
    np.testing.assert_almost_equal(Mrp, Mrp_new, 6)
    np.testing.assert_almost_equal(Mtp, Mtp_new, 6)
Esempio n. 4
0
    def test_RotateMomentTensor(self):
        """
        Tests the moment tensor rotations.
        """
        # A full rotation should not change anything.
        Mrr, Mtt, Mpp, Mrt, Mrp, Mtp = rotations.rotate_moment_tensor(1, 2, 3,
            4, 5, 6, 7, 8, [9, 10, 11], 360)
        self.assertAlmostEqual(Mrr, 1.0, 6)
        self.assertAlmostEqual(Mtt, 2.0, 6)
        self.assertAlmostEqual(Mpp, 3.0, 6)
        self.assertAlmostEqual(Mrt, 4.0, 6)
        self.assertAlmostEqual(Mrp, 5.0, 6)
        self.assertAlmostEqual(Mtp, 6.0, 6)

        # The following ones are tested against a well proven Matlab script by
        # Andreas Fichtner.
        Mrr, Mtt, Mpp, Mrt, Mrp, Mtp = rotations.rotate_moment_tensor( \
            -0.704, 0.071, 0.632, 0.226, -0.611, 3.290,
            rotations.colat2lat(26.08), -21.17,
            [0, 1, 0], 57.5)
        Mrr_new, Mtt_new, Mpp_new, Mrt_new, Mrp_new, Mtp_new = \
            [-0.70400000, 2.04919171, -1.34619171, 0.02718681, -0.65089007,
            2.83207047]
        self.assertAlmostEqual(Mrr, Mrr_new, 6)
        self.assertAlmostEqual(Mtt, Mtt_new, 6)
        self.assertAlmostEqual(Mpp, Mpp_new, 6)
        self.assertAlmostEqual(Mrt, Mrt_new, 6)
        self.assertAlmostEqual(Mrp, Mrp_new, 6)
        self.assertAlmostEqual(Mtp, Mtp_new, 6)
        # Another example.
        Mrr, Mtt, Mpp, Mrt, Mrp, Mtp = rotations.rotate_moment_tensor( \
            -0.818, -1.300, 2.120, 1.720, 2.290, -0.081,
            rotations.colat2lat(53.51), -9.87,
            [np.sqrt(2) / 2, -np.sqrt(2) / 2, 0], -31.34)
        Mrr_new, Mtt_new, Mpp_new, Mrt_new, Mrp_new, Mtp_new = \
            [-0.81800000, -0.69772178, 1.51772178, 2.55423451, 1.29552541,
            1.30522545]
        self.assertAlmostEqual(Mrr, Mrr_new, 6)
        self.assertAlmostEqual(Mtt, Mtt_new, 6)
        self.assertAlmostEqual(Mpp, Mpp_new, 6)
        self.assertAlmostEqual(Mrt, Mrt_new, 6)
        self.assertAlmostEqual(Mrp, Mrp_new, 6)
        self.assertAlmostEqual(Mtp, Mtp_new, 6)
        # The same as before, but with a non-normalized axis. Should work just
        # as well.
        Mrr, Mtt, Mpp, Mrt, Mrp, Mtp = rotations.rotate_moment_tensor( \
            -0.818, -1.300, 2.120, 1.720, 2.290, -0.081,
            rotations.colat2lat(53.51), -9.87,
            [11.12, -11.12, 0], -31.34)
        Mrr_new, Mtt_new, Mpp_new, Mrt_new, Mrp_new, Mtp_new = \
            [-0.81800000, -0.69772178, 1.51772178, 2.55423451, 1.29552541,
            1.30522545]
        self.assertAlmostEqual(Mrr, Mrr_new, 6)
        self.assertAlmostEqual(Mtt, Mtt_new, 6)
        self.assertAlmostEqual(Mpp, Mpp_new, 6)
        self.assertAlmostEqual(Mrt, Mrt_new, 6)
        self.assertAlmostEqual(Mrp, Mrp_new, 6)
        self.assertAlmostEqual(Mtp, Mtp_new, 6)
        # One more.
        Mrr, Mtt, Mpp, Mrt, Mrp, Mtp = rotations.rotate_moment_tensor( \
            0.952, -1.030, 0.076, 0.226, -0.040, -0.165,
            rotations.colat2lat(63.34), 55.80,
            [np.sqrt(3) / 3, -np.sqrt(3) / 3, -np.sqrt(3) / 3], 123.45)
        Mrr_new, Mtt_new, Mpp_new, Mrt_new, Mrp_new, Mtp_new = \
            [0.95200000, -0.41458722, -0.53941278, -0.09170855, 0.21039378,
            0.57370606]
        self.assertAlmostEqual(Mrr, Mrr_new, 6)
        self.assertAlmostEqual(Mtt, Mtt_new, 6)
        self.assertAlmostEqual(Mpp, Mpp_new, 6)
        self.assertAlmostEqual(Mrt, Mrt_new, 6)
        self.assertAlmostEqual(Mrp, Mrp_new, 6)
        self.assertAlmostEqual(Mtp, Mtp_new, 6)