Exemplo n.º 1
0
def VisualHyperventilateBlock(rp, ap):
    '''Block of rotating checkerboard + breathhold.'''

    ## Prepare instructions.
    instr = ['Inhale', 'Inhale', 'Exhale', 'Exhale'] * 5

    ## Log onset of breath hold.
    logging.log(level=logging.EXP, msg='Hyperventilate')

    ## Breath-hold only.
    timer = clock.CountdownTimer(10)
    while timer.getTime() > 0:

        ## Update text.
        Counter.setText('%0.0f' % (1 + ceil(timer.getTime()) % 2))
        Counter.draw()
        W.flip()

        ## Check keys.
        CheckForEscape()

    ## Log onset of radial checkerboard.
    logging.log(level=logging.EXP, msg='Checkerboard')

    ## Breathhold + radial checkerboard.
    timer = clock.CountdownTimer(10)
    while timer.getTime() > 0:

        ## Update radial checkerboard.
        RCB.setRadialPhase(0.025, rp)
        RCB.setAngularPhase(0.025, ap)
        RCB.draw()

        ## Update text.
        Counter.setText('%0.0f' % (1 + ceil(timer.getTime()) % 2))
        Counter.draw()
        W.flip()

        ## Check keys.
        CheckForEscape()

    ## Log offset of breath-hold.
    logging.log(level=logging.EXP, msg='Hyperventilate end')

    ## Radial checkerboard only.
    timer = clock.CountdownTimer(10)
    while timer.getTime() > 0:

        ## Update radial checkerboard.
        RCB.setRadialPhase(0.025, rp)
        RCB.setAngularPhase(0.025, ap)
        RCB.draw()
        fix.draw()
        W.flip()

        ## Check keys.
        CheckForEscape()
Exemplo n.º 2
0
def VisualBreathHoldBlock(rp, ap):
    '''Block of rotating checkerboard + breathhold.'''

    ## Log onset of breath hold.
    logging.log(level=logging.EXP, msg='Breath hold')

    ## Breath-hold only.
    timer = clock.CountdownTimer(10)
    while timer.getTime() > 0:

        ## Update text.
        Counter.setText('%0.0f' % (timer.getTime() + 10))
        Counter.draw()
        W.flip()

        ## Check keys.
        CheckForEscape()

    ## Log onset of radial checkerboard.
    logging.log(level=logging.EXP, msg='Checkerboard')

    ## Breathhold + radial checkerboard.
    timer = clock.CountdownTimer(10)
    while timer.getTime() > 0:

        ## Update radial checkerboard.
        RCB.setRadialPhase(0.025, rp)
        RCB.setAngularPhase(0.025, ap)
        RCB.draw()

        ## Update text.
        Counter.setText('%0.0f' % timer.getTime())
        Counter.draw()
        W.flip()

        ## Check keys.
        CheckForEscape()

    ## Log offset of breath-hold.
    logging.log(level=logging.EXP, msg='Breath hold end')

    ## Radial checkerboard only.
    timer = clock.CountdownTimer(10)
    while timer.getTime() > 0:

        ## Update radial checkerboard.
        RCB.setRadialPhase(0.025, rp)
        RCB.setAngularPhase(0.025, ap)
        RCB.draw()
        fix.draw()
        W.flip()

        ## Check keys.
        CheckForEscape()
Exemplo n.º 3
0
    def _run_trial_main_loop(self, clock, time_bar_x):
        """ To run the main drawing loop """
        started_drawing = False
        cursor_t = np.zeros([10000])  # for recording times with cursor pos
        mouse = event.Mouse(win=self.win)
        #MD: Probably a better pattern -> two separate while loops,
        #   one for activating the cyan square and moving to the beginning
        #   then another one drawing and incrementing the bar
        #
        # As it is currently done, we have to evaluate all the ifs during each
        # while cycle
        # ---> actually this is what is happening...

        while True:
            self.draw_and_flip(exclude=['trace'])
            if mouse.isPressedIn(self.frame['elements']['start_point']):
                self.log.debug('Mouse pressed in startpoint')
                # change to cyan
                # older psychopy versions use str instead of arr to set color
                # eg 'Cyan'
                self.frame['elements']['start_point'].fillColor = [-1, 1, 1]
                tic = clock.getTime()
                self.draw_and_flip(exclude=['trace', 'instructions'])
                break

        while True:
            # drawing has begun
            if mouse.isPressedIn(self.frame['elements']['cursor']):
                self.log.debug('Mouse started drawing with cursor')
                started_drawing = True
                self.frame['lifted'] = False

                trial_timer = clock.CountdownTimer(self.trial_settings['trial_duration'])

                # save start time
                start_t_stamp = clock.getTime()

                # calc pre trial time
                ptt = start_t_stamp - tic

            # shrink time bar, draw trace, once drawing has started
            if started_drawing:

                if self.verbose:
                    print('STARTED DRAWING')
                self._exec_drawing(trial_timer, mouse, time_bar_x, cursor_t)

                # time_bar elapsed
                if self.verbose:
                    print('breaking out of main')

                break

        return ptt, start_t_stamp, cursor_t
Exemplo n.º 4
0
def FixationBlock(sec):
    """Present fixation cross."""

    # Draw/log fixation cross.
    fix.draw()
    W.logOnFlip(level=logging.EXP, msg='Fixation cross')
    W.flip()

    # Wait.
    timer = clock.CountdownTimer(sec)
    while timer.getTime() > 0:

        # Check keys.
        CheckForEscape()
Exemplo n.º 5
0
def FixationBlock(sec):
    '''Block of fixation cross for XX seconds.'''

    ## Draw/log fixation cross.
    fix.draw()
    W.logOnFlip(level=logging.EXP, msg='Fixation cross')
    W.flip()

    ## Wait.
    timer = clock.CountdownTimer(sec)
    while timer.getTime() > 0:

        ## Check keys.
        CheckForEscape()
