Exemple #1
0
    def __init__(self, outdir, fn, intvfn, xLo=0, xHi=3, seed=1041, adapt=True, nzclstr=False, t_hlf_l0_mins=None, t_hlf_q2_mins=None, oneCluster=False):
        oo     = self
        oo.oneCluster = oneCluster
        oo.adapt = adapt
        _N.random.seed(seed)
        oo.nzclstr = nzclstr

        ######################################  DATA input, define intervals
        # bFN = fn[0:-4]
        oo.outdir = outdir

        # if not os.access(bFN, os.F_OK):
        #     os.mkdir(bFN)

        oo.dat    = _N.loadtxt("%s.dat" % datFN(fn, create=False))
        #oo.datprms= _N.loadtxt("%s_prms.dat" % datFN(fn, create=False))

        intvs     = _N.loadtxt("%s.dat" % datFN(intvfn, create=False))

        oo.intvs  = _N.array(intvs*oo.dat.shape[0], dtype=_N.int)
        oo.epochs    = oo.intvs.shape[0] - 1
        
        NT     = oo.dat.shape[0]
        oo.xLo = xLo
        oo.xHi = xHi
Exemple #2
0
    def __init__(self, outdir, fn, intvfn):
        oo     = self
        ######################################  DATA input, define intervals
        # bFN = fn[0:-4]
        oo.outdir = outdir

        # if not os.access(bFN, os.F_OK):
        #     os.mkdir(bFN)

        oo.dat    = _N.loadtxt("%s.dat" % datFN(fn, create=False))
        oo.datprms= _N.loadtxt("%s_prms.dat" % datFN(fn, create=False))

        intvs     = _N.loadtxt("%s.dat" % datFN(intvfn, create=False))

        oo.intvs  = _N.array(intvs*oo.dat.shape[0], dtype=_N.int)
        oo.epochs    = oo.intvs.shape[0] - 1
        
        NT     = oo.dat.shape[0]
Exemple #3
0
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()
Exemple #4
0
    def __init__(self, kde=False, bx=None, Bx=None, Bm=None, mkfns=None, encfns=None, K=None, nTets=None, xLo=0, xHi=3):
        """
        """
        oo = self
        oo.kde = kde

        oo.bx = bx;   oo.Bx = Bx;   oo.Bm = Bm
        oo.mkpos = []
        #  read mkfns
        _sts   = []#  a mark on one of the several tetrodes
        for fn in mkfns:
            _dat = _N.loadtxt(datFN("%s.dat" % fn))
            if K is None:
                K   = _dat.shape[1] - 2
                dat = _dat
            else:
                dat = _dat[:, 0:2+K]
            oo.mkpos.append(dat)
            _sts.extend(_N.where(dat[:, 1] == 1)[0])
        oo.sts = _N.unique(_sts)

        oo.nTets = len(oo.mkpos)
        oo.mdim  = K
        oo.pos  = dat[:, 0]         #  length of 

        if not kde:
            oo.mdim  = K
            oo.nTets  = nTets
        
        oo.xLo = xLo;     oo.xHi = xHi
        
        ####  spatial grid for evaluating firing rates
        oo.xp   = _N.linspace(oo.xLo, oo.xHi, oo.Nx)  #  space points
        oo.xpr  = oo.xp.reshape((oo.Nx, 1))
        #  bin space for occupation histogram.  same # intvs as space points
        oo.dxp   = oo.xp[1] - oo.xp[0]
        oo.xb    = _N.empty(oo.Nx+1)
        oo.xb[0:oo.Nx] = oo.xp - 0.5*oo.dxp
        oo.xb[oo.Nx] = oo.xp[-1]+ 0.5*oo.dxp
        ####

        #oo.lmdFLaT = oo.lmd.reshape(oo.Nx, oo.Nm**oo.mdim)
        oo.dt = 0.001

        oo.pX_Nm = _N.zeros((oo.pos.shape[0], oo.Nx))
        oo.Lklhd = _N.zeros((oo.nTets, oo.pos.shape[0], oo.Nx))

        oo.decmth = "kde"
        #################################################################

        oo.intgrd= _N.empty(oo.Nx)
        oo.intgrd2d= _N.empty((oo.Nx, oo.Nx))
        oo.intgrl = _N.empty(oo.Nx)
        oo.xTrs  = _N.zeros((oo.Nx, oo.Nx))      #  Gaussian

        x  = _N.linspace(oo.xLo, oo.xHi, oo.Nx)
        ##  (xk - a xk1)

        i = 0

        grdsz = (float(oo.xHi-oo.xLo)/oo.Nx)
        spdGrdUnts = _N.diff(oo.pos) / grdsz  # unit speed ( per ms ) in grid units

        #  avg. time it takes to move 1 grid is 1 / _N.mean(_N.abs(spdGrdUnts))
        #  p(i+1, i) = 1/<avg spdGrdUnts>
        p1 = 1.5*_N.mean(_N.abs(spdGrdUnts))*oo.spdMult
        #  assume Nx is even
        #k2 = 0.02
        k2 = 0.1
        k3 = 0.1

        ##  circular maze
        for i in xrange(0, oo.Nx):  #  indexing of xTrs  [to, from]
            oo.xTrs[i, i] = 1-p1   
            if i == 0:
                #oo.xTrs[0, oo.Nx-1] = p1*0.5
                oo.xTrs[0, oo.Nx-1] = p1*0.9  #  backwards
            if i >= 0:
                oo.xTrs[i-1, i] = p1*0.1
                oo.xTrs[i, i-1] = p1*0.9
            if i == oo.Nx-1:
                oo.xTrs[oo.Nx-1, 0] = p1*0.1

        """