Exemplo n.º 1
0
def makeBehavFigs(x):
    # Initialize figure
    behavFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
    gs1 = gridspec.GridSpec(5, 2)
    gs1.update(left=0.10, right=0.9, wspace=0.5, hspace=0.7)
    plt.suptitle('Rat ' + x.rat + ': Session ' + x.session + ' (' +
                 x.contents + ')')

    # Make figures of lick data from each bottle
    ax = plt.subplot(gs1[0, :])
    jmfig.sessionlicksFig(ax, x.lickData)

    ax = plt.subplot(gs1[1, 0])
    jmfig.licklengthFig(ax, x.lickData)

    ax = plt.subplot(gs1[1, 1])
    jmfig.iliFig(ax, x.lickData)

    ax = plt.subplot(gs1[2, 0])
    jmfig.burstlengthFig(ax, x.lickData, color3rdbar=True)

    ax = plt.subplot(gs1[2, 1])
    jmfig.ibiFig(ax, x.lickData)

    #plt.tight_layout()
    pdf_pages.savefig(behavFig)
Exemplo n.º 2
0
def ps_mcc1_fig(df, keys):
    data = []
    for key in keys:
        data.append(df[key])

    f, ax = plt.subplots(figsize=(5, 3))
    f.subplots_adjust(left=0.1, bottom=0.2)

    colors = [color_scheme[0]] * 2 + [color_scheme[2]] * 5
    print(colors)

    jmfig.barscatter(data,
                     paired=True,
                     barwidth=.8,
                     barfacecoloroption='individual',
                     barfacecolor=colors,
                     barlabels=keys,
                     ax=ax)

    ax.set_ylabel('Pellets consumed')
    ax.set_yticks([0, 10, 20, 30])
    ax.set_xlabel('Number of pellets given')
    ax.xaxis.set_label_coords(0.5, -0.13)

    return f
Exemplo n.º 3
0
def cond_photobar_fig(ax, df, diet, keys):

    scattersize = 50

    if diet == 'NR':
        cols = [col['np_cas'], col['np_cas'], col['np_malt'], col['np_malt']]
        title = 'Non-restricted'
    else:
        cols = [col['lp_cas'], col['lp_cas'], col['lp_malt'], col['lp_malt']]
        title = 'Protein restricted'

    x = [[df.xs(diet, level=1)[keys[0][0]],
          df.xs(diet, level=1)[keys[0][1]]],
         [df.xs(diet, level=1)[keys[1][0]],
          df.xs(diet, level=1)[keys[1][1]]]]

    jmfig.barscatter(
        x,
        paired=True,
        unequal=True,
        barfacecoloroption='individual',
        barfacecolor=cols,
        scatteredgecolor=['xkcd:charcoal'],
        scatterlinecolor='xkcd:charcoal',
        grouplabel=['Cas', 'Malt'],
        barlabels=['1', '2', '1', '2'],
        scattersize=scattersize,

        #             ylim=[-5,50],
        ax=ax)
Exemplo n.º 4
0
def sacc_behav_fig(df):
    f, ax = plt.subplots(figsize=(7.2, 2.5), ncols=2)

    scattersize = 50

    x = [[
        df.xs('NR', level=1)['latx1'],
        df.xs('NR', level=1)['latx2'],
        df.xs('NR', level=1)['latx3']
    ],
         [
             df.xs('PR', level=1)['latx1'],
             df.xs('PR', level=1)['latx2'],
             df.xs('PR', level=1)['latx3']
         ]]

    jmfig.barscatter(x,
                     paired=True,
                     unequal=True,
                     barfacecoloroption='individual',
                     barfacecolor=[
                         col['np_cas'], col['np_malt'], col['lp_cas'],
                         col['lp_malt']
                     ],
                     scatteredgecolor=['xkcd:charcoal'],
                     scatterlinecolor='xkcd:charcoal',
                     grouplabel=['NR', 'PR'],
                     barlabels=['Cas', 'Malt', 'Cas', 'Malt'],
                     scattersize=scattersize,
                     ylim=[-1, 20],
                     ax=ax[0])

    x = [[
        df.xs('NR', level=1)['missed1'],
        df.xs('NR', level=1)['missed2'],
        df.xs('NR', level=1)['missed3']
    ],
         [
             df.xs('PR', level=1)['missed1'],
             df.xs('PR', level=1)['missed2'],
             df.xs('PR', level=1)['missed3']
         ]]

    jmfig.barscatter(x,
                     paired=True,
                     unequal=True,
                     barfacecoloroption='individual',
                     barfacecolor=[
                         col['np_cas'], col['np_malt'], col['lp_cas'],
                         col['lp_malt']
                     ],
                     scatteredgecolor=['xkcd:charcoal'],
                     scatterlinecolor='xkcd:charcoal',
                     grouplabel=['NR', 'PR'],
                     barlabels=['Cas', 'Malt', 'Cas', 'Malt'],
                     scattersize=scattersize,
                     ylim=[-5, 50],
                     ax=ax[1])

    return f
