def plot_reactiontime_dynamics(bData, winsize=40, fontsize=12):
    '''
    This function plots a running average for the reaction time based on trial outcomes or which side the animal actually choosed ('choice'). 
    *Invalid trials does not have choice time since timeSideIn is NaN.
    Reaction time is defined as the time it took from hearing sound stimulus to deciding to act (removing head from center port).
    '''
    lineWidth = 2
    reactionTime = bData['timeCenterOut'] - bData['timeTarget']
    correctTrials = bData['outcome'] == bData.labels['outcome']['correct']
    errorTrials = bData['outcome'] == bData.labels['outcome']['error']
    #    invalidTrials = bData['outcome']==bData.labels['outcome']['invalid']
    #Cannot use rewardSide here since some trials will be invalid and contain NaN 'timeSideIn'
    leftTrials = bData['choice'] == bData.labels['choice']['left']
    #Cannot use ~leftTrials for indexing since will include trials where choice is none and timeSideIn will be NaN
    rightTrials = bData['choice'] == bData.labels['choice']['right']

    reactionTCorrect = np.ma.masked_array(reactionTime[correctTrials])
    movAvReactionTime_correct = extrafuncs.moving_average_masked(
        reactionTCorrect, winsize)
    reactionTError = np.ma.masked_array(reactionTime[errorTrials])
    movAvReactionTime_error = extrafuncs.moving_average_masked(
        reactionTError, winsize)
    reactionTLeft = np.ma.masked_array(reactionTime[leftTrials])
    movAvReactionTime_left = extrafuncs.moving_average_masked(
        reactionTLeft, winsize)
    reactionTRight = np.ma.masked_array(reactionTime[rightTrials])
    movAvReactionTime_right = extrafuncs.moving_average_masked(
        reactionTRight, winsize)

    line1, = plt.plot(movAvReactionTime_correct,
                      lw=lineWidth,
                      color='m',
                      alpha=1,
                      label='correct')
    #plt.hold(1)
    line2, = plt.plot(movAvReactionTime_error,
                      lw=lineWidth,
                      color='b',
                      alpha=1,
                      label='error')
    #plt.hold(1)
    line3, = plt.plot(movAvReactionTime_left,
                      lw=lineWidth,
                      color='g',
                      label='left')
    #plt.hold(1)
    line4, = plt.plot(movAvReactionTime_right,
                      lw=lineWidth,
                      color='r',
                      label='right')
    #plt.hold(1)
    #plt.ylim([0,2.5])
    #plt.ylabel('Reaction time(s)',fontsize=fontsize)
    plt.xlabel('Trial number', fontsize=fontsize)
    plt.legend([line1, line2, line3, line4],
               ['correct', 'error', 'left', 'right'],
               loc=1)
    ax = plt.gca()
    ax.set_ylabel('Reaction time(s)', fontsize=fontsize, labelpad=1)
    extraplots.set_ticks_fontsize(ax, fontsize)
def plot_ITI_dynamics(bData, winsize=40, fontsize=12):
    '''
    Plot speed of performance (in intertrial intervals) in time for one session. Plots left- and right- rewardSide trials separately. 
    First argument is an object created by loadbehavior.BehaviorData (or subclasses)
    '''
    lineWidth = 2
    trialStarts = bData['timeTrialStart']
    interTrialIntervals = np.hstack((0, np.diff(trialStarts)))

    #Running average of ITI for the left- or right-rewarded trials, including invalid and error trials too
    #    ITIVec = np.ma.masked_array(interTrialIntervals)
    leftTrials = bData['rewardSide'] == bData.labels['rewardSide']['left']

    leftTrialITIs = np.ma.masked_array(interTrialIntervals[leftTrials])
    movAvITI_left = extrafuncs.moving_average_masked(leftTrialITIs, winsize)
    rightTrialITIs = np.ma.masked_array(interTrialIntervals[~leftTrials])
    movAvITI_right = extrafuncs.moving_average_masked(rightTrialITIs, winsize)
    #plt.plot(range(0,len(leftTrials)),100*movAvChoice_left,
    #             lw=lineWidth,color='g')
    line1 = plt.plot(movAvITI_left, lw=lineWidth, color='g')
    #plt.hold(1)
    line2 = plt.plot(movAvITI_right, lw=lineWidth, color='r')
    #plt.hold(1)
    #(line1, line2) = plt.plot(range(0,len(leftTrials)), movAvITI_left, range(0,len(~leftTrials)), movAvITI_right)
    #plt.setp((line1,line2), color=('g','b'), linewidth=2.0)
    #plt.legend([line1, line2], ['Leftward trials', 'Rightward trials'])

    #plt.ylabel('Intertrial Interval(s)',fontsize=fontsize)
    plt.xlabel('Trial number', fontsize=fontsize)
    #plt.title('Intertrial Interval')
    plt.ylim(0, 30)
    ax = plt.gca()
    ax.set_ylabel('Intertrial Interval(s)', fontsize=fontsize, labelpad=1)
    extraplots.set_ticks_fontsize(ax, fontsize)
