Esempio n. 1
0
def wait_for_trigger():
    event.clearEvents()
    if subdata['simulated_response']:
        msg = "SIMULATION MODE"
    else:
        msg = ''
    message = visual.TextStim(
        win,
        text='%s Waiting for start key (or press %s)\nBe very still!' %
        (msg, subdata['start_key']),
        font='BiauKai',
        height=1,
        color=u'white',
        colorSpace=u'rgb',
        opacity=1,
        depth=0.0,
        alignHoriz='center',
        wrapWidth=50)
    message.setAutoDraw(True)  #automatically draw every frame
    win.flip()
    start = False
    while start == False:
        k = event.waitKeys()
        if k.count(subdata['start_key']
                   ) > 0:  #as soon as subdata['start_key'] is pressed...
            start = True
            message.setText('')  #this clears the screen
            win.flip()
        if k.count(subdata['quit_key']
                   ) > 0:  # if subdata['quit_key'] is pressed...
            exptutils.shut_down_cleanly(subdata, win)
            return False
    return True
Esempio n. 2
0
def wait_for_trigger():
    event.clearEvents()
    if subdata['simulated_response']:
        msg="SIMULATION MODE"
    else:
        msg=''
    message=visual.TextStim(win, text='%s Waiting for start key (or press %s)\nBe very still!'%(msg,subdata['start_key']),
    font='BiauKai', height=1,color=u'white', colorSpace=u'rgb', opacity=1,depth=0.0,
    alignHoriz='center',wrapWidth=50)
    message.setAutoDraw(True) #automatically draw every frame
    win.flip()
    start=False
    while start==False:
        k=event.waitKeys()
        if k.count(subdata['start_key'])>0:#as soon as subdata['start_key'] is pressed...
            start=True
            message.setText('')#this clears the screen
            win.flip()
        if k.count(subdata['quit_key']) >0:# if subdata['quit_key'] is pressed...
            exptutils.shut_down_cleanly(subdata,win)
            return False
    return True
