From e6dc15ebfd8b68583975e7fc675b1032f964dbef Mon Sep 17 00:00:00 2001 From: Ben Pettit Date: Sun, 10 Nov 2024 15:39:52 +1000 Subject: [PATCH 1/3] removed unnecessary trial parameter and fixed aob experiment to run on windows again --- eegnb/experiments/Experiment.py | 2 +- eegnb/experiments/auditory_oddball/aob.py | 10 +++++++--- eegnb/experiments/visual_n170/n170.py | 2 +- eegnb/experiments/visual_p300/p300.py | 2 +- eegnb/experiments/visual_ssvep/ssvep.py | 4 ++-- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/eegnb/experiments/Experiment.py b/eegnb/experiments/Experiment.py index 963a9aa3..e2a68f0c 100644 --- a/eegnb/experiments/Experiment.py +++ b/eegnb/experiments/Experiment.py @@ -185,7 +185,7 @@ def iti_with_jitter(): if rendering_trial < current_trial: # Some form of presenting the stimulus - sometimes order changed in lower files like ssvep # Stimulus presentation overwritten by specific experiment - self.__draw(lambda: self.present_stimulus(current_trial, current_trial)) + self.__draw(lambda: self.present_stimulus(current_trial)) rendering_trial = current_trial else: self.__draw(lambda: self.window.flip()) diff --git a/eegnb/experiments/auditory_oddball/aob.py b/eegnb/experiments/auditory_oddball/aob.py index 607b2df8..a53d583a 100644 --- a/eegnb/experiments/auditory_oddball/aob.py +++ b/eegnb/experiments/auditory_oddball/aob.py @@ -1,8 +1,12 @@ import numpy as np from pandas import DataFrame from psychopy import prefs + # PTB does not yet support macOS Apple Silicon, need to fall back to sounddevice. -prefs.hardware['audioLib'] = ['sounddevice'] +import sys +if sys.platform == 'darwin': + prefs.hardware['audioLib'] = ['sounddevice'] + from psychopy import visual, core, event, sound from time import time @@ -72,11 +76,11 @@ def load_stimulus(self): return - def present_stimulus(self, idx : int, trial): + def present_stimulus(self, idx: int): """ Presents the Stimulus """ # Select and play sound - ind = int(trial["sound_ind"]) + ind = int(self.trials["sound_ind"].iloc[idx]) self.auds[ind].stop() self.auds[ind].play() diff --git a/eegnb/experiments/visual_n170/n170.py b/eegnb/experiments/visual_n170/n170.py index 4cf42aad..6c41fbba 100644 --- a/eegnb/experiments/visual_n170/n170.py +++ b/eegnb/experiments/visual_n170/n170.py @@ -41,7 +41,7 @@ def load_stimulus(self): # Return the list of images as a stimulus object return [self.houses, self.faces] - def present_stimulus(self, idx : int, trial): + def present_stimulus(self, idx: int): # Get the label of the trial label = self.trials["parameter"].iloc[idx] diff --git a/eegnb/experiments/visual_p300/p300.py b/eegnb/experiments/visual_p300/p300.py index 08560d1a..d6a8a1df 100644 --- a/eegnb/experiments/visual_p300/p300.py +++ b/eegnb/experiments/visual_p300/p300.py @@ -35,7 +35,7 @@ def load_stimulus(self): return [self.nontargets, self.targets] - def present_stimulus(self, idx:int, trial): + def present_stimulus(self, idx: int): label = self.trials["parameter"].iloc[idx] image = choice(self.targets if label == 1 else self.nontargets) diff --git a/eegnb/experiments/visual_ssvep/ssvep.py b/eegnb/experiments/visual_ssvep/ssvep.py index 46119f55..94ae9121 100644 --- a/eegnb/experiments/visual_ssvep/ssvep.py +++ b/eegnb/experiments/visual_ssvep/ssvep.py @@ -91,8 +91,8 @@ def init_flicker_stim(frame_rate, cycle, soa): init_flicker_stim(frame_rate, 3, self.soa), ] - def present_stimulus(self, idx, trial): - + def present_stimulus(self, idx: int): + # Select stimulus frequency ind = self.trials["parameter"].iloc[idx] From f57e9f328b04fb9c9ceb3ae94f06ffd5872ae3b1 Mon Sep 17 00:00:00 2001 From: Ben Pettit Date: Tue, 17 Dec 2024 20:29:18 +1000 Subject: [PATCH 2/3] fixed auditory oddball experiment to run on macos for intel, arm is not yet supported. --- eegnb/experiments/__init__.py | 8 +++++++- eegnb/experiments/auditory_oddball/aob.py | 5 ----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/eegnb/experiments/__init__.py b/eegnb/experiments/__init__.py index e17326ff..9306e07b 100644 --- a/eegnb/experiments/__init__.py +++ b/eegnb/experiments/__init__.py @@ -1,4 +1,10 @@ from .visual_n170.n170 import VisualN170 from .visual_p300.p300 import VisualP300 from .visual_ssvep.ssvep import VisualSSVEP -from .auditory_oddball.aob import AuditoryOddball \ No newline at end of file + +# PTB does not yet support macOS Apple Silicon, +# this experiment needs to run as i386 if on macOS. +import sys +import platform +if sys.platform != 'darwin' or platform.processor() != 'arm': + from .auditory_oddball.aob import AuditoryOddball \ No newline at end of file diff --git a/eegnb/experiments/auditory_oddball/aob.py b/eegnb/experiments/auditory_oddball/aob.py index a53d583a..7831f145 100644 --- a/eegnb/experiments/auditory_oddball/aob.py +++ b/eegnb/experiments/auditory_oddball/aob.py @@ -2,11 +2,6 @@ from pandas import DataFrame from psychopy import prefs -# PTB does not yet support macOS Apple Silicon, need to fall back to sounddevice. -import sys -if sys.platform == 'darwin': - prefs.hardware['audioLib'] = ['sounddevice'] - from psychopy import visual, core, event, sound from time import time From 86b9daa55f194b4c3d3d46d5d15272cf9b6ac189 Mon Sep 17 00:00:00 2001 From: Ben Pettit Date: Tue, 17 Dec 2024 20:42:19 +1000 Subject: [PATCH 3/3] removed unneeded requirement, sounddevice also does not work on macOS ARM. --- requirements.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index f70bea07..8cca5a48 100644 --- a/requirements.txt +++ b/requirements.txt @@ -53,8 +53,6 @@ click pyobjc==7.3; sys_platform == 'darwin' #upgrade psychopy to use newer wxpython dependency which is prebuilt for m1 support. psychopy==2023.2.2 -# PTB does not yet support macOS Apple Silicon, need to fallback to sounddevice. -psychopy-sounddevice psychtoolbox scikit-learn>=0.23.2 pandas>=1.1.4