def testRandomRotation(self):
        angles = []
        rstate = num.random.RandomState(10)
        for _ in range(100):
            mt1 = MomentTensor.random_mt(magnitude=-1.0)
            mt2 = mt1.random_rotated(10.0, rstate=rstate)
            angle = kagan_angle(mt1, mt2)
            angles.append(angle)

        assert abs(num.mean(angles) - 8.330) < 0.01

        mt1 = MomentTensor.random_mt(magnitude=-1.0)
        mt2 = mt1.random_rotated(angle=10.0)

        assert abs(kagan_angle(mt1, mt2) - 10.0) < 0.0001
Exemple #2
0
    def testRandomRotation(self):
        angles = []
        rstate = num.random.RandomState(10)
        for _ in range(100):
            mt1 = MomentTensor.random_mt(magnitude=-1.0)
            mt2 = mt1.random_rotated(10.0, rstate=rstate)
            angle = kagan_angle(mt1, mt2)
            angles.append(angle)

        assert abs(num.mean(angles) - 8.330) < 0.01

        mt1 = MomentTensor.random_mt(magnitude=-1.0)
        mt2 = mt1.random_rotated(angle=10.0)

        assert abs(kagan_angle(mt1, mt2) - 10.0) < 0.0001
def plot_val_vs_pred_mt(pred_mt, val_mt):
    for pred_m, real_m in zip(pred_mt, val_mt):
        omega = omega_angle(real_m.m6(), pred_m.m6())
        kagan = mtm.kagan_angle(real_m, pred_m)
        fig = plt.figure()
        axes = fig.add_subplot(1, 1, 1)
        axes.set_xlim(-2., 4.)
        axes.set_ylim(-2., 2.)
        axes.set_axis_off()

        plot.beachball.plot_beachball_mpl(
            real_m,
            axes,
            beachball_type='deviatoric',
            size=60.,
            position=(0, 1),
            color_t=plot.mpl_color('scarletred2'),
            linewidth=1.0)
        plot.beachball.plot_beachball_mpl(
            pred_m,
            axes,
            beachball_type='deviatoric',
            size=60.,
            position=(1.5, 1),
            color_t=plot.mpl_color('scarletred2'),
            linewidth=1.0)
        plt.show()
        print("Omega Angle:", omega, "Kagan Angle:", kagan)
Exemple #4
0
    def testKagan(self):
        eps = 0.01
        for _ in xrange(500):
            mt1 = MomentTensor.random_mt(magnitude=-1.0)
            assert 0.0 == kagan_angle(mt1, mt1)

            mt1 = MomentTensor.random_dc(magnitude=-1.0)
            assert 0.0 == kagan_angle(mt1, mt1)

            angle = random.random() * 90.0

            rot = rotation_from_angle_and_axis(angle, random_axis())

            mrot = rot.T * mt1.m() * rot
            mt2 = MomentTensor(m=mrot)
            angle2 = kagan_angle(mt1, mt2)

            assert abs(angle - angle2) < eps
Exemple #5
0
 def testGeofonMT(self):
     cat = catalog.Geofon()
     tmin = util.str_to_time('2014-01-01 00:00:00')
     tmax = util.str_to_time('2017-01-01 00:00:00')
     events = cat.get_events((tmin, tmax), magmin=8)
     self.assertEqual(len(events), 2)
     mt1, mt2 = [ev.moment_tensor for ev in events]
     angle = moment_tensor.kagan_angle(mt1, mt2)
     self.assertEqual(round(angle - 7.7, 1), 0.0)
Exemple #6
0
    def testKagan(self):
        eps = 0.01
        for _ in range(500):
            mt1 = MomentTensor.random_mt(magnitude=-1.0)
            assert 0.0 == kagan_angle(mt1, mt1)

            mt1 = MomentTensor.random_dc(magnitude=-1.0)
            assert 0.0 == kagan_angle(mt1, mt1)

            angle = random.random() * 90.

            rot = rotation_from_angle_and_axis(angle, random_axis())

            mrot = rot.T * mt1.m() * rot
            mt2 = MomentTensor(m=mrot)
            angle2 = kagan_angle(mt1, mt2)

            assert abs(angle - angle2) < eps
