예제 #1
0
 def plot_all_events_and_fits(self):
     P3 = PH.regular_grid(1,
                          5,
                          order='columns',
                          figsize=(12, 8.),
                          showgrid=False,
                          verticalspacing=0.1,
                          horizontalspacing=0.02,
                          margins={
                              'leftmargin': 0.07,
                              'rightmargin': 0.05,
                              'topmargin': 0.03,
                              'bottommargin': 0.05
                          },
                          labelposition=(-0.12, 0.95))
     idx = [a for a in P3.axdict.keys()]
     ncol = 5
     offset2 = 0.
     k = 0
     for itr in range(len(all_evok)):  # for each trace
         for evok in all_evok[itr]:  # for each ok event in that trace
             P3.axdict[idx[k]].plot([
                 self.cell_summary['indiv_tb'][itr][0],
                 self.cell_summary['indiv_tb'][itr][-1]
             ],
                                    np.zeros(2) + offset2,
                                    'b--',
                                    linewidth=0.3)
             P3.axdict[idx[k]].plot(
                 self.cell_summary['indiv_tb'][itr],
                 self.cell_summary['allevents'][itr][evok] + offset2,
                 'k--',
                 linewidth=0.5)
             P3.axdict[idx[k]].plot(
                 self.cell_summary['indiv_tb'][itr],
                 -self.cell_summary['best_fit'][itr][evok] + offset2,
                 'r--',
                 linewidth=0.5)
             if k == 4:
                 k = 0
                 offset2 += 20.
             else:
                 k += 1
     mpl.show()
예제 #2
0
    def summarize_inputs(self):
        P = PH.regular_grid(2, 3, order='columns', figsize=(10., 8), showgrid=False)
        ax = [P.axdict[x] for x in P.axdict.keys()]
     #   PH.nice_plot(ax)
        allendings = []
        cellendings = {}
        for cell, v in self.VCN_Inputs.items():
            cellendings[cell] = []
            for s in v[1]:
                if isinstance(s, list) or isinstance(s, tuple):
                    allendings.append(s[0])
                    cellendings[cell].append(s[0])
                else:
                    continue
                    # print('not list or tuple: ', cell, s)
                    # allendings.append(s)
                    # cellendings[cell].append(s)

        ax[0].set_title('All ending areas')
        ax[0].hist(allendings, bins=20)
        ax[0].set_ylim((0, 25))
        ax[0].set_ylabel('N')
        ax[0].set_xlim((0,350))
        ax[0].set_xlabel('Area ($um^2$)')
    
        normd = []
        ratio1 = []
        ratio2 = []
        meansize = []
        maxsize = []
        convergence = []
    

        for cell in cellendings.keys():
                normd.extend(cellendings[cell]/np.max(cellendings[cell]))
                ratio1.append(cellendings[cell][1]/cellendings[cell][0])
                ratio2.append(np.mean(cellendings[cell])/cellendings[cell][0])
                meansize.append(np.mean(cellendings[cell]))
                maxsize.append(np.max(cellendings[cell]))
                convergence.append(len(cellendings[cell]))
        print('convergence: ', convergence)

        ax[1].set_title('Normalized by largest')
        ax[1].hist(normd, bins=20, range=(0,1.0), align='mid')
        ax[1].set_xlabel('Area ($um^2$)')
        ax[1].set_ylabel('N')

        ax[2].set_title('Ratio largest to next largest')
        ax[2].hist(ratio1, bins=10, range=(0,1.0), align='mid')
        ax[2].set_xlabel('Area ($um^2$)')

        ax[3].set_title('Ratio of mean to largest')
        ax[3].hist(ratio2, bins=10, range=(0,1.0), align='mid')
        ax[3].set_xlabel('Area ($um^2$)')

        ax[4].set_title('Convergence vs. mean size')
        ax[4].set_xlim((0., 200.))
        ax[4].set_xlabel('Area ($um^2$)')
        ax[4].set_ylim((0., 15.))  
        ax[4].set_ylabel('Convergence')
        fit = np.polyfit(meansize, convergence, 1)
        fit_fn = np.poly1d(fit)
        r, p = scipy.stats.pearsonr(meansize, convergence)
        ax[4].text(x=0.05, y=0.95, s=f"r: {r:.3f}, p={p:.3e}", fontsize=8)
        ax[4].scatter(meansize, convergence)
        ax[4].plot(meansize, fit_fn(meansize), '--k')


        ax[5].set_title('Convergence vs max size')
        fit = np.polyfit(maxsize, convergence, 1)
        fit_fn = np.poly1d(fit)
        r, p = scipy.stats.pearsonr(maxsize, convergence)
        ax[5].text(x=0.05, y=0.95, s=f"r: {r:.3f}, p={p:.3f}", fontsize=8)
        ax[5].scatter(maxsize, convergence)
        ax[5].plot(maxsize, fit_fn(maxsize), '--k')
        ax[5].set_xlim((0., 350.))
        ax[5].set_xlabel('Area ($um^2$)')
        ax[5].set_ylim((0., 15.))
        ax[5].set_xlabel('Convergence')

    

        mpl.show()
