示例#1
0
    def run_fourier_ana(self):
        if not np.any(self.raw_signal):
            self.NoSignalSelected = MessageWindow(
                "Please select a signal first!", "No Signal")
            return False

        # shift new analyser windows
        self.w_position += 20

        if self.cb_use_detrended2.isChecked():
            trend = self.calc_trend()
            signal = self.raw_signal - trend
        else:
            signal = self.raw_signal

        if self.cb_use_envelope2.isChecked():
            L = self.get_L(self.L_edit)
            signal = pyboat.normalize_with_envelope(signal, L, self.dt)

        # periods or frequencies?
        if self.cb_FourierT.isChecked():
            show_T = False
        else:
            show_T = True

        self.anaWindows[self.w_position] = FourierAnalyzer(
            signal=signal,
            dt=self.dt,
            signal_id=self.signal_id,
            position=self.w_position,
            time_unit=self.time_unit,
            show_T=show_T,
        )
示例#2
0
    def run_fourier_ana(self):
        if not np.any(self.raw_signal):
            self.NoSignalSelected = MessageWindow(
                "Please select a signal first!", "No Signal")
            return False

        # shift new analyser windows
        self.w_position += 20

        if self.cb_use_detrended2.isChecked() and not self.T_c:
            self.NoTrend = MessageWindow(
                "Detrending not set, can not use detrended signal!",
                "No Trend")
            return

        elif self.cb_use_detrended2.isChecked():
            trend = self.calc_trend()
            signal = self.raw_signal - trend
        else:
            signal = self.raw_signal

        if self.cb_use_envelope2.isChecked() and not self.L:
            self.NoTrend = MessageWindow(
                "Envelope parameter not set,\n" +
                "specify a sliding window size!",
                "No Envelope",
            )
            return

        elif self.cb_use_envelope2.isChecked():
            signal = pyboat.normalize_with_envelope(signal, self.L)

        # periods or frequencies?
        if self.cb_FourierT.isChecked():
            show_T = False
        else:
            show_T = True

        self.anaWindows[self.w_position] = FourierAnalyzer(
            signal=signal,
            dt=self.dt,
            signal_id="Synthetic Signal",
            position=self.w_position,
            time_unit=self.time_unit,
            show_T=show_T,
        )
示例#3
0
    def run_wavelet_ana(self):
        """ run the Wavelet Analysis """

        if not np.any(self.raw_signal):

            msgBox = QMessageBox()
            msgBox.setWindowTitle("No Signal")
            msgBox.setText("Please select a signal first!")
            msgBox.exec()

            return False

        wlet_pars = self.set_wlet_pars()  # Error handling done there
        if not wlet_pars:
            if self.debug:
                print("Wavelet parameters could not be set!")
            return False

        if self.cb_use_detrended.isChecked():
            trend = self.calc_trend()
            signal = self.raw_signal - trend
        else:
            signal = self.raw_signal

        if self.cb_use_envelope.isChecked():
            window_size = self.get_wsize(self.wsize_edit)
            signal = pyboat.normalize_with_envelope(signal,
                                                    window_size,
                                                    dt=self.dt)

        self.w_position += 20

        self.anaWindows[self.w_position] = WaveletAnalyzer(
            signal=signal,
            dt=self.dt,
            Tmin=wlet_pars['Tmin'],
            Tmax=wlet_pars['Tmax'],
            pow_max=wlet_pars['pow_max'],
            step_num=wlet_pars['step_num'],
            position=self.w_position,
            signal_id=self.signal_id,
            time_unit=self.time_unit,
            DEBUG=self.debug,
        )
