Exemple #1
0
from matplotlib import pyplot as plt
from pyrocko import beachball, moment_tensor as pmt, plot

fig = plt.figure(figsize=(4., 2.))
fig.subplots_adjust(left=0., right=1., bottom=0., top=1.)
axes = fig.add_subplot(1, 1, 1)
axes.set_xlim(0., 4.)
axes.set_ylim(0., 2.)
axes.set_axis_off()

for i, beachball_type in enumerate(['full', 'deviatoric', 'dc']):
    beachball.plot_beachball_mpl(pmt.as_mt(
        (124654616., 370943136., -6965434.0, 553316224., -307467264.,
         84703760.0)),
                                 axes,
                                 beachball_type=beachball_type,
                                 size=60.,
                                 position=(i + 1, 1),
                                 color_t=plot.mpl_color('scarletred2'),
                                 linewidth=1.0)

fig.savefig('beachball-example03.pdf')
plt.show()
Exemple #2
0
    def show_comparison(self, nx=10):
        import matplotlib.pyplot as plt
        from mpl_toolkits.mplot3d import Axes3D  # noqa

        if nx > 1:
            plt.ion()
            plt.show()

        fig = plt.figure()
        axes1 = fig.add_subplot(2, 3, 1, aspect=1.)
        axes2 = fig.add_subplot(2, 3, 2, aspect=1.)
        axes3 = fig.add_subplot(2, 3, 3, aspect=1.)
        axes4 = fig.add_subplot(2, 3, 4, projection='3d', aspect=1.)
        axes5 = fig.add_subplot(2, 3, 5, projection='3d', aspect=1.)

        try:
            import mopad
        except ImportError:
            mopad = None

        for x in range(nx):
            mt = mtm.MomentTensor.random_mt()
            mt = mt.deviatoric()

            for axes in (axes1, axes2, axes3):
                axes.cla()
                axes.axison = False
                axes.set_xlim(-1.05, 1.05)
                axes.set_ylim(-1.05, 1.05)

            for axes in (axes4, axes5):
                axes.cla()

            axes1.set_title('Copacabana')
            axes2.set_title('Contour')
            axes3.set_title('MoPaD')
            axes4.set_title('Patches')
            axes5.set_title('Lines')

            beachball.plot_beachball_mpl(mt, axes1, size_units='data')
            beachball.plot_beachball_mpl_pixmap(mt, axes2, size_units='data')

            beachball.plot_beachball_mpl_construction(mt,
                                                      axes4,
                                                      show='patches')
            beachball.plot_beachball_mpl_construction(mt, axes5, show='lines')

            if mopad:
                try:
                    mop_mt = mopad.MomentTensor(M=mt.m6())
                    mop_beach = mopad.BeachBall(mop_mt)
                    kwargs = dict(plot_projection='lambert',
                                  plot_nodalline_width=2,
                                  plot_faultplane_width=2,
                                  plot_outerline_width=2)

                    mop_beach.ploBB(kwargs, ax=axes3)

                except:
                    print 'mopad failed (maybe patched mopad version is needed'

            fig.canvas.draw()

        if nx == 1:
            plt.show()
Exemple #3
0
    def show_comparison(self, nx=10):
        import matplotlib.pyplot as plt
        from mpl_toolkits.mplot3d import Axes3D  # noqa

        if nx > 1:
            plt.ion()
            plt.show()

        fig = plt.figure()
        axes1 = fig.add_subplot(2, 3, 1, aspect=1.)
        axes2 = fig.add_subplot(2, 3, 2, aspect=1.)
        axes3 = fig.add_subplot(2, 3, 3, aspect=1.)
        axes4 = fig.add_subplot(2, 3, 4, projection='3d', aspect=1.)
        axes5 = fig.add_subplot(2, 3, 5, projection='3d', aspect=1.)

        try:
            import mopad
        except ImportError:
            mopad = None

        for x in range(nx):
            mt = mtm.MomentTensor.random_mt()
            mt = mt.deviatoric()

            for axes in (axes1, axes2, axes3):
                axes.cla()
                axes.axison = False
                axes.set_xlim(-1.05, 1.05)
                axes.set_ylim(-1.05, 1.05)

            for axes in (axes4, axes5):
                axes.cla()

            axes1.set_title('Copacabana')
            axes2.set_title('Contour')
            axes3.set_title('MoPaD')
            axes4.set_title('Patches')
            axes5.set_title('Lines')

            beachball.plot_beachball_mpl(mt, axes1, size_units='data')
            beachball.plot_beachball_mpl_pixmap(mt, axes2, size_units='data')

            beachball.plot_beachball_mpl_construction(
                mt, axes4, show='patches')
            beachball.plot_beachball_mpl_construction(
                mt, axes5, show='lines')

            if mopad:
                try:
                    mop_mt = mopad.MomentTensor(M=mt.m6())
                    mop_beach = mopad.BeachBall(mop_mt)
                    kwargs = dict(
                        plot_projection='lambert',
                        plot_nodalline_width=2,
                        plot_faultplane_width=2,
                        plot_outerline_width=2)

                    mop_beach.ploBB(kwargs, ax=axes3)

                except:
                    print 'mopad failed (maybe patched mopad version is needed'

            fig.canvas.draw()

        if nx == 1:
            plt.show()
Exemple #4
0
fig = plt.figure(figsize=(10., 4.))
fig.subplots_adjust(left=0., right=1., bottom=0., top=1.)
axes = fig.add_subplot(1, 1, 1)