Esempio n. 3
0
def run_block(initial_cor, correct_response, flip, fix):

    # Await scan trigger
    while True:
        example_stim1.draw()
        example_stim2.draw()
        scan_trigger_text.draw()
        win.flip()

        if 'o' in event.waitKeys():
            logging.log(logging.DATA, "start key press")
            break
        event.clearEvents()

    clock = core.Clock()
    t = clock.getTime()
    RT = core.Clock()
    #set up the fixation
    ratings_and_onsets.append(['fixation', t])
    logging.log(logging.DATA, "fixation")
    show_stim(fixation_text, fix)  #blank screen with fixation cross
    #log fixation
    logging.log(logging.DATA, "fixation end")
    t = clock.getTime()

    #reset the clock so the onsets are correct (if onsets have the 8 sec in them then you dont need this)
    clock.reset()
    ratings_and_onsets.append(['start', t])
    logging.log(logging.DATA, "START")

    #initalize stim images
    stim_images = stim_cycle.next()

    #start the taste loop
    for trial in range(ntrials):

        #check for quit
        if check_for_quit(subdata, win):
            exptutils.shut_down_cleanly(subdata, win)
            subdata.update(info)
            f = open(
                '/Users/' + info['computer'] +
                '/Documents/Output/BBX_subdata_%s.pkl' % datestamp, 'wb')
            pickle.dump(subdata, f)
            f.close()

            myfile = open(
                '/Users/' + info['computer'] +
                '/Documents/Output/BBX_subdata_%s.csv' %
                datestamp.format(**info), 'wb')
            wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
            wr.writerow(['event', 'data'])
            for row in ratings_and_onsets:
                wr.writerow(row)
            sys.exit()

        #empty trial data
        trialdata = {}
        trialdata['onset'] = onsets[trial]
        print(initial_cor)

        #check for correct responses##
        if len(correct_response) > initial_cor:
            stim_images = stim_cycle.next()
            logging.log(logging.DATA,
                        'FLIP %s %s' % (stim_images[0], stim_images[1]))
            initial_cor = random.randint(2, 4)
            flip.append(initial_cor)
            logging.log(logging.DATA, 'New flip %i' % (initial_cor))
            logging.flush()
            correct_response = []

        #shuffle the positions
        shuffle(pos_ind)
        visual_stim1 = visual.ImageStim(win,
                                        image=N.zeros((300, 300)),
                                        pos=positions[pos_ind[0]],
                                        size=(0.25, 0.25),
                                        units='height')
        visual_stim2 = visual.ImageStim(win,
                                        image=N.zeros((300, 300)),
                                        pos=positions[pos_ind[1]],
                                        size=(0.25, 0.25),
                                        units='height')

        #set which image is which
        shuffle(indices)
        visual_stim1.setImage(
            stim_images[indices[0]])  #set which image appears
        visual_stim2.setImage(
            stim_images[indices[1]])  #set which image appears

        #creating a dictory which will store the postion with the image and pump, the image and pump need to match
        mydict = {}
        mydict[positions_scan[pos_ind[1]]] = [
            stim_images[indices[1]], pump_responses[indices[1]],
            positions_eng[pos_ind[1]]
        ]
        mydict[positions_scan[pos_ind[0]]] = [
            stim_images[indices[0]], pump_responses[indices[0]],
            positions_eng[pos_ind[0]]
        ]
        print(mydict)

        #which is sweet?
        message = visual.TextStim(win, text='Which is Sweet?', pos=(0, 5))
        print trial
        t = clock.getTime()

        #get the time of the image and log, this log is appending it to the csv file
        visual_stim1.draw()  #making image of the logo appear
        visual_stim2.draw()  #making image of the logo appear
        message.draw()

        #this is logging when the message is shown
        while clock.getTime() < trialdata['onset']:
            pass
        win.flip()

        logging.log(
            logging.DATA, "images %s at position=%s and %s at position=%s" %
            (stim_images[indices[0]], positions_eng[pos_ind[0]],
             stim_images[indices[1]], positions_eng[pos_ind[1]]))
        logging.flush()

        RT.reset()  # reaction time starts immediately after flip

        while clock.getTime() < (
                trialdata['onset'] + cue_time
        ):  #show the image, while clock is less than onset and cue, show cue
            pass
        keys = event.getKeys(keyList=['1', '2'], timeStamped=RT)

        message = visual.TextStim(
            win, text='')  #blank screen while the taste is delivered
        message.draw()
        win.flip()
        logging.log(logging.DATA, "blank screen during taste")
        print(keys)
        logging.flush()

        # get the key press logged, and time stamped
        if len(keys) > 0:
            rt.append(keys[0][1])
            logging.log(logging.DATA,
                        "keypress=%s RT= %f" % (keys[0][0], keys[0][1]))
            logging.flush()
            print("here are the keys:")
            print(keys)
            t = clock.getTime()
            #back up of the key press
            tempArray = [t, keys[0]]
            key_responses.append(tempArray)
            ratings_and_onsets.append(["keypress=%s" % keys[0][0], t])
            if keys[0][0] == '1':
                #from the dictionary find the pump code associated with the key press
                taste = int(mydict['1'][1])
                image = (mydict['1'][0])
                #log the pump used, time, and key press
                print 'injecting via pump at address %s' % taste
                t = clock.getTime()
                ratings_and_onsets.append([
                    "injecting via pump at address %d" % taste, t, keys[0][0]
                ])
                #trigger pump with the numeral from the dictonary above
                logging.log(
                    logging.DATA,
                    "injecting via pump at address %d and a keypress of %s and image of %s"
                    % (taste, keys[0][0], image))
                logging.flush()
                ser.write('%dRUN\r' % taste)
                if taste == 1:
                    correct_response.append(1)
                    total = sum(correct_response)
                    logging.log(logging.DATA, "correct responses %f" % (total))
                    logging.flush()
                while clock.getTime() < (trialdata['onset'] + cue_time +
                                         delivery_time):
                    pass

                message = visual.TextStim(
                    win, text='+', pos=(0, 0),
                    height=2)  #this lasts throught the wait
                message.draw()
                win.flip()
                logging.log(logging.DATA, "start wait")
                logging.flush()
                t = clock.getTime()
                ratings_and_onsets.append(["wait", t])
                trialdata['dis'] = [ser.write('0DIS\r'), ser.write('1DIS\r')]
                print(trialdata['dis'])
                while clock.getTime() < (trialdata['onset'] + cue_time +
                                         delivery_time + wait_time):
                    pass
                message = visual.TextStim(
                    win, text=' ', pos=(0, 0),
                    height=2)  #this lasts throught the rinse
                message.draw()
                win.flip()

                print 'injecting rinse via pump at address %d' % 0
                t = clock.getTime()
                ratings_and_onsets.append(
                    ['injecting rinse via pump at address %d' % 0, t])
                logging.log(logging.DATA, "Start Rinse")
                logging.flush()
                ser.write('%dRUN\r' % 0)
                while clock.getTime() < (trialdata['onset'] + cue_time +
                                         delivery_time + wait_time +
                                         rinse_time):
                    pass

                message = visual.TextStim(win, text='+', pos=(0, 0),
                                          height=2)  #lasts through the jitter
                message.draw()
                win.flip()

                logging.log(logging.DATA, "Start jitter")
                logging.flush()
                t = clock.getTime()
                ratings_and_onsets.append(["jitter", t])

                while clock.getTime() < (trialdata['onset'] + cue_time +
                                         delivery_time + wait_time +
                                         rinse_time + jitter[trial]):
                    pass
            elif keys[0][0] == '2':
                #from the dictonary get the pump associated with the right key press
                taste = int(mydict['2'][1])
                image = (mydict['2'][0])
                #log the time, keypress, and pump
                print 'injecting via pump at address %s' % taste
                t = clock.getTime()
                ratings_and_onsets.append(
                    ["injecting via pump at address %d" % taste, t])
                #trigger the pump with the numeral from the dictionary
                logging.log(
                    logging.DATA,
                    "injecting via pump at address %d and a keypress of %s and image of %s"
                    % (taste, keys[0][0], image))
                logging.flush()
                ser.write('%dRUN\r' % taste)
                if taste == 1:
                    correct_response.append(1)
                    total = sum(correct_response)
                    logging.log(logging.DATA, "correct responses %f" % (total))
                    logging.flush()
                while clock.getTime() < (trialdata['onset'] + cue_time +
                                         delivery_time):
                    pass
                message = visual.TextStim(
                    win, text='+', pos=(0, 0),
                    height=2)  #this lasts throught the wait
                message.draw()
                win.flip()
                logging.log(logging.DATA, "start wait")
                logging.flush()
                t = clock.getTime()
                ratings_and_onsets.append(["wait", t])
                trialdata['dis'] = [ser.write('0DIS\r'), ser.write('1DIS\r')]
                print(trialdata['dis'])

                while clock.getTime() < (trialdata['onset'] + cue_time +
                                         delivery_time + wait_time):
                    pass

                message = visual.TextStim(
                    win, text=' ', pos=(0, 0),
                    height=2)  #this lasts throught the rinse
                message.draw()
                win.flip()

                print 'injecting rinse via pump at address %d' % 0
                t = clock.getTime()
                ratings_and_onsets.append(
                    ['injecting rinse via pump at address %d' % 0, t])
                logging.log(logging.DATA, "RINSE")
                logging.flush()
                ser.write('%dRUN\r' % 0)
                while clock.getTime() < (trialdata['onset'] + cue_time +
                                         delivery_time + wait_time +
                                         rinse_time):
                    pass

                message = visual.TextStim(win, text='+', pos=(0, 0),
                                          height=2)  #lasts through the jitter
                message.draw()
                win.flip()
                logging.log(logging.DATA, "start jitter")
                logging.flush()
                t = clock.getTime()
                ratings_and_onsets.append(["jitter", t])

                while clock.getTime() < (trialdata['onset'] + cue_time +
                                         delivery_time + wait_time +
                                         rinse_time + jitter[trial]):
                    pass
        else:
            taste = 0
            t = clock.getTime()
            logging.log(logging.DATA, "Key Press Missed!")
            logging.flush()
            keys = keys.append(['MISS', t])
            message = visual.TextStim(win,
                                      text='Please answer quicker',
                                      pos=(0, 0),
                                      height=2)  #this lasts throught the taste
            message.draw()
            win.flip()
            logging.log(logging.DATA, "Please answer quicker")
            logging.flush()

            while clock.getTime() < (trialdata['onset'] + cue_time +
                                     delivery_time + wait_time + rinse_time):
                pass

            message = visual.TextStim(win, text='+', pos=(0, 0),
                                      height=2)  #lasts through the jitter
            message.draw()
            win.flip()
            logging.log(logging.DATA, "showing +")
            logging.flush()

            logging.log(logging.DATA, "start jitter")
            logging.flush()
            t = clock.getTime()
            ratings_and_onsets.append(["jitter", t])

            while clock.getTime() < (trialdata['onset'] + cue_time +
                                     delivery_time + wait_time + rinse_time +
                                     jitter[trial]):
                pass

        t = clock.getTime()
        ratings_and_onsets.append(['end time', t])
        logging.log(logging.DATA, "finished")
        logging.flush()
        subdata['trialdata'][trial] = trialdata

        print(key_responses)
        print(correct_response)
        if len(correct_response) > 0:
            logging.log(logging.DATA,
                        "correct responses %i" % correct_response[-1])
        else:
            logging.log(logging.DATA, "no correct responses")

        subdata['key_responses'] = key_responses
        subdata['rt'] = rt

    win.close()