def plot_ITI_dynamics(bData, winsize=40, fontsize=12):
    '''
    Plot speed of performance (in intertrial intervals) in time for one session. Plots left- and right- rewardSide trials separately. 
    First argument is an object created by loadbehavior.BehaviorData (or subclasses)
    '''
    lineWidth = 2
    trialStarts = bData['timeTrialStart']
    interTrialIntervals = np.hstack((0,np.diff(trialStarts)))

    #Running average of ITI for the left- or right-rewarded trials, including invalid and error trials too 
#    ITIVec = np.ma.masked_array(interTrialIntervals)
    leftTrials = bData['rewardSide']==bData.labels['rewardSide']['left']
    
    leftTrialITIs = np.ma.masked_array(interTrialIntervals[leftTrials])
    movAvITI_left = extrafuncs.moving_average_masked(leftTrialITIs, winsize)
    rightTrialITIs = np.ma.masked_array(interTrialIntervals[~leftTrials])
    movAvITI_right = extrafuncs.moving_average_masked(rightTrialITIs, winsize)
    #plt.plot(range(0,len(leftTrials)),100*movAvChoice_left,
    #             lw=lineWidth,color='g')
    line1 = plt.plot(movAvITI_left,lw=lineWidth,color='g')
    #plt.hold(1)
    line2 = plt.plot(movAvITI_right,lw=lineWidth,color='r')
    #plt.hold(1)
    #(line1, line2) = plt.plot(range(0,len(leftTrials)), movAvITI_left, range(0,len(~leftTrials)), movAvITI_right)
    #plt.setp((line1,line2), color=('g','b'), linewidth=2.0)
    #plt.legend([line1, line2], ['Leftward trials', 'Rightward trials'])
    
    #plt.ylabel('Intertrial Interval(s)',fontsize=fontsize)
    plt.xlabel('Trial number',fontsize=fontsize)
    #plt.title('Intertrial Interval')
    plt.ylim(0,30)
    ax = plt.gca()
    ax.set_ylabel('Intertrial Interval(s)',fontsize=fontsize,labelpad=1)
    extraplots.set_ticks_fontsize(ax,fontsize)
Example #4
0
def plot_choicetime_dynamics(bData, winsize=40, fontsize=12):
    '''
    This function plots a running average for the choice time based on trial outcomes or which side the animal actually choosed ('choice'). 
    *Invalid trials does not have choice time since timeSideIn is NaN.
    Choice time is defined as the time it took to get to the side ports to retrieve water from the time of leaving center port.
    '''
    lineWidth = 2

    choiceTime = bData['timeSideIn']-bData['timeCenterOut']
    correctTrials = bData['outcome']==bData.labels['outcome']['correct']
    errorTrials = bData['outcome']==bData.labels['outcome']['error']
#    invalidTrials = bData['outcome']==bData.labels['outcome']['invalid']
#Cannot use rewardSide here since some trials will be invalid and contain NaN 'timeSideIn'
    leftTrials = bData['choice']==bData.labels['choice']['left']
