Exemplo n.º 1
0
def runExp(stimuliDir, exp):
    # instructions = hf.getInstructions(instructionsDir)
    ID, dataPath = hf.getID(exp)
    print(dataPath)
    win = visual.Window(size=[1400, 900], color="white", units='pix')

    # instructions and practice trial
    hf.presentText(win, instr1, text_ht=30)
    presentStimuli(win,
                   demo_item,
                   exp,
                   ID,
                   dataPath,
                   presTime=presTime,
                   catchBuffer=2.3)  # practice trial

    # instructions + rest of trials.
    hf.presentText(win, instr2, text_ht=30)
    presentStimuli(win,
                   stim_list,
                   exp,
                   ID,
                   dataPath,
                   presTime=presTime,
                   catchBuffer=2.3)
Exemplo n.º 2
0
def runExp(stimuliDir):

    # settings for specific counterbalance lists.
    cbal_file = "wc_repetition_secondary_cbals.csv"
    cbal_column = 4

    with open(cbal_file, 'rb') as f:
        reader2 = csv.reader(f)
        full_cbal_list = list(reader2)

    # identify unique cbals
    cbal_unique = sorted(list({cbal[4] for cbal in full_cbal_list}))

    # instructions = hf.getInstructions(instructionsDir)
    ID, cbal, expName = userGUI(exp="rep1", cbal=cbal_unique)
    dataPath = hf.makePath(expName=expName, cbal=cbal, ID=ID)
    # print(dataPath)
    build_subdir(dataPath)
    win = visual.Window(size=[1400, 900], color="white", units='pix')

    # instructions and practice trial
    hf.presentText(win, instr1, text_ht=30)

    # presentStimuli(win,demo_item, exp, ID , dataPath, presTime = presTime, catchBuffer = 2.3) # practice trial

    stim_list = [full_cbal_list[0]]
    for row in full_cbal_list:
        if row[cbal_column] == cbal:
            stim_list.append(row)

    runtime_info = {
        "exp": expName,
        "cbal": cbal,
        "ID": ID,
        "datapath": dataPath
    }
    presentStimuli(win,
                   stim_list,
                   runtime_info,
                   presTime=presTime,
                   catchBuffer=2.3)

    # conclusion
    hf.presentText(win, instr2, text_ht=30)
def runExp():
    # instructions = hf.getInstructions(instructionsDir)
    main_window = visual.Window(size=[1400, 900], color="white", units='pix')
    ID, dataPath = hf.getID(exp)

    # instructions and practice trial
    hf.presentText(main_window, instr1, text_ht=30)
    presentStimuli(main_window,
                   dataPath,
                   ID,
                   demo_item,
                   presTime,
                   catchBuffer=2.3)  # practice trial

    # instructions + rest of trials.
    hf.presentText(main_window, instr2, text_ht=30)
    presentStimuli(main_window,
                   dataPath,
                   ID,
                   stimuli_list,
                   presTime,
                   catchBuffer=2.3)
Exemplo n.º 4
0
def presentStimuli(win,
                   stimuli_list,
                   exp,
                   ID,
                   dataPath,
                   outputFolder="/Data",
                   presTime=.1,
                   catchBuffer=0.5):

    sceneVis = visual.ImageStim(win, image=None)

    # for itemNum, cur_row in enumerate(stim_list[0:2]):
    for itemNum, cur_row in enumerate(stimuli_list):
        key_check = []

        participant = str(ID).zfill(2)
        trial = str(cur_row[2]).zfill(3)
        trial_type = cur_row[0]
        img = cur_row[1]
        if trial_type == 'prac':
            trial = 'p' + trial[1:]
        audio_file = exp + '_' + participant + "_" + trial + ".wav"
        audio_path = dataPath + '/' + audio_file

        stim_path = os.getcwd() + stimuliDir + img

        fixation_duration = float(cur_row[3]) / 1000 + 1

        recorder = hf.AudioRecorder(audio_path)

        # some will be subbed out...
        word, error, word_onset, word_duration = '', '', '', ''
        cur_key = event.getKeys(keyList=['p', 'u', 'q', 'space'])
        if cur_key:
            key_check.append(cur_key[0])

        # load current image.
        sceneVis.setImage(stim_path)
        sceneVis.draw()
        recorder.start()

        win.flip()  # show stim

        core.wait(presTime)  # for this duration,
        print("1 ", key_check)
        win.flip()  # then hide screen

        if buzzerGo:  # play the deadline buzzer
            response, duration = hf.playAudio("bell.wav", catchBuffer)

        recorder.stop()
        print("2 ", key_check, response)

        # write row
        try:
            trial_duration = duration + presTime
        except:
            trial_duration = presTime

        header = [
            "computer", "datetime", "exp", "cbal", "participant", "trial",
            "trial_type", "img", "trial_duration", "audio_path", "audio_file",
            "word", "error", "word_onset", "word_duration"
        ]

        lrow = [
            computer, cur_date, exp, cbal, participant, trial, trial_type, img,
            trial_duration, audio_path, audio_file, word, error, word_onset,
            word_duration
        ]

        # lrow = [cur_date,exp,participant,trial,trial_type,img,dur,audio_path,audio_file]

        # write long format.
        try:
            hf.write_2('data.csv', lrow, header)
            # print(lrow)
        except:
            print("error opening datafile")
            hf.write_2('{0}.csv'.format(file_date), lrow, header)

        # write wide format.
        if trial_type == "trgt":
            intf = stimuli_list[itemNum - 1][0]
            lrow[6] = intf
            try:
                hf.write_2('wdata.csv', lrow, header)
                # print(lrow)
            except:
                print("error opening datafile")
                hf.write_2('w{0}.csv'.format(file_date), lrow, header)
        # key_check = event.getKeys(keyList=['a'])

        # experimenter control functions

        if pause_key in key_check or pause_key in response:
            key_check = ''
            hf.presentText(win, "*paused*", wait=True, timeDelay=2, text_ht=80)

        if quit_key in key_check or quit_key in response:
            break

        if fixGo:  # show the fix cross
            fix_timer = core.Clock()
            hf.presentText(win,
                           "+",
                           wait=False,
                           timeDelay=fixation_duration,
                           text_ht=80)

        event.getKeys(keyList=['p', 'u', 'q', 'space'])