Exemplo n.º 6
0
def BreathHoldBlock(sec):
    '''Block of breathholding for XX seconds.'''

    ## Log onset of breath hold.
    logging.log(level=logging.EXP, msg='Breath hold')

    ## Run breath-hold task.
    timer = clock.CountdownTimer(sec)
    while timer.getTime() > 0:

        ## Update text.
        Counter.setText('%0.0f' % timer.getTime())
        Counter.draw()
        W.flip()

        ## Check keys.
        CheckForEscape()
Exemplo n.º 7
0
def CheckerBoardBlock(sec, rp='+', ap='+'):
    """Block of rotating checkerboard for XX seconds."""

    ## Log onset of checkerboard.
    logging.log(level=logging.EXP, msg='Checkerboard')

    ## Run visual checkerboard.
    timer = clock.CountdownTimer(sec)
    while timer.getTime() > 0:

        ## Update radial checkerboard.
        RCB.setRadialPhase(0.025, rp)
        RCB.setAngularPhase(0.025, ap)
        RCB.draw()
        W.flip()

        ## Check keys.
        CheckForEscape()
Exemplo n.º 8
0
def TextTrial(stimulus, text, time, keyList):
    """Present text to participant."""

    ## Update text.
    stimulus.setText(text)
    stimulus.draw()

    ## Draw text.
    W.logOnFlip(level=logging.EXP, msg=text)
    TimeStamp = W.flip()

    ## Wait for response.
    timer = clock.CountdownTimer(time)

    KeyPress = None
    while timer.getTime() > 0:

        if not KeyPress:

            KeyPress = event.getKeys(keyList=keyList)
Exemplo n.º 9
0
def InstructionsBlock(sec):
    '''Present instructions for XX seconds.'''

    Instr = visual.TextStim(W,
                            units='norm',
                            pos=(0, 0),
                            antialias=False,
                            bold=True,
                            color=(139, 0, 0),
                            colorSpace='rgb255',
                            autoLog=False)

    ## Wait.
    timer = clock.CountdownTimer(sec)
    while timer.getTime() > 0:

        Instr.setText('%s in %0.0f' % (task, timer.getTime()))
        Instr.draw()
        W.flip()

        ## Check keys.
        CheckForEscape()
Exemplo n.º 10
0
    from psychopy.iohub import client

    # launch a win instance to intercept the keypresses
    # so that they are not sent to the console
    win = visual.Window()

    # Start the ioHub process. 'io' can now be used during the
    # experiment to access iohub devices and read iohub device events
    io = client.launchHubServer()
    io.devices.mouse.reporting = False

    print('Press [SPACE] to continue... ')
    waitKeyPress(io, key=' ', timeout=10)

    all_percepts = []
    trial_timer = clock.CountdownTimer(start=3)

    pb = get_percept_report(io, clear=True)
    current_percept = pb[-1]

    while trial_timer.getTime() > 0:
        win.flip()

    pb = get_percept_report(io)
    io.devices.keyboard.reporting = False
    print('Trial ended')

    print(pb)
    pb = merge_percepts(pb)
    for p in pb:
        print(p)
Exemplo n.º 11
0
    For 100 trials, we expect 500 seconds.
    With a TR of 1, this corresponds to 500 volumes.
    '''
    leftmost = stim_order_rnd.choice(actions)
    # Average of 2.0s
    stimulus_duration = stim_order_rnd.choice([1, 2, 3])
    # Average of 3.0s
    feedback_duration = stim_order_rnd.choice([2, 3, 4])

    # Render stimus
    render(
        'stim presentation for duration {:.03f}. feedback duration {:.03f}'.
        format(stimulus_duration, feedback_duration), leftmost)
    keyPress = None
    action = None
    timer = clock.CountdownTimer(stimulus_duration)
    while timer.getTime() > 0:
        keyPress = getKeysOrQuit()
        if '1' in keyPress or '2' in keyPress:
            action = key_and_leftmost_to_action[keyPress[0], leftmost]
            render('stim select', leftmost, action_selected=action)
            break
    while timer.getTime() > 0:
        keyPress = getKeysOrQuit()

    # Render feedback
    if action is None:
        render('no response', leftmost=None)
    else:
        observation, reward, _, _ = env.step(action)
        cumulative_rew += reward
Exemplo n.º 12
0
# transparent left/right and coherent
nAmb_plaids = set(plaid_stims.keys()) - set(['amb', 'fix'])

# get the velocity parameter that will be useful later on
parameters = io.getSessionMetaData()['user_variables']['parameters']
velocity = parameters['velocity']

# TODO: initialise the log-normal parameters to some sensible values
mu, sigma = 3, 2

# set up some timers
# a global timer is available at the experiment level
# this clock should never be reset to have a unique time base
global_timer = core.Clock()
# time to wait until next flip in non-ambiguous stimulus condition
flip_timer = clock.CountdownTimer(0)
# time between different percepts, useful to estimate the parameters mu and sigma
percept_duration = clock.Clock()
# total duration of the trial
trial_timer = clock.CountdownTimer(0)

# markov renewal process, can be updated all throughout the experiment
mrp = stats.MarkovRenewalProcess(
    list(percepts.Percept().percept_dict['perceptual_states']))

# logging experiment messages to file
log_filename = io.getSessionMetaData()['user_variables']['logfile']
logFile = logging.LogFile(f=log_filename, level=logging.EXP)
trigger_filename = io.getSessionMetaData()['user_variables']['triggerfile']
triggerFile = logging.LogFile(f=trigger_filename,
                              level=logging.getLevel('TRIG'))