Beispiel #1
0
    def draw_ridge(self):
        """ makes also the ridge_data !! """

        if not self._has_ridge:

            msgBox = QMessageBox()
            msgBox.setWindowTitle("No Ridge")
            msgBox.setText("Do a ridge detection first!")
            msgBox.exec()

        ridge_data = core.eval_ridge(
            self.ridge,
            self.wlet,
            self.signal,
            self.periods,
            self.tvec,
            power_thresh=self.power_thresh,
            smoothing_wsize=self.rsmoothing,
        )

        # plot the ridge
        ax_spec = self.wCanvas.fig.axes[1]  # the spectrum

        # already has a plotted ridge
        if ax_spec.lines:
            ax_spec.lines = []  # remove old ridge line
            self.cb_coi.setCheckState(0)  # remove COI

        pl.draw_Wavelet_ridge(ax_spec, ridge_data, marker_size=1.5)

        # refresh the canvas
        self.wCanvas.draw()

        self.ridge_data = ridge_data
Beispiel #2
0
    def draw_ridge(self):
        ''' makes also the ridge_data !! '''

        if not self._has_ridge:
            self.e = MessageWindow('Run a ridge detection first!', 'No Ridge')
            return

        ridge_data = core.eval_ridge(self.ridge,
                                     self.wlet,
                                     self.signal,
                                     self.periods,
                                     self.tvec,
                                     power_thresh=self.power_thresh,
                                     smoothing_wsize=self.rsmoothing)

        # plot the ridge
        ax_spec = self.wCanvas.fig.axes[1]  # the spectrum

        # already has a plotted ridge
        if ax_spec.lines:
            ax_spec.lines = []  # remove old ridge line
            self.cb_coi.setCheckState(0)  # remove COI

        pl.draw_Wavelet_ridge(ax_spec, ridge_data, marker_size=1.5)

        # refresh the canvas
        self.wCanvas.draw()

        self.ridge_data = ridge_data
Beispiel #3
0
    def draw_Ridge(self):

        if not self._has_ridge:
            print("Can't draw ridge, need to do a ridge detection first!")
            return

        if not self.ax_spec:
            print("Can't draw ridge, plot the spectrum first!")
            return

        pl.draw_Wavelet_ridge(self.ax_spec, self.ridge_data)
Beispiel #4
0
    def draw_Ridge(self, marker_size=1.5):

        if self.ridge_data is None:
            logger.warning("Can't draw ridge, need to do a ridge detection first!")
            return

        if self.transform is None:
            logger.warning("Can't draw ridge, plot the spectrum first!")
            return

        if self.ax_spec is None:
            logger.warning("No spectrum plotted, can't draw ridge!")
            
        pl.draw_Wavelet_ridge(self.ax_spec, self.ridge_data, marker_size)
# 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)

# get maximum ridge
ridge_ys = pyboat.get_maxRidge_ys(modulus)

# evaluate along the ridge
ridge_results = pyboat.eval_ridge(ridge_ys, wlet, signal, periods, tvec)

# plot spectrum and ridge
ax_sig2, ax_spec2 = pl.mk_signal_modulus_ax(time_unit)

pl.plot_signal_modulus((ax_sig2, ax_spec2), tvec, signal, modulus, periods)
pl.draw_Wavelet_ridge(ax_spec2, ridge_results)
ppl.tight_layout()