예제 #3
0
    # 'AN_Result_VCN_c09_XM13nacncoop_II_soma=1.489_all_multisite_020_tonepip_030dB_16000.0_MS.p'
    patterns = fn.keys()
    print ('patterns: ', patterns)
    p = 'c09'
    gbcs.append('Summary')
    # fig, ax = plt.subplots(2, 4, figsize=(10,6))
    lmar = 0.1
    rmar = -0.01
    tmar = 0.01
    bmar = 0.08
    hspace = 0.05
    vspace = 0.1
    nplts = len(gbcs)
    nrows, ncols = PH.getLayoutDimensions(nplts, pref='height')

    P = PH.regular_grid(nrows, ncols, figsize=(10, 6), panel_labels=gbcs)
    #PH.Plotter(rcshape=sizer, label=False, figsize=(10 , 6))
    P.figure_handle.suptitle('Reverse Correlations, AN types={0:2s}'.format(SR))
    ax2 = {}
    for i, g in enumerate(P.axdict.keys()):
        if i >= len(gbcs):
            continue
        P.axdict[g].set_xlim(-5., 0.)
        # P.axdict[g].set_axis_bgcolor('gainsboro')
        P.axdict[g].tick_params(labelsize=6)
        ax2[g] = twinax(P.figure_handle, P.axdict[g], pos=1.0)
    for l in P.axlabels:
        l.set_text(' ')
    # plt.show()
    # exit()
    sTC = {}
예제 #4
0
    def plot_vciv(self):
        P = PH.regular_grid(2,
                            2,
                            order='columns',
                            figsize=(8., 6.),
                            showgrid=False,
                            verticalspacing=0.1,
                            horizontalspacing=0.12,
                            margins={
                                'leftmargin': 0.12,
                                'rightmargin': 0.12,
                                'topmargin': 0.08,
                                'bottommargin': 0.1
                            },
                            labelposition=(-0.12, 0.95))
        (date, sliceid, cell, proto,
         p3) = self.file_cell_protocol(self.datapath)

        P.figure_handle.suptitle(os.path.join(date, sliceid, cell,
                                              proto).replace('_', '\_'),
                                 fontsize=12)
        for i in range(self.AR.traces.shape[0]):
            P.axdict['A'].plot(self.AR.time_base * 1e3,
                               self.AR.traces[i, :] * 1e12,
                               'k-',
                               linewidth=0.5)

        PH.talbotTicks(P.axdict['A'],
                       tickPlacesAdd={
                           'x': 0,
                           'y': 0
                       },
                       floatAdd={
                           'x': 0,
                           'y': 0
                       })
        P.axdict['A'].set_xlabel('T (ms)')
        P.axdict['A'].set_ylabel('I (pA)')
        PH.crossAxes(P.axdict['C'], xyzero=(-60., 0.))
        P.axdict['C'].plot(self.vcss_vcmd * 1e3,
                           self.vcss_Im * 1e12,
                           'ks-',
                           linewidth=1,
                           markersize=4)
        P.axdict['C'].set_xlabel('V (mV)')
        P.axdict['C'].set_ylabel('I (pA)')
        PH.talbotTicks(P.axdict['C'],
                       tickPlacesAdd={
                           'x': 0,
                           'y': 0
                       },
                       floatAdd={
                           'x': 0,
                           'y': 0
                       })

        P.axdict['B'].set_xlabel('I (nA)')
        P.axdict['B'].set_ylabel('V (mV)')
        PH.talbotTicks(P.axdict['B'],
                       tickPlacesAdd={
                           'x': 1,
                           'y': 0
                       },
                       floatAdd={
                           'x': 2,
                           'y': 0
                       })

        P.axdict['D'].set_xlabel('I (pA)')
        P.axdict['D'].set_ylabel('Latency (ms)')

        self.IVFigure = P.figure_handle

        if self.plot:
            mpl.show()
