def Initialize(self, indim, outdim): #======================================================================= # Set the list of TargetClasss (pseudorandomized) #======================================================================= n_trials = self.params['TrialsPerBlock'].val * self.params['BlocksPerRun'].val classes_per_cluster = self.params['ClusterTargets'].val trials_per_class = int(n_trials / self.nclasses) if classes_per_cluster == 0: #We will cycle through targets. self.target_codes = [item for sublist in [range(self.nclasses) for j in range(trials_per_class)] for item in sublist] self.target_codes = [x+1 for x in self.target_codes] elif classes_per_cluster ==1: self.target_codes = [1 + x / trials_per_class for x in range(n_trials)] #Forcing int yields e.g., [0,0,0,1,1,1,2,2,2] shuffle(self.target_codes) else: n_clusters = trials_per_class / classes_per_cluster temp = [] for cc in range(n_clusters): temp2 = [[j for jj in range(classes_per_cluster)] for j in range(self.nclasses)] #Generate a list of clusters, one per target shuffle(temp2) #Shuffle the list of clusters temp.append(temp2) #Append the list of clusters to what we have already. self.target_codes = 1 + [x2 for x3 in [item for sublist in temp for item in sublist] for x2 in x3] #Flatten #======================================================================= # Screen #======================================================================= self.screen.color = (0,0,0) #let's have a black background self.scrw,self.scrh = self.screen.size #Get the screen dimensions. #=================================================================== # Create a box object as the coordinate frame for the screen. # Manipulate its properties to get positional information for stimuli. #=================================================================== scrsiz = min(self.scrw,self.scrh) siz = (scrsiz, scrsiz) b = box(size=siz, position=(self.scrw/2.0,self.scrh/2.0), sticky=True) center = b.map((0.5,0.5), 'position') self.positions = {'origin': np.matrix(center)} #Save the origin for later. #======================================================================= # Register the basic stimuli. #======================================================================= self.stimulus('cue', z=5, stim=VisualStimuli.Text(text='?', position=center, anchor='center', color=(1,1,1), font_size=50, on=False)) self.stimulus('fixation', z=4.2, stim=Disc(position=center, radius=5, color=(1,1,1), on=False)) #======================================================================= # Make a few variables easier to access. #======================================================================= self.eegfs = self.nominal['SamplesPerSecond'] #Sampling rate self.spb = self.nominal['SamplesPerPacket'] #Samples per block/packet self.block_dur = 1000*self.spb/self.eegfs#duration (ms) of a sample block self.taskMaxNBlocks = self.params['TaskMax'].val * self.eegfs / self.spb#Task will always go to response after this many blocks, even if extensions not ready #======================================================================= # State monitors for debugging. #======================================================================= if int(self.params['ShowSignalTime']): # turn on state monitors iff the packet clock is also turned on addstatemonitor(self, 'Running', showtime=True) addstatemonitor(self, 'CurrentBlock') addstatemonitor(self, 'CurrentTrial') addstatemonitor(self, 'TargetClass') addstatemonitor(self, 'LastTargetClass') addstatemonitor(self, 'TaskMinNBlocks') addphasemonitor(self, 'phase', showtime=True) m = addstatemonitor(self, 'fs_reg') m.func = lambda x: '% 6.1fHz' % x._regfs.get('SamplesPerSecond', 0) m.pargs = (self,) m = addstatemonitor(self, 'fs_avg') m.func = lambda x: '% 6.1fHz' % x.estimated.get('SamplesPerSecond',{}).get('global', 0) m.pargs = (self,) m = addstatemonitor(self, 'fs_run') m.func = lambda x: '% 6.1fHz' % x.estimated.get('SamplesPerSecond',{}).get('running', 0) m.pargs = (self,) m = addstatemonitor(self, 'fr_run') m.func = lambda x: '% 6.1fHz' % x.estimated.get('FramesPerSecond',{}).get('running', 0) m.pargs = (self,) if 'MSEnable' in self.params: MagstimApp.initialize(self, indim, outdim) if 'DigitimerEnable' in self.params: DigitimerApp.initialize(self, indim, outdim) if 'GatingEnable' in self.params: GatingApp.initialize(self, indim, outdim) if 'ERPDatabaseEnable' in self.params: ERPApp.initialize(self, indim, outdim) if 'ContFeedbackEnable' in self.params: FeedbackApp.initialize(self, indim, outdim)
def Initialize(self, indim, outdim): #======================================================================= # Set the list of TargetClasss (pseudorandomized) #======================================================================= n_trials = self.params['TrialsPerBlock'].val * self.params[ 'BlocksPerRun'].val classes_per_cluster = self.params['ClusterTargets'].val trials_per_class = int(n_trials / self.nclasses) if classes_per_cluster == 0: #We will cycle through targets. self.target_codes = [ item for sublist in [range(self.nclasses) for j in range(trials_per_class)] for item in sublist ] self.target_codes = [x + 1 for x in self.target_codes] elif classes_per_cluster == 1: self.target_codes = [ 1 + x / trials_per_class for x in range(n_trials) ] #Forcing int yields e.g., [0,0,0,1,1,1,2,2,2] shuffle(self.target_codes) else: n_clusters = trials_per_class / classes_per_cluster temp = [] for cc in range(n_clusters): temp2 = [[j for jj in range(classes_per_cluster)] for j in range(self.nclasses) ] #Generate a list of clusters, one per target shuffle(temp2) #Shuffle the list of clusters temp.append( temp2 ) #Append the list of clusters to what we have already. self.target_codes = 1 + [ x2 for x3 in [item for sublist in temp for item in sublist] for x2 in x3 ] #Flatten #======================================================================= # Screen #======================================================================= self.screen.color = (0, 0, 0) #let's have a black background self.scrw, self.scrh = self.screen.size #Get the screen dimensions. #=================================================================== # Create a box object as the coordinate frame for the screen. # Manipulate its properties to get positional information for stimuli. #=================================================================== scrsiz = min(self.scrw, self.scrh) siz = (scrsiz, scrsiz) b = box(size=siz, position=(self.scrw / 2.0, self.scrh / 2.0), sticky=True) center = b.map((0.5, 0.5), 'position') self.positions = { 'origin': np.matrix(center) } #Save the origin for later. #======================================================================= # Register the basic stimuli. #======================================================================= self.stimulus('cue', z=5, stim=VisualStimuli.Text(text='?', position=center, anchor='center', color=(1, 1, 1), font_size=50, on=False)) self.stimulus('fixation', z=4.2, stim=Disc(position=center, radius=5, color=(1, 1, 1), on=False)) #======================================================================= # Make a few variables easier to access. #======================================================================= self.eegfs = self.nominal['SamplesPerSecond'] #Sampling rate self.spb = self.nominal['SamplesPerPacket'] #Samples per block/packet self.block_dur = 1000 * self.spb / self.eegfs #duration (ms) of a sample block self.taskMaxNBlocks = self.params[ 'TaskMax'].val * self.eegfs / self.spb #Task will always go to response after this many blocks, even if extensions not ready #======================================================================= # State monitors for debugging. #======================================================================= if int(self.params['ShowSignalTime']): # turn on state monitors iff the packet clock is also turned on addstatemonitor(self, 'Running', showtime=True) addstatemonitor(self, 'CurrentBlock') addstatemonitor(self, 'CurrentTrial') addstatemonitor(self, 'TargetClass') addstatemonitor(self, 'LastTargetClass') addstatemonitor(self, 'TaskMinNBlocks') addphasemonitor(self, 'phase', showtime=True) m = addstatemonitor(self, 'fs_reg') m.func = lambda x: '% 6.1fHz' % x._regfs.get('SamplesPerSecond', 0) m.pargs = (self, ) m = addstatemonitor(self, 'fs_avg') m.func = lambda x: '% 6.1fHz' % x.estimated.get( 'SamplesPerSecond', {}).get('global', 0) m.pargs = (self, ) m = addstatemonitor(self, 'fs_run') m.func = lambda x: '% 6.1fHz' % x.estimated.get( 'SamplesPerSecond', {}).get('running', 0) m.pargs = (self, ) m = addstatemonitor(self, 'fr_run') m.func = lambda x: '% 6.1fHz' % x.estimated.get( 'FramesPerSecond', {}).get('running', 0) m.pargs = (self, ) if 'MSEnable' in self.params: MagstimApp.initialize(self, indim, outdim) if 'DigitimerEnable' in self.params: DigitimerApp.initialize(self, indim, outdim) if 'GatingEnable' in self.params: GatingApp.initialize(self, indim, outdim) if 'ERPDatabaseEnable' in self.params: ERPApp.initialize(self, indim, outdim) if 'ContFeedbackEnable' in self.params: FeedbackApp.initialize(self, indim, outdim)