#Cannot use ~leftTrials for indexing since will include trials where choice is none and timeSideIn will be NaN
    rightTrials = bData['choice']==bData.labels['choice']['right']

    #choiceTCorrect = np.ma.masked_array(choiceTime[correctTrials])
    #movAvChoiceTime_correct = extrafuncs.moving_average_masked(choiceTCorrect, winsize)
    #choiceTError = np.ma.masked_array(choiceTime[errorTrials])
    #movAvChoiceTime_error = extrafuncs.moving_average_masked(choiceTError, winsize)
    bData.find_trials_each_block()
    trialsEachBlock = bData.blocks['trialsEachBlock']
    nBlocks = bData.blocks['nBlocks']
    choiceTLeft = np.ma.masked_array(choiceTime[leftTrials])
    choiceTRight = np.ma.masked_array(choiceTime[rightTrials])
    for block in range(nBlocks):
        choiceTimeThisBlock = choiceTime[trialsEachBlock[:,block]]
        leftTrialsThisBlock = leftTrials[trialsEachBlock[:,block]]
        rightTrialsThisBlock = rightTrials[trialsEachBlock[:,block]]
        choiceTLeftThisBlock = np.ma.masked_array(choiceTimeThisBlock[leftTrialsThisBlock])
        choiceTRightThisBlock = np.ma.masked_array(choiceTimeThisBlock[rightTrialsThisBlock])
        #choiceTLeftThisBlock = choiceTLeft[trialsEachBlock[:,block]]
        #choiceTRightThisBlock = choiceTRight[trialsEachBlock[:,block]]
        movAvChoiceTime_right = extrafuncs.moving_average_masked(choiceTRightThisBlock, winsize)
        movAvChoiceTime_left = extrafuncs.moving_average_masked(choiceTLeftThisBlock, winsize)
        #plt.plot(movAvChoiceTime_correct,lw=lineWidth,color='m',alpha=1)
        #plt.hold(1)
        #plt.plot(movAvChoiceTime_error,lw=lineWidth,color='b',alpha=1)
        xValues = range(block*150,block*150+len(movAvChoiceTime_left))
        plt.plot(xValues,movAvChoiceTime_left,lw=lineWidth,color='g')
        xValues = range(block*150,block*150+len(movAvChoiceTime_right))
        plt.plot(xValues,movAvChoiceTime_right,lw=lineWidth,color='r')
        #plt.hold(1)
        #plt.ylim([0,2.5])
        #plt.axhline(50,color='0.5',ls='--')
        #plt.ylabel('Choice time(s)',fontsize=fontsize)
    plt.xlabel('Trial number',fontsize=fontsize)
    ax = plt.gca()
    extraplots.set_ticks_fontsize(ax,fontsize)
    ax.set_ylabel('Choice time(s)',fontsize=fontsize,labelpad=1)
Example #5
0
def plot_dynamics(behavData, winsize=40, fontsize=12):
    '''
    Plot performance in time for one session.
    First argument is an object created by loadbehavior.BehaviorData (or subclasses)
    '''
    ax = plt.gca()
    ax.cla()
    lineWidth = 2
    possibleRewardSide = np.unique(behavData['rewardSide'])
    possibleColors = ['b', 'r']
    rightChoice = behavData['choice'] == behavData.labels['choice']['right']

    hPlots = []
    plt.hold(True)
    valid = behavData['valid'].astype(bool)
    for indr, thisSide in enumerate(possibleRewardSide):
        thisColor = possibleColors[indr]
        trialsThisSide = (behavData['rewardSide'] == thisSide)
        choiceVecThisSide = np.ma.masked_array(rightChoice[valid])
        choiceVecThisSide.mask = ~trialsThisSide[valid]
        movAvChoice = extrafuncs.moving_average_masked(choiceVecThisSide,
                                                       winsize)
        hp, = plt.plot(range(0, len(movAvChoice)),
                       100 * movAvChoice,
                       lw=lineWidth,
                       color=thisColor)
        hPlots.append(hp)
    plt.ylim([-5, 105])
    plt.axhline(50, color='0.5', ls='--')
    plt.ylabel('% rightward', fontsize=fontsize)
    plt.xlabel('Trial', fontsize=fontsize)
    extraplots.set_ticks_fontsize(ax, fontsize)
    #plt.draw()
    #plt.show()
    return hPlots
