Exemplo n.º 1
0
def get_responsive_nids(rec):
    """Get responsive nids (those with at least 1 detected response event in their PSTH) by
    finding the responsive nids in each state separately, then taking their superset"""
    rnids = []
    allnids = sorted(rec.alln)
    for statei in [0, 1]:  # 0 is desynched, 1 is synched
        tranges = REC2STATETRANGES[rec.absname]
        trange = tranges[statei]
        t, psths, spikets = rec.psth(nids=allnids,
                                     natexps=False,
                                     blank=BLANK,
                                     strange=trange,
                                     plot=False,
                                     binw=BINW,
                                     tres=TRES,
                                     gauss=GAUSS,
                                     norm='ntrials')
        for nid, psth, ts in zip(allnids, psths, spikets):
            # run PSTH peak detection:
            baseline = MEDIANX * np.median(psth)
            thresh = baseline + MINTHRESH  # peak detection threshold
            print("n%d" % nid, end='')
            peakis, lis, ris = get_psth_peaks_gac(ts, t, psth, thresh)
            npeaks = len(peakis)
            if npeaks > 0:
                rnids.append(nid)
        print()  # newline
    rnids = np.unique(rnids)
    return rnids
Exemplo n.º 2
0
def get_responsive_nids(rec):
    """Get responsive nids (those with at least 1 detected response event in their PSTH) by
    finding the responsive nids in each state separately, then taking their superset"""
    rnids = []
    allnids = sorted(rec.alln)
    for statei in [0, 1]: # 0 is desynched, 1 is synched
        tranges = REC2STATETRANGES[rec.absname]
        trange = tranges[statei]
        t, psths, spikets = rec.psth(nids=allnids, natexps=False, blank=BLANK, strange=trange,
                                     plot=False, binw=BINW, tres=TRES, gauss=GAUSS,
                                     norm='ntrials')
        for nid, psth, ts in zip(allnids, psths, spikets):
            # run PSTH peak detection:
            baseline = MEDIANX * np.median(psth)
            thresh = baseline + MINTHRESH # peak detection threshold
            print("n%d" % nid, end='')
            peakis, lis, ris = get_psth_peaks_gac(ts, t, psth, thresh)
            npeaks = len(peakis)
            if npeaks > 0:
                rnids.append(nid)
        print() # newline
    rnids = np.unique(rnids)
    return rnids
rts = {} # index into by [rec.absname][statei]
rpsths = {} # index into by [rec.absname][statei][nid]
for rec, nids, strange, state in zip(recs, recsecnids, stranges, states):
    print(rec.absname, state)
    statei = {'desynch': 0, 'synch': 1}[state]
    if rec.absname not in rts:
        rts[rec.absname] = [None, None] # init, index into using statei
        rpsths[rec.absname] = [{}, {}] # init, index into using statei
    t, psths, spikets = rec.psth(nids=nids, natexps=False, blank=BLANK, strange=strange,
                                 plot=False, binw=BINW, tres=TRES, gauss=GAUSS, norm='ntrials')
    rts[rec.absname][statei] = t
    for nid, psth, ts in zip(nids, psths, spikets):
        # run PSTH peak detection:
        baseline = MEDIANX * np.median(psth)
        thresh = baseline + MINTHRESH # peak detection threshold
        peakis, lis, ris = get_psth_peaks_gac(ts, t, psth, thresh)
        if len(peakis) == 0: # not a responsive PSTH
            continue
        rpsths[rec.absname][statei][nid] = psth
    print('\n') # two newlines

# correlate each PSTH in each recording section with movie signals. Also, collect
# movie motion-PSTH sparseness pairs:
motrhostats, conrhostats, lumrhostats = [], [], []
for corrdelay in CORRDELAYS:
    motrhos = {'desynch': [], 'synch': []}
    conrhos = {'desynch': [], 'synch': []}
    lumrhos = {'desynch': [], 'synch': []}
    motscatspars = {'desynch': [], 'synch': []}
    NULLRHO = -1
    recsecscatmotrhos = {} # index into with [rec.absname][nid][statei], first 2 are dict keys
Exemplo n.º 4
0
for n in ns:
    nid = n.id
    rec = n.sort.r
    stranges = REC2STATETRANGES[rec.absname] # [desynched, synched]
    figure(figsize=figsize)
    for strange, c in zip(stranges[::-1], ['r', 'b']): # [synched, desynched]
        # calculate PSTH:
        t, psths, spikets = rec.psth(nids=[nid], strange=strange, binw=BINW, tres=TRES,
                                     gauss=True, norm='ntrials', plot=False)
        psth, ts = psths[0], spikets[0] # lists of len 1
        # run PSTH peak detection:
        baseline = MEDIANX * np.median(psth)
        thresh = baseline + MINTHRESH # peak detection threshold
        print("n%d" % nid, end='')
        peakis, lis, ris = get_psth_peaks_gac(ts, t, psth, thresh, sigma=sigma)
        plot(t, psth, c=c, marker=None, ls='-')
        if len(peakis) > 0:
            plot(t[peakis], psth[peakis], c=c, marker='.', linestyle='none', ms=ms, mec='none')
        '''
        if len(lis) > 0:
            plot(t[lis], psth[lis], c='e', marker='.', linestyle='none', ms=ms, mec='none')
        if len(ris) > 0:
            plot(t[ris], psth[ris], c='k', marker='.', linestyle='none', ms=ms, mec='none')
        '''
    xlim(xmin=0, xmax=t[-1])
    #ylim(0, 1) # arbitrary units
    #yticks([0, 1])
    yticks([])
    gcfm().window.setWindowTitle(rec.absname+'_n'+str(nid)+'_PSTHs')
    tight_layout(pad=0.3) # crop figure to contents
Exemplo n.º 5
0
     show()
 # n2count is needed for calculating reliability:
 n2count = rec.bintraster(nids=nids,
                          ttranges=ttranges,
                          natexps=False,
                          blank=BLANK,
                          strange=None,
                          binw=TRASTERBINW,
                          tres=TRASTERTRES,
                          gauss=GAUSS)[0]
 for nid, psth, ts in zip(nids, psths, spikets):
     # run PSTH peak detection:
     baseline = MEDIANX * np.median(psth)
     thresh = baseline + MINTHRESH  # peak detection threshold
     print("n%d" % nid, end='')
     peakis, lis, ris = get_psth_peaks_gac(ts, t, psth, thresh)
     psthparams[nid] = t, psth, thresh, baseline, peakis, lis, ris
     #psthparams[nid] = get_psth_peaks(t, psth, nid)
     #t, psth, thresh, baseline, peakis, lis, ris = psthparams[nid] # unpack
     if PLOTPSTH:
         plot_psth(psthparams, nid, FMTS[state])
         show()
     npeaks = len(peakis)
     if npeaks == 0:
         nrnids[state].append(
             nid)  # save nonresponsive nids by state
         continue  # this PSTH has no peaks, skip all subsequent measures
     ntotpeaks += npeaks
     rnids[state].append(nid)  # save responsive nids by state
     rpsths[state].append(psth)  # save responsive PSTH by state
     peaktimes[state].append(peakis * TRES)  # save peak times, s