Esempio n. 4
0
wt = wait_for_trigger()
if not wt:
    print 'quit button pressed!'
    sys.exit()
else:
    print "quit status:", wt

message = visual.TextStim(win, text='')

subdata['trialdata'] = {}
clock.reset()
event.clearEvents()

for trial in range(ntrials):
    if check_for_quit(subdata, win):
        exptutils.shut_down_cleanly(subdata, win)
        sys.exit()

    trialdata = {}
    print 'trial %d' % trial
    trialdata['onset'] = onsets[trial]
    print 'condition %d' % trialcond[trial]
    logging.log(logging.DATA, 'Condition: %d' % trialcond[trial])
    print 'showing image: %s' % stim_images[trialcond[trial]]
    visual_stim.setImage(stim_images[trialcond[trial]])
    visual_stim.draw()
    while clock.getTime() < trialdata[
            'onset']:  #wait until the specified onset time to display image_file
        if check_for_quit(subdata, win):
            exptutils.shut_down_cleanly(subdata, win)
            sys.exit()
Esempio n. 5
0
def run_block(fix):

    # Await scan trigger
    while True:
        scan_trigger_text.draw()
        win.flip()
        if 'o' in event.waitKeys():
            logging.log(logging.DATA, "start key press")
            break
        event.clearEvents()

    clock = core.Clock()
    t = clock.getTime()

    #set up the fixation
    ratings_and_onsets.append(['fixation', t])
    logging.log(logging.DATA, "fixation %f" % t)
    show_stim(fixation_text, fix)  # 8 sec blank screen with fixation cross
    #log fixation
    logging.log(logging.DATA, "fixation end %f" % t)
    t = clock.getTime()

    #reset the clock so the onsets are correct (if onsets have the 8 sec in them then you dont need this)
    clock.reset()
    ratings_and_onsets.append(['start', t])
    logging.log(logging.DATA, "START")

    #initalize starting variables in the loop
    #stim_images=stim_cycle.next()

    #start the taste loop
    for trial in range(ntrials):
        #check for quit
        if check_for_quit(subdata, win):
            exptutils.shut_down_cleanly(subdata, win)
            sys.exit()
        #empty trial data
        trialdata = {}
        trialdata['onset'] = onsets[trial]

        #check for correct responses##
        #        if len(correct_response)>initial_cor:
        #            stim_images=stim_cycle.next()
        #            logging.log(logging.DATA, 'FLIP %s %s'%(stim_images[0],stim_images[1]))
        #            initial_cor=random.randint(3,5)
        #            flip.append(initial_cor)
        #            logging.log(logging.DATA, 'New flip %i'%(initial_cor))
        #            correct_response=[]

        #shuffle the positions
        shuffle(pos_ind)
        visual_stim1 = visual.ImageStim(win,
                                        image=N.zeros((300, 300)),
                                        pos=positions[pos_ind[0]],
                                        size=(0.25, 0.25),
                                        units='height')
        visual_stim2 = visual.ImageStim(win,
                                        image=N.zeros((300, 300)),
                                        pos=positions[pos_ind[1]],
                                        size=(0.25, 0.25),
                                        units='height')

        #set which image is which
        x = int(N.random.choice(prob_index, 1, p=[0.34, 0.33, 0.33]))
        print(x)

        stim_images = stim_list[x]
        trial_prob = prob_list[x]
        trial_inv_prob = inv_prob_list[x]
        visual_stim1.setImage(
            stim_images[indices[0]])  #set which image appears
        visual_stim2.setImage(
            stim_images[indices[1]])  #set which image appears

        master_prob_list = [trial_prob, trial_inv_prob]

        shuffle(indices)
        #creating a dictory which will store the postion with the image and pump, the image and pump need to match
        mydict = {}
        #        mydict[positions_eng[pos_ind[1]]] = [stim_images[indices[1]], master_prob_list[indices[1]]]
        #        mydict[positions_eng[pos_ind[0]]] = [stim_images[indices[0]], master_prob_list[indices[0]]]
        mydict[positions_scan[pos_ind[1]]] = [
            stim_images[indices[1]], master_prob_list[indices[1]]
        ]
        mydict[positions_scan[pos_ind[0]]] = [
            stim_images[indices[0]], master_prob_list[indices[0]]
        ]

        print(mydict)

        #which is sweet?
        message = visual.TextStim(win, text='Which is Sweet?', pos=(0, 5))
        print trial
        t = clock.getTime()

        #get the time of the image and log, this log is appending it to the csv file
        visual_stim1.draw()  #making image of the logo appear
        visual_stim2.draw()  #making image of the logo appear
        message.draw()
        RT = core.Clock()

        #this is logging when the message is shown
        logging.log(
            logging.DATA, "%s at position=%s and %s at position=%s" %
            (stim_images[indices[0]], positions_eng[pos_ind[0]],
             stim_images[indices[1]], positions_eng[pos_ind[1]]))

        while clock.getTime() < trialdata['onset']:
            pass
        win.flip()

        RT.reset()  # reaction time starts immediately after flip

        while clock.getTime() < (
                trialdata['onset'] + cue_time
        ):  #show the image, while clock is less than onset and cue, show cue
            pass

        keys = event.getKeys(keyList=['1', '2'], timeStamped=RT)
        message = visual.TextStim(
            win, text='')  #blank screen while the taste is delivered
        message.draw()
        win.flip()

        # get the key press logged, and time stamped

        if len(keys) > 0:
            logging.log(logging.DATA,
                        "keypress=%s at time= %f" % (keys[0][0], keys[0][1]))
            print("here are the keys:")
            print(keys)
            t = clock.getTime()
            #back up of the key press
            tempArray = [t, keys[0]]
            key_responses.append(tempArray)
            ratings_and_onsets.append(["keypress=%s" % keys[0][0], t])
            if keys[0][0] == '1':
                #from the dictionary find the image code associated with the key press
                #taste=int(mydict['left'][1])
                image = (mydict['1'][0])
                trial_prob = (mydict['1'][1])
                taste = int(N.random.choice(pump_responses, 1, p=trial_prob))
                #if image=='sweet.jpg':
                #taste=int(N.random.choice(pump_responses, 1, p=[0.5, 0.5]))
                #elif image=='unsweet.jpg':
                #taste=int(N.random.choice(pump_responses, 1, p=[0.5, 0.5]))
                print(image)
                print(taste)
                #log the pump used, time, and key press
                print 'injecting via pump at address %s' % taste
                logging.log(
                    logging.DATA,
                    "injecting via pump at address %d and a keypress of %s and image of %s"
                    % (taste, keys[0][0], image))
                t = clock.getTime()
                ratings_and_onsets.append([
                    "injecting via pump at address %d" % taste, t, keys[0][0]
                ])
                #trigger pump with the numeral from the dictonary above
                ser.write('%dRUN\r' % taste)
            elif keys[0][0] == '2':
                #from the dictonary get the image associated with the right key press
                image = (mydict['2'][0])
                trial_prob = (mydict['2'][1])
                taste = int(N.random.choice(pump_responses, 1, p=trial_prob))
                print(image)
                print(taste)
                #log the time, keypress, and pump
                print 'injecting via pump at address %s' % taste
                logging.log(
                    logging.DATA,
                    "injecting via pump at address %d and a keypress of %s and image of %s"
                    % (taste, keys[0][0], image))
                t = clock.getTime()
                ratings_and_onsets.append(
                    ["injecting via pump at address %d" % taste, t])
                #trigger the pump with the numeral from the dictionary
                ser.write('%dRUN\r' % taste)
        else:
            taste = 0
            t = clock.getTime()
            logging.log(logging.DATA, "Key Press Missed!")
            keys = keys.append(['MISS', t])
            message = visual.TextStim(win,
                                      text='Please answer quicker',
                                      pos=(0, 0),
                                      height=2)  #this lasts throught the taste
            message.draw()
            win.flip()

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time):
            pass

        message = visual.TextStim(win, text='+', pos=(0, 0),
                                  height=2)  #this lasts throught the wait
        message.draw()
        win.flip()
        t = clock.getTime()
        ratings_and_onsets.append(["wait", t])

        trialdata['dis'] = [ser.write('0DIS\r'), ser.write('1DIS\r')]
        print(trialdata['dis'])

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time + wait_time):
            pass

        message = visual.TextStim(win, text='RINSE', pos=(0, 0),
                                  height=2)  #this lasts throught the rinse
        message.draw()
        win.flip()

        print 'injecting rinse via pump at address %d' % 0
        t = clock.getTime()
        ratings_and_onsets.append(
            ['injecting rinse via pump at address %d' % 0, t])
        ser.write('%dRUN\r' % 0)

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time + wait_time + rinse_time):
            pass

        message = visual.TextStim(win, text='+', pos=(0, 0),
                                  height=2)  #lasts through the jitter
        message.draw()
        win.flip()
        t = clock.getTime()
        ratings_and_onsets.append(["jitter", t])

        while clock.getTime() < (trialdata['onset'] + cue_time + delivery_time
                                 + wait_time + rinse_time + jitter[trial]):
            pass

        t = clock.getTime()
        ratings_and_onsets.append(['end time', t])
        logging.log(logging.DATA, "finished")
        subdata['trialdata'][trial] = trialdata

        print(key_responses)

    win.close()
