From 7223a584977518c4141ddc8ae37101632ef9e4a7 Mon Sep 17 00:00:00 2001 From: Tab Date: Wed, 9 Oct 2024 20:23:25 -0700 Subject: [PATCH] fixes for offline_analysis TODO something is wrong between matplotlib and pyqt6 --- bcipy/gui/alert.py | 4 +++- bcipy/gui/intertask_gui.py | 11 ++++++----- bcipy/signal/evaluate/artifact.py | 2 +- bcipy/signal/model/offline_analysis.py | 2 +- bcipy/task/actions.py | 4 ++-- bcipy/task/orchestrator/orchestrator.py | 3 ++- requirements.txt | 4 ++-- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/bcipy/gui/alert.py b/bcipy/gui/alert.py index d974349d9..e28985d85 100644 --- a/bcipy/gui/alert.py +++ b/bcipy/gui/alert.py @@ -15,7 +15,9 @@ def confirm(message: str) -> bool: ------- users selection : True for selecting Ok, False for Cancel. """ - app = QApplication(sys.argv) + app = QApplication(sys.argv).instance() + if not app: + app = QApplication(sys.argv) dialog = alert_message(message, message_type=AlertMessageType.INFO, message_response=AlertMessageResponse.OCE) diff --git a/bcipy/gui/intertask_gui.py b/bcipy/gui/intertask_gui.py index b582492e4..7bef836ca 100644 --- a/bcipy/gui/intertask_gui.py +++ b/bcipy/gui/intertask_gui.py @@ -24,12 +24,13 @@ def __init__( tasks: List[str], exit_callback: Callable, ): - # check if IntertaskGUI in tasks, if so, remove it self.tasks = tasks - tasks = [task for task in tasks if task != self.action_name] - self.total_tasks = len(tasks) self.current_task_index = next_task_index self.next_task_name = tasks[self.current_task_index] + self.task_progress = next_task_index - 1 + tasks = [task for task in tasks if task != self.action_name] + self.total_tasks = len(tasks) + self.callback = exit_callback super().__init__("Progress", 800, 150) @@ -38,10 +39,10 @@ def app(self): progress_container = QHBoxLayout() progress_container.addWidget( - QLabel(f"({self.current_task_index}/{self.total_tasks})") + QLabel(f"({self.task_progress}/{self.total_tasks})") ) self.progress = QProgressBar() - self.progress.setValue(int(self.current_task_index / self.total_tasks * 100)) + self.progress.setValue(int(self.task_progress / self.total_tasks * 100)) self.progress.setTextVisible(False) progress_container.addWidget(self.progress) self.contents.addLayout(progress_container) diff --git a/bcipy/signal/evaluate/artifact.py b/bcipy/signal/evaluate/artifact.py index 73eb3bb2b..19ec6180f 100644 --- a/bcipy/signal/evaluate/artifact.py +++ b/bcipy/signal/evaluate/artifact.py @@ -40,7 +40,7 @@ class DefaultArtifactParameters(Enum): """ # Voltage - PEAK_THRESHOLD = 100e-7 + PEAK_THRESHOLD = 75e-7 PEAK_MIN_DURATION = 0.005 FLAT_THRESHOLD = 0.5e-6 FLAT_MIN_DURATION = 0.1 diff --git a/bcipy/signal/model/offline_analysis.py b/bcipy/signal/model/offline_analysis.py index 1e53ae22b..562249e83 100644 --- a/bcipy/signal/model/offline_analysis.py +++ b/bcipy/signal/model/offline_analysis.py @@ -547,7 +547,7 @@ def offline_analysis( figure_handles.extend(et_figure_handles) if alert_finished: - results = [f"\n {model.name}: {model.auc} \n" for model in models] + results = [f"{model.name}: {model.auc}" for model in models] confirm(f"Offline analysis complete! \n Results={results}") log.info("Offline analysis complete") return models, figure_handles diff --git a/bcipy/task/actions.py b/bcipy/task/actions.py index f99749b84..5c26cbd8e 100644 --- a/bcipy/task/actions.py +++ b/bcipy/task/actions.py @@ -96,7 +96,7 @@ def execute(self) -> TaskData: """ logger.info("Running offline analysis action") try: - cmd = f"bcipy-train --parameters {self.parameters_path} -v" + cmd = f"bcipy-train --parameters {self.parameters_path}" if self.alert_finished: cmd += " --alert" response = subprocess.run( @@ -132,7 +132,7 @@ def __init__( self.save_folder = save_path self.parameters = parameters assert progress is not None and tasks is not None, "Either progress or tasks must be provided" - self.next_task_index = progress - 1 # progress is 1-indexed, tasks is 0-indexed so we can use the same index + self.next_task_index = progress # progress is 1-indexed, tasks is 0-indexed so we can use the same index assert self.next_task_index >= 0, "Progress must be greater than 1 " self.tasks = tasks self.task_name = self.tasks[self.next_task_index].name diff --git a/bcipy/task/orchestrator/orchestrator.py b/bcipy/task/orchestrator/orchestrator.py index 2e8458379..1b1311793 100644 --- a/bcipy/task/orchestrator/orchestrator.py +++ b/bcipy/task/orchestrator/orchestrator.py @@ -183,10 +183,11 @@ def execute(self) -> None: # Visualize session data and fail silently if it errors try: visualize_session_data(data_save_location, self.parameters) - pass except Exception as e: self.logger.info(f'Error visualizing session data: {e}') + initialized_task = None + except Exception as e: self.logger.error(f"Task {task.name} failed to execute") self.logger.exception(e) diff --git a/requirements.txt b/requirements.txt index fa3593209..daf366476 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,9 +13,9 @@ SoundFile==0.12.1 scipy==1.10.1 scikit-learn==1.2.2 seaborn==0.9.0 -matplotlib==3.7.2 +matplotlib==3.7.5 pylsl==1.16.2 -pandas==2.2.3 +pandas==2.0.3 psutil==5.7.2 Pillow==9.4.0 py-cpuinfo==9.0.0