Exemplo n.º 5
0
def makeGrantFigs(x):
    if x.leftTrials == True and x.rightTrials == True:

        grantLFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
        gs1 = gridspec.GridSpec(9, 7)
        gs1.update(left=0.125, right=0.9, wspace=0.4, hspace=0.8)
        plt.suptitle('Rat ' + x.rat + ': Session ' + x.session)
        jmfig.trialstiledFig(gs1, x.lickLTrials)
        pdf_pages.savefig(grantLFig)

        grantRFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
        gs1.update(left=0.125, right=0.9, wspace=0.4, hspace=0.8)
        plt.suptitle('Rat ' + x.rat + ': Session ' + x.session)
        jmfig.trialstiledFig(gs1, x.lickRTrials)
        pdf_pages.savefig(grantRFig)

    elif x.rightTrials == False:
        grantLFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
        gs1 = gridspec.GridSpec(9, 7)
        gs1.update(left=0.125, right=0.9, wspace=0.4, hspace=0.8)
        plt.suptitle('Rat ' + x.rat + ': Session ' + x.session)
        jmfig.trialstiledFig(gs1, x.lickLTrials)
        pdf_pages.savefig(grantLFig)

    elif x.leftTrials == False:
        grantRFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
        gs1 = gridspec.GridSpec(9, 7)
        gs1.update(left=0.125, right=0.9, wspace=0.4, hspace=0.8)
        plt.suptitle('Rat ' + x.rat + ': Session ' + x.session)
        jmfig.trialstiledFig(gs1, x.lickRTrials)
        pdf_pages.savefig(grantRFig)
Exemplo n.º 6
0
def photoFigsCol(gs1, col, pps, cues, cuesUV, cuesnoise, licks, licksUV,
                 licksnoise):
    ax = plt.subplot(gs1[1, col])
    jmfig.trialsFig(ax,
                    cues,
                    pps,
                    noiseindex=cuesnoise,
                    eventText='Cue',
                    ylabel='Delta F / F0')

    ax = plt.subplot(gs1[2, col])
    jmfig.trialsMultShadedFig(ax, [cuesUV, cues],
                              pps,
                              noiseindex=cuesnoise,
                              eventText='Cue')

    ax = plt.subplot(gs1[3, col])
    jmfig.trialsFig(ax,
                    licks,
                    pps,
                    noiseindex=licksnoise,
                    eventText='First Lick',
                    ylabel='Delta F / F0')

    ax = plt.subplot(gs1[4, col])
    jmfig.trialsMultShadedFig(ax, [licksUV, licks],
                              pps,
                              noiseindex=licksnoise,
                              eventText='First Lick')
Exemplo n.º 7
0
def makeBehavFigs(x):
    # Initialize figure
    behavFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
    gs1 = gridspec.GridSpec(5, 2)
    gs1.update(left=0.10, right=0.9, wspace=0.5, hspace=0.7)

    # Make figures of lick data from each bottle
    ax = plt.subplot(gs1[0, :])
    x.sessionLicksFig(ax)

    if len(x.lickDataA['licks']) > 1:
        ax = plt.subplot(gs1[1, 0])
        jmfig.licklengthFig(ax, x.lickDataA, contents=x.bottleA)

        ax = plt.subplot(gs1[2, 0])
        jmfig.iliFig(ax, x.lickDataA, contents=x.bottleA)

        ax = plt.subplot(gs1[3, 0])
        jmfig.burstlengthFig(ax, x.lickDataA, contents=x.bottleA)

        ax = plt.subplot(gs1[4, 0])
        jmfig.ibiFig(ax, x.lickDataA, contents=x.bottleA)
    else:
        print('No licks for Bottle A in this session.')

    #plt.tight_layout()
    pdf_pages.savefig(behavFig)