Esempio n. 6
0
wt=wait_for_trigger()
if not wt:
    print 'quit button pressed!'
    sys.exit()
else:
    print "quit status:",wt
    
message=visual.TextStim(win, text='')

subdata['trialdata']={}
clock.reset()
event.clearEvents()

for trial in range(ntrials):
    if check_for_quit(subdata,win):
        exptutils.shut_down_cleanly(subdata,win)
        sys.exit()

    trialdata={}
    print 'trial %d'%trial
    trialdata['onset']=onsets[trial]
    print 'condition %d'%trialcond[trial]
    logging.log(logging.DATA,'Condition: %d'%trialcond[trial])
    print 'showing image: %s'%stim_images[trialcond[trial]]
    visual_stim.setImage(stim_images[trialcond[trial]])
    visual_stim.draw()
    while clock.getTime()<trialdata['onset']:#wait until the specified onset time to display image_file
        if check_for_quit(subdata,win):
            exptutils.shut_down_cleanly(subdata,win)
            sys.exit()
    win.flip()
Esempio n. 7
0
def run_block(fix):

    # Await scan trigger
    while True:
        scan_trigger_text.draw()
        win.flip()
        if 'o' in event.waitKeys():
            logging.log(logging.DATA, "start key press")
            break
        event.clearEvents()

    clock = core.Clock()
    t = clock.getTime()

    #start the loop
    for trial in range(ntrials):
        #check for quit
        if check_for_quit(subdata, win):
            exptutils.shut_down_cleanly(subdata, win)
            sys.exit()
        #empty trial data
        trialdata = {}
        trialdata['onset'] = onsets[trial]

        #shuffle the positions
        shuffle(pos_ind)
        visual_stim1 = visual.ImageStim(win,
                                        image=N.zeros((300, 300)),
                                        pos=positions[pos_ind[0]],
                                        size=(0.25, 0.25),
                                        units='height')
        visual_stim2 = visual.ImageStim(win,
                                        image=N.zeros((300, 300)),
                                        pos=positions[pos_ind[1]],
                                        size=(0.25, 0.25),
                                        units='height')

        #set which image is which
        x = int(
            N.random.choice(
                stim_index,
                1,
                p=[0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125]))
        print("here is the list")
        print(stim_list)
        print(x)
        stim_img_trial = stim_list[x]
        print(stim_img_trial)

        #set which image appears on what side
        visual_stim1.setImage(stim_img_trial[img_index[0]])
        visual_stim2.setImage(stim_img_trial[img_index[1]])

        shuffle(img_index)
        #creating a dictory which will store the image set and which image is at what postion
        mydict = {}
        mydict[positions_eng[pos_ind[1]]] = [stim_img_trial[img_index[1]]]
        mydict[positions_eng[pos_ind[0]]] = [stim_img_trial[img_index[0]]]
        print(mydict)

        #which is sweet?
        message = visual.TextStim(win, text='Which is Correct?', pos=(0, 5))
        print trial
        t = clock.getTime()

        #get the time of the image and log, this log is appending it to the csv file
        visual_stim1.draw()  #making image of the logo appear
        visual_stim2.draw()
        message.draw()
        RT = core.Clock()

        logging.log(
            logging.DATA, "%s at position=%s and %s at position=%s" %
            (stim_img_trial[img_index[0]], positions_eng[pos_ind[0]],
             stim_img_trial[img_index[1]], positions_eng[pos_ind[1]]))

        while clock.getTime() < trialdata['onset']:
            pass
        win.flip()

        RT.reset()  # reaction time starts immediately after flip

        while clock.getTime() < (
                trialdata['onset'] + cue_time
        ):  #show the image, while clock is less than onset and cue, show cue
            pass

        keys = event.getKeys(timeStamped=RT)
        message = visual.TextStim(win, text='')
        message.draw()
        win.flip()

        # get the key press logged, and time stamped

        if len(keys) > 0:
            logging.log(logging.DATA,
                        "keypress=%s at time= %f" % (keys[0][0], keys[0][1]))
            print("here are the keys:")
            print(keys)
            t = clock.getTime()
            #back up of the key press
            tempArray = [t, keys[0]]
            key_responses.append(tempArray)
            ratings_and_onsets.append(["keypress=%s" % keys[0][0], t])
        else:
            taste = 0
            t = clock.getTime()
            logging.log(logging.DATA, "Key Press Missed!")
            keys = keys.append(['MISS', t])
            message = visual.TextStim(win,
                                      text='Please answer quicker',
                                      pos=(0, 0),
                                      height=2)  #this lasts throught the taste
            message.draw()
            win.flip()

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time):
            pass

        message = visual.TextStim(win, text='+', pos=(0, 0),
                                  height=2)  #this lasts throught the wait
        message.draw()
        win.flip()
        t = clock.getTime()
        ratings_and_onsets.append(["wait", t])

        #trialdata['dis']=[ser.write('0DIS\r'),ser.write('1DIS\r')]
        #print(trialdata['dis'])

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time + wait_time):
            pass

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time + wait_time):
            pass

        message = visual.TextStim(win, text='+', pos=(0, 0),
                                  height=2)  #lasts through the jitter
        message.draw()
        win.flip()
        t = clock.getTime()
        ratings_and_onsets.append(["jitter", t])

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time + wait_time):
            pass

        t = clock.getTime()
        ratings_and_onsets.append(['end time', t])
        logging.log(logging.DATA, "finished")
        subdata['trialdata'][trial] = trialdata

        print(key_responses)

    win.close()
