Пример #1
0
def main():

    num_blocks    = 16    # num_blocks * wordsPerBlock should not exceed 512
    wordsPerBlock = 16     # words displayed (both latin and hebrew) per block
    word_lengths = [4, 5, 6]   # character lengths to select from word_list.txt


    #ensure that video mode is at the maxium FPS
    if sys.platform.startswith("linux"):
        from subprocess import call
        call(["xrandr","-r","144"])

    pygame.init()
    pygame.mouse.set_visible(False)

    #get filepath/name for words displayed text file
    if not os.path.isdir("data"):
        os.mkdir("data")
    num = 0
    while True:
        fn = "data/words_displayed_%02d.txt" % num
        if not os.path.isfile(fn):
            break
        num += 1

    #instantiate some objects
    if not SUPRESS_TXT_OUTPUT:
        words_displayed = open(fn, "w")
    FC = FixationCross(color = "black")
    restScreen = Screen(color = "white", fixation_cross = FC)
    blankScreen = Screen(color = "white")
    text = TextDisplay(font_size = 288,
                             font_type = "FreeMono.ttf",
                             screen_bgColor = "white",
                             )

    # get and randomize a list of latin words from the word_list.txt file
    word_list = []
    with neurodot_present.resources.load_wordlist() as list_file:
        for line in list_file.readlines():
            if len(line.rstrip()) in word_lengths:
                word_list.append(line.rstrip().upper())
    random.shuffle(word_list)

    # get list of dictionaries for latin/hebrew words and randomize
    stim_list = []
    for word in word_list[0:num_blocks*wordsPerBlock/2 + 1]:
        vsync_value = len(word) - 3 #words are 4,5,6 letters long
        latin = {'word': word, 'vsync_value': vsync_value}
        hebrew = {'word': code_hebrew(word), 'vsync_value': vsync_value + 3}
        stim_list.append(latin)
        stim_list.append(hebrew)
    random.shuffle(stim_list)

    try:

        #start sequence
        run_start_sequence()
        restScreen.run(duration = 2, vsync_value = 0)

        block = 0
        while block < num_blocks:
            for stim in stim_list[block*wordsPerBlock : block*wordsPerBlock + wordsPerBlock]:

                if not SUPRESS_TXT_OUTPUT:
                    words_displayed.write(stim['word'].encode("utf8") + "\n")

                text.run(text_content = stim['word'],
                         duration = STIMULUS_DURATION,
                         vsync_value = stim['vsync_value']
                         )
                #print text.textSurface.get_width()

                # display blank screen
                blankScreen.run(duration = STIMULUS_DURATION, vsync_value = 0)

            if block < num_blocks-1:

                # add an empty line to text file to signify between trials
                if not SUPRESS_TXT_OUTPUT:
                    words_displayed.write("\n")

                #rest period
                bell()
                restScreen.run(duration = 3, vsync_value = 0)
                bell()
                restScreen.run(duration = random.uniform(1,3), vsync_value = 0)

            block += 1

    except UserEscape as exc:
        print exc
    except:
        print "Unexpected error:"
        raise
    finally:
        if not SUPRESS_TXT_OUTPUT:
            words_displayed.close()

        # stop sequence
        run_stop_sequence()

    pygame.quit()
    sys.exit()
Пример #2
0
from neurodot_present.present_lib import Screen, FixationCross, CheckerBoardFlasher, bell, UserEscape, run_start_sequence, run_stop_sequence



pygame.init()

TASK_DURATION = 30  #seconds

FC = FixationCross()
try:
    #start sequence
    run_start_sequence()
    #setup task
    CBF = CheckerBoardFlasher(flash_rate=0) #no flashing
    CBF.setup_checkerboard(64)
    black_SCR = Screen(color = "black",fixation_cross = FC)
    #run sequence
    CBF.run(duration = TASK_DURATION, vsync_value = 1)
    black_SCR.run(duration = 1, vsync_value = 0)
    bell()
    black_SCR.run(duration = 5, vsync_value = 0)
    black_SCR.run(duration = TASK_DURATION, vsync_value = 2)
    black_SCR.run(duration = 1, vsync_value = 0)
    bell()
except UserEscape:
    print "User stopped the sequence"
except Exception, err:
    raise err