예제 #5
0
    def plot_individual_events(self,
                               fit_err_limit=1000.,
                               tau2_range=2.5,
                               title='',
                               pdf=None):
        P = PH.regular_grid(3,
                            3,
                            order='columns',
                            figsize=(8., 8.),
                            showgrid=False,
                            verticalspacing=0.1,
                            horizontalspacing=0.12,
                            margins={
                                'leftmargin': 0.12,
                                'rightmargin': 0.12,
                                'topmargin': 0.03,
                                'bottommargin': 0.1
                            },
                            labelposition=(-0.12, 0.95))
        P.figure_handle.suptitle(title)
        all_evok = self.cell_summary[
            'indiv_evok']  # this is the list of ok events - a 2d list by
        all_notok = self.cell_summary['indiv_notok']
        # print('all evok: ', all_evok)
        # print('len allevok: ', len(all_evok))
        #
        # # print('all_notok: ', all_notok)
        # # print('indiv tau1: ', self.cell_summary['indiv_tau1'])
        # exit(1)
        trdat = []
        trfit = []
        trdecfit = []
        for itr in range(len(all_evok)):  # for each trace
            for evok in all_evok[itr]:  # for each ok event in that trace
                P.axdict['A'].plot(self.cell_summary['indiv_tau1'][itr][evok],
                                   self.cell_summary['indiv_amp'][itr][evok],
                                   'ko',
                                   markersize=3)
                P.axdict['B'].plot(self.cell_summary['indiv_tau2'][itr][evok],
                                   self.cell_summary['indiv_amp'][itr][evok],
                                   'ko',
                                   markersize=3)
                P.axdict['C'].plot(self.cell_summary['indiv_tau1'][itr][evok],
                                   self.cell_summary['indiv_tau2'][itr][evok],
                                   'ko',
                                   markersize=3)
                P.axdict['D'].plot(
                    self.cell_summary['indiv_amp'][itr][evok],
                    self.cell_summary['indiv_fiterr'][itr][evok],
                    'ko',
                    markersize=3)
                P.axdict['H'].plot(
                    self.cell_summary['indiv_tau1'][itr][evok],
                    self.cell_summary['indiv_Qtotal'][itr][evok],
                    'ko',
                    markersize=3)
                trdat.append(
                    np.column_stack([
                        self.cell_summary['indiv_tb'][itr],
                        self.cell_summary['allevents'][itr][evok]
                    ]))
                #idl = len(self.cell_summary['best_decay_fit'][itr][evok])
                trfit.append(
                    np.column_stack([
                        self.cell_summary['indiv_tb'][itr],
                        -self.cell_summary['best_fit'][itr][evok]
                    ]))
                trdecfit.append(
                    np.column_stack([
                        self.cell_summary['indiv_tb'][itr],
                        -self.cell_summary['best_decay_fit'][itr][evok]
                    ]))
        dat_coll = collections.LineCollection(trdat,
                                              colors='k',
                                              linewidths=0.5)
        fit_coll = collections.LineCollection(trfit,
                                              colors='r',
                                              linewidths=0.25)
        #        decay_fit_coll = collections.LineCollection(trdecfit, colors='c', linewidths=0.3)
        P.axdict['G'].add_collection(dat_coll)
        P.axdict['G'].add_collection(fit_coll)
        #        P.axdict['G'].add_collection(decay_fit_coll)
        n_trdat = []
        n_trfit = []
        for itr in range(len(all_notok)):
            for notok in all_notok[itr]:
                n_trdat.append(
                    np.column_stack([
                        self.cell_summary['indiv_tb'][itr],
                        self.cell_summary['allevents'][itr][notok]
                    ]))
                n_trfit.append(
                    np.column_stack([
                        self.cell_summary['indiv_tb'][itr],
                        -self.cell_summary['best_fit'][itr][notok]
                    ]))
                P.axdict['D'].plot(
                    self.cell_summary['indiv_amp'][itr][notok],
                    self.cell_summary['indiv_fiterr'][itr][notok],
                    'ro',
                    markersize=3)
        n_dat_coll = collections.LineCollection(n_trdat,
                                                colors='b',
                                                linewidths=0.35)
        n_fit_coll = collections.LineCollection(n_trfit,
                                                colors='y',
                                                linewidths=0.25)
        P.axdict['E'].add_collection(n_dat_coll)
        P.axdict['E'].add_collection(n_fit_coll)

        P.axdict['A'].set_xlabel(r'$tau_1$ (ms)')
        P.axdict['A'].set_ylabel(r'Amp (pA)')
        P.axdict['B'].set_xlabel(r'$tau_2$ (ms)')
        P.axdict['B'].set_ylabel(r'Amp (pA)')
        P.axdict['C'].set_xlabel(r'$\tau_1$ (ms)')
        P.axdict['C'].set_ylabel(r'$\tau_2$ (ms)')
        P.axdict['D'].set_xlabel(r'Amp (pA)')
        P.axdict['D'].set_ylabel(r'Fit Error (cost)')
        P.axdict['H'].set_xlabel(r'$\tau_1$ (ms)')
        P.axdict['H'].set_ylabel(r'Qtotal')
        P.axdict['G'].set_ylim((-100., 20.))
        P.axdict['G'].set_xlim((-2., 25.))
        P.axdict['E'].set_ylim((-100., 20.))
        P.axdict['E'].set_xlim((-2., 25.))

        # put in averaged event too
        # self.cell_summary['averaged'].extend([{'tb': aj.avgeventtb, 'avg': aj.avgevent, 'fit': {'amplitude': aj.Amplitude,
        #     'tau1': aj.tau1, 'tau2': aj.tau2, 'risepower': aj.risepower}, 'best_fit': aj.avg_best_fit,
        #     'risetenninety': aj.risetenninety, 'decaythirtyseven': aj.decaythirtyseven}])
        aev = self.cell_summary['averaged']
        for i in range(len(aev)):
            P.axdict['F'].plot(aev[i]['tb'],
                               aev[i]['avg'],
                               'k-',
                               linewidth=0.8)
            P.axdict['F'].plot(aev[i]['tb'],
                               aev[i]['best_fit'],
                               'r--',
                               linewidth=0.4)

        if pdf is None:
            mpl.show()
        else:
            pdf.savefig(dpi=300)
            mpl.close()
