示例#1
0
文件: api.py 项目: tensionhead/pyBOAT
    def plot_signal(self, signal, num=None, figsize=(6.5, 4.5), **pkwargs):

        '''
        Creates the signal-figure and plots the signal.
        
        Parameters
        ----------        
        signal : a sequence
        num : int
              The number of the figure to be created
        figsize : tuple
                  the size of the signal axis in inches (x,y)
        **pkwargs : keyword arguments for the matlotlib `plot`
                    call, e.g. marker='o', lw=3, color='red'
        '''

        # create plotting style dictionary from defaults
        # and potentially overwrite with the arguments of **pkwargs        
        style_dic = dict(pl.SIGNAL_STYLE, **pkwargs)
        
        if num or self.ax_signal is None:
            fig = ppl.figure(num, figsize=figsize)
            self.ax_signal = pl.mk_signal_ax(self.time_unit_label, fig=fig)

        tvec = np.arange(len(signal)) * self.dt
        self.ax_signal.plot(tvec, signal, **style_dic)

        if 'label' in style_dic:
            self.ax_signal.legend(fontsize=pl.tick_label_size, ncol=2)
            ymin, ymax = self.ax_signal.get_ylim()
            self.ax_signal.set_ylim((ymin, 1.2 * ymax))

        fig = ppl.gcf()
        # fig.subplots_adjust(bottom=0.18)
        fig.tight_layout()
示例#2
0
    def plot_envelope(self, signal, legend=False, num=None):
        '''
        Sliding window amplitude envelope
        '''

        if self.L is None:
            print('Set a window size for the sliding window first!')
            return

        if self.ax_signal is None:
            fig = ppl.figure(num, figsize=(6, 3.5))
            self.ax_signal = pl.mk_signal_ax(self.time_unit_label, fig=fig)

        tvec = np.arange(len(signal)) * self.dt
        envelope = self.get_envelope(signal, self.L)
        pl.draw_envelope(self.ax_signal, tvec, envelope)

        if legend:
            self.ax_signal.legend(fontsize=pl.label_size, ncol=3)
            ymin, ymax = self.ax_signal.get_ylim()
            self.ax_signal.set_ylim((ymin, 1.3 * ymax))

        fig = ppl.gcf()
        fig.subplots_adjust(bottom=0.18)
        fig.tight_layout()
示例#3
0
    def plot_signal(self, signal, legend=False, num=None):

        if self.ax_signal is None:
            self.ax_signal = pl.mk_signal_ax(self.time_unit_label)

        tvec = np.arange(len(signal)) * self.dt
        pl.draw_signal(self.ax_signal, tvec, signal)

        if legend:
            self.ax_signal.legend(fontsize=pl.label_size, ncol=3)
            ymin, ymax = self.ax_signal.get_ylim()
            self.ax_signal.set_ylim((ymin, 1.3 * ymax))

        fig = ppl.gcf()
        fig.subplots_adjust(bottom=0.18)
        fig.tight_layout()
示例#4
0
    def plot_detrended(self, signal, legend=False, num=None):

        if self.ax_signal is None:
            fig = ppl.figure(num, figsize=(6, 3.5))
            self.ax_signal = pl.mk_signal_ax(self.time_unit_label, fig=fig)

        tvec = np.arange(len(signal)) * self.dt
        trend = self.get_trend(signal)
        pl.draw_detrended(self.ax_signal, tvec, signal - trend)

        if legend:
            # detrended lives on 2nd axis :/
            pass

        fig = ppl.gcf()
        fig.subplots_adjust(bottom=0.18)
        fig.tight_layout()
示例#5
0
    def doPlot(self):

        '''
        Checks the checkboxes for trend and envelope..
        '''

        # update raw_signal and tvec
        succ = self.vector_prep(self.signal_id)  # error handling done here

        if not succ:
            return False

        if self.debug:
            print(
                "called Plotting [raw] [trend] [detrended] [envelope]",
                self.cb_raw.isChecked(),
                self.cb_trend.isChecked(),
                self.cb_detrend.isChecked(),
                self.cb_envelope.isChecked(),
            )

        # check if trend is needed
        if self.cb_trend.isChecked() or self.cb_detrend.isChecked():
            trend = self.calc_trend()
            if trend is None:
                return
        else:
            trend = None

        # envelope calculation
        if self.cb_envelope.isChecked():
            envelope = self.calc_envelope()
            if envelope is None:
                return

        else:
            envelope = None

        self.tsCanvas.fig1.clf()

        ax1 = pl.mk_signal_ax(self.time_unit, fig=self.tsCanvas.fig1)
        self.tsCanvas.fig1.add_axes(ax1)

        if self.debug:
            print(
                f"plotting signal and trend with {self.tvec[:10]}, {self.raw_signal[:10]}"
            )

        if self.cb_raw.isChecked():
            pl.draw_signal(ax1, time_vector=self.tvec, signal=self.raw_signal)

        if trend is not None and self.cb_trend.isChecked():
            pl.draw_trend(ax1, time_vector=self.tvec, trend=trend)

        if trend is not None and self.cb_detrend.isChecked():
            ax2 = pl.draw_detrended(
                ax1, time_vector=self.tvec, detrended=self.raw_signal - trend
            )
            ax2.legend(fontsize=pl.tick_label_size)
        if envelope is not None and not self.cb_detrend.isChecked():
            pl.draw_envelope(ax1, time_vector=self.tvec, envelope=envelope)

        # plot on detrended axis
        if envelope is not None and self.cb_detrend.isChecked():
            pl.draw_envelope(ax2, time_vector=self.tvec, envelope=envelope)
            ax2.legend(fontsize=pl.tick_label_size)

        self.tsCanvas.fig1.subplots_adjust(bottom=0.15, left=0.15, right=0.85)

        # add a simple legend
        ax1.legend(fontsize=pl.tick_label_size)

        self.tsCanvas.draw()
        self.tsCanvas.show()
