示例#1
0
t = np.linspace(0., tmax, npts)

fmin = .5
fmax = 10
nf = 100

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

# amplitude error
amp_fac = 1.1

# 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

# reference signal
st2_1 = st1.copy()
st2_2 = st1.copy() * 5.
st2 = np.c_[st2_1, st2_2].T
print(st2.shape)

# signal with amplitude error
st1a = st2 * amp_fac

plotTfMisfits(st1a, st2, dt=dt, fmin=fmin, fmax=fmax)
    def _process(self, inputs):
        self.log("In process Misfit")
        ip = inputs["input"]

        syn = ip["synthetic_trace"]
        obs = ip["data_trace"]
        param = ip["parameters"]

        self.log("Starting misfit %s, freqmin %s freqmax %s" %
                 (obs.id, param["min_period"], param["max_period"]))
        nf = 100

        # Plot.
        fig = plotTfMisfits(
            obs.data, syn.data,
            dt=obs.stats.delta,
            nf=nf,
            fmin=1.0 / param["max_period"],
            fmax=1.0 / param["min_period"],
            w0=param["wavelet_parameter"],
            show=False)

        # Calculate misfit values again.
        pm_inf = pm(
            obs.data, syn.data,
            dt=obs.stats.delta,
            nf=nf,
            fmin=1.0 / param["max_period"],
            fmax=1.0 / param["min_period"],
            w0=param["wavelet_parameter"])

        em_inf = em(
            obs.data, syn.data,
            dt=obs.stats.delta,
            nf=nf,
            fmin=1.0 / param["max_period"],
            fmax=1.0 / param["min_period"],
            w0=param["wavelet_parameter"])
        data = ip["data_trace"]
        station_id = "%s.%s" % (data.stats.network,
                                data.stats.station)
        component = data.stats.channel[-1]

        # Metadata for Alessandro!
        meta = [{
            "type": "time_frequency_misfit",
            "station_id": station_id,
            "component": component,
            "phase_misfit": pm_inf,
            "envelope_misfit": em_inf
        }]

     #   self.write("misfit_values", {
     #       "record_type": "time_frequency_misfit",
     #       "output_folder": ip["output_folder"],
     #       "station_id": station_id,
     #       "component": component,
     #       "phase_misfit": pm_inf,
     #       "envelope_misfit": em_inf},metadata=metadata)
        
        fig.suptitle("Component:" + component, fontsize=15)
        with io.BytesIO() as buf:
            fig.savefig(buf)
            buf.seek(0, 0)
            # Not Python 3 compatible but who cares.
            image_string = buf.read()
        plt.close(fig)
        image_type = "time_frequency_misfit"
        self.write(
            "image",
            ({"image_string": image_string, "component": component,
              "output_folder": ip["output_folder"]},
             image_type, station_id),metadata=meta)
fmin = 0.5
fmax = 10
nf = 100

# constants for the signal
A1 = 4.0
t1 = 2.0
f1 = 2.0
phi1 = 0.0

# amplitude and phase error
amp_fac = 1.1

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

ste = 0.001 * A1 * np.exp(-(10 * (t - 2.0 * t1)) ** 2)

# reference signal
st2 = st1.copy()

# signal with amplitude error + small additional pulse aftert 4 seconds
st1a = st1 * amp_fac + ste

plotTfMisfits(st1a, st2, dt=dt, fmin=fmin, fmax=fmax, show=False)
plotTfMisfits(st1a, st2, dt=dt, fmin=fmin, fmax=fmax, norm="local", clim=0.15, show=False)

plt.show()
# constants for the signal
A1 = 4.
t1 = 2.
f1 = 2.
phi1 = 0.

# amplitude and phase error
phase_shift = 0.1
amp_fac = 1.1

# 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

# reference signal
st2 = st1.copy()

# generate analytical signal (hilbert transform) and add phase shift
st1p = hilbert(st1)
st1p = np.real(np.abs(st1p) *
               np.exp((np.angle(st1p) + phase_shift * np.pi) * 1j))

# signal with amplitude error
st1a = st1 * amp_fac

plotTfMisfits(st1a, st2, dt=dt, fmin=fmin, fmax=fmax, show=False)
plotTfMisfits(st1p, st2, dt=dt, fmin=fmin, fmax=fmax, show=False)

plt.show()
f1 = 2.
phi1 = 0.

# amplitude and phase error
amp_fac = 1.1

# 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

ste = 0.001 * A1 * np.exp(-(10 * (t - 2. * t1))**2)

# reference signal
st2 = st1.copy()

# signal with amplitude error + small additional pulse aftert 4 seconds
st1a = st1 * amp_fac + ste

plotTfMisfits(st1a, st2, dt=dt, fmin=fmin, fmax=fmax, show=False)
plotTfMisfits(st1a,
              st2,
              dt=dt,
              fmin=fmin,
              fmax=fmax,
              norm='local',
              clim=0.15,
              show=False)

plt.show()
示例#6
0
# constants for the signal
A1 = 4.
t1 = 2.
f1 = 2.
phi1 = 0.

# amplitude and phase error
phase_shift = 0.1
amp_fac = 1.1

# 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

# reference signal
st2 = st1.copy()

# generate analytical signal (hilbert transform) and add phase shift
st1p = hilbert(st1)
st1p = np.real(
    np.abs(st1p) * np.exp((np.angle(st1p) + phase_shift * np.pi) * 1j))

# signal with amplitude error
st1a = st1 * amp_fac

plotTfMisfits(st1a, st2, dt=dt, fmin=fmin, fmax=fmax, show=False)
plotTfMisfits(st1p, st2, dt=dt, fmin=fmin, fmax=fmax, show=False)

plt.show()