Exemplo n.º 8
0
def makePhotoFigs(x):
    # Initialize photometry figure
    photoFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
    gs1 = gridspec.GridSpec(6, 2)
    gs1.update(left=0.125, right=0.9, wspace=0.4, hspace=0.8)
    plt.suptitle('Rat ' + x.rat + ': Session ' + x.session)

    ax = plt.subplot(gs1[0, :])
    x.sessionFig(ax)

    if x.leftTrials == True:
        photoFigsCol(gs1, 0, x.pps, x.cueLTrials, x.cueLUVTrials, x.cueLnoise,
                     x.lickLTrials, x.lickLUVTrials, x.lickLnoise)

    if x.rightTrials == True:
        photoFigsCol(gs1, 1, x.pps, x.cueRTrials, x.cueRUVTrials, x.cueRnoise,
                     x.lickRTrials, x.lickRUVTrials, x.lickRnoise)

    if x.leftTrials == True and x.rightTrials == True:
        diffcueL = jmf.findphotodiff(x.cueLTrials, x.cueLUVTrials, x.cueLnoise)
        diffcueR = jmf.findphotodiff(x.cueRTrials, x.cueRUVTrials, x.cueRnoise)

        ax = plt.subplot(gs1[5, 0])
        jmfig.trialsMultShadedFig(ax, [diffcueL, diffcueR],
                                  x.pps,
                                  linecolor=['orange', 'g'],
                                  eventText='Cue')

        difflickL = jmf.findphotodiff(x.lickLTrials, x.lickLUVTrials,
                                      x.lickLnoise)
        difflickR = jmf.findphotodiff(x.lickRTrials, x.lickRUVTrials,
                                      x.lickRnoise)

        ax = plt.subplot(gs1[5, 1])
        jmfig.trialsMultShadedFig(ax, [difflickL, difflickR],
                                  x.pps,
                                  linecolor=['orange', 'g'],
                                  eventText='Lick')

    plt.savefig('R:/DA_and_Reward/jem64/1706_THPH1-lp/output/' + x.rat +
                '.eps',
                format='eps',
                dpi=1000)
    pdf_pages.savefig(photoFig)
Exemplo n.º 9
0
def makeBehavFigs(x):
    # Initialize figure
    behavFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
    gs1 = gridspec.GridSpec(5, 2)
    gs1.update(left=0.10, right=0.9, wspace=0.5, hspace=0.7)
    plt.suptitle('Rat ' + x.rat + ': Session ' + x.session)

    #    ax = plt.subplot(gs1[0, :])
    #    jmfig.sessionlicksFig(ax, x.lickData)

    if x.leftTrials == True:
        behavFigsCol(gs1, 0, x.lickDataL, x.cuesL)

    if x.rightTrials == True:
        behavFigsCol(gs1, 1, x.lickDataR, x.cuesR)

    ax = plt.subplot(gs1[4, 0])
    jmfig.latencyFig(ax, x)

    pdf_pages.savefig(behavFig)
Exemplo n.º 10
0
def makeBehavFigs(x, pdf_pages):
    # Initialize figure
    behavFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
    gs1 = gridspec.GridSpec(5, 2)
    gs1.update(left=0.10, right= 0.9, wspace=0.5, hspace = 0.7)
    plt.suptitle('Rat ' + x.rat + ': Session ' + x.session)
    
    ax = plt.subplot(gs1[0, :])
    sessionlicksFig(x, ax)

    if x.left['exist'] == True:
        behavFigsCol(gs1, 0, x.left)
        
    if x.right['exist'] == True:
        behavFigsCol(gs1, 1, x.right)
        
    ax = plt.subplot(gs1[4, 0])
    jmfig.latencyFig(ax, x)

    pdf_pages.savefig(behavFig)
Exemplo n.º 11
0
def makePhotoFigs(x):
    # Initialize photometry figure
    photoFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
    gs1 = gridspec.GridSpec(4, 2)
    gs1.update(left=0.125, right=0.9, wspace=0.4, hspace=0.8)

    ax = plt.subplot(gs1[0, :])
    x.sessionFig(ax)

    if len(x.lickDataA['licks']) > 1:
        ax = plt.subplot(gs1[2, 0])
        jmfig.trialsFig(ax, x.LiATrials, x.pps, eventText='LickA')

        ax = plt.subplot(gs1[2, 1])
        jmfig.trialsMultShadedFig(ax, [x.LiATrials, x.LiAUVTrials],
                                  x.pps,
                                  eventText='LickA')


#    plt.savefig(x.rat + '.eps', format='eps', dpi=1000)
    pdf_pages.savefig(photoFig)
Exemplo n.º 12
0
def peakbargraph(ax,
                 df,
                 diet,
                 keys,
                 peaktype='average',
                 epoch=[100, 149],
                 sc_color='w',
                 colorgroup='control',
                 ylabel=True,
                 ylim=[-0.05, 0.1],
                 grouplabeloffset=0):

    if colorgroup == 'control':
        bar_colors = ['xkcd:silver', 'w']
    else:
        bar_colors = [green, light_green]

    epochrange = range(epoch[0], epoch[1])

    df = df.xs(diet, level=1)

    if peaktype == 'average':
        a1 = [np.mean(rat[epochrange]) for rat in df[keys[0]]]
        a2 = [np.mean(rat[epochrange]) for rat in df[keys[1]]]
        ylab = 'Mean Z-Score'

    elif peaktype == 'auc':
        a1 = [np.trapz(rat[epochrange]) / 10 for rat in df[keys[0]]]
        a2 = [np.trapz(rat[epochrange]) / 10 for rat in df[keys[1]]]
        ylab = 'AUC'

    a = [a1, a2]
    x = jmf.data2obj1D(a)

    ax, x, _, _ = jmfig.barscatter(x,
                                   paired=True,
                                   barfacecoloroption='individual',
                                   barfacecolor=bar_colors,
                                   scatteredgecolor=[almost_black],
                                   scatterlinecolor=almost_black,
                                   scatterfacecolor=[sc_color],
                                   grouplabel=['Cas', 'Malt'],
                                   grouplabeloffset=grouplabeloffset,
                                   scattersize=50,
                                   xfontsize=6,
                                   ax=ax)

    #    ax.set_yticks([-0.05,0,0.05, 0.1])
    #    ax.set_yticklabels(['5%', '0%', '5%', '10%'])
    #    ax.set_ylim(ylim)

    if ylabel:
        ax.set_ylabel(ylab)