Example #6
0
def plot_dynamics_2afc(behavData,winsize=40,fontsize=12):
    '''
    Plot performance in time for one session for left and right trials.
    First argument is an object created by loadbehavior.BehaviorData (or subclasses)
    '''
    ax = plt.gca()
    ax.cla()
    lineWidth = 2
    possibleRewardSide = np.unique(behavData['rewardSide'])
    possibleColors = ['b','r']
    rightChoice = behavData['choice']==behavData.labels['choice']['right']

    hPlots = []
    plt.hold(True)
    valid = behavData['valid'].astype(bool)
    for indr,thisSide in enumerate(possibleRewardSide):
        thisColor = possibleColors[indr]
        trialsThisSide = (behavData['rewardSide']==thisSide)
        choiceVecThisSide = np.ma.masked_array(rightChoice[valid])
        choiceVecThisSide.mask = ~trialsThisSide[valid]
        movAvChoice = extrafuncs.moving_average_masked(choiceVecThisSide,winsize)
        hp, = plt.plot(range(0,len(movAvChoice)),100*movAvChoice,
                       lw=lineWidth,color=thisColor)
        hPlots.append(hp)
    plt.ylim([-5,105])
    plt.axhline(50,color='0.5',ls='--')
    plt.ylabel('% rightward',fontsize=fontsize)
    plt.xlabel('Trial',fontsize=fontsize)
    extraplots.set_ticks_fontsize(ax,fontsize)
    #plt.draw()
    #plt.show()
    return hPlots
Example #7
0
def calculate_dynamics(behavData, winsize=40, soundfreq=None, byBlock=True):
    if soundfreq:
        possibleFreq = soundfreq
    else:
        possibleFreq = np.unique(behavData['targetFrequency'])
    if byBlock:
        behavData.find_trials_each_block()

        nBlocks = behavData.blocks['nBlocks']
        trialsEachBlock = behavData.blocks['trialsEachBlock']
        validEachBlock = trialsEachBlock & (
            behavData['valid'][:, np.newaxis].astype(bool))
        nValidEachBlock = np.sum(validEachBlock, axis=0)
        lastValidEachBlock = np.cumsum(
            nValidEachBlock
        )  # Actually, these values correspond to lastIndex+1
        firstValidEachBlock = np.concatenate(([0], lastValidEachBlock[:-1]))
        rightChoice = behavData['choice'] == behavData.labels['choice'][
            'right']

        movAvChoiceMatrix = np.ndarray([len(possibleFreq), sum(valid)])
        for indb in range(nBlocks):
            trialsThisBlock = trialsEachBlock[:, indb]
            validThisBlock = validEachBlock[:, indb]
            for indf, thisFreq in enumerate(possibleFreq):
                trialsThisFreq = (behavData['targetFrequency'] == thisFreq)
                choiceVecThisFreq = np.ma.masked_array(
                    rightChoice[validThisBlock])
                choiceVecThisFreq.mask = ~trialsThisFreq[validThisBlock]
                movAvChoice = extrafuncs.moving_average_masked(
                    choiceVecThisFreq, winsize)
                print thisFreq
                movAvChoiceMatrix[indf, firstValidEachBlock[indb]:
                                  lastValidEachBlock[indb]] = movAvChoice
    else:
        valid = behavData['valid']
        movAvChoiceMatrix = np.ndarray([len(possibleFreq), sum(valid)])
        rightChoice = behavData['choice'] == behavData.labels['choice'][
            'right']
        for indf, thisFreq in enumerate(possibleFreq):
            trialsThisFreq = (behavData['targetFrequency'] == thisFreq)
            choiceVecThisFreq = np.ma.masked_array(rightChoice[valid])
            choiceVecThisFreq.mask = ~trialsThisFreq[valid]
            movAvChoice = extrafuncs.moving_average_masked(
                choiceVecThisFreq, winsize)
            movAvChoiceMatrix[indf, :] = movAvChoice
    return movAvChoiceMatrix