Exemplo n.º 5
0
def presentStimuli(win,
                   stimuli_list,
                   runtime_info,
                   outputFolder="/Data",
                   presTime=.1,
                   catchBuffer=0.5):

    sceneVis = visual.ImageStim(win, image=None)

    # for itemNum, cur_row in enumerate(stim_list[0:2]):
    for itemNum, cur_row in enumerate(stimuli_list):
        if itemNum == 0:
            header = [
                "computer", "datetime", "exp", "cbal", "participant", "trial",
                "trial_type", "img", "trial_duration", "isi", "audio_path",
                "audio_file", "said", "error"
            ]
            header.extend(cur_row[-3:])
            if deadline:
                header.append("deadline")
            continue
        key_check = []

        participant = str(runtime_info["ID"]).zfill(2)
        trial = str(cur_row[2]).zfill(3)
        trial_type = cur_row[0]
        img = cur_row[1]
        isi = cur_row[3]
        if trial_type == 'prac':
            trial = 'p' + trial[1:]
        audio_file = runtime_info[
            "exp"] + '_' + participant + "_" + trial + ".wav"
        data_file = runtime_info["exp"] + '_' + participant + "_" + ".txt"
        audio_path = runtime_info["datapath"] + '/' + audio_file
        pdata_path = runtime_info["datapath"] + '/' + data_file
        trgt_path = runtime_info["datapath"] + "/trgt_audio" + '/' + audio_file

        stim_path = os.getcwd() + stimuliDir + img

        fixation_duration = .5  # float(cur_row[3])/1000 + 1

        recorder = hf.AudioRecorder(audio_path)

        # some will be subbed out...
        said, error = '', ''
        cur_key = event.getKeys(keyList=['p', 'u', 'q', 'space'])

        # load current image.
        sceneVis.setImage(stim_path)
        sceneVis.draw()
        recorder.start()

        win.flip()  # show stim

        trial_duration = 0

        if advance_on_space:
            timer = core.Clock()
            cur_key = event.waitKeys(keyList=['p', 'u', 'q', 'space'])
            trial_duration += timer.getTime()

        else:
            core.wait(presTime)  # for this duration
            trial_duration += presTime

        if cur_key:
            key_check.append(cur_key[0])

        print("1 ", key_check)
        win.flip()  # then hide screen

        response = []
        if deadline:  # play the deadline buzzer
            response, duration = hf.playAudio("bell.wav", catchBuffer)
            trial_duration += duration

        recorder.stop()
        print("2 ", key_check, response)

        # write row
        # try:
        # trial_duration = duration + presTime
        # except:
        # trial_duration = presTime
        trial_duration_ms = trial_duration * 1000

        # this should be moved to outside the loop

        cur_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
        lrow = [
            computer, cur_date, runtime_info["exp"], runtime_info["cbal"],
            participant, trial, trial_type, img, trial_duration_ms, isi,
            audio_path, audio_file, said, error
        ]
        lrow.extend(cur_row[-3:])

        if deadline:
            header.append("deadline")
            lrow.append(deadline)
        # lrow = [cur_date,exp,participant,trial,trial_type,img,dur,audio_path,audio_file]

        # write long format.
        try:
            hf.write_2('data.csv', lrow, header)
            # print(lrow)
        except:
            print("error opening datafile")
            hf.write_2('{0}.csv'.format(file_date), lrow, header)

        # data.txt for participant in the part folder
        try:
            hf.write_2(pdata_path, lrow, header)
            # print(lrow)
        except:
            print("error opening pdatafile")
            hf.write_2('{0}.csv'.format(file_date), lrow, header)

        # write wide format.
        wide_type_trials = ["target", "repetition", "restxt", "t_img"]

        if trial_type in wide_type_trials:
            intf = stimuli_list[itemNum][5]

            lrow[6] = intf
            try:
                hf.write_2('wdata.csv', lrow, header)
                os.rename(audio_path, trgt_path)
                # print(lrow)
            except:
                print("error opening datafile")
                hf.write_2('w{0}.csv'.format(file_date), lrow, header)
        # key_check = event.getKeys(keyList=['a'])

        # experimenter control functions

        if pause_key in key_check or pause_key in response:
            key_check = ''
            hf.presentText(win, "*paused*", wait=True, timeDelay=2, text_ht=80)

        if quit_key in key_check or quit_key in response:
            break

        if fixGo:  # show the fix cross
            fix_timer = core.Clock()
            hf.presentText(win,
                           "+",
                           wait=False,
                           timeDelay=fixation_duration,
                           text_ht=80)

        event.getKeys(keyList=['p', 'u', 'q', 'space'])