Exemplo n.º 13
0
def ps_myers_figB(df, keys):
    data = [df[keys[0]], df[keys[1]], df[keys[2]]]

    f, ax = plt.subplots(figsize=(3, 3))
    f.subplots_adjust(left=0.2)

    colors = color_scheme

    jmfig.barscatter(data,
                     paired=True,
                     barwidth=.7,
                     barfacecoloroption='individual',
                     barfacecolor=colors,
                     barlabels=keys,
                     xlim=[0.25, 3.75],
                     ax=ax)
    #    ax.set_xlim([0.2,2.8])
    ax.set_ylabel('Food consumed (g)')
    ax.set_yticks([0, 10, 20, 30])

    return f
Exemplo n.º 14
0
def makePhotoFigs(x, pdf_pages):
    # Initialize photometry figure
    photoFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
    gs1 = gridspec.GridSpec(7, 4)
    gs1.update(left=0.125, right= 0.9, wspace=0.4, hspace = 0.8)
    plt.suptitle('Rat ' + x.rat + ': Session ' + x.session)

    ax = plt.subplot(gs1[0, :])
    sessionFig(x, ax, filtered=False)
    
    ax = plt.subplot(gs1[1, :])
    sessionFig(x, ax)

    if x.left['exist'] == True:
        photoFigsCol(gs1, 0, x.pps,
                     x.left['snips_sipper'],
                     x.left['snips_licks'])

    if x.right['exist'] == True:
        photoFigsCol(gs1, 2, x.pps,
                     x.right['snips_sipper'],
                     x.right['snips_licks'])
        
    if x.left['exist'] == True and x.right['exist'] == True:
        ax = plt.subplot(gs1[6, 0])
        jmfig.trialsMultShadedFig(ax, [x.left['snips_sipper']['diff'], x.right['snips_sipper']['diff']],
                                  x.pps,
                                  linecolor=[x.left['color'], x.right['color']],
                                  eventText = 'Sipper')

        ax = plt.subplot(gs1[6, 2])
        jmfig.trialsMultShadedFig(ax, [x.left['snips_licks']['diff'], x.right['snips_licks']['diff']],
                                  x.pps,
                                  linecolor=[x.left['color'], x.right['color']],
                                  eventText = 'Lick')
        
#    plt.savefig(userhome + '/Dropbox/Python/photometry/output-thph1-lp/' + x.rat + '.eps', format='eps', dpi=1000)
    pdf_pages.savefig(photoFig)
Exemplo n.º 15
0
def behavFigsCol(gs1, col, lickdata, cues):
    ax = plt.subplot(gs1[1, col])
    jmfig.licklengthFig(ax, lickdata)

    ax = plt.subplot(gs1[2, col])
    jmfig.iliFig(ax, lickdata)

    ax = plt.subplot(gs1[3, col])
    jmfig.cuerasterFig(ax, cues, lickdata['licks'])
Exemplo n.º 16
0
def behavFigsCol(gs1, col, side):
    ax = plt.subplot(gs1[1, col])
    jmfig.licklengthFig(ax, side['lickdata'], color=side['color'])
    
    ax = plt.subplot(gs1[2, col])
    jmfig.iliFig(ax, side['lickdata'], color=side['color'])
    
    ax = plt.subplot(gs1[3, col])
    jmfig.cuerasterFig(ax, side['sipper'], side['lickdata']['licks'])
Exemplo n.º 17
0
def cond_licks_fig(ax, df, diet):

    scattersize = 50

    if diet == 'NR':
        cols = [col['np_cas'], col['np_cas'], col['np_malt'], col['np_malt']]
        title = 'Non-restricted'
    else:
        cols = [col['lp_cas'], col['lp_cas'], col['lp_malt'], col['lp_malt']]
        title = 'Protein restricted'

    x = [[
        df.xs(diet, level=1)['cond1-cas1-licks'],
        df.xs(diet, level=1)['cond1-cas2-licks']
    ],
         [
             df.xs(diet, level=1)['cond1-malt1-licks'],
             df.xs(diet, level=1)['cond1-malt2-licks']
         ]]

    jmfig.barscatter(x,
                     paired=True,
                     unequal=True,
                     barfacecoloroption='individual',
                     barfacecolor=cols,
                     scatteredgecolor=['xkcd:charcoal'],
                     scatterlinecolor='xkcd:charcoal',
                     grouplabel=[],
                     barlabels=['1', '2', '1', '2'],
                     barlabeloffset=0.025,
                     scattersize=scattersize,
                     ax=ax)

    ax.set_yticks([0, 1000, 2000, 3000, 4000])
    ax.set_yticklabels([0, 1000, 2000, 3000, 4000], fontsize=8)
    ax.set_title(title, fontsize=10)
