def plot_ave_psycurve_reward_change(animal, sessions):    
    FREQCOLORS =  [colorpalette.TangoPalette['Chameleon3'],
                   colorpalette.TangoPalette['ScarletRed1'],
                   colorpalette.TangoPalette['SkyBlue2']]

    allBehavDataThisAnimal = behavioranalysis.load_many_sessions(animal,sessions)
    targetFrequency = allBehavDataThisAnimal['targetFrequency']
    choice=allBehavDataThisAnimal['choice']
    valid=allBehavDataThisAnimal['valid']& (choice!=allBehavDataThisAnimal.labels['choice']['none'])
    choiceRight = choice==allBehavDataThisAnimal.labels['choice']['right']
    currentBlock = allBehavDataThisAnimal['currentBlock']
    blockTypes = [allBehavDataThisAnimal.labels['currentBlock']['same_reward'],allBehavDataThisAnimal.labels['currentBlock']['more_left'],allBehavDataThisAnimal.labels['currentBlock']['more_right']]
    #blockTypes = [allBehavDataThisAnimal.labels['currentBlock']['more_left'],allBehavDataThisAnimal.labels['currentBlock']['more_right']]
    blockLabels = ['same_reward','more_left','more_right']
    #blockLabels = ['more_left','more_right']
    trialsEachType = behavioranalysis.find_trials_each_type(currentBlock,blockTypes)
    
    nFreqs = len(np.unique(targetFrequency))
    print '{}, freqs: {}'.format(animal, str(np.unique(targetFrequency)))
    #print trialsEachType
    nBlocks = len(blockTypes)
    #thisAnimalPos = inda
    #ax1=plt.subplot(gs[thisAnimalPos])
    #plt.clf()
    fontsize = 12
    allPline = []
    blockLegends = []
    fractionHitsEachValueAllBlocks = np.empty((nBlocks,nFreqs))

    for blockType in range(nBlocks):
        if np.any(trialsEachType[:,blockType]):
            targetFrequencyThisBlock = targetFrequency[trialsEachType[:,blockType]]    
            validThisBlock = valid[trialsEachType[:,blockType]]
            choiceRightThisBlock = choiceRight[trialsEachType[:,blockType]]
            #currentBlockValue = currentBlock[trialsEachBlock[0,block]]
            (possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue)=\
                                                                                                    behavioranalysis.calculate_psychometric(choiceRightThisBlock,targetFrequencyThisBlock,validThisBlock)

            fractionHitsEachValueAllBlocks[blockType,:] = fractionHitsEachValue

            (pline, pcaps, pbars, pdots) = extraplots.plot_psychometric(1e-3*possibleValues,fractionHitsEachValue,
                                                                ciHitsEachValue,xTickPeriod=1)

            plt.setp((pline, pcaps, pbars), color=FREQCOLORS[blockType])
            plt.setp(pdots, mfc=FREQCOLORS[blockType], mec=FREQCOLORS[blockType])
            allPline.append(pline)
            blockLegends.append(blockLabels[blockType])
            
            if blockType == nBlocks-1: 
                plt.xlabel('Frequency (kHz)',fontsize=fontsize)
                plt.ylabel('Rightward trials (%)',fontsize=fontsize)
                extraplots.set_ticks_fontsize(plt.gca(),fontsize)
                legend = plt.legend(allPline,blockLegends,loc=2)
                # Add the legend manually to the current Axes.
                ax = plt.gca().add_artist(legend)
                #plt.hold(True)
        #plt.legend(bbox_to_anchor=(1, 1), bbox_transform=plt.gcf().transFigure)
        #plt.show()
    plt.title('%s_%sto%s'%(animal,sessions[0],sessions[-1]))   
    return fractionHitsEachValueAllBlocks