Exemple #7
0
 def testGeofonMT(self):
     cat = catalog.Geofon()
     tmin = util.str_to_time('2014-01-01 00:00:00')
     tmax = util.str_to_time('2017-01-01 00:00:00')
     events = cat.get_events((tmin, tmax), magmin=8)
     self.assertEqual(len(events), 2)
     mt1, mt2 = [ev.moment_tensor for ev in events]
     angle = moment_tensor.kagan_angle(mt1, mt2)
     self.assertEqual(round(angle - 7.7, 1), 0.0)
Exemple #8
0
def get_distance_dc(eventi, eventj):
    '''Normalized Kagan angle distance among DC components of moment tensors.
       Based on Kagan, Y. Y., 1991, GJI
    '''

    mti = eventi.moment_tensor
    mtj = eventj.moment_tensor

    d = moment_tensor.kagan_angle(mti, mtj) / 120.
    if d > 1.:
        d = 1.

    return d
def plot_pred_bayesian_mt_hist(pred_mts, best_mt=None, hist=True):
    fig = plt.figure(figsize=(4., 4.))
    fig.subplots_adjust(left=0., right=1., bottom=0., top=1.)
    gs = GridSpec(3, 5)
    axes = fig.add_subplot(gs[0:2, :])

    plot_kwargs = {
        'beachball_type': 'full',
        'size': 3,
        'position': (5, 5),
        'color_t': 'black',
        'edgecolor': 'black'
    }

    beachball.plot_fuzzy_beachball_mpl_pixmap(pred_mts, axes, best_mt,
                                              **plot_kwargs)
    axes.set_xlim(0., 10.)
    axes.set_ylim(0., 10.)
    axes.set_axis_off()
    plt.axis('off')
    if hist is True:
        omegas = []
        kagans = []
        for mt in pred_mts:
            omega = omega_angle(mt.m6(), best_mt.m6())
            kagan = mtm.kagan_angle(mt, best_mt)
            omegas.append(omega)
            kagans.append(kagan)

        ax = fig.add_subplot(gs[2, 1])
        sns.distplot(omegas, kde=False)
        plt.xlabel('Omega angle (°)', fontsize=12)
        plt.ylabel('#', fontsize=12)
        xmin, xmax = ax.get_xlim()
        ax.set_xticks(np.round(np.linspace(xmin, xmax, 2), 2))
        plt.xticks(fontsize=12)
        plt.yticks(fontsize=12)

        ax = fig.add_subplot(gs[2, 3])
        sns.distplot(kagans, color="orange", kde=False)
        plt.xlabel('Kagan angle (°)', fontsize=12)
        plt.ylabel('#', fontsize=12)
        xmin, xmax = ax.get_xlim()
        ax.set_xticks(np.round(np.linspace(xmin, xmax, 2), 2))
        plt.xticks(fontsize=12)
        plt.yticks(fontsize=12)

        plt.show()

    return fig
Exemple #10
0
    def testGeofonMT(self):
        cat = catalog.Geofon()
        tmin = util.str_to_time('2014-01-01 00:00:00')
        tmax = util.str_to_time('2017-01-01 00:00:00')
        events_a = cat.get_events((tmin, tmax), magmin=8)
        events_b = [
            cat.get_event('gfz2015sfdd'),
            cat.get_event('gfz2014gkgf')]

        for events in [events_a, events_b]:
            self.assertEqual(len(events), 2)
            mt1, mt2 = [ev.moment_tensor for ev in events]
            angle = moment_tensor.kagan_angle(mt1, mt2)
            self.assertEqual(round(angle - 7.7, 1), 0.0)

        ev = cat.get_event('gfz2020vimx')
        assert isinstance(ev.moment_tensor, moment_tensor.MomentTensor)