def plot_dynamics(behavData, winsize=40, fontsize=12, soundfreq=None):
    '''
    Plot performance in time for one session.
    First argument is an object created by loadbehavior.BehaviorData (or subclasses)
    '''
    ax = plt.gca()
    ax.cla()
    lineWidth = 2
    if not np.any(soundfreq):
        possibleFreq = np.unique(behavData['targetFrequency'])
    else:
        possibleFreq = soundfreq
    print possibleFreq
    possibleColors = FREQCOLORS + ['k', 'm', 'c', 'b', 'r', 'g']
    colorEachFreq = dict(zip(possibleFreq, possibleColors))

    behavData.find_trials_each_block()

    nBlocks = behavData.blocks['nBlocks']
    trialsEachBlock = behavData.blocks['trialsEachBlock']
    validEachBlock = trialsEachBlock & (
        behavData['valid'][:, np.newaxis].astype(bool))
    nValidEachBlock = np.sum(validEachBlock, axis=0)
    lastValidEachBlock = np.cumsum(
        nValidEachBlock)  # Actually, these values correspond to lastIndex+1
    firstValidEachBlock = np.concatenate(([0], lastValidEachBlock[:-1]))
    rightChoice = behavData['choice'] == behavData.labels['choice']['right']

    hPlots = []
    curveLegends = list(possibleFreq)
    plt.hold(True)
    for indb in range(nBlocks):
        trialsThisBlock = trialsEachBlock[:, indb]
        validThisBlock = validEachBlock[:, indb]
        for indf, thisFreq in enumerate(possibleFreq):
            thisColor = colorEachFreq[thisFreq]
            trialsThisFreq = (behavData['targetFrequency'] == thisFreq)
            choiceVecThisFreq = np.ma.masked_array(rightChoice[validThisBlock])
            choiceVecThisFreq.mask = ~trialsThisFreq[validThisBlock]
            movAvChoice = extrafuncs.moving_average_masked(
                choiceVecThisFreq, winsize)
            hp, = plt.plot(range(firstValidEachBlock[indb],
                                 lastValidEachBlock[indb]),
                           100 * movAvChoice,
                           lw=lineWidth,
                           color=thisColor)
            hPlots.append(hp)

    plt.ylim([-5, 105])
    plt.axhline(50, color='0.5', ls='--')
    plt.ylabel('% rightward', fontsize=fontsize)
    plt.xlabel('Trial', fontsize=fontsize)
    extraplots.set_ticks_fontsize(ax, fontsize)
    #legend = plt.legend(hPlots,curveLegends,loc=2)
    #ax = plt.gca().add_artist(legend)
    plt.draw()
    plt.show()
    return hPlots
def plot_choicetime_dynamics(bData, winsize=40, fontsize=12):
    '''
    This function plots a running average for the choice time based on trial outcomes or which side the animal actually choosed ('choice'). 
    *Invalid trials does not have choice time since timeSideIn is NaN.
    Choice time is defined as the time it took to get to the side ports to retrieve water from the time of leaving center port.
    '''
    lineWidth = 2
#    reactionTime = bData['timeCenterOut']-bData['timeTarget']
    choiceTime = bData['timeSideIn']-bData['timeCenterOut']
    correctTrials = bData['outcome']==bData.labels['outcome']['correct']
    errorTrials = bData['outcome']==bData.labels['outcome']['error']
#    invalidTrials = bData['outcome']==bData.labels['outcome']['invalid']
#Cannot use rewardSide here since some trials will be invalid and contain NaN 'timeSideIn'
    leftTrials = bData['choice']==bData.labels['choice']['left']
#Cannot use ~leftTrials for indexing since will include trials where choice is none and timeSideIn will be NaN
    rightTrials = bData['choice']==bData.labels['choice']['right']

    choiceTCorrect = np.ma.masked_array(choiceTime[correctTrials])
    movAvChoiceTime_correct = extrafuncs.moving_average_masked(choiceTCorrect, winsize)
    choiceTError = np.ma.masked_array(choiceTime[errorTrials])
    movAvChoiceTime_error = extrafuncs.moving_average_masked(choiceTError, winsize)
    choiceTLeft = np.ma.masked_array(choiceTime[leftTrials])
    movAvChoiceTime_left = extrafuncs.moving_average_masked(choiceTLeft, winsize)
    choiceTRight = np.ma.masked_array(choiceTime[rightTrials])
    movAvChoiceTime_right = extrafuncs.moving_average_masked(choiceTRight, winsize)
   
    plt.plot(movAvChoiceTime_correct,lw=lineWidth,color='m',alpha=1)
    #plt.hold(1)
    plt.plot(movAvChoiceTime_error,lw=lineWidth,color='b',alpha=1)
    #plt.hold(1)
    plt.plot(movAvChoiceTime_left,lw=lineWidth,color='g')
    #plt.hold(1)
    plt.plot(movAvChoiceTime_right,lw=lineWidth,color='r')
    #plt.hold(1)
    #plt.ylim([0,2.5])
    #plt.axhline(50,color='0.5',ls='--')
    #plt.ylabel('Choice time(s)',fontsize=fontsize)
    plt.xlabel('Trial number',fontsize=fontsize)
    ax = plt.gca()
    extraplots.set_ticks_fontsize(ax,fontsize)
    ax.set_ylabel('Choice time(s)',fontsize=fontsize,labelpad=1)
