def cmpGTtoFIT(basefn, datfn, itvfn, M, epc, xticks=None, yticks=None): dmp = open(_ed.resFN("posteriors.dump", dir=basefn), "rb") gt = _N.loadtxt(_ed.datFN("%s_prms.dat" % datfn)) _intvs = _N.loadtxt(_ed.datFN("%s.dat" % itvfn)) intvs = _N.array(gt.shape[0] * _intvs, dtype=_N.int) pckl = pickle.load(dmp) dmp.close() N = 300 x = _N.linspace(0, 3, N) smpls = pckl["cp%d" % epc] mds = pckl["md"] l0s = smpls[0] # GIBBS ITER x M fs = smpls[1] q2s = smpls[2] frm = 200 Nsmp = l0s.shape[0] - frm SMPS = 1000 rfsmps= _N.empty((SMPS, N, M)) # samples rs = _N.random.rand(SMPS, 3, M) for m in xrange(M): for ss in xrange(SMPS): i_l0 = int((Nsmp-frm)*rs[ss, 0, m]) # one of the iters i_f = int((Nsmp-frm)*rs[ss, 1, m]) i_q2 = int((Nsmp-frm)*rs[ss, 2, m]) l0 = l0s[frm+i_l0, m] f = fs[frm+i_f, m] q2 = q2s[frm+i_q2, m] rfsmps[ss, :, m] = (l0 / _N.sqrt(2*_N.pi*q2)) * _N.exp(-0.5*(x - f)*(x-f)/q2) #_plt.plot(x, rfsmps[ss], color="black") Arfsmps = _N.sum(rfsmps, axis=2) srtd = _N.sort(Arfsmps, axis=0) fig = _plt.figure(figsize=(5, 4)) ax = fig.add_subplot(1, 1, 1) #_plt.fill_between(x, srtd[50, :], srtd[950, :], alpha=0.3) _plt.fill_between(x, srtd[50, :], srtd[950, :], color="#CCCCFF") fr_s = _N.zeros(N) fr_e = _N.zeros(N) Mgt = gt.shape[1]/3 print Mgt for m in xrange(Mgt): l0_s = gt[intvs[epc], 2+3*m] l0_e = gt[intvs[epc+1]-1, 2+3*m] f_s = gt[intvs[epc], 3*m] f_e = gt[intvs[epc+1]-1, 3*m] q2_s = gt[intvs[epc], 1+3*m] q2_e = gt[intvs[epc+1]-1, 1+3*m] fr_s += (l0_s / _N.sqrt(2*_N.pi*q2_s)) * _N.exp(-0.5*(x - f_s)*(x-f_s)/q2_s) fr_e += (l0_e / _N.sqrt(2*_N.pi*q2_e)) * _N.exp(-0.5*(x - f_e)*(x-f_e)/q2_e) _plt.plot(x, 0.5*(fr_s+fr_e), lw=3, color="black") fr_m = _N.zeros(N) for m in xrange(M): l0_m = mds[epc, 3*m] f_m = mds[epc, 1+3*m] q2_m = mds[epc, 2+3*m] fr_m += (l0_m / _N.sqrt(2*_N.pi*q2_m)) * _N.exp(-0.5*(x - f_m)*(x-f_m)/q2_m) _plt.plot(x, fr_m, lw=3, color="blue") mF.setTicksAndLims(xlabel="position", ylabel="Hz", xticks=xticks, yticks=yticks, tickFS=22, labelFS=24) mF.arbitaryAxes(ax, axesVis=[True, True, False, False]) fig.subplots_adjust(left=0.2, bottom=0.2, right=0.95, top=0.95) _plt.savefig(_ed.resFN("cmpGT2FIT%d.eps" % epc, dir=basefn))
def timeline_v2(bfn, datfn, itvfn, outfn="timeline", ch1=0, ch2=1, xL=0, xH=3, yticks=[0, 1, 2, 3], thin=1, allFR=None, tcksz=19, lblsz=21, t0=None, t1=None, figw=10, figh=10, ytpos="left"): # 25Hz d = _N.loadtxt(datFN("%s.dat" % datfn)) # marks N = d.shape[0] # ALL spikes itv = _N.loadtxt(datFN("%s.dat" % itvfn)) epochs = itv.shape[0] - 1 ch1 += 2 # because this is data col ch2 += 2 wvfmMin = _N.min(d[:, 2:], axis=0) print(wvfmMin) wvfmMax = _N.max(d[:, 2:], axis=0) print(wvfmMax) Aint = _N.array(itv * N, dtype=_N.int) Asts = _N.where(d[Aint[0]:Aint[1], 1] == 1)[0] N1 = len(Asts) # num spikes in 1st epoch _x = _N.empty((N1, 5)) _x[:, 0] = d[Asts, 0] _x[:, 1:] = d[Asts, 2:] T1 = Aint[1] - Aint[0] hz = _x.shape[0] / float(T1 * 0.001) if allFR is not None: unonhash, hashsp, hashthresh = sepHash(_x, BINS=20, blksz=5, xlo=xL, xhi=xH) rh = len(hashsp) / float(N1) rnh = len(unonhash) / float(N1) #(m x rh + rnh)*hz = allFR #allFR - rnh x hz = m x rh x hz # m = (rnh x hz - allFR) / (rh x hz) m = (allFR - rnh * hz) / (rh * hz) # ((m*len(hashsp) + len(unonhash)) / (T1*0.001)) == allFR (target FR) # how much of hashsp should we remove? # Find lowest (1 - m) _x[:, 1:].sort(axis=0) chmins = channelMins(_x, 100, 4, int((1 - m) * len(hashsp))) #spk_n, chs = _N.where(_x[:, 1:] > chmins) #unique, counts = _N.unique(spk_n, return_counts=True) #print len(_N.where(counts > 0)[0]) # at least 1 channel above #print (len(_N.where(counts > 0)[0]) / float(T1*0.001)) _sts = _N.where(d[:, 1] == 1)[0] # ALL spikes in ALL epochs spk_n, chs = _N.where(d[_sts, 2:] > chmins) unique_spk_IDs, counts = _N.unique(spk_n, return_counts=True) sts = _sts[unique_spk_IDs[_N.where(counts > 0)[0]]] if allFR is None: _sts = _N.where(d[:, 1] == 1)[0] if thin == 1: sts = _sts else: sts = _sts[::thin] fig = _plt.figure(figsize=(figw, figh)) ####################### #ax =_plt.subplot2grid((5, 3), (0, 0), colspan=3) ax = _plt.subplot2grid((33, 3), (0, 0), colspan=3, rowspan=5) _plt.scatter(sts / 1000., d[sts, 0], s=2, color="black") if ytpos == "left": mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="time (s)", ylabel="position", yticks=[-6, -5, -3, -1, 0, 1, 3, 5, 6], xticks=None, yticksD=[ "H ", "C", "L ", "C", "H ", "C", "R ", "C", "H " ], xticksD=None, xlim=[0, N / 1000.], ylim=[xL - 0.3, xH + 0.3], tickFS=tcksz, labelFS=lblsz) else: mF.arbitraryAxes(ax, axesVis=[False, True, True, False], xtpos="bottom", ytpos="right") mF.setTicksAndLims( xlabel="time (s)", ylabel="position", yticks=[-6, -5, -3, -1, 0, 1, 3, 5, 6], xticks=None, yticksD=["H", " C", "L", " C", "H", " C", "R", " C", "H"], xticksD=None, xlim=[0, N / 1000.], ylim=[xL - 0.3, xH + 0.3], tickFS=tcksz, labelFS=lblsz) for ep in range(epochs): _plt.axvline(x=(itv[ep + 1] * N / 1000.), color="red", ls="--") ####################### #ax = _plt.subplot2grid((5, 3), (1, 0), colspan=3) ax = _plt.subplot2grid((33, 3), (10, 0), colspan=3, rowspan=5) print(len(sts)) _plt.scatter(sts / 1000., d[sts, 2], s=2, color="black") if ytpos == "left": mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel=None, ylabel="channel 1\nmark (mV)", xticks=None, yticks=[], xticksD=None, yticksD=None, xlim=[0, N / 1000.], ylim=[wvfmMin[0], wvfmMax[0]], tickFS=tcksz, labelFS=lblsz) else: mF.arbitraryAxes(ax, axesVis=[False, True, True, False], xtpos="bottom", ytpos="right") mF.setTicksAndLims(xlabel=None, ylabel="channel 1\nmark (mV)", xticks=None, yticks=[], xticksD=None, yticksD=None, xlim=[0, N / 1000.], ylim=[wvfmMin[0], wvfmMax[0]], tickFS=tcksz, labelFS=lblsz) for ep in range(epochs): _plt.axvline(x=(itv[ep + 1] * N / 1000.), color="red", ls="--") ####################### ax = _plt.subplot2grid((33, 3), (16, 0), colspan=3, rowspan=5) #ax = _plt.subplot2grid((5, 3), (2, 0), colspan=3) _plt.scatter(sts / 1000., d[sts, 3], s=2, color="black") if ytpos == "left": mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel=None, ylabel="channel 2\nmark (mV)", xticks=None, yticks=[], xticksD=None, yticksD=None, xlim=[0, N / 1000.], ylim=[wvfmMin[1], wvfmMax[1]], tickFS=tcksz, labelFS=lblsz) else: mF.arbitraryAxes(ax, axesVis=[False, True, True, False], xtpos="bottom", ytpos="right") mF.setTicksAndLims(xlabel=None, ylabel="channel 2\nmark (mV)", xticks=None, yticks=[], xticksD=None, yticksD=None, xlim=[0, N / 1000.], ylim=[wvfmMin[1], wvfmMax[1]], tickFS=tcksz, labelFS=lblsz) for ep in range(epochs): _plt.axvline(x=(itv[ep + 1] * N / 1000.), color="red", ls="--") ####################### #ax = _plt.subplot2grid((5, 3), (3, 0), colspan=3) ax = _plt.subplot2grid((33, 3), (22, 0), colspan=3, rowspan=5) print(len(sts)) _plt.scatter(sts / 1000., d[sts, 4], s=2, color="black") if ytpos == "left": mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel=None, ylabel="channel 3\nmark (mV)", xticks=None, yticks=[], xticksD=None, yticksD=None, xlim=[0, N / 1000.], ylim=[wvfmMin[2], wvfmMax[2]], tickFS=tcksz, labelFS=lblsz) else: mF.arbitraryAxes(ax, axesVis=[False, True, True, False], xtpos="bottom", ytpos="right") mF.setTicksAndLims(xlabel=None, ylabel="channel 3\nmark (mV)", xticks=None, yticks=[], xticksD=None, yticksD=None, xlim=[0, N / 1000.], ylim=[wvfmMin[2], wvfmMax[2]], tickFS=tcksz, labelFS=lblsz) for ep in range(epochs): _plt.axvline(x=(itv[ep + 1] * N / 1000.), color="red", ls="--") ####################### ax = _plt.subplot2grid((33, 3), (28, 0), colspan=3, rowspan=5) #ax = _plt.subplot2grid((5, 3), (4, 0), colspan=3) _plt.scatter(sts / 1000., d[sts, 5], s=2, color="black") if ytpos == "left": mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="time (s)", ylabel="channel 4\nmark (mV)", xticks=None, yticks=[], xticksD=None, yticksD=None, xlim=[0, N / 1000.], ylim=[wvfmMin[3], wvfmMax[3]], tickFS=tcksz, labelFS=lblsz) else: mF.arbitraryAxes(ax, axesVis=[False, True, True, False], xtpos="bottom", ytpos="right") mF.setTicksAndLims(xlabel="time (s)", ylabel="channel 4\nmark (mV)", xticks=None, yticks=[], xticksD=None, yticksD=None, xlim=[0, N / 1000.], ylim=[wvfmMin[3], wvfmMax[3]], tickFS=tcksz, labelFS=lblsz) for ep in range(epochs): _plt.axvline(x=(itv[ep + 1] * N / 1000.), color="red", ls="--") #fig.subplots_adjust(left=0.08, bottom=0.08, right=0.95, top=0.95, wspace=0.9, hspace=0.9) if ytpos == "left": fig.subplots_adjust(left=0.16, bottom=0.08, right=0.98, top=0.95, wspace=0.4, hspace=0.4) if ytpos == "right": fig.subplots_adjust(left=0.05, bottom=0.08, right=0.84, top=0.95, wspace=0.4, hspace=0.4) epochs = len(itv) - 1 for fmt in ["eps"]: choutfn = "%(of)s.%(fmt)s" % {"of": outfn, "fmt": fmt} _plt.savefig(resFN(choutfn, dir=bfn), transparent=True) _plt.close()
def pos_timeline(bfn, datfn, itvfn, outfn="timeline", ch1=0, ch2=1, xL=0, xH=3, yticks=[0, 1, 2, 3], yticksD=[0, 1, 2, 3], thin=1, t0=None, t1=None, skp=1, maze=_mkd.mz_CRCL): d = _N.loadtxt(datFN("%s.dat" % datfn)) # marks t0 = 0 if (t0 is None) else t0 t1 = d.shape[0] if (t1 is None) else t1 itv = _N.loadtxt(datFN("%s.dat" % itvfn)) N = d.shape[0] epochs = itv.shape[0] - 1 ch1 += 2 # because this is data col ch2 += 2 _sts = _N.where(d[t0:t1, 1] == 1)[0] + t0 if thin == 1: sts = _sts else: sts = _sts[::thin] wvfmMin = _N.min(d[t0:t1, 2:], axis=0) wvfmMax = _N.max(d[t0:t1, 2:], axis=0) #fig = _plt.figure(figsize=(4, 2.2)) fig = _plt.figure(figsize=(10, 2.2)) ####################### ax = _plt.subplot2grid((1, 3), (0, 0), colspan=3) _plt.scatter(_N.arange(d[t0:t1:100].shape[0], dtype=_N.float) / 10., d[t0:t1:100, 0], s=9, color="black") _plt.scatter(sts[::skp] / 1000., d[sts[::skp], 0], s=1, color="orange") if maze == _mkd.mz_W: _plt.axhline(y=-6, ls="--", lw=1, color="black") _plt.axhline(y=-3, ls=":", lw=1, color="black") _plt.axhline(y=0, ls="--", lw=1, color="black") _plt.axhline(y=3, ls=":", lw=1, color="black") _plt.axhline(y=6, ls="--", lw=1, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") #itv[-1] = 0.97 for ep in range(epochs): _plt.axvline(x=(itv[ep + 1] * N / 1000.), color="red", ls="-.") mF.setTicksAndLims(xlabel="time (s)", ylabel="position", xticks=None, yticks=yticks, xticksD=None, yticksD=yticksD, xlim=[t0 / 1000., t1 / 1000.], ylim=[xL - 0.3, xH + 0.3], tickFS=15, labelFS=18) choutfn = "%(of)s_%(1)d,%(2)d" % { "of": outfn, "1": (ch1 - 1), "2": (ch2 - 1) } fig.subplots_adjust(bottom=0.28, left=0.1, top=0.96, right=0.99) _plt.savefig(resFN("%s.pdf" % choutfn, dir=bfn), transparent=True) _plt.close()
def timeline(bfn, datfn, itvfn, outfn="timeline", ch1=0, ch2=1, xL=0, xH=3, yticks=[0, 1, 2, 3], thin=1, allFR=None): # 25Hz d = _N.loadtxt(datFN("%s.dat" % datfn)) # marks itv = _N.loadtxt(datFN("%s.dat" % itvfn)) N = d.shape[0] # ALL spikes epochs = itv.shape[0] - 1 ch1 += 2 # because this is data col ch2 += 2 wvfmMin = _N.min(d[:, 2:], axis=0) wvfmMax = _N.max(d[:, 2:], axis=0) Aint = _N.array(itv * N, dtype=_N.int) Asts = _N.where(d[Aint[0]:Aint[1], 1] == 1)[0] N1 = len(Asts) # num spikes in 1st epoch _x = _N.empty((N1, 5)) _x[:, 0] = d[Asts, 0] _x[:, 1:] = d[Asts, 2:] T1 = Aint[1] - Aint[0] hz = _x.shape[0] / float(T1 * 0.001) if allFR is not None: unonhash, hashsp, hashthresh = sepHash(_x, BINS=20, blksz=5, xlo=xL, xhi=xH) rh = len(hashsp) / float(N1) rnh = len(unonhash) / float(N1) #(m x rh + rnh)*hz = allFR #allFR - rnh x hz = m x rh x hz # m = (rnh x hz - allFR) / (rh x hz) m = (allFR - rnh * hz) / (rh * hz) # ((m*len(hashsp) + len(unonhash)) / (T1*0.001)) == allFR (target FR) # how much of hashsp should we remove? # Find lowest (1 - m) _x[:, 1:].sort(axis=0) chmins = channelMins(_x, 100, 4, int((1 - m) * len(hashsp))) #spk_n, chs = _N.where(_x[:, 1:] > chmins) #unique, counts = _N.unique(spk_n, return_counts=True) #print len(_N.where(counts > 0)[0]) # at least 1 channel above #print (len(_N.where(counts > 0)[0]) / float(T1*0.001)) _sts = _N.where(d[:, 1] == 1)[0] # ALL spikes in ALL epochs spk_n, chs = _N.where(d[_sts, 2:] > chmins) unique_spk_IDs, counts = _N.unique(spk_n, return_counts=True) sts = _sts[unique_spk_IDs[_N.where(counts > 0)[0]]] if allFR is None: _sts = _N.where(d[:, 1] == 1)[0] if thin == 1: sts = _sts else: sts = _sts[::thin] fig = _plt.figure(figsize=(10, 12)) ####################### ax = _plt.subplot2grid((4, 3), (0, 0), colspan=3) _plt.scatter(sts / 1000., d[sts, 0], s=2, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="time (s)", ylabel="position", xticks=None, yticks=yticks, xticksD=None, yticksD=None, xlim=[0, N / 1000.], ylim=[xL - 0.3, xH + 0.3], tickFS=15, labelFS=18) for ep in range(epochs): _plt.axvline(x=(itv[ep + 1] * N / 1000.), color="red", ls="--") ####################### ax = _plt.subplot2grid((4, 3), (1, 0), colspan=3) print(len(sts)) _plt.scatter(sts / 1000., d[sts, ch1], s=2, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="time (s)", ylabel=("mk elctrd %d" % (ch1 - 1)), xticks=None, yticks=[0, 3, 6], xticksD=None, yticksD=None, xlim=[0, N / 1000.], ylim=[wvfmMin[0], wvfmMax[0]], tickFS=15, labelFS=18) for ep in range(epochs): _plt.axvline(x=(itv[ep + 1] * N / 1000.), color="red", ls="--") ####################### ax = _plt.subplot2grid((4, 3), (2, 0), colspan=3) _plt.scatter(sts / 1000., d[sts, ch2], s=2, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="time (s)", ylabel=("mk elctrd %d" % (ch2 - 1)), xticks=None, yticks=[0, 3, 6], xticksD=None, yticksD=None, xlim=[0, N / 1000.], ylim=[wvfmMin[1], wvfmMax[1]], tickFS=15, labelFS=18) for ep in range(epochs): _plt.axvline(x=(itv[ep + 1] * N / 1000.), color="red", ls="--") ############## ax = _plt.subplot2grid((4, 3), (3, 0), colspan=1) _plt.scatter(d[sts, ch1], d[sts, ch2], s=2, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel=("mk elctrd %d" % (ch1 - 1)), ylabel=("mk elctrd %d" % (ch2 - 1)), xticks=[0, 3, 6], yticks=[0, 3, 6], xticksD=None, yticksD=None, xlim=[wvfmMin[0], wvfmMax[0]], ylim=[wvfmMin[1], wvfmMax[1]], tickFS=15, labelFS=18) ############## ax = _plt.subplot2grid((4, 3), (3, 1), colspan=1) _plt.scatter(d[sts, 0], d[sts, ch1], s=2, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="pos", ylabel=("mk elctrd %d" % (ch1 - 1)), xticks=_N.linspace(xL, xH, 3), yticks=[0, 3, 6], xticksD=None, yticksD=None, xlim=[xL, xH], ylim=None, tickFS=15, labelFS=18) ############## ax = _plt.subplot2grid((4, 3), (3, 2), colspan=1) _plt.scatter(d[sts, 0], d[sts, ch2], s=2, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="pos", ylabel=("mk elctrd %d" % (ch2 - 1)), xticks=_N.linspace(xL, xH, 3), yticks=[0, 3, 6], xticksD=None, yticksD=None, xlim=[xL, xH], ylim=None, tickFS=15, labelFS=18) ############## fig.subplots_adjust(left=0.15, bottom=0.15, wspace=0.38, hspace=0.38) epochs = len(itv) - 1 choutfn = "%(of)s_%(1)d,%(2)d" % { "of": outfn, "1": (ch1 - 1), "2": (ch2 - 1) } _plt.savefig(resFN(choutfn, dir=bfn), transparent=True) _plt.close()
# the parts of the model in which making a proposal distribution is # difficult. #us = -1 us = 0 std= 1.3#.5 tcksz=15 labsz=17 us = us + std*_N.random.randn(20000) ps = 1/(1 + _N.exp(-us)) fig = _plt.figure(figsize=(5, 10)) ax = fig.add_subplot(3, 1, 1) _plt.hist(ps, bins=_N.linspace(0, 1, 1001)) mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="ps", ylabel="prob", xticks=None, yticks=None, xticksD=None, yticksD=None, xlim=None, ylim=None, tickFS=tcksz, labelFS=labsz) ax = fig.add_subplot(3, 1, 2) _plt.hist(1-ps, bins=_N.linspace(0, 1, 1001)) mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="ps", ylabel="prob", xticks=None, yticks=None, xticksD=None, yticksD=None, xlim=None, ylim=None, tickFS=tcksz, labelFS=labsz) ax = fig.add_subplot(3, 1, 3) _plt.hist(1/(1-ps), bins=_N.linspace(1, 5, 1001)) mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="ps", ylabel="prob", xticks=None, yticks=None, xticksD=None, yticksD=None, xlim=None, ylim=None, tickFS=tcksz, labelFS=labsz) fig.subplots_adjust(left=0.15, bottom=0.15, wspace=0.3, hspace=0.3)
for p in xrange(4): print "#### 3 %d" % p ax = fig.add_subplot(2, 2, p + 1) maxY = _N.max(rscldA[:, 1 + p]) minY = _N.min(rscldA[:, 1 + p]) A = maxY - minY _plt.scatter(rscldA[:, 0], rscldA[:, 1 + p], color="black", s=10) mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="rescaled time", ylabel=("mark channel %d" % (p + 1)), xticks=[0, 3000, 6000], yticks=None, xticksD=None, yticksD=None, xlim=[-1, maxT * 1.03], ylim=[minY - 0.01 * A, maxY + 0.01 * A], tickFS=25, labelFS=27) if tets is not None: _plt.savefig("%(df)s/rescltets%(ep)d%(ts)s%(ptrb)s" % { "df": outdirN, "ep": epch, "ts": tetstr, "ptrb": sPrtrb }, transparent=True) _plt.savefig("%(df)s/rescltets%(ep)d%(ts)s%(ptrb)s.eps" % { "df": outdirN, "ep": epch,
def timeline(bfn, datfn, itvfn, outfn="timeline", ch1=0, ch2=1, xL=0, xH=3, yticks=[0, 1, 2, 3], thin=1): d = _N.loadtxt(datFN("%s.dat" % datfn)) # marks itv = _N.loadtxt(datFN("%s.dat" % itvfn)) N = d.shape[0] epochs = itv.shape[0]-1 ch1 += 2 # because this is data col ch2 += 2 _sts = _N.where(d[:, 1] == 1)[0] if thin == 1: sts = _sts else: sts = _sts[::thin] wvfmMin = _N.min(d[:, 2:], axis=0) wvfmMax = _N.max(d[:, 2:], axis=0) fig = _plt.figure(figsize=(10, 12)) ####################### ax =_plt.subplot2grid((4, 3), (0, 0), colspan=3) _plt.scatter(sts/1000., d[sts, 0], s=2, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="time (s)", ylabel="position", xticks=None, yticks=yticks, xticksD=None, yticksD=None, xlim=[0, N/1000.], ylim=[xL-0.3, xH+0.3], tickFS=15, labelFS=18) for ep in xrange(epochs): _plt.axvline(x=(itv[ep+1]*N/1000.), color="red", ls="--") ####################### ax = _plt.subplot2grid((4, 3), (1, 0), colspan=3) _plt.scatter(sts/1000., d[sts, ch1], s=2, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="time (s)", ylabel=("mk tet%d" % (ch1-1)), xticks=None, yticks=[0, 3, 6], xticksD=None, yticksD=None, xlim=[0, N/1000.], ylim=[wvfmMin[0], wvfmMax[0]], tickFS=15, labelFS=18) for ep in xrange(epochs): _plt.axvline(x=(itv[ep+1]*N/1000.), color="red", ls="--") ####################### ax = _plt.subplot2grid((4, 3), (2, 0), colspan=3) _plt.scatter(sts/1000., d[sts, ch2], s=2, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="time (s)", ylabel=("mk tet%d" % (ch2-1)), xticks=None, yticks=[0, 3, 6], xticksD=None, yticksD=None, xlim=[0, N/1000.], ylim=[wvfmMin[1], wvfmMax[1]], tickFS=15, labelFS=18) for ep in xrange(epochs): _plt.axvline(x=(itv[ep+1]*N/1000.), color="red", ls="--") ############## ax = _plt.subplot2grid((4, 3), (3, 0), colspan=1) _plt.scatter(d[sts, ch1], d[sts, ch2], s=2, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel=("mk tet%d" % (ch1-1)), ylabel=("mk tet%d" % (ch2-1)), xticks=[0, 3, 6], yticks=[0, 3, 6], xticksD=None, yticksD=None, xlim=[wvfmMin[0], wvfmMax[0]], ylim=[wvfmMin[1], wvfmMax[1]], tickFS=15, labelFS=18) ############## ax = _plt.subplot2grid((4, 3), (3, 1), colspan=1) _plt.scatter(d[sts, 0], d[sts, ch1], s=2, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="pos", ylabel=("mk tet%d" % (ch1-1)), xticks=_N.linspace(xL, xH, 3), yticks=[0, 3, 6], xticksD=None, yticksD=None, xlim=[xL, xH], ylim=None, tickFS=15, labelFS=18) ############## ax = _plt.subplot2grid((4, 3), (3, 2), colspan=1) _plt.scatter(d[sts, 0], d[sts, ch2], s=2, color="black") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="pos", ylabel=("mk tet%d" % (ch2-1)), xticks=_N.linspace(xL, xH, 3), yticks=[0, 3, 6], xticksD=None, yticksD=None, xlim=[xL, xH], ylim=None, tickFS=15, labelFS=18) ############## fig.subplots_adjust(left=0.15, bottom=0.15, wspace=0.38, hspace=0.38) epochs = len(itv)-1 choutfn = "%(of)s_%(1)d,%(2)d" % {"of" : outfn, "1" : (ch1-1), "2" : (ch2-1)} _plt.savefig(resFN(choutfn, dir=bfn), transparent=True) _plt.close()
marker=".", ms=12, color="black") _plt.text(u[iP1m2] + 0.2, j[iP1m2] + yoff + 0.02, "0.01") _plt.plot([u[iP5m2], u[iP5m2]], [j[iP5m2], j[iP5m2]], marker=".", ms=12, color="black") _plt.text(u[iP5m2] + 0.2, j[iP5m2] + 0.02, "0.05") _plt.plot([u[iP5m2], u[iP5m2]], [j[iP5m2] + yoff, j[iP5m2] + yoff], marker=".", ms=12, color="black") _plt.text(u[iP5m2] + 0.2, j[iP5m2] + yoff + 0.02, "0.05") mF.arbitraryAxes(ax, axesVis=[True, True, False, False], xtpos="bottom", ytpos="left") mF.setTicksAndLims(xlabel="u", ylabel="j(u)", yticks=[0, 0.5, 1, yoff, yoff + 0.5, yoff + 1], yticksD=["0", "0.5", "1", "0", "0.5", "1"], xlim=None, ylim=None, tickFS=18, labelFS=20) fig.subplots_adjust(left=0.12, bottom=0.12, right=0.95, top=0.95) _plt.savefig("jx.pdf")