示例#1
0
 def _plotResults(self):
     """
     Plots original, filtered original and real time processed traces into
     a single plot.
     """
     # plot only if test is started manually
     if __name__ != '__main__':
         return
     # create empty stream
     st = Stream()
     st.label = self._testMethodName
     # original trace
     self.orig_trace.label = "Original Trace"
     st += self.orig_trace
     # use header information of original trace with filtered trace data
     tr = self.orig_trace.copy()
     tr.data = self.filt_trace_data
     tr.label = "Filtered original Trace"
     st += tr
     # real processed chunks
     for i, tr in enumerate(self.rt_appended_traces):
         tr.label = "RT Chunk %02d" % (i + 1)
         st += tr
     # real time processed trace
     self.rt_trace.label = "RT Trace"
     st += self.rt_trace
     st.plot(automerge=False, color='blue', equal_scale=False)
示例#2
0
 def _plot_results(self):
     """
     Plots original, filtered original and real time processed traces into
     a single plot.
     """
     # plot only if test is started manually
     if __name__ != '__main__':
         return
     # create empty stream
     st = Stream()
     st.label = self._testMethodName
     # original trace
     self.orig_trace.label = "Original Trace"
     st += self.orig_trace
     # use header information of original trace with filtered trace data
     tr = self.orig_trace.copy()
     tr.data = self.filt_trace_data
     tr.label = "Filtered original Trace"
     st += tr
     # real processed chunks
     for i, tr in enumerate(self.rt_appended_traces):
         tr.label = "RT Chunk %02d" % (i + 1)
         st += tr
     # real time processed trace
     self.rt_trace.label = "RT Trace"
     st += self.rt_trace
     st.plot(automerge=False, color='blue', equal_scale=False)
示例#3
0
def merger(noise_trace, st_events_poisson, samp_rate, delta):
    """ Merges the noise with the events """
    # Creates the stream with the noise and events
    newnoise_t_formerging = noise_trace.slice(0, (st_events_poisson[-1].stats.endtime)+100)
    seis = Stream()
    seis += newnoise_t_formerging
    seis += st_events_poisson
    figs = plt.figure(figsize=(14,5))
    seis.plot(fig = figs)
    figs.suptitle("Noise and events", fontsize = 12)
    ylab=figs.text(0.05, 0.5, 'Amplitude of signal', va='center', 
                rotation='vertical', fontsize=12)
    figs.text(0.5, 0, 'Timestamp', ha='center', fontsize=12)
    seis.merge()
    seis += st_events_poisson
    seis.merge(method = 1, interpolation_samples=-1)
    figs = plt.figure(figsize=(14,5))
    seis.plot(fig = figs)
    plt.title("Synthetic seismogram", fontsize = 12)
    ylab=figs.text(0.05, 0.5, 'Amplitude of signal', va='center', 
                rotation='vertical', fontsize=12)
    figs.text(0.5, 0, 'Timestamp', ha='center', fontsize=12)

    syn_seis = seis[0]
    syn_seis.stats.sampling_rate = samp_rate
    syn_seis.stats.delta = delta
    
    return syn_seis
示例#4
0
model_Pangles = [25]
model_Sangles = [26]

n = 0
for a in model_Pangles:
    print('P')
    stP = stP_og.copy()
    hhQ, hhL = rotate(stP[1].data, stP[2].data, a)
    t1, t2, t3 = Trace(stP[0].data, header=headerP), Trace(
        hhQ, header=headerP), Trace(hhL, header=headerP)
    stP_LQ = Stream(traces=[t1, t2, t3])
    stP_LQ[0].stats.component = 'T'
    stP_LQ[1].stats.component = 'Q'
    stP_LQ[2].stats.component = 'L'

    stP_LQ.plot(equal_scale=True)
    n += 1

#S-wave
n = 0
for a in model_Sangles:
    print('S')
    stS = stS_og.copy()
    hhQ, hhL = rotate(stS[1].data, stS[2].data, a)
    t1, t2, t3 = Trace(stS[0].data, header=headerS), Trace(
        hhQ, header=headerS), Trace(hhL, header=headerS)
    stS_LQ = Stream(traces=[t1, t2, t3])
    stS_LQ[0].stats.component = 'T'
    stS_LQ[1].stats.component = 'Q'
    stS_LQ[2].stats.component = 'L'
示例#5
0
                 mseed_storage=data_path + "waveforms/USC/",
                 stationxml_storage=data_path + "stations/")

#%% Read in a couple test waveforms
plots = False

HNx_st = Stream()
LNx_st = Stream()

# High Broad Band (H??)
HNx_st += read(data_path + "waveforms/USC/*HN*.mseed")
# Long Period (L??)
LNx_st += read(data_path + "waveforms/USC/*LN*.mseed")

if plots:
    HNx_st.plot()
    LNx_st.plot()

#%% Try to get Arias intensity ...
HNx_st = HNx_st.detrend()
LNx_st = LNx_st.detrend()

