async def coro_preprocess_selected_signal(self) -> List[ndarray]: sig = self.get_selected_signal() if not self.preproc_mp_handler: self.preproc_mp_handler = MPHandler() return await self.preproc_mp_handler.coro_preprocess(sig, None, None)
async def coro_preprocess_selected_signal(self) -> List[ndarray]: """ Coroutine to preprocess the currently selected signal. :return: the preprocessed signal as a 1D array """ sig = self.get_selected_signal() fmin = self.view.get_fmin() fmax = self.view.get_fmax() if not self.preproc_mp_handler: self.preproc_mp_handler = MPHandler() return await self.preproc_mp_handler.coro_preprocess(sig, fmin, fmax)
async def coro_plot_preprocessed_signal(self) -> None: """ Coroutine to preprocess the signal and plot the result. """ sig = self.get_selected_signal() fmin = self.view.get_fmin() fmax = self.view.get_fmax() if not self.preproc_mp_handler: self.preproc_mp_handler = MPHandler() result = await self.preproc_mp_handler.coro_preprocess(sig, fmin, fmax) if result and result[0] is not None: self.view.plot_preprocessed_signal(sig.times, sig.signal, result[0])
async def coro_preprocess_all_signals(self) -> List[ndarray]: """ Coroutine to preprocess all signals. :return: a list containing the preprocessed signals as a 1D array each """ signals = self.signals try: fmin = self.view.get_fmin() fmax = self.view.get_fmax() except AttributeError: fmin, fmax = None, None if not self.preproc_mp_handler: self.preproc_mp_handler = MPHandler() return await self.preproc_mp_handler.coro_preprocess(signals, fmin, fmax)
async def coro_calculate(self, calculate_all: bool) -> None: self.view.enable_save_data(False) self.is_calculating_all = calculate_all if self.mp_handler: self.mp_handler.stop() self.is_plotted = False self.invalidate_data() self.view.main_plot().clear() self.view.main_plot().set_in_progress(True) self.view.amplitude_plot().clear() self.view.amplitude_plot().set_in_progress(True) params = self.get_params(all_signals=calculate_all) self.params = params self.surrogate_count = self.view.get_surr_count() self.surrogates_enabled = self.view.get_surr_enabled() self.mp_handler = MPHandler() self.view.main_plot().set_log_scale(logarithmic=True) self.view.amplitude_plot().set_log_scale(logarithmic=True) self.view.on_calculate_started() data = await self.mp_handler.coro_transform( params=params, on_progress=self.on_progress_updated) for d in data: self.on_transform_completed(*d) all_data = await self.coro_phase_coherence(self.signals_calc, params, self.on_progress_updated) for d in all_data: self.on_phase_coherence_completed(*d) self.plot_phase_coherence() self.view.on_calculate_stopped() self.on_all_tasks_completed() print("Finished calculating phase coherence.")
async def coro_calculate(self): if self.mp_handler: self.mp_handler.stop() self.mp_handler = MPHandler() data = await self.mp_handler.coro_bayesian(self.signals, self.get_paramsets(), self.on_progress_updated) for d in data: self.on_bayesian_inference_completed(*d) if data: self.plot_bayesian() else: print("No data returned; are any parameter sets added?") print("Dynamical Bayesian inference completed.") self.view.on_calculate_stopped()
async def coro_calculate(self, calculate_all: bool) -> None: """ Coroutine to perform the calculation. :param calculate_all: whether to calculate for all signals, or just the current signal """ self.is_calculating_all = calculate_all self.view.enable_save_data(False) for s in self.signals: s.data = None if self.mp_handler: self.mp_handler.stop() self.mp_handler = MPHandler() params = self.get_params(all_signals=calculate_all) self.params = params self.params.preprocess = self.view.get_preprocess() self.is_plotted = False self.view.main_plot().clear() self.invalidate_data() self.view.main_plot().set_log_scale(logarithmic=True) self.view.on_calculate_started() all_data = await self.mp_handler.coro_harmonics( self.signals_calc, params, self.params.preprocess, self.on_progress_updated) if not isinstance(all_data, List): all_data = [all_data] for signal, data in zip(self.signals_calc, all_data): signal.data = data self.view.enable_save_data(bool(all_data)) self.view.on_calculate_stopped() self.update_plots()