def presentStimuli(main_window,
                   dataPath,
                   ID,
                   stimuli_list,
                   presTime=.1,
                   catchBuffer=0.5,
                   outputFolder="/Data"):
    win = main_window
    sceneVis = visual.ImageStim(win, image=None)
    # foo()

    for itemNum, cur_row in enumerate(stimuli_list):

        participant = str(ID).zfill(2)
        trial = str(cur_row[2]).zfill(3)
        trial_type = cur_row[0]
        img = cur_row[1]
        if trial_type == 'prac':
            trial = 'p' + trial[1:]
        audio_file = exp + '_' + participant + "_" + trial + ".wav"
        data_file = exp + '_' + participant + "_" + ".txt"
        audio_path = dataPath + '/' + audio_file
        pdata_path = dataPath + '/' + data_file

        stim_path = os.getcwd() + stimuliDir + img

        # fixation duration set in gui by researcher
        fixation_duration = fixDur  # float(cur_row[3])/1000 + 1

        recorder = hf.AudioRecorder(audio_path)

        # vars to be recorded. some will be subbed out...
        word, error, word_onset, word_duration = '', '', '', ''

        # set up key press watcher
        key_check = []
        cur_key = event.getKeys(keyList=['p', 'u', 'q', 'space'])
        if cur_key:
            key_check.append(cur_key[0])

        # load current image.
        sceneVis.setImage(stim_path)
        sceneVis.draw()
        recorder.start()

        main_window.flip()  # show stim

        core.wait(presTime)  # for this duration,
        # print("1 ",key_check)
        main_window.flip()  # then hide screen

        trial_duration = presTime
        response = []
        if buzzerGo:  # play the deadline buzzer
            response, duration = hf.playAudio("bell.wav", catchBuffer)
            trial_duration += duration

        recorder.stop()
        # print("2 ",key_check,response)

        header = [
            "computer", "datetime", "exp", "cbal", "participant", "trial",
            "trial_type", "img", "trial_duration", "audio_path", "audio_file",
            "word", "error", "word_onset", "word_duration"
        ]
        # this should be moved to outside the loop

        # cur_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
        lrow = [
            computer, cur_date, exp, cbal, participant, trial, trial_type, img,
            trial_duration, audio_path, audio_file, word, error, word_onset,
            word_duration
        ]

        # write long format.
        try:
            hf.write_2('data.csv', lrow, header)
            # print(lrow)
        except:
            print("error opening datafile")
            hf.write_2('{0}.csv'.format(file_date), lrow, header)

        # data.txt for participant in the part folder
        try:
            hf.write_2(pdata_path, lrow, header)
            # print(lrow)
        except:
            print("error opening pdatafile")
            hf.write_2('{0}.csv'.format(file_date), lrow, header)

        # write wide format.
        if trial_type == "trgt":
            # lrow[6] = stimuli_list[itemNum - 1][0] # pull the label from previous trial to determine 'trial_type'
            try:
                hf.write_2('wdata.csv', lrow, header)
                print("wdata")
                print(lrow)
            except:
                print("error opening datafile")
                hf.write_2('w{0}.csv'.format(file_date), lrow, header)
        # key_check = event.getKeys(keyList=['a'])

        # experimenter control functions

        if pause_key in key_check or pause_key in response:
            key_check = ''
            hf.presentText(main_window,
                           "*paused*",
                           wait=True,
                           timeDelay=2,
                           text_ht=80)

        if quit_key in key_check or quit_key in response:
            break

        if fixGo:  # show the fix cross
            fix_timer = core.Clock()
            hf.presentText(main_window,
                           "+",
                           wait=False,
                           timeDelay=fixation_duration,
                           text_ht=80)

        event.getKeys(keyList=['p', 'u', 'q', 'space'])