HNx_arias = get_arias(HNx_st)
LNx_arias = get_arias(LNx_st)

#%% Plot Arias
HNx_arias.plot()
LNx_arias.plot()

# ... Not what I expected ...
# Derp, needed to detrend at the very least
示例#6
0
    def plot(self):
        stream = Stream()
        stream += self.BW_obs.BW_stream.traces[0]
        # stream += self.BW_obs.S_stream.traces[1]
        # stream += self.BW_obs.S_stream.traces[2]
        #
        #
        stream += self.BW_syn.BW_stream.traces[0]
        # stream += self.BW_syn.S_stream.traces[1]
        # stream += self.BW_syn.S_stream.traces[2]
        #
        stream.plot()

        fig = plt.figure(figsize=(10, 12))
        delta = self.BW_obs.P_stream.traces[0].meta.delta
        p_time_array = np.arange(len(self.BW_obs.P_stream.traces[0].data)) * delta
        s_time_array = np.arange(len(self.BW_obs.S_stream.traces[0].data)) * delta

        start_P = int((self.BW_obs.start_P.timestamp - self.or_time.timestamp - 10) / delta)
        end_P = int((self.BW_obs.start_P.timestamp - self.or_time.timestamp + 30) / delta)

        start_S = int((self.BW_obs.start_S.timestamp - self.or_time.timestamp - 20) / delta)
        end_S = int((self.BW_obs.start_S.timestamp - self.or_time.timestamp + 100) / delta)

        ax1 = plt.subplot2grid((5, 1), (0, 0))
        plt.plot(p_time_array[start_P:end_P], self.BW_obs.P_stream.traces[0].data[start_P:end_P], 'b', label='Observed')
        plt.plot(p_time_array[start_P:end_P], self.BW_syn.P_stream.traces[0].data[start_P:end_P], 'r',
                 label='Synthetic')
        ymin, ymax = ax1.get_ylim()
        xmin, xmax = ax1.get_xlim()
        plt.text(xmax - 5, ymax / 1.7, "P-Z", fontsize=20, color='b')
        ax1.ticklabel_format(style="sci", axis='y', scilimits=(-2, 2))
        ax1.tick_params(axis='x', labelsize=18)
        ax1.tick_params(axis='y', labelsize=18)
        plt.tight_layout()
        plt.legend(loc='lower left', fontsize=15)

        ax2 = plt.subplot2grid((5, 1), (1, 0))
        plt.plot(p_time_array[start_P:end_P], self.BW_obs.P_stream.traces[1].data[start_P:end_P], 'b')
        plt.plot(p_time_array[start_P:end_P], self.BW_syn.P_stream.traces[1].data[start_P:end_P], 'r')
        ymin, ymax = ax2.get_ylim()
        xmin, xmax = ax2.get_xlim()
        plt.text(xmax - 5, ymax / 1.7, "P-R", fontsize=20, color='b')
        ax2.ticklabel_format(style="sci", axis='y', scilimits=(-2, 2))
        ax2.tick_params(axis='x', labelsize=18)
        ax2.tick_params(axis='y', labelsize=18)
        plt.tight_layout()

        ax3 = plt.subplot2grid((5, 1), (2, 0))
        plt.plot(s_time_array[start_S:end_S], self.BW_obs.S_stream.traces[0].data[start_S:end_S], 'b')
        plt.plot(s_time_array[start_S:end_S], self.BW_syn.S_stream.traces[0].data[start_S:end_S], 'r')
        ymin, ymax = ax3.get_ylim()
        xmin, xmax = ax3.get_xlim()
        plt.text(xmax - 10, ymax / 1.7, "S-Z", fontsize=20, color='b')
        ax3.ticklabel_format(style="sci", axis='y', scilimits=(-2, 2))
        ax3.tick_params(axis='x', labelsize=18)
        ax3.tick_params(axis='y', labelsize=18)
        plt.tight_layout()

        ax4 = plt.subplot2grid((5, 1), (3, 0))
        plt.plot(s_time_array[start_S:end_S], self.BW_obs.S_stream.traces[1].data[start_S:end_S], 'b')
        plt.plot(s_time_array[start_S:end_S], self.BW_syn.S_stream.traces[1].data[start_S:end_S], 'r')
        ymin, ymax = ax4.get_ylim()
        xmin, xmax = ax4.get_xlim()
        plt.text(xmax - 10, ymax / 1.7, "S-R", fontsize=20, color='b')
        ax4.ticklabel_format(style="sci", axis='y', scilimits=(-2, 2))
        ax4.tick_params(axis='x', labelsize=18)
        ax4.tick_params(axis='y', labelsize=18)
        plt.tight_layout()

        ax5 = plt.subplot2grid((5, 1), (4, 0))
        plt.plot(s_time_array[start_S:end_S], self.BW_obs.S_stream.traces[2].data[start_S:end_S], 'b')
        plt.plot(s_time_array[start_S:end_S], self.BW_syn.S_stream.traces[2].data[start_S:end_S], 'r')
        ymin, ymax = ax5.get_ylim()
        xmin, xmax = ax5.get_xlim()
        plt.text(xmax - 10, ymax / 1.9, "S-T", fontsize=20, color='b')
        ax5.ticklabel_format(style="sci", axis='y', scilimits=(-2, 2))
        ax5.tick_params(axis='x', labelsize=18)
        ax5.tick_params(axis='y', labelsize=18)
        ax5.set_xlabel(self.BW_obs.start_P.strftime('From P arrival: %Y-%m-%dT%H:%M:%S + [sec]'), fontsize=18)
        plt.tight_layout()
        # plt.show()
        plt.savefig(self.prior['save_dir'] + '/plots/%s_%i.png' % (self.prior['save_name'], self.i))
        # plt.show()
        plt.close()
    'TOK.2011.328.21.10.54.OKR07.HHN.inv',
    'TOK.2011.328.21.10.54.OKR08.HHN.inv',
    'TOK.2011.328.21.10.54.OKR09.HHN.inv',
    'TOK.2011.328.21.10.54.OKR10.HHN.inv'
]
# Earthquakes' epicenter
eq_lat = 35.565
eq_lon = -96.792