# plot readout
pl.plot_readout(ridge_results)
Beispiel #6
0
    def do_the_loop(self):
        '''
        Uses the explicitly parsed self.wlet_pars 
        to control signal analysis settings.

        Takes general analysis Parameters

        self.parentDV.dt
        self.parentDV.time_unit

        and the DataFrame

        self.parentDV.df

        from the parent DataViewer.
        Reads additional settings from this Batch Process Window.

        '''

        if self.export_options.isChecked():
            OutPath = self.get_OutPath()
            if OutPath is None:
                return

        periods = np.linspace(self.wlet_pars['T_min'], self.wlet_pars['T_max'],
                              self.wlet_pars['step_num'])

        # retrieve batch settings
        power_thresh = self.get_thresh()
        rsmooth = self.get_ridge_smooth()

        ridge_results = {}
        for i, signal_id in enumerate(self.parentDV.df):

            # log to terminal
            print(f"processing {signal_id}..")

            # sets parentDV.raw_signal and parentDV.tvec
            succ = self.parentDV.vector_prep(signal_id)
            # ui silently passes over..
            if not succ:
                print(f"Can't process signal {signal_id}..")
                continue

            # detrend?!
            if self.parentDV.cb_use_detrended.isChecked():
                trend = self.parentDV.calc_trend()
                signal = self.parentDV.raw_signal - trend
            else:
                signal = self.parentDV.raw_signal

            # amplitude normalization?
            if self.parentDV.cb_use_envelope.isChecked():
                if self.debug:
                    print('Calculating envelope with L=', self.wlet_pars['L'])
                signal = pyboat.normalize_with_envelope(
                    signal, self.wlet_pars['L'], self.parentDV.dt)

            # compute the spectrum
            modulus, wlet = pyboat.compute_spectrum(signal, self.parentDV.dt,
                                                    periods)
            # get maximum ridge
            ridge = pyboat.get_maxRidge_ys(modulus)
            # generate time vector
            tvec = np.arange(len(signal)) * self.parentDV.dt
            # evaluate along the ridge
            ridge_data = pyboat.eval_ridge(ridge,
                                           wlet,
                                           signal,
                                           periods,
                                           tvec,
                                           power_thresh,
                                           smoothing_wsize=rsmooth)
            ridge_results[signal_id] = (ridge_data)

            # -- Save out individual results --

            if self.cb_specs.isChecked():
                # plot spectrum and ridge
                ax_sig, ax_spec = pl.mk_signal_modulus_ax(
                    self.parentDV.time_unit)
                pl.plot_signal_modulus((ax_sig, ax_spec),
                                       tvec,
                                       signal,
                                       modulus,
                                       periods,
                                       p_max=self.wlet_pars['p_max'])
                pl.draw_Wavelet_ridge(ax_spec, ridge_data)
                plt.tight_layout()
                fname = f'{OutPath}/{signal_id}_wspec.png'
                if self.debug:
                    print(f'Plotting and saving {signal_id} to {fname}')
                plt.savefig(fname)
                plt.close()

            if self.cb_readout_plots.isChecked():
                pl.plot_readout(ridge_data)
                fname = f'{OutPath}/{signal_id}_readout.png'
                if self.debug:
                    print(f'Plotting and saving {signal_id} to {fname}')
                plt.savefig(fname)
                plt.close()

            if self.cb_readout.isChecked():
                fname = f'{OutPath}/{signal_id}_readout.csv'
                if self.debug:
                    print(f'Saving ridge reatout to {fname}')
                ridge_data.to_csv(fname,
                                  sep=',',
                                  float_format='%.3f',
                                  index=False)

            self.progress.setValue(i)

        return ridge_results