Esempio n. 8
0
def run_block():

    # Await scan trigger
    while True:
        scan_trigger_text.draw()
        win.flip()
        if 'o' in event.waitKeys():
            logging.log(logging.DATA, "start key press")
            break
        event.clearEvents()

    clock=core.Clock()
    t = clock.getTime()
    ratings_and_onsets.append(['fixation',t])
    show_stim(fixation_text, 8)  # 8 sec blank screen with fixation cross
    t = clock.getTime()
    clock.reset()
    ratings_and_onsets.append(['start',t])
    #logging.log(logging.DATA, "start")
    for trial in range(ntrials):
        if check_for_quit(subdata,win):
            subdata.update(info)
            f=open('/Users/'+info['computer']+'/Documents/Output/BBX_subdata_%s.pkl'%datestamp,'wb')
            pickle.dump(subdata,f)
            f.close()

            myfile = open('/Users/'+info['computer']+'/Documents/Output/BBX_subdata_%s.csv'%datestamp.format(**info), 'wb')
            wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
            wr.writerow(['event','data'])
            for row in ratings_and_onsets:
                wr.writerow(row)
            exptutils.shut_down_cleanly(subdata,win)
            sys.exit()
        tastes(pump_phases)
        trialdata={}
        trialdata['onset']=onsets[trial]
        visual_stim.setImage(stim_images[trialcond[trial]])#set which image appears
        print trial
        print 'condition %d'%trialcond[trial]
        print 'showing image: %s'%stim_images[trialcond[trial]]
        t = clock.getTime()
        ratings_and_onsets.append(["image=%s"%stim_images[trialcond[trial]],t])
        visual_stim.draw()#making image of the logo appear
        logging.log(logging.DATA, "image=%s"%stim_images[trialcond[trial]])
            
        while clock.getTime()<trialdata['onset']:
            pass
        win.flip()
            
        while clock.getTime()<(trialdata['onset']+cue_time):#show the image
            pass

        message=visual.TextStim(win, text='')#blank screen while the taste is delivered
        message.draw()
        win.flip()

        print 'injecting via pump at address %d'%pump[trial]
        logging.log(logging.DATA,"injecting via pump at address %d"%pump[trial])
        t = clock.getTime()
        ratings_and_onsets.append(["injecting via pump at address %d"%pump[trial], t])
        ser.write('%dRUN\r'%pump[trial])

        while clock.getTime()<(trialdata['onset']+cue_time+delivery_time):
            pass
        
        message=visual.TextStim(win, text='+', pos=(0, 0), height=2)#this lasts throught the wait
        message.draw()
        win.flip()
        t = clock.getTime()
        ratings_and_onsets.append(["wait", t])
        
        trialdata['dis']=[ser.write('0DIS\r'),ser.write('1DIS\r')]
        print(trialdata['dis'])
        tastes(pump_phases2)
        
        
        if pump[trial]==0:
            while clock.getTime()<(trialdata['onset']+cue_time+delivery_time+wait_time):
                pass
            message=visual.TextStim(win, text='NO RINSE', pos=(0, 0), height=2)#lasts through the jitter 
            message.draw()
            win.flip()
            t = clock.getTime()
            ratings_and_onsets.append(["jitter", t])
            
            while clock.getTime()<(trialdata['onset']+cue_time+delivery_time+wait_time+rinse_time+jitter[trial]):
                pass
        
            t = clock.getTime()
            ratings_and_onsets.append(['end time', t])
            logging.log(logging.DATA,"finished")
            subdata['trialdata'][trial]=trialdata
            tastes(pump_phases)
        else:
            while clock.getTime()<(trialdata['onset']+cue_time+delivery_time+wait_time):
                pass
            message=visual.TextStim(win, text='RINSE', pos=(0, 0), height=2)#this lasts throught the rinse 
            message.draw()
            win.flip()
                
            print 'injecting rinse via pump at address %d'%0
            t = clock.getTime()
            ratings_and_onsets.append(['injecting rinse via pump at address %d'%0, t])
            ser.write('%dRUN\r'%0)
        
            while clock.getTime()<(trialdata['onset']+cue_time+delivery_time+wait_time+rinse_time):
                pass

            message=visual.TextStim(win, text='+', pos=(0, 0), height=2)#lasts through the jitter 
            message.draw()
            win.flip()
            t = clock.getTime()
            ratings_and_onsets.append(["jitter", t])

            while clock.getTime()<(trialdata['onset']+cue_time+delivery_time+wait_time+rinse_time+jitter[trial]):
                pass
        
            t = clock.getTime()
            ratings_and_onsets.append(['end time', t])
            logging.log(logging.DATA,"finished")
            subdata['trialdata'][trial]=trialdata
            #tastes(pump_phases)
    win.close()