# Reading the waveforms
st = Stream()
for waveform in files:
    st += read(host + waveform)

# Calculating distance from SAC headers lat/lon
# (trace.stats.sac.stla and trace.stats.sac.stlo)
for tr in st:
    tr.stats.distance = gps2DistAzimuth(tr.stats.sac.stla, tr.stats.sac.stlo,
                                        eq_lat, eq_lon)[0]
    # Setting Network name for plot title
    tr.stats.network = 'TOK'

st.filter('bandpass', freqmin=0.1, freqmax=10)
# Plot
st.plot(type='section',
        plot_dx=20e3,
        recordlength=100,
        time_down=True,
        linewidth=.25,
        grid_linewidth=.25)
        axs.append(fig.add_axes([0.83, 0.1, 0.03, 0.8]))
        #fig, axs = plt.subplots(n_chans)
        st = Stream()
        for i, channel in enumerate(channels):
            channel_path = os.path.join(station_path, channel)
            chan = read(channel_path)
            st.append(chan[0])
            ax2 = chan.spectrogram(title='Canal: %s' % (channel),
                                   show=False,
                                   axes=axs[i],
                                   cmap=j)
        #print(ax2[0].images[0])
        #canvas = FigureCanvas(fig2)
        #image = np.fromstring(canvas.tostring_rgb(), dtype='uint8')
        #print(list(axs[0]y.get_images()))
        mappable = ax2[0].images[0]
        plt.colorbar(mappable=mappable, cax=axs[-1])
        try:
            if not path.exists(
                    os.path.join(station_path, 'seismograms_plot.png')):
                st.plot(
                    outfile=os.path.join(station_path, 'seismograms_plot.png'))
            if path.exists(os.path.join(station_path,
                                        'spectrograms_plot.png')):
                os.remove(os.path.join(station_path, 'spectrograms_plot.png'))
            plt.savefig(os.path.join(station_path, 'spectrograms_plot.png'))
        except IndexError:
            print("No data for station %s" % (station))
        plt.clf()
        plt.close()
from obspy.core.util import gps2DistAzimuth

host = 'http://examples.obspy.org/'
# Files (fmt: SAC)
files = ['TOK.2011.328.21.10.54.OKR01.HHN.inv',
'TOK.2011.328.21.10.54.OKR02.HHN.inv', 'TOK.2011.328.21.10.54.OKR03.HHN.inv',
'TOK.2011.328.21.10.54.OKR04.HHN.inv', 'TOK.2011.328.21.10.54.OKR05.HHN.inv',
'TOK.2011.328.21.10.54.OKR06.HHN.inv', 'TOK.2011.328.21.10.54.OKR07.HHN.inv',
'TOK.2011.328.21.10.54.OKR08.HHN.inv', 'TOK.2011.328.21.10.54.OKR09.HHN.inv',
'TOK.2011.328.21.10.54.OKR10.HHN.inv']
# Earthquakes' epicenter
eq_lat = 35.565
eq_lon = -96.792

# Reading the waveforms
st = Stream()
for waveform in files:
	st += read(host + waveform)

# Calculating distance from SAC headers lat/lon
# (trace.stats.sac.stla and trace.stats.sac.stlo)
for tr in st:
	tr.stats.distance = gps2DistAzimuth(tr.stats.sac.stla,
									tr.stats.sac.stlo, eq_lat, eq_lon)[0]
	# Setting Network name for plot title
	tr.stats.network = 'TOK'

st.filter('bandpass', freqmin=0.1, freqmax=10)
# Plot
st.plot(type='section', plot_dx=20e3, recordlength=100,
			time_down=True, linewidth=.25, grid_linewidth=.25)