Exemplo n.º 18
0
def ps_mcc2_fig(df, keys):
    data = []
    for key in keys:
        data.append(df[key])

    f, ax = plt.subplots(figsize=(3, 3))
    f.subplots_adjust(left=0.2, bottom=0.2)

    colors = [color_scheme[2]] * 4

    jmfig.barscatter(data,
                     paired=True,
                     barwidth=.8,
                     barfacecoloroption='individual',
                     barfacecolor=colors,
                     barlabels=keys,
                     ax=ax)

    ax.set_ylabel('Peanut butter consumed (g)')
    ax.set_yticks([0, 1, 2, 3])
    ax.set_xlabel('Amount of peanut butter given (g)')
    ax.xaxis.set_label_coords(0.5, -0.13)

    return f
Exemplo n.º 19
0
def summary_subfig_bars(ax, df, keys):

    df_NR = df.xs('NR', level=1)
    df_PR = df.xs('PR', level=1)

    a = [[df_NR[keys[0]], df_NR[keys[1]], df_NR[keys[2]]],
         [df_PR[keys[0]], df_PR[keys[1]], df_PR[keys[2]]]]

    x = jmf.data2obj2D(a)

    cols = ['xkcd:silver', green]

    xlabels = ['NR \u2192 PR', 'PR \u2192 NR']

    jmfig.barscatter(
        x,
        paired=True,
        barfacecoloroption='individual',
        barfacecolor=[cols[0], cols[1], cols[1], cols[1], cols[0], cols[0]],
        scatteredgecolor=[almost_black],
        scatterlinecolor=almost_black,
        scattersize=50,
        grouplabel=xlabels,
        ax=ax)
Exemplo n.º 20
0
def nplp2Dfig(df, factor1, factor2, ax):
    dietmsk = df.diet == 'NR'
    
    a = [[df[factor1][dietmsk], df[factor2][dietmsk]],
          [df[factor1][~dietmsk], df[factor2][~dietmsk]]]

    ax, x, _, _ = jmfig.barscatter(a, paired=True,
                 barfacecoloroption = 'individual',
                 barfacecolor = [col['np_cas'], col['np_malt'], col['lp_cas'], col['lp_malt']],
                 scatteredgecolor = ['xkcd:charcoal'],
                 scatterlinecolor = 'xkcd:charcoal',
                 grouplabel=['NR', 'PR'],
                 grouplabeloffset=0.1,
                 barlabels=['Cas', 'Malt', 'Cas', 'Malt'],
                 barlabeloffset=0.025,
                 scattersize = 80,
                 ax=ax)
Exemplo n.º 21
0
def makeHeatmapFigs(x):

    heatmapsFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
    gs1 = gridspec.GridSpec(2, 1)
    gs1.update(left=0.125, right=0.9, wspace=0.4, hspace=0.8)

    ax = plt.subplot(gs1[0, 0])
    jmfig.heatmapFig(ax, x.LiATrials, pps=x.pps)
    data = jmf.nearestevents(x.lickDataA['rStart'], x.lickDataA['licks'])
    nLicks = [len(i) for i in data]
    sortOrder = np.argsort(nLicks)

    ax = plt.subplot(gs1[1, 0])
    jmfig.heatmapFig(ax, x.LiATrials, pps=x.pps, sortEvs=nLicks)

    sortedData = []
    for val in sortOrder:
        sortedData.append(data[val])

    jmfig.addevent2heatmap(ax, sortedData, pps=x.pps)

    pdf_pages.savefig(heatmapsFig)
Exemplo n.º 22
0
def makeHeatmapFigs(x):
    heatmapsFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
    gs1 = gridspec.GridSpec(3, 2)
    gs1.update(left=0.125, right=0.9, wspace=0.4, hspace=0.8)

    ax = plt.subplot(gs1[0, 0])
    jmfig.heatmapFig(ax, x.siTrials, pps=x.pps)
    data = jmf.nearestevents(x.output.Sir.onset, x.lickDataA['licks'])
    jmfig.addevent2heatmap(ax, data, pps=x.pps)

    ax = plt.subplot(gs1[0, 1])
    data = jmf.nearestevents(x.output.Sir.onset, x.lickDataA['licks'])
    sortEv = jmf.findfirst(data)
    jmfig.heatmapFig(ax, x.siTrials, pps=x.pps, sortEvs=sortEv)

    jmfig.addevent2heatmap(ax, data, pps=x.pps)

    ax = plt.subplot(gs1[1, 0])
    jmfig.heatmapFig(ax, x.LiATrials, pps=x.pps)
    data = jmf.nearestevents(x.lickDataA['rStart'], x.output.Sir.onset)
    jmfig.addevent2heatmap(ax, data, pps=x.pps)

    pdf_pages.savefig(heatmapsFig)