def plot_reactiontime_dynamics(bData, winsize=40, fontsize=12):
    '''
    This function plots a running average for the reaction time based on trial outcomes or which side the animal actually choosed ('choice'). 
    *Invalid trials does not have choice time since timeSideIn is NaN.
    Reaction time is defined as the time it took from hearing sound stimulus to deciding to act (removing head from center port).
    '''
    lineWidth = 2
    reactionTime = bData['timeCenterOut']-bData['timeTarget']
    correctTrials = bData['outcome']==bData.labels['outcome']['correct']
    errorTrials = bData['outcome']==bData.labels['outcome']['error']
#    invalidTrials = bData['outcome']==bData.labels['outcome']['invalid']
#Cannot use rewardSide here since some trials will be invalid and contain NaN 'timeSideIn'
    leftTrials = bData['choice']==bData.labels['choice']['left']
#Cannot use ~leftTrials for indexing since will include trials where choice is none and timeSideIn will be NaN
    rightTrials = bData['choice']==bData.labels['choice']['right']

    reactionTCorrect = np.ma.masked_array(reactionTime[correctTrials])
    movAvReactionTime_correct = extrafuncs.moving_average_masked(reactionTCorrect, winsize)
    reactionTError = np.ma.masked_array(reactionTime[errorTrials])
    movAvReactionTime_error = extrafuncs.moving_average_masked(reactionTError, winsize)
    reactionTLeft = np.ma.masked_array(reactionTime[leftTrials])
    movAvReactionTime_left = extrafuncs.moving_average_masked(reactionTLeft, winsize)
    reactionTRight = np.ma.masked_array(reactionTime[rightTrials])
    movAvReactionTime_right = extrafuncs.moving_average_masked(reactionTRight, winsize)
   
    line1,=plt.plot(movAvReactionTime_correct,lw=lineWidth,color='m',alpha=1,label='correct')
    #plt.hold(1)
    line2,=plt.plot(movAvReactionTime_error,lw=lineWidth,color='b',alpha=1,label='error')
    #plt.hold(1)
    line3,=plt.plot(movAvReactionTime_left,lw=lineWidth,color='g',label='left')
    #plt.hold(1)
    line4,=plt.plot(movAvReactionTime_right,lw=lineWidth,color='r',label='right')
    #plt.hold(1)
    #plt.ylim([0,2.5])
    #plt.ylabel('Reaction time(s)',fontsize=fontsize)
    plt.xlabel('Trial number',fontsize=fontsize)
    plt.legend([line1,line2,line3,line4],['correct','error','left','right'],loc=1)
    ax = plt.gca()
    ax.set_ylabel('Reaction time(s)',fontsize=fontsize,labelpad=1)
    extraplots.set_ticks_fontsize(ax,fontsize)
