def plotIV(cell, infile, plottau=False): sizer = OrderedDict([('A', {'pos': [0.2, 0.6, 0.3, 0.5]}), ('B', {'pos': [0.2, 0.6, 0.1, 0.15]}) ]) # dict elements are [left, width, bottom, height] for the axes in the plot. gr = [(a, a+1, 0, 1) for a in range(0, len(sizer.keys()))] # just generate subplots - shape does not matter axmap = OrderedDict(zip(sizer.keys(), gr)) P = PH.Plotter((len(sizer.keys()), 1), axmap=axmap, label=True, figsize=(6., 4.)) # PH.show_figure_grid(P.figure_handle) P.resize(sizer) # perform positioning magic P.figure_handle.suptitle(cell) ivr, d, tr = readIVFile(infile) mon1 = d['runInfo']['electrodeSection'] mon2 = d['runInfo']['dendriticElectrodeSection'] # print mon1 # print mon2 taufit = ivr['taufit'] for i, k in enumerate(tr.keys()): P.axdict['A'].plot(tr[k]['monitor']['time'], tr[k]['monitor']['postsynapticV'], 'k-', linewidth=0.75) P.axdict['B'].plot(tr[k]['monitor']['time'], tr[k]['monitor']['postsynapticI'], 'b-', linewidth=0.75) if plottau: for k in taufit[0].keys(): P.axdict['A'].plot(taufit[0][k], taufit[1][k], 'r-') P.axdict['A'].set_xlim(0, 150.) P.axdict['A'].set_ylabel('V (mV)') P.axdict['A'].set_xticklabels([]) PH.calbar(P.axdict['A'], calbar=[125., -120., 25., 25.], unitNames={'x': 'ms', 'y': 'mV'}) # def calbar(axl, calbar=None, axesoff=True, orient='left', unitNames=None, fontsize=11, weight='normal', font='Arial'): P.axdict['B'].set_xlim(0., 150.) P.axdict['B'].set_xlabel('T (ms)') P.axdict['B'].set_ylabel('I (nA)') PH.calbar(P.axdict['B'], calbar=[125., 0.1, 25., 0.5], unitNames={'x': 'ms', 'y': 'nA'})
def plot(self): P = PH.Plotter((2, 1), figsize=(6, 4)) cell_ax = list(P.axdict.keys())[0] iax = list(P.axdict.keys())[1] for i in range(self.traces.shape[0]): P.axdict[cell_ax].plot(self.time, self.traces.view(np.ndarray)[i], linewidth=1.0) P.axdict[iax].plot(self.time, self.cmd_wave.view(np.ndarray)[i], linewidth=1.0) P.axdict[cell_ax].set_xlim(0., 150.) P.axdict[cell_ax].set_ylim(-200., 50.) PH.calbar(P.axdict[cell_ax], calbar=[120., -95., 25., 20.], axesoff=True, orient='left', unitNames={'x': 'ms', 'y': 'mV'}, font='Arial', fontsize=8) # mpl.savefig(outfile) mpl.show()
def showpicklediv(name): f = open(name, 'r') result = pickle.load(f) f.close() d = result['results'] ncells = len(d) vr = result['cells']['varrange'] fig, ax = mpl.subplots(ncells + 1, 2, figsize=(8.5, 11.)) # fig.set_size_inches(8.5, 11., forward=True) for ni in range(len(d[0]['i'])): ax[-1, 0].plot(d[0]['t'], d[0]['i'][ni], 'k', linewidth=0.5) ax[-1, 0].set_ylim([-2., 2.]) for nc in range(ncells): for ni in range(len(d[nc]['v'])): ax[nc, 0].plot(d[nc]['t'], d[nc]['v'][ni], 'k', linewidth=0.5) ax[nc, 0].set_ylim([-180., 40.]) if ni == 0: ax[nc, 0].annotate('%.2f' % vr[nc], (180., 20.)) PH.nice_plot(ax.ravel().tolist()) PH.noaxes(ax.ravel()[:-1].tolist()) PH.calbar(ax[0, 0], calbar=[120., -130., 25., 50.], axesoff=True, orient='left', unitNames={ 'x': 'ms', 'y': 'mV' }, fontsize=9, weight='normal', font='Arial') PH.calbar(ax[-1, 0], calbar=[120., 0.5, 25., 1.], axesoff=True, orient='left', unitNames={ 'x': 'ms', 'y': 'nA' }, fontsize=9, weight='normal', font='Arial') mpl.show()
def plotResults(self, res, runInfo, somasite=['postsynapticV', 'postsynapticI', 'dendriteV']): clist={'axon': 'r', 'heminode': 'g', 'stalk':'y', 'branch': 'g', 'neck': 'b', 'swelling': 'm', 'tip': 'k', 'parentaxon': '', r'synapse': 'c', 'Soma': 'k', 'dendrite': 'c', 'dend': 'c'} dx = np.array([x for k,x in res['distanceMap'].items()]) dlen = res['monitor']['postsynapticV'].shape[0] dxmax = np.max(dx) if self.plotmode == 'pg': self.plots['Soma'].setLabel('left', 'V') self.plots['Soma'].plot(res['monitor']['time'][:dlen], res['monitor']['postsynapticV'], pen=pg.mkPen(clist['Soma'], width=0.5), ) if 'dendriteV' in somasite and self.plots['Dendrite'] is not None and len(res['monitor']['dendriteV']) > 0: self.plots['Dendrite'].plot(res['monitor']['time'][:dlen], res['monitor']['dendriteV'], pen=pg.mkPen(clist['dendrite'], width=0.5), ) self.plots['Dendrite'].setLabel('left', 'V (mV)') if 'vec' in res.keys()and self.plots['p4'] is not None: for v in res['vec']: self.plots['p4'].plot(res['monitor']['time'], res['vec'][v], pen=pg.mkPen(pg.intColor(int(255.*res['distanceMap'][v]/dxmax))), width=1.5) if 'postsynapticI' in somasite and self.plots['Iinj'] is not None: vlen = len(res['monitor']['postsynapticI']) self.plots['Iinj'].plot(res['monitor']['time'][0:vlen], res['monitor']['postsynapticI'], pen = pg.mkPen('b', width=0.5)) self.plots['Iinj'].setLabel('left', 'I (inj, nA)') if 'vec' in res.keys() and self.plots['p4'] is not None: for v in res['vec']: self.plots['p4'].plot(res['monitor']['time'], res['vec'][v], pen=pg.mkPen(pg.intColor(int(255.*res['distanceMap'][v]/dxmax))), width=0.5) #for c in res['ICa']: # self.plots['Dendrite'].plot(res['monitor']['time'], res['ICa'][c]*1e12, pen=pg.mkPen('b', width=1.5)) # self.plots['Iinj'].plot(res['vec']['time'], res['Cai'][c]*1e6, pen=pg.mkPen('g', width=1.5)) #p2.set_ylim(-5e-12, 1e-12) self.plots['Soma'].setXRange(0., 120., padding=0.2) self.plots['Dendrite'].setXRange(0., 120., padding=0.2) if self.plots['Iinj'] is not None: self.plots['Iinj'].setXRange(0., 120., padding=0.2) pgPH.cleanAxes([self.plots['Soma'], self.plots['Dendrite'], self.plots['Iinj'], self.plots['p4']]) pgPH.nice_plot(self.plots['Soma']) pgPH.calbar(self.plots['Soma'], [110, -50, 20, 50]) # pgPH.nice_plot(self.plots['Dendrite']) # pgPH.calbar(self.plots['Dendrite'], [110, 0.1, 20, 1]) if self.plots['Iinj'] is not None: pgPH.nice_plot(self.plots['Iinj']) pgPH.calbar(self.plots['Iinj'], [110, -0.1, 20, 1]) elif self.plotmode == 'mpl': self.plots['Soma'].set_ylabel('V') self.plots['Soma'].plot(res['monitor']['time'][:dlen], res['monitor']['postsynapticV'], color=clist['Soma'], linewidth=0.5) if 'dendriteV' in somasite and self.plots['Dendrite'] is not None and len(res['monitor']['dendriteV']) > 0: self.plots['Dendrite'].plot(res['monitor']['time'][:dlen], res['monitor']['dendriteV'], color=clist['dendrite'], linewidth=0.5) self.plots['Dendrite'].set_ylabel('V (mV)') if 'vec' in res.keys()and self.plots['p4'] is not None: for v in res['vec']: self.plots['p4'].plot(res['monitor']['time'], res['vec'][v], color=[[int(255.*res['distanceMap'][v]/dxmax)]*3], linewidth=0.75) if 'postsynapticI' in somasite and self.plots['Iinj'] is not None: vlen = len(res['monitor']['postsynapticI']) self.plots['Iinj'].plot(res['monitor']['time'][0:vlen], res['monitor']['postsynapticI'], color='b', linewidth=0.5) self.plots['Iinj'].set_ylabel('I (inj, nA)') if 'vec' in res.keys() and self.plots['p4'] is not None: for v in res['vec']: self.plots['p4'].plot(res['monitor']['time'], res['vec'][v], color=[[int(255.*res['distanceMap'][v]/dxmax)]*3], linewidth=0.75) #for c in res['ICa']: # self.plots['Dendrite'].plot(res['monitor']['time'], res['ICa'][c]*1e12, pen=pg.mkPen('b', width=1.5)) # self.plots['Iinj'].plot(res['vec']['time'], res['Cai'][c]*1e6, pen=pg.mkPen('g', width=1.5)) #p2.set_ylim(-5e-12, 1e-12) self.plots['Soma'].set_xlim(0., 120.) self.plots['Dendrite'].set_xlim(0., 120.) if self.plots['Iinj'] is not None: self.plots['Iinj'].set_xlim(0., 120.) PH.cleanAxes([self.plots['Soma'], self.plots['Dendrite'], self.plots['Iinj']]) PH.nice_plot(self.plots['Soma']) PH.calbar(self.plots['Soma'], [110, -50, 20, 50]) PH.nice_plot(self.plots['Dendrite']) PH.calbar(self.plots['Dendrite'], [110, -50, 20, 50]) # pgPH.nice_plot(self.plots['Dendrite']) # pgPH.calbar(self.plots['Dendrite'], [110, 0.1, 20, 1]) if self.plots['Iinj'] is not None: PH.nice_plot(self.plots['Iinj']) PH.calbar(self.plots['Iinj'], [110, -0.1, 20, 1])
def showplots(name): """ Show traces from sound stimulation - without current injection """ f = open(name, 'r') d = pickle.load(f) f.close() ncells = len(d['results']) stiminfo = d['stim'] dur = stiminfo['rundur'] * 1000. print 'dur: ', dur print 'stim info: ' print ' fmod: ', stiminfo['fmod'] print ' dmod: ', stiminfo['dmod'] print ' f0: ', stiminfo['f0'] print ' cf: ', stiminfo['cf'] varsg = np.linspace(0.25, 2.0, int((2.0 - 0.25) / 0.25) + 1) # was not stored... fig, ax = mpl.subplots(ncells + 1, 2, figsize=(8.5, 11.)) spikelists = [[]] * ncells prespikes = [[]] * ncells xmin = 50. for i in range(ncells): vdat = d['results'][i]['v'] idat = d['results'][i]['i'] tdat = d['results'][i]['t'] pdat = d['results'][i]['pre'] PH.noaxes(ax[i, 0]) # if i == 0: # PH.calbar(ax[0, 0], calbar=[120., -120., 25., 20.], axesoff=True, orient='left', # unitNames={'x': 'ms', 'y': 'mV'}, fontsize=9, weight='normal', font='Arial') for j in range(len(vdat)): if j == 2: ax[i, 0].plot(tdat - xmin, vdat[j], 'k', linewidth=0.5) if j == 0: ax[i, 0].annotate('%.2f' % varsg[i], (180., 20.)) ax[i, 0].set_xlim([0, dur - xmin]) ax[i, 0].set_ylim([-75, 50]) PH.referenceline(ax[i, 0], reference=-62.0, limits=None, color='0.33', linestyle='--', linewidth=0.5, dashes=[3, 3]) for j in range(len(vdat)): detected = PU.findspikes(tdat, vdat[j], -20.) detected = clean_spiketimes(detected) spikelists[i].extend(detected) if j == 0: n, bins = np.histogram(detected, np.linspace(0., dur, 201), density=False) else: m, bins = np.histogram(detected, np.linspace(0., dur, 201), density=False) n += m prespikes[i].extend(pdat) if j == 0: n, bins = np.histogram(pdat, np.linspace(0., dur, 201), density=False) else: m, bins = np.histogram(pdat, np.linspace(0., dur, 201), density=False) n += m ax[i, 1].bar(bins[:-1] - xmin, n, width=bins[1], facecolor='k', alpha=0.75) ax[i, 1].set_xlim([0, dur - xmin]) ax[i, 1].set_ylim([0, 30]) vs = PU.vector_strength(spikelists[i], stiminfo['fmod']) pre_vs = PU.vector_strength(prespikes[i], stiminfo['fmod']) # print 'pre: ', pre_vs # print 'post: ', vs # apos = ax[i,1].get_position() # ax[i, 1].set_title('VS = %4.3f' % pre_vs['r']) # # vector_plot(fig, vs['ph'], np.ones(len(vs['ph'])), yp = apos) # phase_hist(fig, vs['ph'], yp=apos) # phase_hist(fig, pre_vs['ph'], yp=apos) prot = Variations(runtype, runname) # stim_info = {'nreps': nrep, 'cf': cf, 'f0': f0, 'rundur': rundur, 'pipdur': pipdur, 'dbspl': dbspl, 'fmod': fmod, 'dmod': dmod} if stiminfo['dmod'] > 0: stimulus = 'SAM' else: stimulus = 'tone' prot.make_stimulus(stimulus=stimulus, cf=stiminfo['cf'], f0=stiminfo['f0'], simulator=None, rundur=stiminfo['rundur'], pipdur=stiminfo['pipdur'], dbspl=stiminfo['dbspl'], fmod=stiminfo['fmod'], dmod=stiminfo['dmod']) ax[-1, 1].plot(prot.stim.time * 1000. - xmin, prot.stim.sound, 'k-', linewidth=0.75) ax[-1, 1].set_xlim([0, (dur - xmin)]) PH.noaxes(ax[-1, 0]) ax[-1, 0].set_xlim([0, dur - xmin]) ax[-1, 0].set_ylim([-75, 50]) # PH.referenceline(ax[-1, 0], reference=-62.0, limits=None, color='0.33', linestyle='--' ,linewidth=0.5, dashes=[3, 3]) PH.calbar(ax[-1, 0], calbar=[20., 0., 25., 20.], axesoff=True, orient='left', unitNames={ 'x': 'ms', 'y': 'mV' }, fontsize=9, weight='normal', font='Arial') PH.cleanAxes(ax.ravel().tolist()) mpl.show()
def run_democlamp(cell, dend, vsteps=[-60,-70,-60], tsteps=[10,50,100]): """ Does some stuff. """ f1 = pylab.figure(1) gs = GS.GridSpec(2, 2, width_ratios=[1, 1], height_ratios=[1, 1]) # note numbering for insets goes from 1 (upper right) to 4 (lower right) # counterclockwise pA = f1.add_subplot(gs[0]) pAi = INSETS.inset_axes(pA, width="66%", height="40%", loc=2) pB = f1.add_subplot(gs[1]) pBi = INSETS.inset_axes(pB, width="66%", height="40%", loc=4) pC = f1.add_subplot(gs[2]) pCi = INSETS.inset_axes(pC, width="66%", height="40%", loc=2) pD = f1.add_subplot(gs[3]) pDi = INSETS.inset_axes(pD, width="66%", height="40%", loc=1) #h.topology() Ld = 0.5 Ld2 = 1.0 VClamp = h.SEClamp(0.5, cell) VClamp.dur1 = tsteps[0] VClamp.amp1 = vsteps[0] VClamp.dur2 = tsteps[1] VClamp.amp2 = vsteps[1] VClamp.dur3 = tsteps[2] VClamp.amp3 = vsteps[2] Rs0 = 10. VClamp.rs = Rs0 compensation = [0., 70., 95.] cms = [cell.cm*(100.-c)/100. for c in compensation] vrec = h.iStim(Ld, sec=dend[0]) vrec.delay = 0 vrec.dur = 1e9 # these actually do not matter... vrec.iMax = 0.0 vrec2 = h.iStim(Ld2, sec=dend[0]) vrec2.delay = 0 vrec2.dur = 1e9 # these actually do not matter... vrec2.iMax = 0.0 stim = {} stim['NP'] = 1 stim['Sfreq'] = 20 # stimulus frequency stim['delay'] = tsteps[0] stim['dur'] = tsteps[1] stim['amp'] = vsteps[1] stim['PT'] = 0.0 stim['hold'] = vsteps[0] # (secmd, maxt, tstims) = make_pulse(stim) tend = 79.5 linetype = ['-', '-', '-'] linethick = [0.5, 0.75, 1.25] linecolor = [[0.66, 0.66, 0.66], [0.4, 0.4, 0.3], 'k'] n = 0 vcmds = [-70, -20] vplots = [(pA, pAi, pC, pCi), (pB, pBi, pD, pDi)] for m, VX in enumerate(vcmds): stim['amp'] = VX pl = vplots[m] print m, VX (secmd, maxt, tstims) = make_pulse(stim) for n, rsc in enumerate(compensation): vec={} for var in ['VCmd', 'i_inj', 'time', 'Vsoma', 'Vdend', 'Vdend2', 'VCmdR']: vec[var] = h.Vector() VClamp.rs = Rs0*(100.-rsc)/100. cell.cm = cms[n] # print VClamp.rs, cell.cm, VClamp.rs*cell.cm vec['VCmd'] = h.Vector(secmd) vec['Vsoma'].record(cell(0.5)._ref_v, sec=cell) vec['Vdend'].record(dend[0](Ld)._ref_v, sec=dend[0]) vec['time'].record(h._ref_t) vec['i_inj'].record(VClamp._ref_i, sec=cell) vec['VCmdR'].record(VClamp._ref_vc, sec=cell) VClamp.amp2 = VX # vec['VCmd'].play(VClamp.amp2, h.dt, 0, sec=cell) h.tstop = tend h.init() h.finitialize(-60) h.run() vc = np.asarray(vec['Vsoma']) tc = np.asarray(vec['time']) # now plot the data, raw and as insets for k in [0, 1]: pl[k].plot(vec['time'], vec['i_inj'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n]) yl = pl[k].get_ylim() if k == 0: pass #pl[k].set_ylim([1.5*yl[0], -1.5*yl[1]]) else: pass for k in [2,3]: pl[k].plot(vec['time'], vec['Vsoma'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n]) pl[k].plot(vec['time'], vec['VCmdR'], color=linecolor[n], linestyle = '--', linewidth=1, dashes=(1,1)) pl[k].plot(vec['time'], vec['Vdend'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n], dashes=(3,3)) if VX < vsteps[0]: pl[k].set_ylim([-72, -40]) else: pl[k].set_ylim([-62,VX+30]) ptx = 10.8 pBi.set_xlim([9.8, ptx]) pAi.set_xlim([9.8, ptx]) PH.setX(pAi, pCi) PH.setX(pBi, pDi) pD.set_ylim([-65, 10]) # PH.setY(pC, pCi) # match Y limits PH.cleanAxes([pA, pAi, pB, pBi, pC, pCi, pD, pDi]) PH.formatTicks([pA, pB, pC, pD], axis='x', fmt='%d') PH.formatTicks([pC, pD], axis='y', fmt='%d') PH.calbar(pAi, [ptx-1, 0, 0.2, 2.]) PH.calbar(pCi, [ptx-1, -50., 0.2, 10]) PH.calbar(pBi, [ptx-1, 0, 0.2, 10]) PH.calbar(pDi, [ptx-1, -50., 0.2, 20]) pylab.draw() pylab.show()
def plot_iv(self, pubmode=False): x = -0.08 y = 1.02 sizer = { 'A': { 'pos': [0.05, 0.50, 0.08, 0.78], 'labelpos': (x, y), 'noaxes': False }, 'B': { 'pos': [0.62, 0.30, 0.64, 0.22], 'labelpos': (x, y), 'noaxes': False }, 'C': { 'pos': [0.62, 0.30, 0.34, 0.22], 'labelpos': (x, y) }, 'D': { 'pos': [0.62, 0.30, 0.08, 0.22], 'labelpos': (x, y) }, } # dict pos elements are [left, width, bottom, height] for the axes in the plot. gr = [(a, a + 1, 0, 1) for a in range(0, 4) ] # just generate subplots - shape does not matter axmap = OrderedDict(zip(sizer.keys(), gr)) P = PH.Plotter((4, 1), axmap=axmap, label=True, figsize=(8., 6.)) # PH.show_figure_grid(P.figure_handle) P.resize(sizer) # perform positioning magic # 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)) P.figure_handle.suptitle(self.datapath, fontsize=8) dv = 50. jsp = 0 for i in range(self.AR.traces.shape[0]): if i in list(self.SP.spikeShape.keys()): idv = float(jsp) * dv jsp += 1 else: idv = 0. P.axdict['A'].plot(self.AR.time_base * 1e3, idv + self.AR.traces[i, :].view(np.ndarray) * 1e3, '-', linewidth=0.35) ptps = np.array([]) paps = np.array([]) if i in list(self.SP.spikeShape.keys()): for j in list(self.SP.spikeShape[i].keys()): paps = np.append(paps, self.SP.spikeShape[i][j]['peak_V'] * 1e3) ptps = np.append(ptps, self.SP.spikeShape[i][j]['peak_T'] * 1e3) P.axdict['A'].plot(ptps, idv + paps, 'ro', markersize=0.5) # mark spikes outside the stimlulus window ptps = np.array([]) paps = np.array([]) for window in ['baseline', 'poststimulus']: ptps = np.array(self.SP.analysis_summary[window + '_spikes'][i]) uindx = [int(u / self.AR.sample_interval) + 1 for u in ptps] paps = np.array(self.AR.traces[i, uindx]) P.axdict['A'].plot(ptps * 1e3, idv + paps * 1e3, 'bo', markersize=0.5) for k in self.RM.taum_fitted.keys(): P.axdict['A'].plot(self.RM.taum_fitted[k][0] * 1e3, self.RM.taum_fitted[k][1] * 1e3, '--k', linewidth=0.30) for k in self.RM.tauh_fitted.keys(): P.axdict['A'].plot(self.RM.tauh_fitted[k][0] * 1e3, self.RM.tauh_fitted[k][1] * 1e3, '--r', linewidth=0.50) if pubmode: PH.calbar(P.axdict['A'], calbar=[0., -90., 25., 25.], axesoff=True, orient='left', unitNames={ 'x': 'ms', 'y': 'mV' }, fontsize=10, weight='normal', font='Arial') P.axdict['B'].plot(self.SP.analysis_summary['FI_Curve'][0] * 1e9, self.SP.analysis_summary['FI_Curve'][1] / (self.AR.tend - self.AR.tstart), 'ko-', markersize=4, linewidth=0.5) clist = ['r', 'b', 'g', 'c', 'm'] # only 5 possiblities linestyle = ['-', '--', '-.', '-', '--'] n = 0 for i, figrowth in enumerate(self.SP.analysis_summary['FI_Growth']): legstr = '{0:s}\n'.format(figrowth['FunctionName']) if len(figrowth['parameters']) == 0: # no valid fit P.axdict['B'].plot([np.nan, np.nan], [np.nan, np.nan], label='No valid fit') else: for j, fna in enumerate(figrowth['names'][0]): legstr += '{0:s}: {1:.3f} '.format( fna, figrowth['parameters'][0][j]) if j in [2, 5, 8]: legstr += '\n' P.axdict['B'].plot(figrowth['fit'][0][0] * 1e9, figrowth['fit'][1][0], linestyle=linestyle[i], color=clist[i], linewidth=0.5, label=legstr) n += 1 if n > 0: P.axdict['B'].legend(fontsize=6) P.axdict['C'].plot(self.RM.ivss_cmd * 1e9, self.RM.ivss_v * 1e3, 'ko-', markersize=4, linewidth=1.0) if not pubmode: if self.RM.analysis_summary['CCComp']['CCBridgeEnable'] == 1: enable = 'On' else: enable = 'Off' tstr = ( r'RMP: {0:.1f} mV {1:s}${{R_{{in}}}}$: {2:.1f} ${{M\Omega}}${3:s}${{\tau_{{m}}}}$: {4:.2f} ms' .format(self.RM.analysis_summary['RMP'], '\n', self.RM.analysis_summary['Rin'], '\n', self.RM.analysis_summary['taum'] * 1e3)) tstr += ( r'{0:s}Holding: {1:.1f} pA{2:s}Bridge [{3:3s}]: {4:.1f} ${{M\Omega}}$' .format( '\n', np.mean(self.RM.analysis_summary['Irmp']) * 1e12, '\n', enable, np.mean(self.RM.analysis_summary['CCComp'] ['CCBridgeResistance'] / 1e6))) tstr += ( r'{0:s}Bridge Adjust: {1:.1f} ${{M\Omega}}$ {2:s}Pipette: {3:.1f} mV' .format( '\n', self.RM.analysis_summary['BridgeAdjust'] / 1e6, '\n', np.mean( self.RM.analysis_summary['CCComp']['CCPipetteOffset'] * 1e3))) P.axdict['C'].text(-0.05, 0.80, tstr, transform=P.axdict['C'].transAxes, horizontalalignment='left', verticalalignment='top', fontsize=7) # P.axdict['C'].xyzero=([0., -0.060]) 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('V (mV)') P.axdict['B'].set_xlabel('I (nA)') P.axdict['B'].set_ylabel('Spikes/s') PH.talbotTicks(P.axdict['B'], tickPlacesAdd={ 'x': 1, 'y': 0 }, floatAdd={ 'x': 2, 'y': 0 }) try: maxv = np.max(self.RM.ivss_v * 1e3) except: maxv = 0. # sometimes IVs do not have negative voltages for an IVss to be available... ycross = np.around(maxv / 5., decimals=0) * 5. if ycross > maxv: ycross = maxv PH.crossAxes(P.axdict['C'], xyzero=(0., ycross)) PH.talbotTicks(P.axdict['C'], tickPlacesAdd={ 'x': 1, 'y': 0 }, floatAdd={ 'x': 2, 'y': 0 }) P.axdict['C'].set_xlabel('I (nA)') P.axdict['C'].set_ylabel('V (mV)') for i in range(len(self.SP.spikes)): if len(self.SP.spikes[i]) == 0: continue spx = np.argwhere((self.SP.spikes[i] > self.SP.Clamps.tstart) & ( self.SP.spikes[i] <= self.SP.Clamps.tend)).ravel() spkl = (np.array(self.SP.spikes[i][spx]) - self.SP.Clamps.tstart) * 1e3 # just shorten... if len(spkl) == 1: P.axdict['D'].plot(spkl[0], spkl[0], 'or', markersize=4) else: P.axdict['D'].plot(spkl[:-1], np.diff(spkl), 'o-', markersize=3, linewidth=0.5) PH.talbotTicks(P.axdict['C'], tickPlacesAdd={ 'x': 1, 'y': 0 }, floatAdd={ 'x': 1, 'y': 0 }) P.axdict['D'].set_yscale('log') P.axdict['D'].set_ylim((1.0, P.axdict['D'].get_ylim()[1])) P.axdict['D'].set_xlabel('Latency (ms)') P.axdict['D'].set_ylabel('ISI (ms)') P.axdict['D'].text(0.05, 0.05, 'Adapt Ratio: {0:.3f}'.format( self.SP.analysis_summary['AdaptRatio']), fontsize=9, transform=P.axdict['D'].transAxes, horizontalalignment='left', verticalalignment='bottom') self.IVFigure = P.figure_handle if self.plot: mpl.show()
def plotSingles(inpath, cmd): seaborn.set_style('ticks') print( cmd['cell']) sites, celltype = CFG.makeDict(cmd['cell']) # print sites nInputs = 0 for s in sites: nInputs += len(s['postlocations'].keys()) #nInputs = len(sites) print ('cell: ', cmd['cell'], ' nInputs: ', nInputs) nrow, ncol = get_dimensions(nInputs, pref='width') nimax = 4 if nInputs > nimax: nshow = nimax else: nshow = nInputs fig, ax = plt.subplots(nshow, 1, figsize=(2.5,4)) fig.suptitle('{0:s} SR: {1:s}'.format(cmd['cell'], cmd['SR'])) vmax = -50. template = synfile_template tmin = -100. trange = [-50., 100.] if cmd['analysis'] == 'omit': template = excsynfile_template if cmd['analysis'] == 'io': template = synIOfile_template tmin = 0. trange = [0., 50.] fig2, ax2 = plt.subplots(2, 2, figsize=(4.75,6)) fig2.suptitle('{0:s} SR: {1:s}'.format(cmd['cell'], cmd['SR'])) axr = ax2.ravel() if cmd['analysis'] == 'singles': tmin = 25. template = synfile_template for i in range(nInputs): print(template) fname = template.format(cmds['cell'], modeltype, i, int(cmds['nReps']), cmds['SR']) fname = os.path.join(inpath, fname) print (fname) try: spikeTimes, inputSpikeTimes, stimInfo, d = readFile(fname, cmd) except: print('Missing: ', fname) continue #print ('stiminfo: ', stimInfo) if cmd['respike']: spiketimes = {} for k in d['somaVoltage'].keys(): dt = d['time'][1]-d['time'][0] spikeTimes[k] = pu.findspikes(d['time'], d['somaVoltage'][k], thresh=cmd['threshold']) spikeTimes[k] = clean_spiketimes(spikeTimes[k]) nReps = stimInfo['nReps'] if i < nshow: pl = ax[i] pl.set_title('Input {0:d}: N sites: {1:d}'.format(i+1, sites[i]['nSyn']), fontsize=8, x=0.05, y=0.92, horizontalalignment = 'left', verticalalignment='top') PH.noaxes(pl) sv = d['somaVoltage'] tm = d['time'] for j in range(nReps): m = np.max(sv[j]) if m > vmax: vmax = m vmax = 00. # print('tmin, minsv, maxsv', tmin, np.min(sv[j]), np.max(sv[j])) imin = int(tmin/np.mean(np.diff(d['time']))) for j in range(nReps): if j > nshow: continue # print('Rep, tmin, minsv, maxsv', j, tmin, np.min(sv[j]), np.max(sv[j]), tm.shape, sv[j].shape) pv = pl.plot(tm[imin:]-tmin, sv[j][imin:], linewidth=0.8) # pl.vlines(spikeTimes[j]-tmin, -j*2+vmax, -j*2-2+vmax, # color=pv[0].get_c(), linewidth=1.5) # spike marker same color as trace pl.set_ylabel('mV') pl.set_ylim(-80., vmax) pl.set_xlim(np.min(tm-tmin), np.max(tm-tmin)) if pl != ax[-1]: pl.set_xticklabels([]) else: plt.setp(pl.get_xticklabels(), fontsize=9) pl.set_xlabel('ms') # if cmd['analysis'] == 'io': # plt.setp(pl.get_yticklabels(), fontsize=9) # iof = np.zeros(len(sv.keys())) # iofdv = np.zeros(len(sv.keys())) # for k in sv.keys(): # iof[k] = np.max(sv[k]) # iofdv[k] = np.max(np.diff(sv[k])/np.mean(np.diff(tm))) # axr[0].plot(stimInfo['gSyns'], iof, 'o-', markersize=4) # axr[1].plot(stimInfo['gSyns'], iofdv, 's-', markersize=4) # axr.set_title('Input {0:d}: N sites: {1:d}'.format(i+1, sites[i]['nSyn']), fontsize=8, x=0.05, y=0.92, # horizontalalignment = 'left', verticalalignment='top') PH.calbar(ax[-1], calbar=[np.min(tm-tmin)+150, -40., 20., 25.], unitNames={'x': 'ms', 'y': 'mV'}) # for i in range(nInputs): # rescale all plots the same # ax[i].set_ylim(-65., vmax+cmd['nReps']*3) # ax[0].set_ylim(-65., vmax) seaborn.despine(fig) plt.savefig('VCN_c09.pdf')