示例#4
0
    def run_wavelet_ana(self):
        """ run the Wavelet Analysis on the synthetic signal """

        if not np.any(self.raw_signal):
            self.NoSignalSelected = MessageWindow(
                "Please create a signal first!", "No Signal")
            return False

        wlet_pars = self.set_wlet_pars()  # Error handling done there
        if not wlet_pars:
            if self.debug:
                print("Wavelet parameters could not be set!")
            return False

        if self.cb_use_detrended.isChecked():
            trend = self.calc_trend()
            signal = self.raw_signal - trend
        else:
            signal = self.raw_signal

        if self.cb_use_envelope.isChecked():
            L = self.get_L(self.L_edit)
            signal = pyboat.normalize_with_envelope(signal, L, dt=self.dt)

        self.w_position += 20

        self.anaWindows[self.w_position] = WaveletAnalyzer(
            signal=signal,
            dt=self.dt,
            T_min=wlet_pars['T_min'],
            T_max=wlet_pars['T_max'],
            p_max=wlet_pars['p_max'],
            step_num=wlet_pars['step_num'],
            position=self.w_position,
            signal_id='Synthetic Signal',
            time_unit=self.time_unit,
            DEBUG=self.debug,
        )
示例#5
0
    def run_fourier_ana(self):
        if not np.any(self.raw_signal):

            msgBox = QMessageBox()
            msgBox.setWindowTitle("No Signal")
            msgBox.setText("Please select a signal first!")
            msgBox.exec()
            return False

        # shift new analyser windows
        self.w_position += 20

        if self.cb_use_detrended2.isChecked():
            trend = self.calc_trend()
            signal = self.raw_signal - trend
        else:
            signal = self.raw_signal

        if self.cb_use_envelope2.isChecked():
            window_size = self.get_wsize(self.wsize_edit)
            signal = pyboat.normalize_with_envelope(signal, window_size,
                                                    self.dt)

        # periods or frequencies?
        if self.cb_FourierT.isChecked():
            show_T = False
        else:
            show_T = True

        self.anaWindows[self.w_position] = FourierAnalyzer(
            signal=signal,
            dt=self.dt,
            signal_id=self.signal_id,
            position=self.w_position,
            time_unit=self.time_unit,
            show_T=show_T,
        )
示例#6
0
    def run_wavelet_ana(self):
        """ run the Wavelet Analysis """

        if not np.any(self.raw_signal):
            self.NoSignalSelected = MessageWindow(
                "Please select a signal first!", "No Signal")
            return False

        succ = self.set_wlet_pars()  # Error handling done there
        if not succ:
            if self.debug:
                print("Wavelet parameters could not be set!")
            return False

        # move to set_wlet_pars?!
        if self.step_num_value > 1000:

            choice = QMessageBox.question(
                self,
                "Too much periods?: ",
                "High number of periods: Do you want to continue?",
                QMessageBox.Yes | QMessageBox.No,
            )
            if choice == QMessageBox.Yes:
                pass
            else:
                return

        # detrend for the analysis?
        if self.cb_use_detrended.isChecked() and not self.T_c:
            self.NoTrend = MessageWindow(
                "Detrending parameter not set,\n" +
                "specify a cut-off period!",
                "No Trend",
            )
            return

        elif self.cb_use_detrended.isChecked():
            trend = self.calc_trend()
            signal = self.raw_signal - trend
        else:
            signal = self.raw_signal

        # amplitude normalization is downstram of detrending!
        if self.cb_use_envelope.isChecked() and not self.L:
            self.NoTrend = MessageWindow(
                "Envelope parameter not set,\n" +
                "specify a sliding window size!",
                "No Envelope",
            )
            return

        elif self.cb_use_envelope.isChecked():
            signal = pyboat.normalize_with_envelope(signal, self.L)

        self.w_position += 20

        self.anaWindows[self.w_position] = WaveletAnalyzer(
            signal=signal,
            dt=self.dt,
            T_min=self.T_min_value,
            T_max=self.T_max_value,
            position=self.w_position,
            signal_id="Synthetic Signal",
            step_num=self.step_num_value,
            p_max=self.p_max_value,
            time_unit=self.time_unit,
            DEBUG=self.debug,
        )
示例#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.

        '''

        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
示例#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['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
示例#9
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