Exemplo n.º 23
0
def makePhotoFigs(x):
    # Initialize photometry figure
    photoFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
    gs1 = gridspec.GridSpec(5, 2)
    gs1.update(left=0.125, right=0.9, wspace=0.4, hspace=0.8)

    ax = plt.subplot(gs1[0, :])
    x.sessionFig(ax)

    #    if x.siTrials != None:
    try:
        ax = plt.subplot(gs1[1, 0])
        jmfig.trialsFig(ax, x.siTrials, x.pps, eventText='Sipper Out')

        ax = plt.subplot(gs1[1, 1])
        jmfig.trialsShadedFig(ax, x.siTrials, x.pps, eventText='Sipper Out')
    except:
        print('No no')

    if len(x.lickDataA['licks']) > 1:
        ax = plt.subplot(gs1[2, 0])
        jmfig.trialsFig(ax, x.LiATrials, x.pps, eventText=x.bottleA)

        ax = plt.subplot(gs1[2, 1])
        jmfig.trialsShadedFig(ax, x.LiATrials, x.pps, eventText=x.bottleA)

    if len(x.lickDataB['licks']) > 1:
        ax = plt.subplot(gs1[3, 0])
        jmfig.trialsFig(ax, x.LiBTrials, x.pps, eventText=x.bottleB)

        ax = plt.subplot(gs1[3, 1])
        jmfig.trialsShadedFig(ax, x.LiBTrials, x.pps, eventText=x.bottleB)

    if x.ATrials == True and x.BTrials == True:
        ax = plt.subplot(gs1[4, 0])
        jmfig.trialsMultShadedFig(ax, [x.LiATrials, x.LiBTrials], x.pps)


#
#    ax = plt.subplot(gs1[3, :])
#    rats[i].sessions[j].trialsHeatMap(ax)
#    plt.savefig(userhome + '\\Dropbox\\Python\\figformasa.eps', format='eps', dpi=1000)
    pdf_pages.savefig(photoFig)
Exemplo n.º 24
0
for key in keys:
    NR[key] = []
    PR[key] = []

dietmsk = df.diet == 'NR'

for x in quinconcs:
    quinmsk = df.quin == x
    for groupdict, msk in zip([NR, PR], [dietmsk, ~dietmsk]):
        groupdict[keys[0]].append(list(df['pref'][msk & quinmsk]))
        groupdict[keys[1]].append(list(df['cas_pal'][msk & quinmsk]))
        groupdict[keys[2]].append(list(df['malt_pal'][msk & quinmsk]))

#jmfig.barscatter([nr_data, pr_data], transpose=False)
#_,_,_,_ = jmfig.barscatter(PR['pref'])
_, _, _, _ = jmfig.barscatter(PR['caspal'])
#_,_,_,_ = jmfig.barscatter(PR['maltpal'])
#_,_,_,_ = jmfig.barscatter([PR['caspal'], PR['maltpal']], transpose=True, paired=True)

figQPPpref, ax = plt.subplots()
jmfig.barscatter(PR['pref'],
                 barwidth=0.8,
                 barfacecolor=['xkcd:kelly green'],
                 scatteredgecolor=['xkcd:charcoal'],
                 barlabels=[str(x) for x in quinconcs],
                 barlabeloffset=2500,
                 ax=ax)
ax.set_ylabel('Casein preference')
ax.set_xlabel('Quinine concentration (mM)', labelpad=30)

try:
Exemplo n.º 25
0
def averagetrace(ax,
                 df,
                 diet,
                 keys,
                 event='',
                 fullaxis=True,
                 colorgroup='control',
                 ylabel=True):

    if colorgroup == 'control':
        color = [almost_black, 'xkcd:bluish grey']
        errorcolors = ['xkcd:silver', 'xkcd:silver']
    else:
        color = [green, light_green]
        errorcolors = ['xkcd:silver', 'xkcd:silver']


