コード例 #1
0
ファイル: visualization.py プロジェクト: msimon00/LASIF
def plot_tf(data, delta):
    """
    Plots a time frequency representation of any time series.
    """
    npts = len(data)

    plotTfr(data, dt=delta, fmin=1.0 / (npts * delta),
        fmax=1.0 / (2.0 * delta))
コード例 #2
0
ファイル: test_tf_misfit.py プロジェクト: rpratt20/obspy
    def test_plot_tfr(self):
        n = 295
        t, dt = np.linspace(0., 20 * np.pi, n, retstep=True)
        sig = np.sin(t)

        with ImageComparison(self.path, 'time_frequency_representation.png') \
                as ic:
            plotTfr(sig, dt=dt, show=False)
            plt.savefig(ic.name)
コード例 #3
0
ファイル: test_tf_misfit.py プロジェクト: 3rdcycle/obspy
    def test_plot_tfr(self):
        n = 295
        t, dt = np.linspace(0., 20 * np.pi, n, retstep=True)
        sig = np.sin(t)

        with ImageComparison(self.path, 'time_frequency_representation.png') \
                as ic:
            plotTfr(sig, dt=dt, show=False)
            plt.savefig(ic.name)
コード例 #4
0
ファイル: visualization.py プロジェクト: msimon00/LASIF
def plot_tf(data, delta):
    """
    Plots a time frequency representation of any time series.
    """
    npts = len(data)

    plotTfr(data,
            dt=delta,
            fmin=1.0 / (npts * delta),
            fmax=1.0 / (2.0 * delta))
コード例 #5
0
ファイル: visualization.py プロジェクト: seancug/LASIF
def plot_tf(data, delta, freqmin=None, freqmax=None):
    """
    Plots a time frequency representation of any time series. Right now it is
    basically limited to plotting source time functions.
    """
    npts = len(data)

    fig = plotTfr(data, dt=delta, fmin=1.0 / (npts * delta),
                  fmax=1.0 / (2.0 * delta), show=False)

    # Get the different axes...use some kind of logic to determine which is
    # which. This is super flaky as dependent on the ObsPy version and what
    # not.
    axes = {}
    for ax in fig.axes:
        xlim = ax.get_xlim()
        ylim = ax.get_ylim()

        # Colorbar.
        if xlim == ylim:
            continue

        # Spectral axis.
        elif xlim[0] > xlim[1]:
            axes["spec"] = ax

        elif ylim[0] < 0:
            axes["time"] = ax

        else:
            axes["tf"] = ax

    fig.suptitle("Source Time Function")

    if len(axes) != 3:
        msg = "Could not plot frequency limits!"
        print msg
        plt.gcf().patch.set_alpha(0.0)
        plt.show()
        return

    axes["spec"].grid()
    axes["time"].grid()
    axes["tf"].grid()

    axes["spec"].xaxis.tick_top()
    axes["spec"].set_ylabel("Frequency [Hz]")

    axes["time"].set_xlabel("Time [s]")
    axes["time"].set_ylabel("Velocity [m/s]")

    if freqmin is not None and freqmax is not None:
        xmin, xmax = axes["tf"].get_xlim()
        axes["tf"].hlines(freqmin, xmin, xmax, color="green", lw=2)
        axes["tf"].hlines(freqmax, xmin, xmax, color="red", lw=2)
        axes["tf"].text(xmax - (0.02 * (xmax - xmin)),
                        freqmin,
                        "%.1f s" % (1.0 / freqmin),
                        color="green",
                        horizontalalignment="right", verticalalignment="top")
        axes["tf"].text(xmax - (0.02 * (xmax - xmin)),
                        freqmax,
                        "%.1f s" % (1.0 / freqmax),
                        color="red",
                        horizontalalignment="right",
                        verticalalignment="bottom")

        xmin, xmax = axes["spec"].get_xlim()
        axes["spec"].hlines(freqmin, xmin, xmax, color="green", lw=2)
        axes["spec"].hlines(freqmax, xmin, xmax, color="red", lw=2)

    plt.gcf().patch.set_alpha(0.0)
    plt.show()
コード例 #6
0
ファイル: visualization.py プロジェクト: LongyanU/LASIF
def plot_tf(data, delta, freqmin=None, freqmax=None):
    """
    Plots a time frequency representation of any time series. Right now it is
    basically limited to plotting source time functions.
    """
    npts = len(data)

    fig = plotTfr(data,
                  dt=delta,
                  fmin=1.0 / (npts * delta),
                  fmax=1.0 / (2.0 * delta),
                  show=False)

    # Get the different axes...use some kind of logic to determine which is
    # which. This is super flaky as dependent on the ObsPy version and what
    # not.
    axes = {}
    for ax in fig.axes:
        xlim = ax.get_xlim()
        ylim = ax.get_ylim()

        # Colorbar.
        if xlim == ylim:
            continue

        # Spectral axis.
        elif xlim[0] > xlim[1]:
            axes["spec"] = ax

        elif ylim[0] < 0:
            axes["time"] = ax

        else:
            axes["tf"] = ax

    fig.suptitle("Source Time Function")

    if len(axes) != 3:
        msg = "Could not plot frequency limits!"
        print msg
        plt.gcf().patch.set_alpha(0.0)
        plt.show()
        return

    axes["spec"].grid()
    axes["time"].grid()
    axes["tf"].grid()

    axes["spec"].xaxis.tick_top()
    axes["spec"].set_ylabel("Frequency [Hz]")

    axes["time"].set_xlabel("Time [s]")
    axes["time"].set_ylabel("Velocity [m/s]")

    if freqmin is not None and freqmax is not None:
        xmin, xmax = axes["tf"].get_xlim()
        axes["tf"].hlines(freqmin, xmin, xmax, color="green", lw=2)
        axes["tf"].hlines(freqmax, xmin, xmax, color="red", lw=2)
        axes["tf"].text(xmax - (0.02 * (xmax - xmin)),
                        freqmin,
                        "%.1f s" % (1.0 / freqmin),
                        color="green",
                        horizontalalignment="right",
                        verticalalignment="top")
        axes["tf"].text(xmax - (0.02 * (xmax - xmin)),
                        freqmax,
                        "%.1f s" % (1.0 / freqmax),
                        color="red",
                        horizontalalignment="right",
                        verticalalignment="bottom")

        xmin, xmax = axes["spec"].get_xlim()
        axes["spec"].hlines(freqmin, xmin, xmax, color="green", lw=2)
        axes["spec"].hlines(freqmax, xmin, xmax, color="red", lw=2)

    plt.gcf().patch.set_alpha(0.0)
    plt.show()
コード例 #7
0
import numpy as np
from obspy.signal.tf_misfit import plotTfr

# general constants
tmax = 6.
dt = 0.01
npts = int(tmax / dt + 1)
t = np.linspace(0., tmax, npts)

fmin = .5
fmax = 10

# constants for the signal
A1 = 4.
t1 = 2.
f1 = 2.
phi1 = 0.

# generate the signal
H1 = (np.sign(t - t1) + 1) / 2
st1 = A1 * (t - t1) * np.exp(-2 * (t - t1)) * \
        np.cos(2. * np.pi * f1 * (t - t1) + phi1 * np.pi) * H1

plotTfr(st1, dt=dt, fmin=fmin, fmax=fmax)