Exemple #11
0
    def update_distances_and_angles(self,
                                    indices=None,
                                    want_angles=False,
                                    want_distances=False):
        '''Calculate and update distances and kagan angles between events.

        :param indices: list of lists of indices (optional)

        Ideally, indices are consecutive for best performance.'''
        want_angles = want_angles or \
            not self.marker_table_view.isColumnHidden(
                _column_mapping['Kagan Angle [deg]'])
        want_distances = want_distances or \
            not self.marker_table_view.isColumnHidden(
                _column_mapping['Dist [km]'])

        if not (want_distances or want_angles):
            return

        indices = indices or [[]]
        indices = [i for ii in indices for i in ii]

        if len(indices) != 1:
            return

        if self.last_active_event == self.pile_viewer.get_active_event():
            return
        else:
            self.last_active_event = self.pile_viewer.get_active_event()

        markers = self.pile_viewer.markers
        nmarkers = len(markers)
        omarker = markers[indices[0]]
        if not isinstance(omarker, EventMarker):
            return
        else:
            oevent = omarker.get_event()

        emarkers = [m for m in markers if isinstance(m, EventMarker)]
        if len(emarkers) < 2:
            return
        else:
            events = [em.get_event() for em in emarkers]
            nevents = len(events)

        if want_distances:
            lats = num.zeros(nevents)
            lons = num.zeros(nevents)
            for i in range(nevents):
                lats[i] = events[i].lat
                lons[i] = events[i].lon

            olats = num.zeros(nevents)
            olons = num.zeros(nevents)
            olats[:] = oevent.lat
            olons[:] = oevent.lon
            dists = orthodrome.distance_accurate50m_numpy(
                lats, lons, olats, olons)
            dists /= 1000.

            dists = [round(x, 1) for x in dists]
            self.distances = dict(list(zip(emarkers, dists)))

        if want_angles:
            if oevent.moment_tensor:
                for em in emarkers:
                    e = em.get_event()
                    if e.moment_tensor:
                        a = kagan_angle(oevent.moment_tensor, e.moment_tensor)
                        self.kagan_angles[em] = a
            else:
                self.kagan_angles = {}

        istart = self.index(0, _column_mapping['Dist [km]'])
        istop = self.index(nmarkers - 1, _column_mapping['Kagan Angle [deg]'])

        self.dataChanged.emit(istart, istop)
Exemple #12
0
    def update_distances_and_angles(self, indices=None, want_angles=False,
                                    want_distances=False):
        '''Calculate and update distances and kagan angles between events.

        :param indices: list of lists of indices (optional)

        Ideally, indices are consecutive for best performance.'''
        want_angles = want_angles or \
            not self.marker_table_view.isColumnHidden(
                _column_mapping['Kagan Angle [deg]'])
        want_distances = want_distances or \
            not self.marker_table_view.isColumnHidden(
                _column_mapping['Dist [km]'])

        if not (want_distances or want_angles):
            return

        indices = indices or [[]]
        indices = [i for ii in indices for i in ii]

        if len(indices) != 1:
            return

        if self.last_active_event == self.pile_viewer.get_active_event():
            return
        else:
            self.last_active_event = self.pile_viewer.get_active_event()

        markers = self.pile_viewer.markers
        nmarkers = len(markers)
        omarker = markers[indices[0]]
        if not isinstance(omarker, EventMarker):
            return
        else:
            oevent = omarker.get_event()

        emarkers = [m for m in markers if isinstance(m, EventMarker)]
        if len(emarkers) < 2:
            return
        else:
            events = [em.get_event() for em in emarkers]
            nevents = len(events)

        if want_distances:
            lats = num.zeros(nevents)
            lons = num.zeros(nevents)
            for i in range(nevents):
                lats[i] = events[i].lat
                lons[i] = events[i].lon

            olats = num.zeros(nevents)
            olons = num.zeros(nevents)
            olats[:] = oevent.lat
            olons[:] = oevent.lon
            dists = orthodrome.distance_accurate50m_numpy(
                lats, lons, olats, olons)
            dists /= 1000.

            dists = [round(x, 1) for x in dists]
            self.distances = dict(list(zip(emarkers, dists)))

        if want_angles:
            if oevent.moment_tensor:
                for em in emarkers:
                    e = em.get_event()
                    if e.moment_tensor:
                        a = kagan_angle(oevent.moment_tensor, e.moment_tensor)
                        self.kagan_angles[em] = a
            else:
                self.kagan_angles = {}

        istart = self.index(0, _column_mapping['Dist [km]'])
        istop = self.index(nmarkers-1, _column_mapping['Kagan Angle [deg]'])

        self.dataChanged.emit(
                  istart,
                  istop)