Beispiel #7
0
    def do_the_loop(self):
        '''
        Uses the explicitly parsed self.wlet_pars 
        to control signal analysis settings.

        Takes general analysis Parameters

        self.parentDV.dt
        self.parentDV.time_unit

        and the DataFrame

        self.parentDV.df

        from the parent DataViewer.
        Reads additional settings from this Batch Process Window.

        '''

        EmptyRidge = 0

        if self.export_options.isChecked():
            OutPath = self.get_OutPath()
            if OutPath is None:
                return

        periods = np.linspace(self.wlet_pars['T_min'], self.wlet_pars['T_max'],
                              self.wlet_pars['step_num'])

        # retrieve batch settings
        power_thresh = self.get_thresh()
        rsmooth = self.get_ridge_smooth()

        # results get stored here
        ridge_results = {}
        df_fouriers = pd.DataFrame(index=periods)
        df_fouriers.index.name = 'period'

        for i, signal_id in enumerate(self.parentDV.df):

            # log to terminal
            print(f"processing {signal_id}..")

            # sets parentDV.raw_signal and parentDV.tvec
            succ = self.parentDV.vector_prep(signal_id)
            # ui silently passes over..
            if not succ:
                print(f"Can't process signal {signal_id}..")
                continue

            # detrend?!
            if self.parentDV.cb_use_detrended.isChecked():
                trend = self.parentDV.calc_trend()
                signal = self.parentDV.raw_signal - trend
            else:
                signal = self.parentDV.raw_signal

            # amplitude normalization?
            if self.parentDV.cb_use_envelope.isChecked():
                if self.debug:
                    print('Calculating envelope with L=', self.wlet_pars['L'])
                signal = pyboat.normalize_with_envelope(
                    signal, self.wlet_pars['L'], self.parentDV.dt)

            # compute the spectrum
            modulus, wlet = pyboat.compute_spectrum(signal, self.parentDV.dt,
                                                    periods)
            # get maximum ridge
            ridge = pyboat.get_maxRidge_ys(modulus)
            # generate time vector
            tvec = np.arange(len(signal)) * self.parentDV.dt
            # evaluate along the ridge
            ridge_data = pyboat.eval_ridge(ridge,
                                           wlet,
                                           signal,
                                           periods,
                                           tvec,
                                           power_thresh,
                                           smoothing_wsize=rsmooth)

            # from ridge thresholding..
            if ridge_data.empty:
                EmptyRidge += 1
            else:
                ridge_results[signal_id] = ridge_data

            # time average the spectrum, all have shape len(periods)!
            averaged_Wspec = np.mean(modulus, axis=1)
            df_fouriers[signal_id] = averaged_Wspec

            # -- Save out individual results --

            if self.cb_specs.isChecked():

                # plot spectrum and ridge
                ax_sig, ax_spec = pl.mk_signal_modulus_ax(
                    self.parentDV.time_unit)
                pl.plot_signal_modulus((ax_sig, ax_spec),
                                       tvec,
                                       signal,
                                       modulus,
                                       periods,
                                       p_max=self.wlet_pars['p_max'])
                pl.draw_Wavelet_ridge(ax_spec, ridge_data)
                plt.tight_layout()
                fname = os.path.join(OutPath, f'{signal_id}_wspec.png')
                if self.debug:
                    print(
                        f'Plotting and saving spectrum {signal_id} to {fname}')
                plt.savefig(fname, dpi=DPI)
                plt.close()

            if self.cb_specs_noridge.isChecked():

                # plot spectrum without ridge
                ax_sig, ax_spec = pl.mk_signal_modulus_ax(
                    self.parentDV.time_unit)
                pl.plot_signal_modulus((ax_sig, ax_spec),
                                       tvec,
                                       signal,
                                       modulus,
                                       periods,
                                       p_max=self.wlet_pars['p_max'])
                plt.tight_layout()
                fname = os.path.join(OutPath, f'{signal_id}_wspecNR.png')
                if self.debug:
                    print(
                        f'Plotting and saving spectrum {signal_id} to {fname}')
                plt.savefig(fname, dpi=DPI)
                plt.close()

            if self.cb_readout_plots.isChecked() and not ridge_data.empty:

                pl.plot_readout(ridge_data)
                fname = os.path.join(OutPath, f'{signal_id}_readout.png')
                if self.debug:
                    print(f'Plotting and saving {signal_id} to {fname}')
                plt.savefig(fname, dpi=DPI)
                plt.close()

            if self.cb_readout.isChecked() and not ridge_data.empty:

                fname = os.path.join(OutPath, f'{signal_id}_readout.csv')
                if self.debug:
                    print(f'Saving ridge reatout to {fname}')
                ridge_data.to_csv(fname,
                                  sep=',',
                                  float_format='%.3f',
                                  index=False)

            self.progress.setValue(i)

        if EmptyRidge > 0:
            self.NoRidges = MessageWindow(
                f'{EmptyRidge} ridge readouts entirely below threshold..',
                'Discarded ridges')

        return ridge_results, df_fouriers