예제 #6
0
def summarize_inputs():
    import matplotlib.pyplot as mpl
    import pylibrary.PlotHelpers as PH
    P = PH.regular_grid(2, 3, order='columns', figsize=(10., 8), showgrid=False)
    ax = [P.axdict[x] for x in P.axdict.keys()]
    print(ax)
 #   PH.nice_plot(ax)
    allendings = []
    cellendings = {}
    for cell, v in iter(VCN_Inputs_Clean.items()):
        cellendings[cell] = []
        for s in v[1]:
            # print cell, s[0]
            allendings.append(s[0])
            cellendings[cell].append(s[0])
    ax[0].hist(allendings, bins=20)
    ax[0].set_title('All ending areas')
    ax[0].set_ylim((0, 25))
    ax[0].set_ylabel('N')
    ax[0].set_xlim((0,350))
    ax[0].set_xlabel('Area (um^2)')
    
    normd = []
    ratio1 = []
    ratio2 = []
    meansize = []
    maxsize = []
    convergence = []
    
    for cell in cellendings.keys():
            normd.extend(cellendings[cell]/np.max(cellendings[cell]))
            ratio1.append(cellendings[cell][1]/cellendings[cell][0])
            ratio2.append(np.mean(cellendings[cell])/cellendings[cell][0])
            meansize.append(np.mean(cellendings[cell]))
            maxsize.append(np.max(cellendings[cell]))
            convergence.append(len(cellendings[cell]))
    print('convergence: ', convergence)
    ax[1].set_title('Normaized by largest')
    ax[1].hist(normd, bins=20, range=(0,1.0), align='mid')
    ax[1].set_xlabel('Area (um^2)')
    ax[1].set_ylabel('N')

    ax[2].set_title('ratio largest to next largest')
    ax[2].hist(ratio1, bins=10, range=(0,1.0), align='mid')
    ax[2].set_xlabel('Area (um^2)')
    ax[2].set_title('ratio mean to largest')

    ax[3].set_title('Ratio of mean to largest')
    ax[3].hist(ratio2, bins=10, range=(0,1.0), align='mid')
    ax[3].set_xlabel('Area (um^2)')

    ax[4].set_xlim((0., 200.))
    ax[4].set_xlabel('Area (um^2)')
    ax[4].set_ylim((0., 15.))  
    ax[4].set_ylabel('Convergence')
    ax[4].set_title('Convergence vs. mean size')
    fit = np.polyfit(meansize, convergence, 1)
    fit_fn = np.poly1d(fit) 
    ax[4].scatter(meansize, convergence)
    ax[4].plot(meansize, fit_fn(meansize), '--k')


    ax[5].set_title('Convergence vs max size')
    fit = np.polyfit(maxsize, convergence, 1)
    fit_fn = np.poly1d(fit) 
    ax[5].scatter(maxsize, convergence)
    ax[5].plot(maxsize, fit_fn(maxsize), '--k')
    ax[5].set_xlim((0., 350.))
    ax[5].set_xlabel('Area (um^2)')
    ax[5].set_ylim((0., 15.))
    ax[5].set_xlabel('Convergence')

    

    mpl.show()