Esempio n. 9
0
def run_block():

    # Await scan trigger
    while True:
        scan_trigger_text.draw()
        win.flip()
        if 'o' in event.waitKeys():
            logging.log(logging.DATA, "start key press")
            break
        event.clearEvents()

    clock = core.Clock()
    t = clock.getTime()
    ratings_and_onsets.append(['fixation', t])
    show_stim(fixation_text, 8)  # 8 sec blank screen with fixation cross
    t = clock.getTime()
    clock.reset()
    ratings_and_onsets.append(['start', t])
    #logging.log(logging.DATA, "start")
    for trial in range(ntrials):
        if check_for_quit(subdata, win):
            exptutils.shut_down_cleanly(subdata, win)
            wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
            wr.writerow(['event', 'data'])
            for row in ratings_and_onsets:
                wr.writerow(row)
            sys.exit()

        trialdata = {}
        trialdata['onset'] = onsets[trial]
        logging.log(logging.DATA, "onset of trial =%f" % trialdata['onset'])
        ratings_and_onsets.append(["onset =%f" % trialdata['onset']])
        logging.flush()

        visual_stim.setImage(
            stim_images[trialcond[trial]])  #set which image appears
        print trial
        print 'condition %d' % trialcond[trial]
        print 'showing image: %s' % stim_images[trialcond[trial]]

        visual_stim.draw()  #setting the image

        while clock.getTime() < trialdata['onset']:
            pass
        win.flip()  #showing the image of the stimulus
        t = clock.getTime()
        logging.log(logging.DATA, "image=%s" % stim_images[trialcond[trial]])
        ratings_and_onsets.append(
            ["image=%s" % stim_images[trialcond[trial]], t])
        logging.flush()

        while clock.getTime() < (trialdata['onset'] +
                                 cue_time):  #show the image
            pass

        message = visual.TextStim(
            win, text='')  #blank screen while the taste is delivered
        message.draw()
        win.flip()  #making the blank screen appear

        print 'injecting via pump at address %d' % pump[trial]

        #        logging.log(logging.DATA,"injecting via pump at address %d"%pump[trial])
        #        logging.flush()
        t = clock.getTime()
        ratings_and_onsets.append(
            ["injecting via pump at address %d" % pump[trial], t])
        logging.log(logging.DATA,
                    "injecting via pump at address %d" % pump[trial])
        logging.flush()
        ser.write('%dRUN\r' % pump[trial])
        logging.log(logging.DATA,
                    "post injecting via pump at address %d" % pump[trial])

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time):
            pass

        message = visual.TextStim(win, text='+', pos=(0, 0),
                                  height=2)  #this lasts throught the wait
        message.draw()
        win.flip()
        logging.log(logging.DATA, "start wait")
        t = clock.getTime()
        ratings_and_onsets.append(["wait", t])
        logging.flush()

        trialdata['dis'] = [ser.write('0DIS\r'), ser.write('1DIS\r')]
        print(trialdata['dis'])

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time + wait_time):
            pass

        if pump[trial] == 0:
            message = visual.TextStim(win, text='+', pos=(0, 0),
                                      height=2)  #lasts through the jitter
            message.draw()
            win.flip()
            logging.log(logging.DATA, "NO RINSE")
            logging.flush()

            t = clock.getTime()
            ratings_and_onsets.append(["jitter", t])

            while clock.getTime() < (trialdata['onset'] + cue_time +
                                     delivery_time + wait_time + rinse_time +
                                     jitter[trial]):
                pass

            t = clock.getTime()
            ratings_and_onsets.append(['end time', t])
            logging.log(logging.DATA, "finished")
            logging.flush()
            subdata['trialdata'][trial] = trialdata

        else:
            message = visual.TextStim(win, text=' ', pos=(0, 0),
                                      height=2)  #this lasts throught the rinse
            message.draw()
            win.flip()

            print 'injecting rinse via pump at address %d' % 0
            t = clock.getTime()
            ratings_and_onsets.append(
                ['injecting rinse via pump at address %d' % 0, t])
            ser.write('%dRUN\r' % 3)
            logging.log(logging.DATA, "RINSE")
            logging.flush()

            while clock.getTime() < (trialdata['onset'] + cue_time +
                                     delivery_time + wait_time + rinse_time):
                pass

            message = visual.TextStim(win, text='+', pos=(0, 0),
                                      height=2)  #lasts through the jitter
            message.draw()
            win.flip()
            logging.log(logging.DATA, "Start Jitter")
            logging.flush()
            t = clock.getTime()
            ratings_and_onsets.append(["jitter", t])

            while clock.getTime() < (trialdata['onset'] + cue_time +
                                     delivery_time + wait_time + rinse_time +
                                     jitter[trial]):
                pass
            t = clock.getTime()

            ratings_and_onsets.append(['end time', t])
            logging.log(logging.DATA, "finished")
            logging.flush()
            subdata['trialdata'][trial] = trialdata

    win.close()
