コード例 #1
0
    def plot_cwt_spectrogram(self, canvas: MatplotlibCanvas):
        tr = ObspyUtil.get_tracer_from_file(self.file_selector.file_path)
        ts, te = self.get_time_window()
        tr.trim(starttime=ts, endtime=te)
        tr.detrend(type="demean")
        fs = tr.stats.sampling_rate
        f_min = 1. / self.spectrum_box.win_bind.value if self.filter.min_freq == 0 else self.filter.min_freq
        f_max = self.filter.max_freq
        ObspyUtil.filter_trace(tr, self.filter.filter_value, f_min, f_max)
        nf = 40
        tt = int(self.spectrum_box.win_bind.value *
                 self.tracer_stats.Sampling_rate)
        wmin = self.spectrum_box.w1_bind.value
        wmax = self.spectrum_box.w2_bind.value
        npts = len(tr.data)
        [ba, nConv, frex,
         half_wave] = ccwt_ba_fast(npts, self.tracer_stats.Sampling_rate,
                                   f_min, f_max, wmin, wmax, tt, nf)
        cf, sc, scalogram = cwt_fast(tr.data, ba, nConv, frex, half_wave, fs)
        #scalogram = ccwt(tr.data, self.tracer_stats.Sampling_rate, f_min, f_max, wmin, wmax, tt, nf)

        scalogram = np.abs(scalogram)**2

        t = np.linspace(0, self.tracer_stats.Delta * npts, npts)
        scalogram2 = 10 * (np.log10(scalogram / np.max(scalogram)))
        x, y = np.meshgrid(t, np.linspace(f_min, f_max, scalogram2.shape[0]))

        max_cwt = np.max(scalogram2)
        min_cwt = np.min(scalogram2)
        canvas.plot(t[0:len(t) - 1],
                    cf,
                    0,
                    clear_plot=False,
                    is_twinx=True,
                    color="red",
                    linewidth=0.5)

        norm = Normalize(vmin=min_cwt, vmax=max_cwt)
        canvas.plot_contour(x,
                            y,
                            scalogram2,
                            axes_index=1,
                            clabel="Power [dB]",
                            levels=100,
                            cmap=plt.get_cmap("jet"),
                            norm=norm)
        canvas.set_xlabel(1, "Time (s)")
コード例 #2
0
 def trace(self):
     return ObspyUtil.get_tracer_from_file(self.file_selector.file_path)