ridge_results = {} # store the individual time averaged Wavelet spectra df_fouriers = pd.DataFrame(index=wAn.periods) for ID in signals: wAn.compute_spectrum(signals[ID], do_plot=False) rd = wAn.get_maxRidge(smoothing_wsize=11) ridge_results[ID] = rd df_fouriers[ID] = wAn.get_averaged_spectrum() # the time-averaged power distribution, # index holds the signal ids if given, otherwise just a column index powers_series = em.average_power_distribution(ridge_results.values(), signal_ids=ridge_results.keys()) # is bi-modal! pl.power_distribution(powers_series) # filter out the pure noise signals with a power threshold high_power_ids = powers_series[powers_series > 10].index high_power_ridge_results = [ridge_results[ID] for ID in high_power_ids] # creates a tuple of 4 DataFrames, one summary statistic over time # for period, amplitude, power and phase each res = em.get_ensemble_dynamics(high_power_ridge_results) pl.ensemble_dynamics(*res) # the Fourier power distribution with pure noise signals
def run_batch(self): ''' Retrieve all batch settings and loop over the signals present in the parentDV ''' dataset_name = self.parentDV.df.name if self.export_options.isChecked(): OutPath = self.get_OutPath() if OutPath is None: return # TODO: parallelize ridge_results, df_fouriers = self.do_the_loop() # check for empty ridge_results if not ridge_results: self.NoResults = MessageWindow( 'All ridges below threshold.. no results!', 'No results') return # --- compute the time-averaged powers --- if self.cb_power_dis.isChecked() or self.cb_sorted_powers.isChecked(): powers_series = em.average_power_distribution( ridge_results.values(), ridge_results.keys(), exclude_coi=True) if self.cb_power_dis.isChecked(): # plot the distribution self.pdw = PowerDistributionWindow(powers_series, dataset_name=dataset_name) # save out the sorted average powers if self.export_options.isChecked() and self.cb_sorted_powers.isChecked( ): fname = os.path.join(OutPath, f'{dataset_name}_ridge-powers.csv') powers_series.to_csv(fname, sep=',', index=True, header=False) # --- compute summary statistics over time --- if self.cb_plot_ens_dynamics.isChecked( ) or self.cb_save_ensemble_dynamics.isChecked(): # res is a tuple of DataFrames, one each for # periods, amplitude, power and phase res = em.get_ensemble_dynamics(ridge_results.values()) if self.cb_plot_ens_dynamics.isChecked(): self.edw = EnsembleDynamicsWindow( res, dt=self.parentDV.dt, time_unit=self.parentDV.time_unit, dataset_name=dataset_name) if self.export_options.isChecked( ) and self.cb_save_ensemble_dynamics.isChecked(): # create time axis, all DataFrames have same number of rows tvec = np.arange(res[0].shape[0]) * self.parentDV.dt for obs, df in zip(['periods', 'amplitudes', 'powers', 'phasesR'], res): fname = os.path.join(OutPath, f'{dataset_name}_{obs}.csv') df.index = tvec df.index.name = 'time' df.to_csv(fname, sep=',', float_format='%.3f') # --- Fourier Distribution Outputs --- if self.cb_plot_Fourier_dis.isChecked(): self.fdw = FourierDistributionWindow(df_fouriers, self.parentDV.time_unit, dataset_name) if self.export_options.isChecked( ) and self.cb_save_Fourier_dis.isChecked(): fname = os.path.join(OutPath, f'{dataset_name}_fourier-distribution.csv') # save out median and quartiles of Fourier powers df_fdis = pd.DataFrame(index=df_fouriers.index) df_fdis['Median'] = df_fouriers.median(axis=1) df_fdis['Q1'] = df_fouriers.quantile(q=0.25, axis=1) df_fdis['Q3'] = df_fouriers.quantile(q=0.75, axis=1) df_fdis.to_csv(fname, sep=',', float_format='%.3f') if self.debug: print(list(ridge_results.items())[:2])
def run_batch(self): ''' Retrieve all batch settings and loop over the signals present in the parentDV ''' dataset_name = self.parentDV.df.name if self.export_options.isChecked(): OutPath = self.get_OutPath() if OutPath is None: return # is a dictionary holding the ridge-data # for each signal and the signal_id as key ridge_results = self.do_the_loop() # compute the time-averaged powers if self.cb_power_dis.isChecked() or self.cb_sorted_powers.isChecked(): powers = em.average_power_distribution(ridge_results.values()) powers_series = pd.Series(index=ridge_results.keys(), data=powers) # sort by power, descending powers_series.sort_values(ascending=False, inplace=True) if self.cb_power_dis.isChecked(): # plot the distribution self.pdw = PowerDistributionWindow(powers_series, dataset_name=dataset_name) # save out the sorted average powers if self.export_options.isChecked() and self.cb_sorted_powers.isChecked( ): fname = f'{OutPath}/average_powers_{dataset_name}.csv' powers_series.to_csv(fname, sep=',', index=True, header=False) # compute summary statistics over time if self.cb_plot_ens_dynamics.isChecked( ) or self.cb_save_ensemble_dynamics.isChecked(): # res is a tuple of DataFrames, one each for # periods, amplitude, power and phase res = em.get_ensemble_dynamics(ridge_results.values()) if self.cb_plot_ens_dynamics.isChecked(): self.edw = EnsembleDynamicsWindow( res, dt=self.parentDV.dt, time_unit=self.parentDV.time_unit, dataset_name=dataset_name) if self.export_options.isChecked( ) and self.cb_save_ensemble_dynamics.isChecked(): # create time axis, all DataFrames have same number of rows tvec = np.arange(res[0].shape[0]) * self.parentDV.dt for obs, df in zip(['periods', 'amplitudes', 'powers', 'phasesR'], res): fname = f'{OutPath}/{obs}_{dataset_name}.csv' df.index = tvec df.index.name = 'time' df.to_csv(fname, sep=',', float_format='%.3f') if self.debug: print(list(ridge_results.items())[:2])
def run_batch(self): """ Retrieve all batch settings and loop over the signals present in the parentDV """ dataset_name = self.parentDV.df.name if self.export_options.isChecked(): OutPath = self.get_OutPath() if OutPath is None: return # TODO: parallelize ridge_results, df_fouriers = self.do_the_loop() # check for empty ridge_results if not ridge_results: msgBox = QMessageBox() msgBox.setWindowTitle("No Results") msgBox.setText("All ridges below threshold.. no results!") msgBox.exec() return settings = QSettings() float_format = settings.value('float_format', '%.3f') # --- compute the time-averaged powers --- if self.cb_power_dis.isChecked() or self.cb_sorted_powers.isChecked(): powers_series = em.average_power_distribution( ridge_results.values(), ridge_results.keys(), exclude_coi=True) if self.cb_power_dis.isChecked(): # plot the distribution self.pdw = PowerDistributionWindow(powers_series, dataset_name=dataset_name) # save out the sorted average powers if self.export_options.isChecked() and self.cb_sorted_powers.isChecked( ): fname = os.path.join(OutPath, f"{dataset_name}_ridge-powers.csv") powers_series.to_csv(fname, sep=",", float_format=float_format, index=True, header=False) # --- compute summary statistics over time --- if (self.cb_plot_ens_dynamics.isChecked() or self.cb_save_ensemble_dynamics.isChecked()): # res is a tuple of DataFrames, one each for # periods, amplitude, power and phase res = em.get_ensemble_dynamics(ridge_results.values()) if self.cb_plot_ens_dynamics.isChecked(): self.edw = EnsembleDynamicsWindow( res, dt=self.parentDV.dt, time_unit=self.parentDV.time_unit, dataset_name=dataset_name, ) if (self.export_options.isChecked() and self.cb_save_ensemble_dynamics.isChecked()): # create time axis, all DataFrames have same number of rows tvec = np.arange(res[0].shape[0]) * self.parentDV.dt for obs, df in zip(["periods", "amplitudes", "powers", "phasesR"], res): fname = os.path.join(OutPath, f"{dataset_name}_{obs}.csv") df.index = tvec df.index.name = "time" df.to_csv(fname, sep=",", float_format=float_format) # --- Fourier Distribution Outputs --- if self.cb_plot_Fourier_dis.isChecked(): self.fdw = FourierDistributionWindow(df_fouriers, self.parentDV.time_unit, dataset_name) if self.export_options.isChecked( ) and self.cb_save_Fourier_dis.isChecked(): fname = os.path.join(OutPath, f"{dataset_name}_fourier-distribution.csv") # save out median and quartiles of Fourier powers df_fdis = pd.DataFrame(index=df_fouriers.index) df_fdis["Median"] = df_fouriers.median(axis=1) df_fdis["Mean"] = df_fouriers.mean(axis=1) df_fdis["Q1"] = df_fouriers.quantile(q=0.25, axis=1) df_fdis["Q3"] = df_fouriers.quantile(q=0.75, axis=1) df_fdis.to_csv(fname, sep=",", float_format=float_format) if self.debug: print(list(ridge_results.items())[:2]) Nsignals = len(self.parentDV.df.columns) msg = f"Processed {Nsignals} signals!" msgBox = QMessageBox() msgBox.setWindowTitle("Batch processing done") msgBox.setText(msg) msgBox.exec()