finally:
    #stop sequence
    run_stop_sequence()
    FC_left = FixationCross(color = 'black', position = (CBF.xL + 0.5*CBF.board_width, 0.0))
    FC_right = FixationCross(color = 'black', position = (CBF.xR + 0.5*CBF.board_width, 0.0))
    aFC_left = AnimatedFixationCross(position_initial = [0,0],
                                     position_final = [CBF.xL + 0.5*CBF.board_width, 0.0],
                                     movement_duration = MOVEMENT_DURATION,
                                     color = 'black',
                                     dt_threshold = 0.0005,
                                     )
    aFC_right = AnimatedFixationCross(position_initial = [0,0],
                                      position_final = [CBF.xR + 0.5*CBF.board_width, 0.0],
                                      movement_duration = MOVEMENT_DURATION,
                                      color = 'black',
                                      dt_threshold = 0.0005,
                                      )

    SCR_rest = Screen(color = 'neutral-gray', fixation_cross = FC_center)
    SCR_left = Screen(color = 'neutral-gray', fixation_cross = FC_left)
    SCR_right = Screen(color = 'neutral-gray', fixation_cross = FC_right)
    aSCR_left = AnimatedScreen(screen_bgColor = 'neutral-gray', sprite_list = [aFC_left])
    aSCR_right = AnimatedScreen(screen_bgColor = 'neutral-gray', sprite_list = [aFC_right])
    aSCR_both = AnimatedScreen(screen_bgColor = 'neutral-gray', sprite_list = [aFC_left, aFC_right])

    stimAttrs = zip(FLASH_RATES_LEFT, FLASH_RATES_RIGHT, VSYNC_VALUES)

    try:
        #start sequence
        run_start_sequence()

        while BLOCKS > 0:
            # get reversal rates and vsync values for this block
            random.shuffle(stimAttrs)
Пример #4
0
    FLASH_DURATION = 8       #seconds
    PAUSE_DURATION_RANGE = (2.0,5.0)

    FC = FixationCross()

    #CBFs

    try:
        #start sequence
        run_start_sequence()
        #trials
        for b in range(BLOCKS):
            stims = REPITITIONS*zip(FLASH_RATES, VSYNC_VALUES)
            random.shuffle(stims)
            for flash_rate, vsync_value in stims:
                CBF = CheckerBoardFlasher(flash_rate=flash_rate)
                CBF.setup_checkerboard(nrows = CHECKERBOARD_NROWS, show_fixation_dot = True)
                CBF.run(duration = FLASH_DURATION, vsync_value = vsync_value)
                SCR = Screen(color = "black", fixation_cross = FC)
                pause_duration = random.uniform(*PAUSE_DURATION_RANGE)
                SCR.run(duration = pause_duration, vsync_value = 0)
    except UserEscape as exc:
        print exc
    finally:
        #stop sequence
        run_stop_sequence()
    #exit
    print "Exiting the presentation"
    pygame.quit()
    sys.exit()
import neurodot_present.present_lib as pl
from neurodot_present.present_lib import Screen, CheckerBoard, UserEscape, VsyncPatch

pl.DEBUG = False
################################################################################
if __name__ == "__main__":

    pygame.init()
    pygame.mouse.set_visible(True)

    LOOP_MODE = 2  # 2 is using DoubleCheckerboardFlasher loop structure, 1 is using regular CheckerboardFlasher delay
    DURATION = 20
    flash_rate = 19  # Hz
    display_mode = pygame.display.list_modes()[-1]

    scr = Screen(display_mode = display_mode)
    vsync_patch = VsyncPatch(left   = scr.screen_right - pl.VSYNC_PATCH_WIDTH_DEFAULT,
                                      bottom = scr.screen_bottom,
                                      width  = pl.VSYNC_PATCH_WIDTH_DEFAULT,
                                      height = pl.VSYNC_PATCH_HEIGHT_DEFAULT
                                     )
    cb1 = CheckerBoard(1, color1 = [1.0, 1.0, 1.0], color2 = [0.0, 0.0, 0.0], width = 0.5)
    cb2 = CheckerBoard(1, color1 = [0.0, 0.0, 0.0], color2 = [1.0, 1.0, 1.0], width = 0.5)
    CB_cycle = itertools.cycle((cb2, cb1))
    vvals_cycle = itertools.cycle((0, 15))

    try:

        vsync_value = vvals_cycle.next()
        CB = CB_cycle.next()