def run_block(fix):

    # Await scan trigger
    while True:
        scan_trigger_text.draw()
        win.flip()
        if 'o' in event.waitKeys():
            logging.log(logging.DATA, "start key press")
            break
        event.clearEvents()

    clock = core.Clock()
    t = clock.getTime()

    #set up the fixation
    ratings_and_onsets.append(['fixation', t])
    logging.log(logging.DATA, "fixation %f" % t)
    show_stim(fixation_text, fix)  # 8 sec blank screen with fixation cross

    #log fixation
    logging.log(logging.DATA, "fixation end %f" % t)
    t = clock.getTime()

    #reset the clock so the onsets are correct (if onsets have the 8 sec in them then you dont need this)
    clock.reset()
    ratings_and_onsets.append(['start', t])
    logging.log(logging.DATA, "START")

    #start the taste loop
    for trial in range(ntrials):
        #check for quit
        if check_for_quit(subdata, win):
            exptutils.shut_down_cleanly(subdata, win)
            sys.exit()
        #empty trial data
        trialdata = {}
        trialdata['onset'] = onsets[trial]

        #Set which side IMG1 and IMG2 are on.

        #shuffle(pos_ind) <- moved to the end of the script
        visual_stim1 = visual.ImageStim(win,
                                        image=N.zeros((300, 300)),
                                        pos=positions[pos_ind[0]],
                                        size=(0.25, 0.25),
                                        units='height')
        visual_stim2 = visual.ImageStim(win,
                                        image=N.zeros((300, 300)),
                                        pos=positions[pos_ind[1]],
                                        size=(0.25, 0.25),
                                        units='height')

        #set which image pair to show.
        x = trialcond[trial]
        print(x)

        stim_images = stim_list[x]
        trial_prob = prob_list[x]
        trial_inv_prob = inv_prob_list[x]
        master_prob_list = [trial_prob, trial_inv_prob]

        #Set which shape is IMG1 and IMG2
        visual_stim1.setImage(
            stim_images[indices[0]])  #set which image appears
        visual_stim2.setImage(
            stim_images[indices[1]])  #set which image appears

        #shuffle(indicies) <- moved lower in script

        #creating a dictory which will store the postion with the image and pump, the image and pump need to match
        mydict = {}
        mydict[positions_scan[pos_ind[1]]] = [
            stim_images[indices[1]], master_prob_list[indices[1]]
        ]
        mydict[positions_scan[pos_ind[0]]] = [
            stim_images[indices[0]], master_prob_list[indices[0]]
        ]

        print(mydict)

        #Question Prompt
        message = visual.TextStim(win, text='Which is Correct?', pos=(0, 5))
        print trial
        t = clock.getTime()

        #get the time of the image and log, this log is appending it to the csv file
        visual_stim1.draw()  #making image of the logo appear
        visual_stim2.draw()  #making image of the logo appear
        message.draw()
        RT = core.Clock()

        #this is logging when the message is shown
        logging.log(
            logging.DATA, "%s at position=%s and %s at position=%s" %
            (stim_images[indices[0]], positions_eng[pos_ind[0]],
             stim_images[indices[1]], positions_eng[pos_ind[1]]))
        logging.flush()

        while clock.getTime() < trialdata['onset']:
            pass
        win.flip()

        RT.reset()  # reaction time starts immediately after flip

        while clock.getTime() < (
                trialdata['onset'] + cue_time
        ):  #show the image, while clock is less than onset and cue, show cue
            pass

        keys = event.getKeys(keyList=['1', '2'], timeStamped=RT)
        print(keys)
        win.flip()

        # get the key press logged, and time stamped

        if len(keys) > 0:
            logging.log(logging.DATA,
                        "keypress=%s at time= %f" % (keys[0][0], keys[0][1]))
            print("here are the keys:")
            print(keys)
            t = clock.getTime()
            logging.flush()

            #back up of the key press
            tempArray = [t, keys[0]]
            key_responses.append(tempArray)
            ratings_and_onsets.append(["keypress=%s" % keys[0][0], t])
            if keys[0][0] == '1':
                #draw a box on the left shape
                rectangle_l = visual.Rect(win,
                                          pos=(-0.25, 0),
                                          size=(0.75, 0.75),
                                          units='height',
                                          fillColor=[0, 0, 0],
                                          lineColor=[1, -1, -1])
                rectangle_l.draw()
                visual_stim1.draw()
                visual_stim2.draw()
                #from the dictionary find the image code associated with the key press
                #taste=int(mydict['left'][1])
                image = (mydict['1'][0])
                trial_prob = (mydict['1'][1])

                #choose the feedback
                taste = int(
                    N.random.choice(reinforcer_responses, 1, p=trial_prob))
                print(taste)
                if taste == 1:
                    message = visual.TextStim(win,
                                              text='Correct',
                                              pos=(0, 5),
                                              height=2)
                    message.draw()
                    print 'Reinforcement is correct'
                else:
                    message = visual.TextStim(win,
                                              text='Incorrect',
                                              pos=(0, 5),
                                              height=2)
                    message.draw()
                    print 'Reinforcement is incorrect'
                #log the pump used, time, and key press
                print 'Reinforcement is %s' % taste
                logging.log(
                    logging.DATA,
                    "Reinforcement of %s and a keypress of %s for image of %s"
                    % (taste, keys[0][0], image))
                t = clock.getTime()
                ratings_and_onsets.append(
                    ["Reinforcement is %s" % taste, t, keys[0][0]])
                logging.flush()

            elif keys[0][0] == '2':
                # show a rectangle on the right
                rectangle_r = visual.Rect(win,
                                          pos=(0.25, 0),
                                          size=(0.75, 0.75),
                                          units='height',
                                          fillColor=[0, 0, 0],
                                          lineColor=[1, -1, -1])
                rectangle_r.draw()
                visual_stim1.draw()
                visual_stim2.draw()
                #from the dictonary get the image associated with the right key press
                image = (mydict['2'][0])
                trial_prob = (mydict['2'][1])

                #choose the feedback
                taste = int(
                    N.random.choice(reinforcer_responses, 1, p=trial_prob))
                print(taste)
                if taste == 1:
                    message = visual.TextStim(win,
                                              text='Correct',
                                              pos=(0, 5),
                                              height=2)
                    message.draw()
                    print 'Reinforcement is correct'
                else:
                    message = visual.TextStim(win,
                                              text='Incorrect',
                                              pos=(0, 5),
                                              height=2)
                    message.draw()
                    print 'Reinforcement is incorrect'

                #log the time, keypress, and pump
                print 'Reinforcement is %s' % taste
                logging.log(
                    logging.DATA,
                    "Reinforcement of %s and a keypress of %s for image of %s"
                    % (taste, keys[0][0], image))
                t = clock.getTime()
                ratings_and_onsets.append(
                    ["Reinforcement is %s" % taste, t, keys[0][0]])
                logging.flush()
        else:
            taste = 0
            t = clock.getTime()
            logging.log(logging.DATA, "Key Press Missed!")
            keys = keys.append(['MISS', t])
            logging.flush()
            message = visual.TextStim(win,
                                      text='Please answer faster',
                                      pos=(0, 0),
                                      height=2)  #this lasts throught the taste
            message.draw()
            win.flip()

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time):
            pass

        message = visual.TextStim(win, text='', pos=(0, 0),
                                  height=2)  #this lasts throught the wait
        message.draw()
        win.flip()
        t = clock.getTime()
        ratings_and_onsets.append(["wait", t])

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time + wait_time):
            pass

        message = visual.TextStim(win, text='', pos=(0, 0),
                                  height=2)  #this lasts throught the rinse
        message.draw()
        win.flip()

        #print 'injecting rinse via pump at address %d'%0
        #t = clock.getTime()
        #ratings_and_onsets.append(['injecting rinse via pump at address %d'%0, t])
        #ser.write('%dRUN\r'%0)
        #logging.log(logging.DATA, "RINSE")
        #logging.flush()

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time + wait_time + rinse_time):
            pass

        message = visual.TextStim(win, text='+', pos=(0, 0),
                                  height=2)  #lasts through the jitter
        message.draw()
        win.flip()
        t = clock.getTime()
        ratings_and_onsets.append(["jitter", t])

        while clock.getTime() < (trialdata['onset'] + cue_time + delivery_time
                                 + wait_time + rinse_time + jitter[trial]):
            pass

        t = clock.getTime()
        ratings_and_onsets.append(['end time', t])
        logging.log(logging.DATA, "finished")
        logging.flush()
        subdata['trialdata'][trial] = trialdata

        print(key_responses)

        #shuffle indices for the next trial
        shuffle(indices)
        shuffle(pos_ind)

    win.close()
