예제 #1
0
 def test_farfield_with_quiver(self):
     """
     Tests to plot P/S wave farfield radiation pattern
     """
     # Peru 2001/6/23 20:34:23:
     mt = [2.245, -0.547, -1.698, 1.339, -3.728, 1.444]
     plot_radiation_pattern(
         mt, kind=['beachball', 's_quiver', 'p_quiver'], show=False)
예제 #2
0
# source (strike, dip, rake) and P, S velocities at source depth.
# thrust fault thats roughly orientated like the faults on the CF
fault = [120, 45, 90]
mt = getmt(fault)
# manual input from the models based on the depth of the marsquake (unknown so can be done later)
Pvelz = 5.84666
Svelz = 3.28116

from obspy.imaging.beachball import beachball
beachball(mt, size=200, linewidth=2, facecolor='b')

# configuration:
azimuth = 270  #from the marsquake to the station
# exit angles based on velocity at depth
iP = np.degrees(np.arcsin(Pvelz * Pp / radius))
jS = np.degrees(np.arcsin(Svelz * Sp / radius))
print('P exit at ', iP)
print('S exit at ', jS)
P, SV, SH = Rpattern(fault, azimuth, [iP, jS])
print(P, SV, SH)

from obspy.imaging.source import plot_radiation_pattern
plot_radiation_pattern(mt,
                       kind=['p_sphere', 'beachball', 's_sphere', 's_quiver'],
                       coordinate_system='RTP',
                       p_sphere_direction='inwards',
                       fig=None,
                       show=True)
# loops over all possible exit angles and azimuths
예제 #3
0
파일: event.py 프로젝트: znamy/obspy
    def plot(self,
             kind=[['ortho', 'beachball'], ['p_sphere', 's_sphere']],
             subplot_size=4.0,
             show=True,
             outfile=None,
             **kwargs):
        """
        Plot event location and/or the preferred focal mechanism
        and radiation pattern.

        :type kind: list of str or nested list of str
        :param kind: A list of strings (for a 1-row plot) or a nested list of
            strings (one list of strings per row), with the following keywords
            to generate a matplotlib figure:

            * ``'ortho'`` (Orthographic plot of event location
              see :meth:`~obspy.core.event.catalog.Catalog.plot`)
            * ``'global'`` (Global plot of event location
              see :meth:`~obspy.core.event.catalog.Catalog.plot`)
            * ``'local'`` (Local plot of event location
              see :meth:`~obspy.core.event.catalog.Catalog.plot`)
            * ``'beachball'`` (Beachball of preferred focal mechanism)
            * ``'p_quiver'`` (quiver plot of p wave farfield)
            * ``'s_quiver'`` (quiver plot of s wave farfield)
            * ``'p_sphere'`` (surface plot of p wave farfield)
            * ``'s_sphere'`` (surface plot of s wave farfield)

        :type subplot_size: float
        :param subplot_size: Width/height of one single subplot cell in inches.
        :type show: bool
        :param show: Whether to show the figure after plotting or not. Can be
            used to do further customization of the plot before
            showing it. Has no effect if `outfile` is specified.
        :type outfile: str
        :param outfile: Output file path to directly save the resulting image
            (e.g. ``"/tmp/image.png"``). Overrides the ``show`` option, image
            will not be displayed interactively. The given path/filename is
            also used to automatically determine the output format. Supported
            file formats depend on your matplotlib backend.  Most backends
            support png, pdf, ps, eps and svg. Defaults to ``None``.
            The figure is closed after saving it to file.
        :returns: Figure instance with the plot.

        .. rubric:: Examples

        Default plot includes an orthographic map plot, a beachball plot and
        plots of P/S farfield radiation patterns (preferred -- or first --
        focal mechanism has to have a moment tensor set).

        >>> from obspy import read_events
        >>> event = read_events("/path/to/CMTSOLUTION")[0]
        >>> event.plot()  # doctest:+SKIP

        .. plot::

            from obspy import read_events
            event = read_events("/path/to/CMTSOLUTION")[0]
            event.plot()

        Individual subplot parts and the setup of the grid of subplots
        (rows/columns) can be specified by using certain keywords, see `kind`
        parameter description.

        >>> event.plot(kind=[['global'],
        ...                  ['p_sphere', 'p_quiver']])  # doctest:+SKIP

        .. plot::

            from obspy import read_events
            event = read_events("/path/to/CMTSOLUTION")[0]
            event.plot(kind=[['global'], ['p_sphere', 'p_quiver']])
        """
        import matplotlib.pyplot as plt
        try:
            fm = self.preferred_focal_mechanism() or self.focal_mechanisms[0]
            mtensor = fm.moment_tensor.tensor
        except (IndexError, AttributeError) as e:
            msg = "Could not access event's moment tensor ({}).".format(str(e))
            raise ValueError(msg)

        mt = [
            mtensor.m_rr, mtensor.m_tt, mtensor.m_pp, mtensor.m_rt,
            mtensor.m_rp, mtensor.m_tp
        ]
        fig, axes, kind_ = _setup_figure_and_axes(kind,
                                                  subplot_size=subplot_size)
        if any([k_ in ("ortho", "global", "local") for k_ in kind_]):
            from .catalog import Catalog
            cat_ = Catalog([self])
        for ax, kind__ in zip(axes, kind_):
            if kind__ in ("ortho", "global", "local"):
                cat_.plot(projection=kind__, fig=ax, show=False, **kwargs)
                # shrink plot a bit to avoid it looking oversized compared to
                # 3d axes that have some white space around them
                if kind__ == "ortho":
                    scale = 0.8
                    for getter, setter in zip((ax.get_xlim, ax.get_ylim),
                                              (ax.set_xlim, ax.set_ylim)):
                        min_, max_ = getter()
                        margin = (max_ - min_) * (1 - scale) / 2.0
                        setter(min_ - margin, max_ + margin)
        plot_radiation_pattern(mt,
                               kind=kind,
                               coordinate_system='RTP',
                               fig=fig,
                               show=False)

        fig.tight_layout(pad=0.1)

        if outfile:
            fig.savefig(outfile)
            plt.close(fig)
        else:
            if show:
                plt.show()

        return fig