Beispiel #8
0
    def do_the_loop(self):
        """
        Uses the explicitly parsed self.wlet_pars 
        to control signal analysis settings.

        Takes general analysis Parameters

        self.parentDV.dt
        self.parentDV.time_unit

        and the DataFrame

        self.parentDV.df

        from the parent DataViewer.
        Reads additional settings from this Batch Process Window.

        """

        EmptyRidge = 0

        if self.export_options.isChecked():
            OutPath = self.get_OutPath()
            if OutPath is None:
                return

        periods = np.linspace(self.wlet_pars["Tmin"], self.wlet_pars["Tmax"],
                              self.wlet_pars["step_num"])

        # retrieve batch settings
        power_thresh = self.get_thresh()
        rsmooth = self.get_ridge_smooth()

        # results get stored here
        ridge_results = {}
        df_fouriers = pd.DataFrame(index=periods)
        df_fouriers.index.name = "period"

        for i, signal_id in enumerate(self.parentDV.df):

            # log to terminal
            print(f"processing {signal_id}..")

            # sets parentDV.raw_signal and parentDV.tvec
            succ = self.parentDV.vector_prep(signal_id)
            # ui silently passes over..
            if not succ:
                print(f"Warning, can't process signal {signal_id}..")
                continue

            # detrend?!
            if self.parentDV.cb_use_detrended.isChecked():
                trend = self.parentDV.calc_trend()
                signal = self.parentDV.raw_signal - trend
            else:
                signal = self.parentDV.raw_signal

            # amplitude normalization?
            if self.parentDV.cb_use_envelope.isChecked():
                if self.debug:
                    print("Calculating envelope with L=",
                          self.wlet_pars["window_size"])
                signal = pyboat.normalize_with_envelope(
                    signal, self.wlet_pars["window_size"], self.parentDV.dt)

            # compute the spectrum
            modulus, wlet = pyboat.compute_spectrum(signal, self.parentDV.dt,
                                                    periods)
            # get maximum ridge
            ridge = pyboat.get_maxRidge_ys(modulus)
            # generate time vector
            tvec = np.arange(len(signal)) * self.parentDV.dt
            # evaluate along the ridge
            ridge_data = pyboat.eval_ridge(
                ridge,
                wlet,
                signal,
                periods,
                tvec,
                power_thresh,
                smoothing_wsize=rsmooth,
            )

            # from ridge thresholding..
            if ridge_data.empty:
                EmptyRidge += 1
            else:
                ridge_results[signal_id] = ridge_data

            # time average the spectrum, all have shape len(periods)!
            averaged_Wspec = np.mean(modulus, axis=1)
            df_fouriers[signal_id] = averaged_Wspec

            # -- Save out individual results --
            settings = QSettings()
            float_format = settings.value('float_format', '%.3f')
            graphics_format = settings.value('graphics_format', 'png')

            exbox_checked = self.export_options.isChecked()

            if exbox_checked and self.cb_filtered_sigs.isChecked():

                signal_df = pd.DataFrame()
                signal_df['signal'] = signal
                signal_df.index = tvec
                signal_df.index.name = 'time'

                fname = os.path.join(OutPath, f"{signal_id}_filtered.csv")
                if self.debug:
                    print(f"Saving filtered signal to {fname}")
                signal_df.to_csv(fname,
                                 sep=",",
                                 float_format=float_format,
                                 index=True,
                                 header=True)

            if exbox_checked and self.cb_specs.isChecked():

                # plot spectrum and ridge
                ax_sig, ax_spec = pl.mk_signal_modulus_ax(
                    self.parentDV.time_unit)
                pl.plot_signal_modulus(
                    (ax_sig, ax_spec),
                    tvec,
                    signal,
                    modulus,
                    periods,
                    p_max=self.wlet_pars["pow_max"],
                )
                pl.draw_Wavelet_ridge(ax_spec, ridge_data)
                plt.tight_layout()
                fname = os.path.join(OutPath,
                                     f"{signal_id}_wspec.{graphics_format}")
                if self.debug:
                    print(
                        f"Plotting and saving spectrum {signal_id} to {fname}")
                plt.savefig(fname, dpi=DPI)
                plt.close()

            if exbox_checked and self.cb_specs_noridge.isChecked():

                # plot spectrum without ridge
                ax_sig, ax_spec = pl.mk_signal_modulus_ax(
                    self.parentDV.time_unit)
                pl.plot_signal_modulus(
                    (ax_sig, ax_spec),
                    tvec,
                    signal,
                    modulus,
                    periods,
                    p_max=self.wlet_pars["pow_max"],
                )
                plt.tight_layout()
                fname = os.path.join(OutPath,
                                     f"{signal_id}_wspecNR.{graphics_format}")
                if self.debug:
                    print(
                        f"Plotting and saving spectrum {signal_id} to {fname}")
                plt.savefig(fname, dpi=DPI)
                plt.close()

            if exbox_checked and self.cb_readout_plots.isChecked(
            ) and not ridge_data.empty:

                pl.plot_readout(ridge_data)
                fname = os.path.join(OutPath,
                                     f"{signal_id}_readout.{graphics_format}")
                if self.debug:
                    print(f"Plotting and saving {signal_id} to {fname}")
                plt.savefig(fname, dpi=DPI)
                plt.close()

            if exbox_checked and self.cb_readout.isChecked(
            ) and not ridge_data.empty:

                fname = os.path.join(OutPath, f"{signal_id}_readout.csv")
                if self.debug:
                    print(f"Saving ridge readout to {fname}")
                ridge_data.to_csv(fname,
                                  sep=",",
                                  float_format=float_format,
                                  index=False)

            self.progress.setValue(i)

        if EmptyRidge > 0:

            msg = f"{EmptyRidge} ridge readouts entirely below threshold.."
            msgBox = QMessageBox()
            msgBox.setWindowTitle("Discarded Ridges")
            msgBox.setText(msg)
            msgBox.exec()

        return ridge_results, df_fouriers