Esempio n. 11
0
def run_block():

    # Await scan trigger
    while True:
        scan_trigger_text.draw()
        win.flip()
        if 'o' in event.waitKeys():
            logging.log(logging.DATA, "start key press")
            break
        event.clearEvents()

    clock = core.Clock()
    t = clock.getTime()
    ratings_and_onsets.append(['fixation', t])
    show_stim(fixation_text, 8)  # 8 sec blank screen with fixation cross
    t = clock.getTime()
    clock.reset()
    ratings_and_onsets.append(['start', t])
    #logging.log(logging.DATA, "start")
    for trial in range(ntrials):
        if check_for_quit(subdata, win):
            exptutils.shut_down_cleanly(subdata, win)
            sys.exit()

        trialdata = {}
        trialdata['onset'] = onsets[trial]
        visual_stim.setImage(stim_images[trialcond[trial]])
        print trial
        print 'condition %d' % trialcond[trial]
        print 'showing image: %s' % stim_images[trialcond[trial]]
        t = clock.getTime()
        ratings_and_onsets.append(
            ["image=%s" % stim_images[trialcond[trial]], t])
        visual_stim.draw()
        logging.log(logging.DATA, "image=%s" % stim_images[trialcond[trial]])

        while clock.getTime() < trialdata['onset']:
            pass
        win.flip()

        while clock.getTime() < (trialdata['onset'] +
                                 cue_time):  #show the image
            pass

        print 'injecting via pump at address %d' % pump[trial]
        logging.log(logging.DATA,
                    "injecting via pump at address %d" % pump[trial])
        t = clock.getTime()
        ratings_and_onsets.append(
            ["injecting via pump at address %d" % pump[trial], t])
        ser.write('%drun\r' % pump[trial])

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time):
            pass

        message = visual.TextStim(win, text='')
        #ratings_and_onsets.append(["wait", t])
        message.draw()
        win.flip()

        trialdata['dis'] = [ser.write('0DIS\r'), ser.write('1DIS\r')]
        print(trialdata['dis'])

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time + wait_time):
            pass

        print 'injecting rinse via pump at address %d' % 0
        t = clock.getTime()
        ratings_and_onsets.append(
            ['injecting rinse via pump at address %d' % 0, t])
        ser.write('%dRUN\r' % 0)

        while clock.getTime() < (trialdata['onset'] + cue_time +
                                 delivery_time + wait_time + rinse_time):
            pass

        message = visual.TextStim(win, text='swallow')
        #ratings_and_onsets.append(["swallow", t])
        message.draw()
        win.flip()

        while clock.getTime() < (trialdata['onset'] + cue_time + delivery_time
                                 + wait_time + rinse_time + jitter[trial]):
            pass
        message = visual.TextStim(win, text='')
        message.draw()
        win.flip()

        while clock.getTime() < (trialdata['onset'] + cue_time + delivery_time
                                 + wait_time + rinse_time + jitter[trial]):
            pass

        t = clock.getTime()
        ratings_and_onsets.append(['end time', t])
        logging.log(logging.DATA, "finished")
        subdata['trialdata'][trial] = trialdata
    win.close()