11
2- #change the pref libraty to PTB and set the latency mode to high precision
3- from psychopy import prefs
4- prefs .hardware ['audioLib' ] = 'PTB'
5- prefs .hardware ['audioLatencyMode' ] = 3
2+ try :
3+ #change the pref libraty to PTB and set the latency mode to high precision
4+ from psychopy import prefs
5+ prefs .hardware ['audioLib' ] = 'PTB'
6+ prefs .hardware ['audioLatencyMode' ] = 3
7+ except ImportError :
8+ pass
69
710
811from eegnb .devices .eeg import EEG
9-
10- from eegnb .experiments import VisualN170 , Experiment
11- from eegnb .experiments import VisualP300
12- from eegnb .experiments import VisualSSVEP
13- from eegnb .experiments import AuditoryOddball
14- from eegnb .experiments .visual_cueing import cueing
15- from eegnb .experiments .visual_codeprose import codeprose
16- from eegnb .experiments .auditory_oddball import diaconescu
17- from eegnb .experiments .auditory_ssaep import ssaep , ssaep_onefreq
1812from typing import Optional
1913
14+ def get_experiments ():
15+ from eegnb .experiments import VisualN170 , Experiment
16+ from eegnb .experiments import VisualP300
17+ from eegnb .experiments import VisualSSVEP
18+ from eegnb .experiments import AuditoryOddball
19+ from eegnb .experiments .visual_cueing import cueing
20+ from eegnb .experiments .visual_codeprose import codeprose
21+ from eegnb .experiments .auditory_oddball import diaconescu
22+ from eegnb .experiments .auditory_ssaep import ssaep , ssaep_onefreq
2023
21- # New Experiment Class structure has a different initilization, to be noted
22- experiments = {
23- "visual-N170" : VisualN170 () ,
24- "visual-P300" : VisualP300 () ,
25- "visual-SSVEP" : VisualSSVEP () ,
26- "visual-cue" : cueing ,
27- "visual-codeprose" : codeprose ,
28- "auditory-SSAEP orig" : ssaep ,
29- "auditory-SSAEP onefreq" : ssaep_onefreq ,
30- "auditory-oddball orig" : AuditoryOddball () ,
31- "auditory-oddball diaconescu" : diaconescu ,
32- }
24+ # New Experiment Class structure has a different initilization, to be noted
25+ return {
26+ "visual-N170" : VisualN170 ,
27+ "visual-P300" : VisualP300 ,
28+ "visual-SSVEP" : VisualSSVEP ,
29+ "visual-cue" : cueing ,
30+ "visual-codeprose" : codeprose ,
31+ "auditory-SSAEP orig" : ssaep ,
32+ "auditory-SSAEP onefreq" : ssaep_onefreq ,
33+ "auditory-oddball orig" : AuditoryOddball ,
34+ "auditory-oddball diaconescu" : diaconescu ,
35+ }
3336
3437
3538def get_exp_desc (exp : str ):
39+ experiments = get_experiments ()
3640 if exp in experiments :
3741 module = experiments [exp ]
3842 if hasattr (module , "__title__" ):
@@ -43,17 +47,24 @@ def get_exp_desc(exp: str):
4347def run_experiment (
4448 experiment : str , eeg_device : EEG , record_duration : Optional [float ] = None , save_fn = None
4549):
50+ experiments = get_experiments ()
4651 if experiment in experiments :
47- module = experiments [experiment ]
52+ exp_item = experiments [experiment ]
53+
54+ from eegnb .experiments import Experiment
4855
4956 # Condition added for different run types of old and new experiment class structure
50- if isinstance (module , Experiment .BaseExperiment ):
51- module .duration = record_duration
52- module .eeg = eeg_device
53- module .save_fn = save_fn
54- module .run ()
57+ # If it's a class (BaseExperiment subclass), instantiate it
58+ if isinstance (exp_item , type ) and issubclass (exp_item , Experiment .BaseExperiment ):
59+ # Concrete subclasses supply defaults for BaseExperiment's required args; mypy can't see which subclass.
60+ exp_instance = exp_item () # type: ignore[call-arg]
61+ exp_instance .duration = record_duration
62+ exp_instance .eeg = eeg_device
63+ exp_instance .save_fn = save_fn
64+ exp_instance .run ()
5565 else :
56- module .present (duration = record_duration , eeg = eeg_device , save_fn = save_fn ) # type: ignore
66+ # Otherwise it's an old-style module
67+ exp_item .present (duration = record_duration , eeg = eeg_device , save_fn = save_fn ) # type: ignore
5768 else :
5869 print ("\n Error: Unknown experiment '{}'" .format (experiment ))
5970 print ("\n Experiment can be one of:" )
0 commit comments