def plot_fitted_psycurve(bdata, color='k', linestyle=None):
    rightTrials = bdata['choice'] == bdata.labels['choice']['right']
    freqEachTrial = bdata['targetFrequency']
    valid = bdata['valid']
    (possibleValues, fractionHitsEachValue, ciHitsEachValue, nTrialsEachValue,
     nHitsEachValue) = behavioranalysis.calculate_psychometric(
         rightTrials, freqEachTrial, valid)

    pline, pcaps, pbars, pdots = extraplots.plot_psychometric(
        possibleValues, fractionHitsEachValue, ciHitsEachValue)
    setp(pline, color='w')
    setp(pcaps, color=color)
    setp(pbars, color=color)
    setp(pdots, markerfacecolor=color)

    estimate = extrastats.psychometric_fit(possibleValues, nTrialsEachValue,
                                           nHitsEachValue)

    yvals = nHitsEachValue.astype(float) / nTrialsEachValue
    xvals = possibleValues
    xRange = xvals[-1] - xvals[0]
    fitxval = np.linspace(xvals[0] - 0.1 * xRange, xvals[-1] + 0.1 * xRange,
                          40)
    fityval = extrastats.psychfun(fitxval, *estimate)
    hfit = plot(fitxval, 100 * fityval, '-', linewidth=2, color=color)

    return (estimate, (pline, pcaps, pbars, pdots, hfit))
Exemplo n.º 3
0
def muscimol_plot_sound_type(animal, muscimolSessions, salineSessions, soundType, fontsize=12):

    '''
    DEPRECATED - this is a bad function
    Plot the average psycurve for muscimol sessions in red on top of the average saline psycurve in black.
    Psycurves are limited by the sound type.
    '''

    muscimolData = behavioranalysis.load_many_sessions(animal, muscimolSessions)

    trialsSoundTypeMus = muscimolData['soundType']==muscimolData.labels['soundType'][soundType]
    rightTrialsMus = (muscimolData['choice']==muscimolData.labels['choice']['right'])[trialsSoundTypeMus]
    freqEachTrialMus = muscimolData['targetFrequency'][trialsSoundTypeMus]
    validMus = muscimolData['valid'][trialsSoundTypeMus]


    (possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue)=\
       calculate_psychometric(rightTrialsMus,freqEachTrialMus,validMus)
    (plineM, pcapsM, pbarsM, pdotsM) = extraplots.plot_psychometric(1e-3*possibleValues,fractionHitsEachValue,
                                                                ciHitsEachValue,xTickPeriod=1)
    plt.xlabel('Frequency (kHz)',fontsize=fontsize)
    plt.ylabel('Rightward trials (%)',fontsize=fontsize)
    extraplots.set_ticks_fontsize(plt.gca(),fontsize)




    setp(plineM, color='r')
    setp(pcapsM, color='r')
    setp(pbarsM, color='r')
    setp(pdotsM, markerfacecolor='r')

    salineData = behavioranalysis.load_many_sessions(animal, salineSessions)

    trialsSoundTypeSal = salineData['soundType']==salineData.labels['soundType'][soundType]
    rightTrialsSal = (salineData['choice']==salineData.labels['choice']['right'])[trialsSoundTypeSal]
    freqEachTrialSal = salineData['targetFrequency'][trialsSoundTypeSal]
    validSal = salineData['valid'][trialsSoundTypeSal]


    (possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue)=\
       calculate_psychometric(rightTrialsSal,freqEachTrialSal,validSal)
    (plineS, pcapsS, pbarsS, pdotsS) = extraplots.plot_psychometric(1e-3*possibleValues,fractionHitsEachValue,
                                                                ciHitsEachValue,xTickPeriod=1)


    title("{}, {}".format(animal, soundType))
Exemplo n.º 4
0
def psycurveLinear(bdata):
    from jaratoolbox import extraplots
    fontsize=FONTSIZE
    if 'targetPercentage' in bdata.viewkeys():
        targetPercentage = bdata['targetPercentage']
    else:
        targetPercentage = bdata['targetFrequency'] # I used name 'frequency' initially
    choiceRight = bdata['choice']==bdata.labels['choice']['right']
    valid=bdata['valid']& (bdata['choice']!=bdata.labels['choice']['none'])
    (possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue)=\
           behavioranalysis.calculate_psychometric(choiceRight,targetPercentage,valid)
    (pline, pcaps, pbars, pdots) = extraplots.plot_psychometric(1e-3*possibleValues,fractionHitsEachValue,
                                                                    ciHitsEachValue,xTickPeriod=1, xscale='linear')
    plt.xlabel('Stimulus',fontsize=fontsize)
    plt.ylabel('Rightward trials (%)',fontsize=fontsize)
    extraplots.set_ticks_fontsize(plt.gca(),fontsize)
    plt.gcf().set_size_inches([8,6])