示例#6
0
                                 alpha=alpha)

# add slower oscillatory trend
signal2 = ssg.create_chirp(T1=70 / dt, T2=70 / dt, Nt=Nt)

# linear superposition
signal = signal1 + 1.5 * signal2

# --- calculate trend ---

trend = pyboat.sinc_smooth(signal, T_cut_off, dt)
detr_signal = signal - trend

# plot the signal/trend
tvec = np.arange(len(signal)) * dt
ax = pl.mk_signal_ax(time_unit='s')
pl.draw_signal(ax, tvec, signal)
# pl.draw_detrended(ax, tvec, signal)
pl.draw_trend(ax, tvec, trend)
ppl.legend(ncol=2)
ppl.tight_layout()

# --- compute spectrum on the original signal ---
modulus, wlet = pyboat.compute_spectrum(signal, dt, periods)

# plot spectrum and ridge
ax_sig, ax_spec = pl.mk_signal_modulus_ax(time_unit)
pl.plot_signal_modulus((ax_sig, ax_spec), tvec, signal, modulus, periods)

# --- compute spectrum on the detrended signal ---
modulus, wlet = pyboat.compute_spectrum(detr_signal, dt, periods)
示例#7
0
    def doPlot(self):

        if self.raw_signal is None:
            self.NoSignal = MessageWindow("Please create a signal first!",
                                          "No Signal")

        if self.debug:
            print(
                "called Plotting [raw] [trend] [detrended] [envelope]",
                self.cb_raw.isChecked(),
                self.cb_trend.isChecked(),
                self.cb_detrend.isChecked(),
                self.cb_envelope.isChecked(),
            )

        # check if trend is needed
        if self.T_c and (self.cb_trend.isChecked()
                         or self.cb_detrend.isChecked()):
            if self.debug:
                print("Calculating trend with T_c = ", self.T_c)
            trend = self.calc_trend()

        else:
            trend = None

        # envelope calculation
        if self.L and self.cb_envelope.isChecked():
            if self.debug:
                print("Calculating envelope with L = ", self.L)
            envelope = self.calc_envelope()

        else:
            envelope = None

        self.tsCanvas.fig1.clf()

        ax1 = pl.mk_signal_ax(self.time_unit, fig=self.tsCanvas.fig1)
        self.tsCanvas.fig1.add_axes(ax1)

        if self.debug:
            print(
                f"plotting signal and trend with {self.tvec[:10]}, {self.raw_signal[:10]}"
            )

        if self.cb_raw.isChecked():
            pl.draw_signal(ax1, time_vector=self.tvec, signal=self.raw_signal)

        if trend is not None and self.cb_trend.isChecked():
            pl.draw_trend(ax1, time_vector=self.tvec, trend=trend)

        if trend is not None and self.cb_detrend.isChecked():
            ax2 = pl.draw_detrended(ax1,
                                    time_vector=self.tvec,
                                    detrended=self.raw_signal - trend)
            ax2.legend(fontsize=pl.tick_label_size)
        if envelope is not None and not self.cb_detrend.isChecked():
            pl.draw_envelope(ax1, time_vector=self.tvec, envelope=envelope)

        # plot on detrended axis
        if envelope is not None and self.cb_detrend.isChecked():
            pl.draw_envelope(ax2, time_vector=self.tvec, envelope=envelope)
            ax2.legend(fontsize=pl.tick_label_size)
        self.tsCanvas.fig1.subplots_adjust(bottom=0.15, left=0.15, right=0.85)
        # add a simple legend
        ax1.legend(fontsize=pl.tick_label_size)

        self.tsCanvas.draw()
        self.tsCanvas.show()