예제 #4
0
파일: moment_tensor.py 프로젝트: MMesch/x3d
def main():
    # mt = [1., 1., 1., 0., 0., 0.]  # explosion
    # mt = [0., 0., 0., 1., -1., 0.]  # double couple
    mt = [0., 0., 0., 1., -1., -1.]
    plot_radiation_pattern(mt, kind='mayavi')
예제 #5
0
파일: event.py 프로젝트: htxu007/obspy
    def plot(self, kind=[['ortho', 'beachball'], ['p_sphere', 's_sphere']],
             subplot_size=4.0, show=True, outfile=None, **kwargs):
        """
        Plot event location and/or the preferred focal mechanism
        and radiation pattern.

        :type kind: list of str or nested list of str
        :param kind: A list of strings (for a 1-row plot) or a nested list of
            strings (one list of strings per row), with the following keywords
            to generate a matplotlib figure:
                * 'ortho' (Orthographic plot of event location,
                  see :meth:`~obspy.core.event.catalog.Catalog.plot`),
                * 'global' (Global plot of event location,
                  see :meth:`~obspy.core.event.catalog.Catalog.plot`),
                * 'local' (Local plot of event location,
                  see :meth:`~obspy.core.event.catalog.Catalog.plot`),
                * 'beachball' (Beachball of preferred focal mechanism),
                * 'p_quiver' (quiver plot of p wave farfield),
                * 's_quiver' (quiver plot of s wave farfield),
                * 'p_sphere' (surface plot of p wave farfield),
                * 's_sphere' (surface plot of s wave farfield).
        :type subplot_size: float
        :param subplot_size: Width/height of one single subplot cell in inches.
        :type show: bool
        :param show: Whether to show the figure after plotting or not. Can be
            used to do further customization of the plot before
            showing it. Has no effect if `outfile` is specified.
        :type outfile: str
        :param outfile: Output file path to directly save the resulting image
            (e.g. ``"/tmp/image.png"``). Overrides the ``show`` option, image
            will not be displayed interactively. The given path/filename is
            also used to automatically determine the output format. Supported
            file formats depend on your matplotlib backend.  Most backends
            support png, pdf, ps, eps and svg. Defaults to ``None``.
            The figure is closed after saving it to file.
        :returns: Figure instance with the plot.

        .. rubric:: Examples

        Default plot includes an orthographic map plot, a beachball plot and
        plots of P/S farfield radiation patterns (preferred -- or first --
        focal mechanism has to have a moment tensor set).

        >>> from obspy import read_events
        >>> cat = read_events("/path/to/CMTSOLUTION")
        >>> cat.plot()  # doctest:+SKIP

        .. plot::

            from obspy import read_events
            cat = read_events("/path/to/CMTSOLUTION")
            cat.plot()

        Individual subplot parts and the setup of the grid of subplots
        (rows/columns) can be specified by using certain keywords, see `kind`
        parameter description.

        >>> cat.plot(kind=[['global'],
        ...                ['p_sphere', 'p_quiver']])  # doctest:+SKIP

        .. plot::

            from obspy import read_events
            cat = read_events("/path/to/CMTSOLUTION")
            cat.plot(kind=[['global'], ['p_sphere', 'p_quiver']])
        """
        import matplotlib.pyplot as plt
        try:
            fm = self.preferred_focal_mechanism() or self.focal_mechanisms[0]
            mtensor = fm.moment_tensor.tensor
        except (IndexError, AttributeError) as e:
            msg = "Could not access event's moment tensor ({}).".format(str(e))
            raise ValueError(msg)

        mt = [mtensor.m_rr, mtensor.m_tt, mtensor.m_pp,
              mtensor.m_rt, mtensor.m_rp, mtensor.m_tp]
        fig, axes, kind_ = _setup_figure_and_axes(kind,
                                                  subplot_size=subplot_size)
        if any([k_ in ("ortho", "global", "local") for k_ in kind_]):
            from .catalog import Catalog
            cat_ = Catalog([self])
        for ax, kind__ in zip(axes, kind_):
            if kind__ in ("ortho", "global", "local"):
                cat_.plot(projection=kind__, fig=ax, show=False,
                          **kwargs)
                # shrink plot a bit to avoid it looking oversized compared to
                # 3d axes that have some white space around them
                if kind__ == "ortho":
                    scale = 0.8
                    for getter, setter in zip((ax.get_xlim, ax.get_ylim),
                                              (ax.set_xlim, ax.set_ylim)):
                        min_, max_ = getter()
                        margin = (max_ - min_) * (1 - scale) / 2.0
                        setter(min_ - margin, max_ + margin)
        plot_radiation_pattern(
            mt, kind=kind, coordinate_system='RTP', fig=fig, show=False)

        fig.tight_layout(pad=0.1)

        if outfile:
            fig.savefig(outfile)
            plt.close(fig)
        else:
            if show:
                plt.show()

        return fig