Exemplo n.º 5
0
def plot_multiple_psycurves(bdataList, colorsList, fontsize=12):

    '''
    Nick 2016-05-20

    Plots psychometric curves for bdata objects in different colors on the same plot

    Args:

    bdataList (list of jaratoolbox.loadbehavior.LoadBehaviorData objects): list of bdata to plot
    colorsList (list of str): list of color strings the same length as bdataList ('k', 'b', etc.)
    fontsize (int): Size of the label font for the figure
    '''

    plt.hold(1)
    for ind, bdata in enumerate(bdataList):
        rightTrials = bdata['choice']==bdata.labels['choice']['right']
        freqEachTrial = bdata['targetFrequency']
        valid = bdata['valid']

        (possibleValues,
         fractionHitsEachValue,
         ciHitsEachValue,
         nTrialsEachValue,
         nHitsEachValue)= calculate_psychometric(rightTrials,
                                                 freqEachTrial,
                                                 valid)

        (pline,
         pcaps,
         pbars,
         pdots) = extraplots.plot_psychometric(1e-3*possibleValues,
                                               fractionHitsEachValue,
                                               ciHitsEachValue,
                                               xTickPeriod=1)

        plt.xlabel('Frequency (kHz)',fontsize=fontsize)
        plt.ylabel('Rightward trials (%)',fontsize=fontsize)
        extraplots.set_ticks_fontsize(plt.gca(),fontsize)

        plt.setp(pline, color=colorsList[ind])
        plt.setp(pcaps, color=colorsList[ind])
        plt.setp(pbars, color=colorsList[ind])
        plt.setp(pdots, markerfacecolor=colorsList[ind])
Exemplo n.º 6
0
def plot_frequency_psycurve(bdata,fontsize=12):
    '''
    Show psychometric curve (for frequency)
    '''
    targetFrequency = bdata['targetFrequency']
    choice=bdata['choice']
    valid=bdata['valid']& (choice!=bdata.labels['choice']['none'])
    choiceRight = choice==bdata.labels['choice']['right']
    possibleFreq = np.unique(targetFrequency)
    nFreq = len(possibleFreq)
    trialsEachFreq = find_trials_each_type(targetFrequency,possibleFreq)
    (possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue)=\
       calculate_psychometric(choiceRight,targetFrequency,valid)
    (pline, pcaps, pbars, pdots) = extraplots.plot_psychometric(1e-3*possibleValues,fractionHitsEachValue,
                                                                ciHitsEachValue,xTickPeriod=1)
    plt.xlabel('Frequency (kHz)',fontsize=fontsize)
    plt.ylabel('Rightward trials (%)',fontsize=fontsize)
    extraplots.set_ticks_fontsize(plt.gca(),fontsize)
    return (pline, pcaps, pbars, pdots)
def plot_frequency_psycurve_soundtype(bdata, soundType, fontsize=12):
    '''
    Show psychometric curve (for any arbitrary sound type)
    '''

    trialsSoundType = bdata['soundType']==bdata.labels['soundType'][soundType]
    choice = bdata['choice']
    choiceRight = choice==bdata.labels['choice']['right']
    choiceRightSoundType = choiceRight[trialsSoundType]
    targetFrequencySoundType = bdata['targetFrequency'][trialsSoundType]
    valid = bdata['valid']
    validSoundType = valid[trialsSoundType]
    (possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue)=\
        behavioranalysis.calculate_psychometric(choiceRightSoundType,targetFrequencySoundType,validSoundType)
    (pline, pcaps, pbars, pdots) = extraplots.plot_psychometric(1e-3*possibleValues,
                                                                fractionHitsEachValue,
                                                                ciHitsEachValue,
                                                                xTickPeriod=1)
    plt.xlabel('Frequency (kHz)',fontsize=fontsize)
    plt.ylabel('Rightward trials (%)',fontsize=fontsize)
    extraplots.set_ticks_fontsize(plt.gca(),fontsize)
    return (pline, pcaps, pbars, pdots)