def plot_dynamics(behavData,winsize=40,fontsize=12,soundfreq=None):
    '''
    Plot performance in time for one session.
    First argument is an object created by loadbehavior.BehaviorData (or subclasses)
    '''
    ax = plt.gca()
    ax.cla()
    lineWidth = 2
    if not np.any(soundfreq):
        possibleFreq = np.unique(behavData['targetFrequency'])
    else:
        possibleFreq = soundfreq
    print possibleFreq
    possibleColors = FREQCOLORS + ['k','m','c', 'b','r','g']
    colorEachFreq = dict(zip(possibleFreq,possibleColors))

    behavData.find_trials_each_block()

    nBlocks = behavData.blocks['nBlocks']
    trialsEachBlock = behavData.blocks['trialsEachBlock']
    validEachBlock = trialsEachBlock & (behavData['valid'][:,np.newaxis].astype(bool))
    nValidEachBlock = np.sum(validEachBlock,axis=0)
    lastValidEachBlock = np.cumsum(nValidEachBlock) # Actually, these values correspond to lastIndex+1
    firstValidEachBlock = np.concatenate(([0],lastValidEachBlock[:-1]))
    rightChoice = behavData['choice']==behavData.labels['choice']['right']

    hPlots = []
    curveLegends=list(possibleFreq)
    plt.hold(True)
    for indb in range(nBlocks):
        trialsThisBlock = trialsEachBlock[:,indb]
        validThisBlock = validEachBlock[:,indb]
        for indf,thisFreq in enumerate(possibleFreq):
            thisColor = colorEachFreq[thisFreq]
            trialsThisFreq = (behavData['targetFrequency']==thisFreq)
            choiceVecThisFreq = np.ma.masked_array(rightChoice[validThisBlock])
            choiceVecThisFreq.mask = ~trialsThisFreq[validThisBlock]
            movAvChoice = extrafuncs.moving_average_masked(choiceVecThisFreq,winsize)
            hp, = plt.plot(range(firstValidEachBlock[indb],lastValidEachBlock[indb]),100*movAvChoice,
                           lw=lineWidth,color=thisColor)
            hPlots.append(hp)
    
    plt.ylim([-5,105])
    plt.axhline(50,color='0.5',ls='--')
    plt.ylabel('% rightward',fontsize=fontsize)
    plt.xlabel('Trial',fontsize=fontsize)
    extraplots.set_ticks_fontsize(ax,fontsize)
    legend = plt.legend(hPlots,curveLegends,loc=2)
    ax = plt.gca().add_artist(legend)
    plt.draw()
    plt.show()
    return hPlots
Example #12
0
def plot_dynamics_sound_type(behavData, soundType, winsize=40,fontsize=12,soundfreq=None):
    '''
    DEPRECATED - load data into two data objects (one per sound type) and use the regular func
    Plot performance in time for one session.
    First argument is an object created by loadbehavior.BehaviorData (or subclasses)
    '''

    print 'FIXME: no removal of invalid trials in sound type dynamics'

    trialsSoundType = behavData['soundType']==behavData.labels['soundType'][soundType]

    valid = behavData['valid']
    validSoundType = valid[trialsSoundType]

    freqEachTrialSoundType = behavData['targetFrequency'][trialsSoundType]

    blockIDthisSoundType = behavData['currentBlock'][trialsSoundType]
    possibleBlockID = np.unique(blockIDthisSoundType)

    ax = plt.gca()
    ax.cla()
    lineWidth = 2

    if soundfreq is None:
        possibleFreq = [min(np.unique(freqEachTrialSoundType)), max(np.unique(freqEachTrialSoundType))]
    else:
        possibleFreq = soundfreq

    #########

    possibleColors = FREQCOLORS + ['k','m','c', 'b','r','g']
    colorEachFreq = dict(zip(possibleFreq,possibleColors))

    rightChoice = behavData['choice']==behavData.labels['choice']['right']
    rightChoiceSoundType = rightChoice[trialsSoundType]

    hPlots = []
    plt.hold(True)

    for indf,thisFreq in enumerate(possibleFreq):

        thisColor = colorEachFreq[thisFreq]
        trialsThisFreqSoundType = (freqEachTrialSoundType==thisFreq)

        choiceVecThisFreq = np.ma.masked_array(rightChoiceSoundType)
        choiceVecThisFreq.mask = ~trialsThisFreqSoundType

        movAvChoice = extrafuncs.moving_average_masked(choiceVecThisFreq,winsize)

        hp, = plt.plot(range(len(movAvChoice)), 100*movAvChoice,
                        lw=lineWidth,color=thisColor)
        hPlots.append(hp)

    plt.ylim([-5,105])
    plt.axhline(50,color='0.5',ls='--')
    plt.ylabel('% rightward',fontsize=fontsize)
    plt.xlabel('Trial',fontsize=fontsize)
    extraplots.set_ticks_fontsize(ax,fontsize)
    plt.draw()
    plt.show()
    return hPlots