def test_StaticPeriod_finish_on_time(): """Test successful completion (finishing "on time") """ static = StaticPeriod() static.start(0.1) wait(0.01) assert static.complete() == 1
def test_StaticPeriod_overrun(): """Test unsuccessful completion (period "overran") """ static = StaticPeriod() static.start(0.1) wait(0.11) assert static.complete() == 0
def test_StaticPeriod(): static = StaticPeriod() static.start(0.1) wait(0.05) assert static.complete()==1 static.start(0.1) wait(0.11) assert static.complete()==0 win = Window(autoLog=False) static = StaticPeriod(screenHz=60, win=win) static.start(.002) assert win.recordFrameIntervals is False static.complete() assert static._winWasRecordingIntervals == win.recordFrameIntervals win.close() # Test if screenHz parameter is respected, i.e., if after completion of the # StaticPeriod, 1/screenHz seconds are still remaining, so the period will # complete after the next flip. refresh_rate = 100.0 period_duration = 0.1 timer = CountdownTimer() win = Window(autoLog=False) static = StaticPeriod(screenHz=refresh_rate, win=win) static.start(period_duration) timer.reset(period_duration ) static.complete() assert np.allclose(timer.getTime(), 1.0/refresh_rate, atol=0.001) win.close()
def prepare(self): self.prepare_answers() self.win.flip() self.log('Preparation complete for ' + str(self)) clock.wait(.5) pass
def play(self): """ Play all the sequences together """ for s in range(self.num_seq): self.play_seq(s) # Wait the Inter Sequence Interval time clock.wait(self.iseqi)
def show_stimulus(self): for n in self.stimulus: self.draw_number(n) clock.wait(self.stimulusDuration) self.grid.draw() self.win.flip() clock.wait(.5)
def collect_response(self): # PsychoPy click response stuff? self.draw_answer_grids() self.win.flip() clock.wait(1) response = self.get_mouse_input() self.log('Answer = ' + str(response["answer"])) self.log('Mouse position = ' + str(response["position"])) if response["answer"] == self.answerIndex: self.log('CORRECT!') else: self.log('WRONG!')
def complete(self): """Completes the period, using up whatever time is remaining with a call to wait() :return: 1 for success, 0 for fail (the period overran) """ self.status=FINISHED timeRemaining = self.countdown.getTime() if self.win: self.win.recordFrameIntervals = self._winWasRecordingIntervals if timeRemaining<0: logging.warn('We overshot the intended duration of %s by %.4fs. The intervening code took too long to execute.' %(self.name, abs(timeRemaining))) return 0 else: wait(timeRemaining) return 1
def complete(self): """Completes the period, using up whatever time is remaining with a call to wait() :return: 1 for success, 0 for fail (the period overran) """ self.status = FINISHED timeRemaining = self.countdown.getTime() if self.win: self.win.recordFrameIntervals = self._winWasRecordingIntervals if timeRemaining < 0: logging.warn( 'We overshot the intended duration of %s by %.4fs. The intervening code took too long to execute.' % (self.name, abs(timeRemaining))) return 0 else: wait(timeRemaining) return 1
def drawnum(numtext, x_coord, y_coord): coords = grid.coordToPixelOffset(x_coord, y_coord) coords = (coords[0] - halfCharPx, coords[1]) stim = visual.TextStim( win=win, font='monospace', text="", pos=coords, color=[-1, -1, 1], # autoDraw=True, wrapWidth=1 ) # no idea why we need this, but apparently we do. Complaints to PsychoPy :) for i in numtext: stim.text = i+1 make_grid(grid) stim.draw() win.flip() clock.wait(1)
def play_emoji(self, s, e): """ Draw emoji augmentation from sequence s and emoji e""" # Move blue rectangle and draw everything self.stimuli.items[-1].pos = ( self.imXaxis[self.aug_shuffle[s, e]], 0) self.stimuli.draw() # Window flip self.window.flip() # Wait the aug_dur time clock.wait(self.aug_dur) # Draw just the emojis, getting rid of the rectangle self.stimuli.draw_int(0, -1) # Window flip self.window.flip() # Pause aug_wait time clock.wait(self.aug_wait)
def play_emoji(self, t): 'Singluar run threw one trial.' print('Loc OFF = 0 | ON == 1: ', self.loc_shuffle[t]) if t == 0: 'Initial Stim Presentation and Pause before localizer begins.' # Position and draw emoji. self.stimuli.items[-2].pos = ( self.imXaxis[0], 0) self.stimuli.draw_one(-2) self.window.flip() clock.wait(self.itrint) # Stim Info print('SELF STIM', self.stimuli, 'SELF STIM DIMS: ', vars( self.stimuli), 'SELF STIM SIZE: ', sys.getsizeof(self.stimuli)) elif t != 0: 'During Locaizer Reset of Emoji Stimulus begins immediately after inter-trial interval.' # Position and draw emoji. self.stimuli.items[-2].pos = ( self.imXaxis[0], 0) self.stimuli.draw_one(-2) self.window.flip() # Augmentation. # Position and Draw Flash Rect. if self.loc_shuffle[t] == 1: self.stimuli.items[-1].pos = ( self.imXaxis[0], 0) self.stimuli.draw_one(-1) # Window flip self.window.flip() # Wait the aug_dur time. clock.wait(self.aug_dur) # Position and Draw Emoji. self.stimuli.items[-2].pos = ( self.imXaxis[0], 0) self.stimuli.draw_one(-2) # Draw just the emoji. self.stimuli.draw_one(-2) # Window flip self.window.flip() else: clock.wait(self.aug_dur) 'Pause for Inter-Trial Interval' clock.wait(self.itrint)
def play_emoji(self, e, s, t): """ Draw emoji augmentation from sequence s and emoji e""" # Draw fixation fix_dis = self.emoji_size / 2 if s == 0 and e == 0: # Stim Info # print('SELF STIM', self.stimuli, 'SELF STIM DIMS: ', vars( # self.stimuli), 'SELF STIM SIZE: ', sys.getsizeof(self.stimuli)) # Position and Draw Cue. self.stimuli.items[-2].pos = (self.imXaxis[self.fix_shuffle[t]], -fix_dis) self.stimuli.draw_one(-2) self.window.flip() clock.wait(0.5) # Position and Draw Cue. self.stimuli.items[-2].pos = (self.imXaxis[self.fix_shuffle[t]], -fix_dis) self.stimuli.draw_one(-2) # Draw Emoji self.stimuli.draw_int(0, self.num_emoji) # Flip Screen, wait as it's the first cue to appear in sequence. # print('Cue Time') self.window.flip() clock.wait(0.5) # Position and Draw Cue. self.stimuli.items[-2].pos = (self.imXaxis[self.fix_shuffle[t]], -fix_dis) self.stimuli.draw_one(-2) # Draw emoji. self.stimuli.draw_int(0, self.num_emoji) 'Aug List Technique' # Print Aug Index # print('Aug Index: ', self.aug_non_con[e, s, t]) # Position and Flash Emoji em_pos = -1 self.stimuli.items[em_pos].pos = (self.imXaxis[self.aug_non_con[e, s, t]], 0) self.stimuli.draw_one(em_pos) # Window flip self.window.flip() # Wait the aug_dur time clock.wait(self.aug_dur) # Position and Draw Cue. self.stimuli.items[-2].pos = (self.imXaxis[self.fix_shuffle[t]], -fix_dis) self.stimuli.draw_one(-2) # Draw just the emoji. self.stimuli.draw_int(0, self.num_emoji) # Window flip self.window.flip()
def play_seq(self, s, t, aug, marker_outlet, marker_inlet, eeg_stream, imp_stream, ammount): ''' Play sequence number s as aug_non_con is ordered ''' # Set Marker Label and Marker Timestamp variables. seq_sample1 = [] seq_timestamp1 = [] seq_sample2 = [] seq_timestamp2 = [] if aug == 'Invert': for e in range(self.num_emoji): sample1, timestamp1, sample2, timestamp2 = self.play_emoji_inv( e, s, t, marker_outlet, marker_inlet, eeg_stream, imp_stream, ammount) # Marker Variables. seq_sample1 = np.append(seq_sample1, sample1) seq_timestamp1 = np.append(seq_timestamp1, timestamp1) seq_sample2 = np.append(seq_sample2, sample2) seq_timestamp2 = np.append(seq_timestamp2, timestamp2) 'Data End' # Ensure you only finish collecting at 7th emoji, after cue augmentations, # before ITIs and allow for final P300 waveform delay to play through. clock.wait(self.iseqi) eeg, eeg_time = eeg_stream.inlet.pull_chunk(max_samples=ammount) imp, imp_time = imp_stream.inlet.pull_chunk(max_samples=ammount) # EEG vs Marker Time Check. eeg = np.asarray(eeg) eeg_time = np.asarray(eeg_time) print('----EEG Chunk DIMS: ', eeg.shape) print('----EEG Chunk Time DIMS: ', eeg_time.shape) print('----EEG Chunk Time Start: ', eeg_time[0], 'EEG Chunk Time End: ', eeg_time[-1]) print('----Diff between EEG Chunk and Start Timestamps: ', eeg_time[0] - seq_timestamp1[0]) # Imp vs Marker Time Check. imp = np.asarray(imp) imp_time = np.asarray(imp_time) print('----IMP Chunk DIMS: ', imp.shape) print('----IMP Chunk Time DIMS: ', imp_time.shape) print('----IMP Chunk Time Start: ', imp_time[0], 'IMP Chunk Time End: ', imp_time[-1]) print('----Diff between IMP Chunk and Start Timestamps: ', imp_time[0] - seq_timestamp1[0]) clock.wait(self.iseqi) if aug == 'Flash': for e in range(self.num_emoji): 'RUN STIMULUS.' sample1, timestamp1, sample2, timestamp2 = self.play_emoji_fl( e, s, t, marker_outlet, marker_inlet, eeg_stream, imp_stream, ammount) # Marker Variables. seq_sample1 = np.append(seq_sample1, sample1) seq_timestamp1 = np.append(seq_timestamp1, timestamp1) seq_sample2 = np.append(seq_sample2, sample2) seq_timestamp2 = np.append(seq_timestamp2, timestamp2) 'Data End' # Ensure you only finish collecting at 7th emoji, after cue augmentations, # before ITIs and allow for final P300 waveform delay to play through. clock.wait(self.iseqi) eeg, eeg_time = eeg_stream.inlet.pull_chunk(max_samples=ammount) imp, imp_time = imp_stream.inlet.pull_chunk(max_samples=ammount) # Data vs Marker Time Check eeg = np.asarray(eeg) eeg_time = np.asarray(eeg_time) print('----EEG Chunk DIMS: ', eeg.shape) print('----EEG Chunk Time DIMS: ', eeg_time.shape) print('----EEG Chunk Time Start: ', eeg_time[0], 'EEG Chunk Time End: ', eeg_time[-1]) print('----Diff between EEG Chunk and Start Timestamps: ', eeg_time[0] - seq_timestamp1[0]) # Imp vs Marker Time Check. imp = np.asarray(imp) imp_time = np.asarray(imp_time) print('----IMP Chunk DIMS: ', imp.shape) print('----IMP Chunk Time DIMS: ', imp_time.shape) print('----IMP Chunk Time Start: ', imp_time[0], 'IMP Chunk Time End: ', imp_time[-1]) print('----Diff between IMP Chunk and Start Timestamps: ', imp_time[0] - seq_timestamp1[0]) clock.wait(self.iseqi) return seq_sample1, seq_timestamp1, seq_sample2, seq_timestamp2, eeg, eeg_time, imp, imp_time
def play_emoji_fl(self, e, s, t, marker_outlet, marker_inlet, eeg_stream, imp_stream, ammount): ''' Draw emoji augmentation from sequence s and emoji e''' # Draw fixation fix_dis = self.emoji_size / 2 if t == 0 and s == 0 and e == 0: # Initialization Period for 1st Trial, 1st Sequence, 1st Emoji. clock.wait(self.pres_dur) if s == 0 and e == 0: # Position and Draw Cue. self.stimuli.items[-2].pos = (self.imXaxis[self.fix_shuffle[t]], -fix_dis) self.stimuli.draw_one(-2) # Draw Emoji self.stimuli.draw_int(0, self.num_emoji) # Flip Screen, wait as it's the first cue to appear in sequence. self.window.flip() clock.wait(self.cue_int) 'Data Start : EEG / IMP.' if e == 0: # Ensure you only start collecting at 1st emoji, after cue. eeg, eeg_time = eeg_stream.inlet.pull_chunk( max_samples=np.int(ammount * 1.1)) imp, imp_time = imp_stream.inlet.pull_chunk( max_samples=np.int(ammount * 1.1)) 'Marker Start.' # Marker for labelling and time-stamping. marker_rand = np.array2string(self.aug_non_con[e, s, t]) # Push and Pull Marker Denoting Start of Emoji augmentation. marker_outlet.push(marker=marker_rand) sample1, timestamp1 = marker_inlet.pull(timeout=1) if e == 0: print('Start Marker Time: ', timestamp1) # Position and Draw Cue. self.stimuli.items[-2].pos = (self.imXaxis[self.fix_shuffle[t]], -fix_dis) self.stimuli.draw_one(-2) # Draw emoji. self.stimuli.draw_int(0, self.num_emoji) 'Aug List Technique' # Position and Flash Emoji em_pos = -1 self.stimuli.items[em_pos].pos = (self.imXaxis[self.aug_non_con[e, s, t]], 0) self.stimuli.draw_one(em_pos) # Window flip self.window.flip() # Wait the aug_dur time clock.wait(self.aug_dur) # Position and Draw Cue. self.stimuli.items[-2].pos = (self.imXaxis[self.fix_shuffle[t]], -fix_dis) self.stimuli.draw_one(-2) # Draw just the emoji. self.stimuli.draw_int(0, self.num_emoji) # Window flip self.window.flip() # Pause aug_wait time clock.wait(self.aug_wait) 'Marker End.' # Push and Pull Marker Denoting Start of Emoji augmentation. marker_outlet.push(marker=marker_rand) sample2, timestamp2 = marker_inlet.pull(timeout=1) if e == 6: print('End Marker Time: ', timestamp2) return sample1, timestamp1, sample2, timestamp2
pylink.getEYELINK().sendMessage("!V IMGLOAD CENTER %s" % (scenestim)) #IAPS # Send onset time offset = int((t - iaps_display.tStart) * 1000) msg = str(offset) + " IAPS_Onset" pylink.getEYELINK().sendMessage(msg) #IAPS # Send offset time offset = int((t - blank.tStart) * 1000) msg = str(offset) + " IAPS_Offset" pylink.getEYELINK().sendMessage(msg) #Waits 50ms to allow eyelink to prepare clock.wait(.05) #stop recording pylink.getEYELINK().stopRecording() #VARIABLES msg = "!V TRIAL_VAR picture %s" % (scenestim) #scenestim pylink.getEYELINK().sendMessage(msg) msg = "!V TRIAL_VAR valence %s" % (valence) #valence pylink.getEYELINK().sendMessage(msg) msg = "!V TRIAL_VAR valmean %s" % (valmean) #valmean pylink.getEYELINK().sendMessage(msg) msg = "!V TRIAL_VAR arousal %s" % (arousal) #arousal pylink.getEYELINK().sendMessage(msg) msg = "!V TRIAL_VAR arousalmean %s" % (arousalmean) #arousalmean pylink.getEYELINK().sendMessage(msg) msg = "!V TRIAL_VAR BlockVar %s" % (blocknum) #blocknum
if CONFIRMATION_DURATION < t_now < CONFIRMATION_DURATION + FEEDBACK_DURATION: sampleDirectionLine.draw() if t_now >= CONFIRMATION_DURATION + FEEDBACK_DURATION: #fish_1.pos = basePos feedbackCompleted = True break win.flip() # 6. Write trial data output outputLine = [str(experiment_parameters[trial_index][h]) for h in headers] outputLine = ','.join(outputLine) output_file_handle.write(outputLine + '\n') dotStim.save_stim_data(root_folder + '\\data_fishing\\' + filename + "_trial_" + str(trial_index) + ".csv") win.flip() clock.wait(ISI_DURATION) output_file_handle.close() # Turn of all display elements and show final instruction screen for s in autoDrawList: s.setAutoDraw(False) myText = visual.TextStim(win, str(opponentFishies), units='pix',pos=[1018-640,-(451-360)], color=(-1,-1,-1), height=28) opText = visual.TextStim(win, str(nFishies), units='pix',pos=[718-640,-(451-360)], color=(-1,-1,-1),height = 28) instructionImages[BLOCK_8_SLIDE-1].draw() myText.draw() opText.draw() win.flip() event.waitKeys(keyList=['space'])
for r in range(grid.width): for c in range(grid.height): # Set grid cell position properties rect = grid.rect rect.pos = grid.coordToPixelOffset(r, c) rect.draw() # Draw stimulus coords = grid.coordToPixelOffset(2, 4) coords = (coords[0] - halfCharPx, coords[1]) stim = visual.TextStim( win=win, font='monospace', text='4', pos=coords, color=[-1, -1, 1], # autoDraw=True, wrapWidth=1 # no idea why we need this, but apparently we do. Complaints to PsychoPy :) ) make_grid(grid) win.flip() clock.wait(2) make_grid(grid) stim.draw() win.flip() clock.wait(2)
def play_seq(self, s, t): """ Play sequence number s as aug_shuffle is ordered """ for e in range(self.num_emoji): self.play_emoji(e, s, t) clock.wait(self.iseqi)
mywin = visual.Window(SCREEN, monitor="testMonitor", units="deg") #create a window LEVELS = [] for i, level in enumerate([0, 1, -1, 0]): LEVELS.append( visual.GratingStim(win=mywin, size=1000, pos=[0, 0], sf=0, color=level)) for i, duration in enumerate([1, 2, 2, 1]): LEVELS[i].draw() mywin.flip() clock.wait(duration) mywin.close() core.quit() if sys.argv[-1] == 'grating': mywin = visual.Window(SCREEN, monitor="testMonitor", units="deg") #create a window ORI = [] for i, theta in enumerate(np.linspace(0, 5 * 180 / 6., 6)): ORI.append(visual.GratingStim(win=mywin, size=1000, sf=1, ori=theta)) blank = visual.GratingStim(win=mywin, size=1000, pos=[0, 0], sf=0, color=0) for i in range(len(ORI)): ORI[i].draw() mywin.flip()
win.callOnFlip(trigger.send, 'trial', 'start', io) img = visual.ImageStim(win, image=trial['img']) img.draw() win.flip() percepts.waitKeyPress(io, key=' ', timeout=20) """ fixation of 200 to 500 ms at start of trial """ # send trigger to indicate a start of the trial condition win.callOnFlip(trigger.send, 'condition', trial['cond'], io) fix_duration = random.uniform(0.2, 0.5) trial['fix_duration'] = fix_duration stim = plaid_stims['fix'] for s in stim: s.draw() win.flip() clock.wait(fix_duration) # TODO: we could potentially do a drift check here (is the subject truly fixating) """ set kb reporting as a function of the condition """ io.devices.keyboard.reporting = True if kb_cond == 'Kp' else False """ prepare the stimulus """ if stim_cond == 'nAmb': trial['mu'] = mu trial['sigma'] = sigma # reset the timer for the waiting times flip_timer.reset(t=0) trial_start = True needs_flip = True # make the plaids autoDraw themselves as the window flips