def plot_fitted_psycurve(bdata, color='k', linestyle=None):
    rightTrials = bdata['choice']==bdata.labels['choice']['right']
    freqEachTrial = bdata['targetFrequency']
    valid = bdata['valid']
    (possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue) = behavioranalysis.calculate_psychometric(rightTrials, freqEachTrial, valid)

    pline, pcaps, pbars, pdots = extraplots.plot_psychometric(possibleValues, fractionHitsEachValue, ciHitsEachValue)
    setp(pline, color='w')
    setp(pcaps, color=color)
    setp(pbars, color=color)
    setp(pdots, markerfacecolor=color)

    estimate = extrastats.psychometric_fit(possibleValues, nTrialsEachValue, nHitsEachValue)

    yvals = nHitsEachValue.astype(float)/nTrialsEachValue
    xvals = possibleValues
    xRange = xvals[-1]-xvals[0]
    fitxval = np.linspace(xvals[0]-0.1*xRange,xvals[-1]+0.1*xRange,40)
    fityval = extrastats.psychfun(fitxval,*estimate)
    hfit = plot(fitxval,100*fityval,'-',linewidth=2, color=color)

    return (estimate, (pline, pcaps, pbars, pdots, hfit))
Exemplo n.º 9
0
def plot_frequency_psycurve_soundtype(bdata, soundType, fontsize=12):
    '''
    Show psychometric curve (for any arbitrary sound type)
    '''

    trialsSoundType = bdata['soundType']==bdata.labels['soundType'][soundType]
    choice = bdata['choice']
    choiceRight = choice==bdata.labels['choice']['right']
    choiceRightSoundType = choiceRight[trialsSoundType]
    targetFrequencySoundType = bdata['targetFrequency'][trialsSoundType]
    valid = bdata['valid']
    validSoundType = valid[trialsSoundType]
    (possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue)=\
        behavioranalysis.calculate_psychometric(choiceRightSoundType,targetFrequencySoundType,validSoundType)
    (pline, pcaps, pbars, pdots) = extraplots.plot_psychometric(1e-3*possibleValues,
                                                                fractionHitsEachValue,
                                                                ciHitsEachValue,
                                                                xTickPeriod=1)
    plt.xlabel('Frequency (kHz)',fontsize=fontsize)
    plt.ylabel('Rightward trials (%)',fontsize=fontsize)
    extraplots.set_ticks_fontsize(plt.gca(),fontsize)
    return (pline, pcaps, pbars, pdots)
    nNoLaser = np.sum(validNoLaser)
    nLaser = np.sum(validLaser)
    fractionCorrectNoLaser = np.mean(correct[validNoLaser])
    fractionCorrectLaser = np.mean(correct[validLaser])
    print('Correct: NoLaser({})={:0.1%}  Laser({})={:0.1%}'.format(
        nNoLaser, fractionCorrectNoLaser, nLaser, fractionCorrectLaser))

    #plt.subplot(4,2,inds+1)
    #plt.title('{0} [{1}]'.format(subject,session))

    plt.hold(1)
    (pline, pcaps, pbars,
     pdots) = extraplots.plot_psychometric(1e-3 * possibleValues,
                                           fractionHitsEachValue,
                                           ciHitsEachValue,
                                           xTickPeriod=1,
                                           xscale='linear')
    (plineL, pcapsL, pbarsL,
     pdotsL) = extraplots.plot_psychometric(1e-3 * possibleValuesL,
                                            fractionHitsEachValueL,
                                            ciHitsEachValueL,
                                            xTickPeriod=1,
                                            xscale='linear')

    plt.setp([pline, plineL], lw=3)
    plt.setp([plineL, pcapsL, pbarsL, pdotsL], color=laserColor)
    plt.setp(pdotsL, mfc=laserColor)
    #plt.setp([plineL,pcapsL,pbarsL,pdotsL],visible=False)
    #plt.setp([pline,pcaps,pbars,pdots],visible=False)
    validCorrect = outcome[valid.astype(bool)]==bdata.labels['outcome']['correct']

    nValid = np.sum(valid)
    fractionValid = np.mean(valid)
    fractionCorrect = np.mean(validCorrect)

    (possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue)=\
                           behavioranalysis.calculate_psychometric(choiceRight,targetFrequency,valid)

    nValidAll.append(nValid)
    fractionValidAll.append(fractionValid)
    fractionCorrectAll.append(fractionCorrect)

    plt.subplot(nSubjects//2+1,2,inds+1)
    # -- plot things here --
    (plineC, pcapsC, pbarsC, pdotsC) = extraplots.plot_psychometric(possibleValues,
                                                                    fractionHitsEachValue,
                                                                    ciHitsEachValue)
    #plt.ylabel('{0}'.format(animalList[inds]))
    plt.ylabel('Trials rightward (%)')
    #plt.xlim([-0.1,0.8])
    plt.xlabel('Frequency (Hz)')

    
    #if inds==0:
    plt.title('[{0}] Delay-to-go = {1:0.2}s'.format(animalList[inds],float(delayToGoSignal)))
    plt.draw()
    plt.show()


Exemplo n.º 12
0
behavFile = loadbehavior.path_to_behavior_data(animalName,experimenter,paradigm,session)
bdata = loadbehavior.FlexCategBehaviorData(behavFile)

targetFrequency = bdata['targetFrequency']
choice=bdata['choice']
valid=bdata['valid']& (choice!=bdata.labels['choice']['none'])
choiceRight = choice==bdata.labels['choice']['right']

possibleFreq = np.unique(targetFrequency)
nFreq = len(possibleFreq) 
trialsEachFreq = behavioranalysis.find_trials_each_type(targetFrequency,possibleFreq)

(possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue)=\
   behavioranalysis.calculate_psychometric(choiceRight,targetFrequency,valid)

(pline, pcaps, pbars, pdots) = extraplots.plot_psychometric(possibleValues,fractionHitsEachValue,ciHitsEachValue)

'''
upperWhisker = ciHitsEachValue[1,:]-fractionHitsEachValue
lowerWhisker = fractionHitsEachValue-ciHitsEachValue[0,:]

(pline, pcaps, pbars) = errorbar(possibleValues, 100*fractionHitsEachValue, 
                                 yerr = [100*lowerWhisker, 100*upperWhisker],color='k')
plot(possibleValues, 100*fractionHitsEachValue, 'o',mec='none',mfc='k',ms=8)
setp(pline,lw=2)
axhline(y=50, color = '0.5',ls='--')
ax=gca()
ax.set_xscale('log')
#ax.set_xticks([3000,5000,7000,10000,14000,20000,40000])
ax.set_xticks([3000,7000,16000])
ax.set_xticks(np.arange(1000,40000,1000),minor=True)
def plot_ave_photostim_psycurve_by_trialtype(animal,
                                             sessions,
                                             trialLimit=None):
    '''
    Arguments:
    animal is a string of the animal name you want to plot.
    sessions is a list of strings of the behavior session names you want to plot.
    trialLimit is an optional parameter, should be a list of integers giving the beginning and end of trials numbers you want to plot.
    '''

    FREQCOLORS = [
        colorpalette.TangoPalette['Chameleon3'],
        colorpalette.TangoPalette['ScarletRed1'],
        colorpalette.TangoPalette['SkyBlue2'], 'g', 'm', 'k'
    ]

    allBehavDataThisAnimal = behavioranalysis.load_many_sessions(
        animal, sessions)
    targetFrequency = allBehavDataThisAnimal['targetFrequency']
    choice = allBehavDataThisAnimal['choice']
    valid = allBehavDataThisAnimal['valid'] & (
        choice != allBehavDataThisAnimal.labels['choice']['none'])
    if trialLimit:
        trialSelector = np.zeros(len(valid), dtype=bool)
        trialSelector[trialLimit[0]:trialLimit[1]] = True
    else:
        trialSelector = np.ones(len(valid), dtype=bool)
    valid = (valid & trialSelector)
    #print sum(trialSelector), sum(valid)

    choiceRight = choice == allBehavDataThisAnimal.labels['choice']['right']
    trialType = allBehavDataThisAnimal['trialType']
    stimTypes = [
        allBehavDataThisAnimal.labels['trialType']['no_laser'],
        allBehavDataThisAnimal.labels['trialType']['laser_left'],
        allBehavDataThisAnimal.labels['trialType']['laser_right']
    ]

    stimLabels = ['no_laser', 'laser_left', 'laser_right']

    trialsEachType = behavioranalysis.find_trials_each_type(
        trialType, stimTypes)
    #trialsEachType=np.vstack(( ( (trialType==0) | (trialType==2) ),trialType==1, np.zeros(len(trialType),dtype=bool) )).T  ###This is a hack when percentLaserTrials were sum of both sides and just did one side stim
    #print trialsEachType

    nBlocks = len(stimTypes)
    #thisAnimalPos = inda
    #ax1=plt.subplot(gs[thisAnimalPos,0])
    #ax1=plt.subplot(gs[thisAnimalPos])

    #plt.figure()
    fontsize = 8
    allPline = []
    curveLegends = []
    for stimType in range(nBlocks):
        if np.any(trialsEachType[:, stimType]):
            targetFrequencyThisBlock = targetFrequency[
                trialsEachType[:, stimType]]
            validThisBlock = valid[trialsEachType[:, stimType]]
            #print len(validThisBlock), sum(validThisBlock)
            choiceRightThisBlock = choiceRight[trialsEachType[:, stimType]]
            numValidTrialThisBlock = sum(validThisBlock)
            (possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue)=\
                                                                                                    behavioranalysis.calculate_psychometric(choiceRightThisBlock,targetFrequencyThisBlock,validThisBlock)
            (pline, pcaps, pbars,
             pdots) = extraplots.plot_psychometric(1e-3 * possibleValues,
                                                   fractionHitsEachValue,
                                                   ciHitsEachValue,
                                                   xTickPeriod=1)

            plt.setp((pline, pcaps, pbars), color=FREQCOLORS[stimType])
            plt.hold(True)
            plt.setp(pdots, mfc=FREQCOLORS[stimType], mec=FREQCOLORS[stimType])
            plt.hold(True)
            plt.annotate('%s: %s trials' %
                         (stimLabels[stimType], numValidTrialThisBlock),
                         xy=(0.2, 0.35 + stimType / 10.0),
                         fontsize=fontsize,
                         xycoords='axes fraction')
            allPline.append(pline)
            curveLegends.append(stimLabels[stimType])
            #plt.hold(True)
    plt.xlabel('Frequency (kHz)', fontsize=fontsize)
    plt.ylabel('Rightward trials (%)', fontsize=fontsize)
    extraplots.set_ticks_fontsize(plt.gca(), fontsize)
    legend = plt.legend(allPline,
                        curveLegends,
                        loc='best',
                        labelspacing=0.2,
                        prop={'size': 4})
    # Add the legend manually to the current Axes.
    #ax = plt.gca().add_artist(legend)
    plt.gca().add_artist(legend)

    #plt.legend(bbox_to_anchor=(1, 1), bbox_transform=plt.gcf().transFigure)
    #plt.show()
    if len(sessions) == 1:
        plt.title('%s_%s' % (animal, sessions[0]), fontsize=fontsize)
    else:
        plt.title('%s_%sto%s' % (animal, sessions[0], sessions[-1]),
                  fontsize=fontsize)
    plt.show()
    '''
validControl = valid & ~laserTrials
validLaser = valid & laserTrials

# -- Calculate and plot psychometric points --
(possibleValuesControl,fractionHitsEachValueControl,ciHitsEachValueControl,
    nTrialsEachValueControl,nHitsEachValueControl)=\
        behavioranalysis.calculate_psychometric(choiceRight,targetFrequency,validControl)
(possibleValuesLaser,fractionHitsEachValueLaser,ciHitsEachValueLaser,
    nTrialsEachValueLaser,nHitsEachValueLaser)=\
        behavioranalysis.calculate_psychometric(choiceRight,targetFrequency,validLaser)

plt.clf()
plt.hold(True)
(plineC, pcapsC, pbarsC,
 pdotsC) = extraplots.plot_psychometric(possibleValuesControl,
                                        fractionHitsEachValueControl,
                                        ciHitsEachValueControl)
(plineL, pcapsL, pbarsL,
 pdotsL) = extraplots.plot_psychometric(possibleValuesLaser,
                                        fractionHitsEachValueLaser,
                                        ciHitsEachValueLaser)
plt.setp([plineL, pcapsL, pbarsL], color='g')
plt.setp(pdotsL, mfc='g', mec='g')

plt.hold(False)
plt.xlabel('Frequency (Hz)')
plt.ylabel('Rightward choice (%)')
plt.title('{0} - {1}'.format(subject, session))
plt.legend([plineC, plineL], ['Control', 'Laser'], loc='upper left')
plt.show()
        valid = bdata['valid'] & (choice != bdata.labels['choice']['none'])
        intensities = bdata['targetIntensity']
        choiceRight = choice == bdata.labels['choice']['right']

        possibleFreq = np.unique(targetFrequency)
        nFreq = len(possibleFreq)
        trialsEachFreq = behavioranalysis.find_trials_each_type(
            targetFrequency, possibleFreq)

        (possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue)=\
           behavioranalysis.calculate_psychometric(choiceRight,targetFrequency,valid)

        hold(True)
        (pline, pcaps, pbars,
         pdots) = extraplots.plot_psychometric(possibleValues,
                                               fractionHitsEachValue,
                                               ciHitsEachValue)
        setp(pdots, ms=6, mec='k', mew=2, mfc=markerFaceColors[indset])
        plotHandles.append(pdots[0])
    xlabel('Frequency (Hz)', fontsize=fontSize)
    ylabel('Rightward choice (%)', fontsize=fontSize)
    legend(plotHandles, ['pre', 'post'],
           numpoints=1,
           loc='upper left',
           fontsize=fontSize - 2)
    title(animalName)

show()

# -- Save figure --
outputDir = '/tmp/'  #figparams.figuresDir
    
    #print trialsEachType
    nBlocks = len(blockTypes)
    thisAnimalPos = inda
    ax1=plt.subplot(gs[thisAnimalPos])
    fontsize = 12
    allPline = []
    legendLabels = []
    for blockType in range(nBlocks):
        targetFrequencyThisBlock = targetFrequency[trialsEachType[:,blockType]]    
        validThisBlock = valid[trialsEachType[:,blockType]]
        choiceRightThisBlock = choiceRight[trialsEachType[:,blockType]]
        #currentBlockValue = currentBlock[trialsEachBlock[0,block]]
        (possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue)=\
                                                                                                behavioranalysis.calculate_psychometric(choiceRightThisBlock,targetFrequencyThisBlock,validThisBlock)
        (pline, pcaps, pbars, pdots) = extraplots.plot_psychometric(1e-3*possibleValues,fractionHitsEachValue,
                                                            ciHitsEachValue,xTickPeriod=1)

        plt.setp((pline, pcaps, pbars), color=FREQCOLORS[blockType])
        plt.setp(pdots, mfc=FREQCOLORS[blockType], mec=FREQCOLORS[blockType])
        allPline.append(pline)
     
        if blockType == nBlocks-1: 
            plt.xlabel('Frequency (kHz)',fontsize=fontsize)
            plt.ylabel('Rightward trials (%)',fontsize=fontsize)
            extraplots.set_ticks_fontsize(plt.gca(),fontsize)
            legend = plt.legend(allPline,blockLabels,loc=2)
            # Add the legend manually to the current Axes.
            ax = plt.gca().add_artist(legend)
            #plt.hold(True)
        #plt.legend(bbox_to_anchor=(1, 1), bbox_transform=plt.gcf().transFigure)
        plt.show()
Exemplo n.º 17
0
margins(0.2)
plt.subplots_adjust(bottom=0.2)
title(animal)
ylabel('Average Percent Correct')
show()




#### Need to start moving towards loading the data already split by sound type and then using generic fxns from behavioranalysis and extraplots

animal = 'amod002'

dataObjs, dataSoundTypes = behavioranalysis.load_behavior_sessions_sound_type(animal, ['20160421a'])

for bdata in dataObjs

bdata = dataObjs[0]
hitTrials = bdata['choice']==bdata.labels['choice']['right']
paramValueEachTrial = bdata['targetFrequency']
valid = bdata['valid']

(possibleValues,fractionHitsEachValue,ciHitsEachValue,nTrialsEachValue,nHitsEachValue) = behavioranalysis.calculate_psychometric(hitTrials, paramValueEachTrial, valid)


clf()
extraplots.plot_psychometric(possibleValues,fractionHitsEachValue,ciHitsEachValue)