for i in xrange(200):

    # create random moment tensor
    mt = pmt.MomentTensor.random_mt()

    try:
        # create beachball from moment tensor
        beachball.plot_beachball_mpl(
            mt,
            axes,
            # type of beachball: deviatoric, full or double couple (dc)
            beachball_type='full',
            size=random.random() * 120.,
            position=(random.random() * 10., random.random() * 10.),
            alpha=random.random(),
            linewidth=1.0)

    except beachball.BeachballError, e:
        logger.error('%s for MT:\n%s' % (e, mt))

axes.set_xlim(0., 10.)
axes.set_ylim(0., 10.)
axes.set_axis_off()
fig.savefig('beachball-example01.pdf')

plt.show()
Exemple #5
0
from pyrocko import util

logger = logging.getLogger(sys.argv[0])

util.setup_logging()

fig = plt.figure(figsize=(10., 10.))
fig.subplots_adjust(left=0., right=1., bottom=0., top=1.)
axes = fig.add_subplot(1, 1, 1)

for i in xrange(200):
    mt = pmt.MomentTensor.random_mt()
    try:
        beachball.plot_beachball_mpl(
            mt, axes,
            beachball_type='full',
            size=random.random()*120.,
            position=(random.random()*10., random.random()*10.),
            alpha=random.random(),
            linewidth=1.0)

    except beachball.BeachballError, e:
        logger.error('%s for MT:\n%s' % (e, mt))

axes.set_xlim(0., 10.)
axes.set_ylim(0., 10.)
axes.set_axis_off()
fig.savefig('copacabana.pdf')

plt.show()
Exemple #6
0
from matplotlib import pyplot as plt
from pyrocko import beachball, moment_tensor as pmt

fig = plt.figure(figsize=(10., 10.))
fig.subplots_adjust(left=0., right=1., bottom=0., top=1.)
axes = fig.add_subplot(1, 1, 1)
axes.set_xlim(0., 4.)
axes.set_ylim(0., 3.)
axes.set_axis_off()

for (strike, dip, rake), position, color in [
        ((0., 30., 120.), (1, 1.), 'red'),
        ((0., 30., 150.), (2., 1.), 'black'),
        ((0., 30., 180.), (3., 1), (0.5, 0.3, 0.7)),
        ((0., 30., -180.), (1., 2.), (0.1, 0.6, 0.1)),
        ((0., 30., -150.), (2., 2.), (0.2, 0.7, 1.0)),
        ((0., 30., -120.), (3., 2.), (0.2, 0.3, 0.1))]:

    beachball.plot_beachball_mpl(
        pmt.as_mt((strike, dip, rake)),
        axes,
        beachball_type='full',
        size=100.,
        position=position,
        color_t=color,
        linewidth=1.0)

fig.savefig('beachballs.pdf')

plt.show()
Exemple #7
0
# create a translation matrix, based on the final figure size and
# beachball location
move_trans = transforms.ScaledTranslation(szpt, -szpt, fig.dpi_scale_trans)

# get the inverse matrix for the axis where the beachball will be plotted
inv_trans = ax.transData.inverted()

# set the bouding point relative to the plotted axis of the beachball
x0, y1 = inv_trans.transform(
    move_trans.transform(ax.transData.transform((x0, y1))))

# plot beachball
beachball.plot_beachball_mpl(source1.pyrocko_moment_tensor(),
                             ax,
                             beachball_type='full',
                             size=sz,
                             position=(x0, y1),
                             linewidth=1.)

# create source object
source2 = gf.RectangularExplosionSource(depth=35e3, strike=0., dip=90.)

# set size of beachball
sz = 30.
# set beachball offset in points (one point from each axis)
szpt = (sz / 2.) / 72. + 1. / 72.

# get the bounding point (right-upper)
x1 = ax.get_xlim()[1]
y1 = ax.get_ylim()[1]
Exemple #8
0
phases = cake.PhaseDef.classic('P')

# setup figure with aspect=1.0/1.0, ranges=[-1.1, 1.1]
fig = plt.figure(figsize=(2., 2.))  # size in inch
fig.subplots_adjust(left=0., right=1., bottom=0., top=1.)
axes = fig.add_subplot(1, 1, 1, aspect=1.0)
axes.set_axis_off()
axes.set_xlim(-1.1, 1.1)
axes.set_ylim(-1.1, 1.1)

projection = 'lambert'

beachball.plot_beachball_mpl(mt,
                             axes,
                             position=(0., 0.),
                             size=2.0,
                             color_t=(0.7, 0.4, 0.4),
                             projection=projection,
                             size_units='data')

for rlat, rlon in rlatlons:
    distance = orthodrome.distance_accurate50m(slat, slon, rlat, rlon)
    rays = mod.arrivals(phases=cake.PhaseDef('P'),
                        zstart=sdepth,
                        zstop=rdepth,
                        distances=[distance * cake.m2d])

    if not rays:
        continue

    takeoff = rays[0].takeoff_angle()
Exemple #9
0
logger = logging.getLogger(sys.argv[0])

util.setup_logging()

fig = plt.figure(figsize=(10., 10.))
fig.subplots_adjust(left=0., right=1., bottom=0., top=1.)
axes = fig.add_subplot(1, 1, 1)

for i in xrange(200):
    mt = pmt.MomentTensor.random_mt()
    try:
        beachball.plot_beachball_mpl(mt,
                                     axes,
                                     beachball_type='full',
                                     size=random.random() * 120.,
                                     position=(random.random() * 10.,
                                               random.random() * 10.),
                                     alpha=random.random(),
                                     linewidth=1.0)

    except beachball.BeachballError, e:
        logger.error('%s for MT:\n%s' % (e, mt))

axes.set_xlim(0., 10.)
axes.set_ylim(0., 10.)
axes.set_axis_off()
fig.savefig('copacabana.pdf')

plt.show()