# Selects diet group to plot
    df = df.xs(diet, level=1)

    # Plots casein and maltodextrin shaded erros
    jmfig.shadedError(ax,
                      df[keys[0]],
                      linecolor=color[0],
                      errorcolor=errorcolors[0],
                      linewidth=2)
    jmfig.shadedError(ax,
                      df[keys[1]],
                      linecolor=color[1],
                      errorcolor=errorcolors[1],
                      linewidth=2)

    #ax.legend(['Casein', 'Maltodextrin'], fancybox=True)
    if fullaxis == False:
        ax.axis('off')

        # Adds y scale bar
        y = [y for y in ax.get_yticks() if y > 0][:2]
        l = y[1] - y[0]
        scale_label = '{0:.0f}% \u0394F'.format(l * 100)
        ax.plot([50, 50], [y[0], y[1]], c=almost_black)
        ax.text(40, y[0] + (l / 2), scale_label, va='center', ha='right')

        # Adds x scale bar
        y = ax.get_ylim()[0]
        ax.plot([251, 300], [y, y], c=almost_black, linewidth=2)
        ax.annotate('5 s',
                    xy=(276, y),
                    xycoords='data',
                    xytext=(0, -5),
                    textcoords='offset points',
                    ha='center',
                    va='top')

    else:
        ax.set_xticks([0, 100, 200, 300])
        ax.set_xticklabels(['-10', '0', '10', '20'])
        ax.set_xlabel('Time from first lick (s)')

    if ylabel:
        ax.set_ylabel('Z-Score')
Exemplo n.º 26
0
def cond_photo_fig(ax,
                   df,
                   diet,
                   keys,
                   event='',
                   color=[almost_black, 'xkcd:bluish grey'],
                   errorcolors=['xkcd:silver', 'xkcd:silver'],
                   yerror=True):

    if diet == 'NR':
        color = [almost_black, 'xkcd:bluish grey']
        errorcolors = ['xkcd:silver', 'xkcd:silver']
        title = 'Non-restricted'
    else:
        color = [green, light_green]
        errorcolors = ['xkcd:silver', 'xkcd:silver']
        title = 'Protein restricted'

    df = df.xs(diet, level=1)

    # Plots casein and maltodextrin shaded erros
    jmfig.shadedError(ax,
                      df[keys[0]],
                      linecolor=color[0],
                      errorcolor=errorcolors[0])
    jmfig.shadedError(ax,
                      df[keys[1]],
                      linecolor=color[1],
                      errorcolor=errorcolors[1])

    #ax.legend(['Casein', 'Maltodextrin'], fancybox=True)
    ax.axis('off')

    # Marks location of event on graph with arrow
    arrow_y = ax.get_ylim()[1]
    ax.plot([100, 150], [arrow_y, arrow_y], color='xkcd:silver', linewidth=3)
    ax.annotate(event,
                xy=(125, arrow_y),
                xytext=(0, 5),
                textcoords='offset points',
                ha='center',
                va='bottom')

    # Adds y scale bar
    if yerror:
        y = [y for y in ax.get_yticks() if y > 0][:2]
        l = y[1] - y[0]
        scale_label = '{0:.0f}% \u0394F'.format(l * 100)
        ax.plot([50, 50], [y[0], y[1]], c=almost_black)
        ax.text(40, y[0] + (l / 2), scale_label, va='center', ha='right')


# Adds x scale bar
    y = ax.get_ylim()[0]
    ax.plot([251, 300], [y, y], c=almost_black, linewidth=2)
    ax.annotate('5 s',
                xy=(276, y),
                xycoords='data',
                xytext=(0, -5),
                textcoords='offset points',
                ha='center',
                va='top')
Exemplo n.º 27
0
def makePhotoFigs(x):
    # Initialize photometry figure
    photoFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
    gs1 = gridspec.GridSpec(5, 2)
    gs1.update(left=0.125, right=0.9, wspace=0.4, hspace=0.8)
    plt.suptitle('Rat ' + x.rat + ': Session ' + x.session + ' (' +
                 x.contents + ')')

    ax = plt.subplot(gs1[0, :])
    x.sessionFig(ax)

    ax = plt.subplot(gs1[1, 0])
    jmfig.trialsFig(ax,
                    x.LiTrials,
                    x.pps,
                    eventText='First lick',
                    ylabel='Delta F / F0')

    ax = plt.subplot(gs1[1, 1])
    jmfig.trialsMultShadedFig(ax, [x.LiUVTrials, x.LiTrials],
                              x.pps,
                              eventText='First lick')

    ax = plt.subplot(gs1[2, 0])
    jmfig.heatmapFig(ax, x.LiTrials, pps=x.pps)

    ax = plt.subplot(gs1[2, 1])
    data = jmf.nearestevents(x.lickData['rStart'], x.lickData['licks'])
    nLicks = [len(i) for i in data]
    sortOrder = np.argsort(nLicks)
    jmfig.heatmapFig(ax, x.LiTrials, pps=x.pps, sortEvs=nLicks)

    if hasattr(x, 'distractedArray'):
        ax = plt.subplot(gs1[3, 0])
        jmfig.trialsMultShadedFig(
            ax,
            [x.siUVTrials[x.distractedArray], x.siTrials[x.distractedArray]],
            x.pps,
            eventText='',
            title='Distracted trials (n=%i)' % np.sum(x.distractedArray))

        ax = plt.subplot(gs1[3, 1])
        jmfig.trialsMultShadedFig(
            ax,
            [x.siUVTrials[~x.distractedArray], x.siTrials[~x.distractedArray]],
            x.pps,
            eventText='',
            title='Non-distracted trials')

        ax = plt.subplot(gs1[4, 0])
        jmfig.heatmapFig(ax, x.siTrials, pps=x.pps)

        ax = plt.subplot(gs1[4, 1])
        jmfig.heatmapFig(ax, x.siTrials, pps=x.pps, sortEvs=x.firstlick)