예제 #7
0
                     ('VCN_c14', {'pos': [l1, wid, yp[3], ht]}),
                     ('VCN_c16', {'pos': [l1, wid, yp[4], ht]}),
                     ('VCN_c17', {'pos': [l2, wid, yp[5], ht]}),
                     ('VCN_c18', {'pos': [l2, wid, yp[0], ht]}),
                     ('VCN_c19', {'pos': [l2, wid, yp[1], ht]}),
                     ('VCN_c20', {'pos': [l2, wid, yp[3], ht]}), 
                     ('VCN_c21', {'pos': [l1, wid, yp[4], ht]}),
                     ('VCN_c22', {'pos': [l2, wid, yp[5], ht]}),
                     ('None', {}),
])  # dict elements are [left, width, bottom, height] for the axes in the plot.
# gr = [(a, a+1, 0, 1) for a in range(0, 8)]   # just generate subplots - shape does not matter

gbc_names = [s[-2:] for s in sizer.keys()]
gbc_names = ['09']

P = PH.regular_grid(6, 2, figsize=(6,8), panel_labels=list(sizer.keys()), labelposition=(0.05, 0.95))
# P = PH.Plotter(rcshape=sizer, label=False, figsize=(6, 8), labeloffset=[0.6, 0.])

inputPattern = "VCN_c10" # None # 'VCN_c10'

for gbc in gbc_names:
    if gbc == 'ne':
        continue
    print ('='*32)
    cell = 'VCN_c{0:s}'.format(gbc)
    
    # an_result_file = 'AN_Result_VCN_c{0:s}_delays_N{1:03d}_040dB_4000.0_{2:2s}.p'.format(gbc, nrep, SR)
    # andatafile = Path(baseDirectory, cell, simDirectory, 'AN', an_result_file)
    # print('  an result file: {0:s}'.format(str(andatafile)))
    # print (andatafile.is_file() )
    # if not andatafile.is_file() or forcerun: # only run if no evidence we have run this already