#    plt.savefig(x.rat + '.eps', format='eps', dpi=1000)
    pdf_pages.savefig(photoFig)
Exemplo n.º 28
0
def makeBehavFigs(x):
    # Initialize figure
    behavFig = plt.figure(figsize=(8.27, 11.69), dpi=100)
    gs1 = gridspec.GridSpec(5, 2)
    gs1.update(left=0.10, right=0.9, wspace=0.5, hspace=0.7)
    plt.suptitle('Rat ' + x.rat + ': Session ' + x.session + ' (' +
                 x.contents + ')')

    ax = plt.subplot(gs1[0, :])
    jmfig.sessionlicksFig(ax, x.lickData)

    ax = plt.subplot(gs1[1, 0])
    jmfig.licklengthFig(ax, x.lickData)

    ax = plt.subplot(gs1[1, 1])
    jmfig.iliFig(ax, x.lickData)

    ax = plt.subplot(gs1[2, 0])
    jmfig.burstlengthFig(ax, x.lickData, color3rdbar=True)

    ax = plt.subplot(gs1[2, 1])
    jmfig.ibiFig(ax, x.lickData)

    ax = plt.subplot(gs1[3, 0])
    jmfig.distractionrasterFig(ax,
                               x.distractors,
                               x.lickData['licks'],
                               post=1.1)
    ax.set_title('%i distractors' % len(x.distractors))

    ax = plt.subplot(gs1[3, 1])
    jmfig.distractionrasterFig(ax,
                               x.distractors,
                               x.lickData['licks'],
                               post=1.1,
                               sortevents=x.firstlick,
                               sortdirection='backwards')
    ax.set_title('Sorted by first lick after')

    ax = plt.subplot(gs1[4, 0])
    jmfig.cumulativelickFig(ax, x.firstlick)

    #plt.tight_layout()
    pdf_pages.savefig(behavFig)
longsnipUV, _ = jmf.snipper(x.dataUV, [EOI],
                            t2sMap=x.t2sMap,
                            fs=x.fs,
                            bins=longbins,
                            preTrial=longlength / 2,
                            trialLength=longlength)

f = plt.figure(figsize=(8.27, 11.69), dpi=100)
gs1 = gridspec.GridSpec(3, 2)
gs1.update(left=0.125, right=0.9, wspace=0.4, hspace=0.8)

ax = plt.subplot(gs1[0, :])
#ax.vlines(triallicks, 1, 2)
#ax.set_xlim([EOI-longlength/2, EOI+longlength/2])
ax.hist(triallicksnorm, range(0, longlength, 1))

ax = plt.subplot(gs1[1, :])

jmfig.trialsMultFig(ax, [longsnipUV, longsnip],
                    longpps,
                    preTrial=longlength / 2,
                    scale=60,
                    eventText='lick')

ax = plt.subplot(gs1[2, 1])
jmfig.trialsMultFig(ax, [shortsnipUV, shortsnip], shortpps)

plt.savefig(userhome + '/Dropbox/Python/photometry/output-thph1-lp/' + x.rat +
            '.eps',
            format='eps',
            dpi=1000)
Exemplo n.º 30
0
def photoFigsCol(gs1, col, pps, snips_sipper, snips_licks):
    ax = plt.subplot(gs1[2, col])
    jmfig.trialsFig(ax, snips_sipper['blue'], pps, noiseindex = snips_sipper['noise'],
                    eventText = 'Sipper',
                    ylabel = 'Delta F / F0')
    
    ax = plt.subplot(gs1[3, col])
    jmfig.trialsMultShadedFig(ax, [snips_sipper['uv'], snips_sipper['blue']],
                              pps, noiseindex = snips_sipper['noise'],
                              eventText = 'Sipper')
    
    ax = plt.subplot(gs1[2, col+1])
    jmfig.shadedError(ax, snips_sipper['blue_z'])
    
    ax = plt.subplot(gs1[4, col])
    jmfig.trialsFig(ax, snips_licks['blue'], pps, noiseindex=snips_licks['noise'],
                    eventText = 'First Lick',
                    ylabel = 'Delta F / F0')
    
    ax = plt.subplot(gs1[5, col])
    jmfig.trialsMultShadedFig(ax, [snips_licks['uv'], snips_licks['blue']],
                              pps, noiseindex=snips_licks['noise'],
                              eventText = 'First Lick')
    
    ax = plt.subplot(gs1[4, col+1])
    jmfig.shadedError(ax, snips_licks['blue_z'])