Example #1
0
 # n2count is needed for calculating reliability:
 n2count = rec.bintraster(nids=nids, blank=BLANK, strange=strange,
                          binw=TRASTERBINW, tres=TRASTERTRES, gauss=GAUSS)[0]
 ntrials = n2count[nids[0]].shape[0] # should be the same for all nids
 print('ntrials: %d' % ntrials)
 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, fmt)
     npeaks = len(peakis)
     if npeaks == 0:
         nrnids[statei].append(nid) # save nonresponsive nids, indexed by state
         continue # this PSTH has no peaks, skip all subsequent measures
     rnids[statei].append(nid) # save responsive nids, indexed by state
     rpsths[statei].append(psth) # save responsive PSTH, indexed by state
     # calculate peak precision:
     widths = (ris - lis) * TRES * 1000 # ms
     psthswidths.append(widths)
     psthsts.append(peakis * TRES) # sec
     psthsheights.append(psth[peakis] - baseline) # peak height above baseline
     #psthsheights.append(psth[peakis]) # peak height above 0
     lspikeis, rspikeis = ts.searchsorted(lis*TRES), ts.searchsorted(ris*TRES)
     nspikes = rspikeis - lspikeis # nspikes of each detected peak
     assert (nspikes > 0).all()
EPS = np.spacing(1) # epsilon, smallest representable non-zero number

BINW, TRES = 0.02, 0.0001 # PSTH time bins, sec
# 2.5 Hz thresh is 1 spike in the same 20 ms wide bin every 20 trials, assuming 0 baseline:
MINTHRESH = 3 # peak detection thresh, Hz
MEDIANX = 2 # PSTH median multiplier, Hz
FWFRACTION = 0.5 # full width fraction of max
WIDTHMAX = 200 # maximum width, ms
WIDTHMAXPOINTS = intround(WIDTHMAX / 1000 / TRES) # maximum width, number of PSTH timepoints

# plotting params:
PLOTPSTH = True
FIGSIZE = 3.14, 2
YMAX = 6 # Hz
YTICKS = 0, 3, 6
MS = 5

t, psths, spikets = rec.psth(nids=nids, natexps=False, strange=strange, plot=False,
                             binw=BINW, tres=TRES, norm='ntrials')

psthparams = {} # params returned for each PSTH by get_psth_peaks
for nid, psth in zip(nids, psths):
    psthparams[nid] = get_psth_peaks_simple(t, psth, nid, WIDTHMAXPOINTS, minthresh=MINTHRESH,
                                            medianx=MEDIANX, fwfraction=FWFRACTION)
    if PLOTPSTH:
        plot_psth(psthparams, nid, fmt='k-', ms=MS, ymax=YMAX, yticks=YTICKS, figsize=FIGSIZE)
    #t, psth, thresh, baseline, peakis, lis, ris = psthparams[nid] # unpack

pl.show()
Example #3
0
                          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
     # calculate peak precision:
     widths = (ris - lis) * TRES * 1000  # ms
     peakwidths[state].append(widths)
     peakheights[state].append(
         psth[peakis] - baseline)  # peak height above baseline
MS = 5

t, psths, spikets = rec.psth(nids=nids,
                             natexps=False,
                             strange=strange,
                             plot=False,
                             binw=BINW,
                             tres=TRES,
                             norm='ntrials')

psthparams = {}  # params returned for each PSTH by get_psth_peaks
for nid, psth in zip(nids, psths):
    psthparams[nid] = get_psth_peaks_simple(t,
                                            psth,
                                            nid,
                                            WIDTHMAXPOINTS,
                                            minthresh=MINTHRESH,
                                            medianx=MEDIANX,
                                            fwfraction=FWFRACTION)
    if PLOTPSTH:
        plot_psth(psthparams,
                  nid,
                  fmt='k-',
                  ms=MS,
                  ymax=YMAX,
                  yticks=YTICKS,
                  figsize=FIGSIZE)
    #t, psth, thresh, baseline, peakis, lis, ris = psthparams[nid] # unpack

pl.show()
                          binw=TRASTERBINW,
                          tres=TRASTERTRES,
                          gauss=GAUSS)[0]
 ntrials = n2count[nids[0]].shape[0]  # should be the same for all nids
 print('ntrials: %d' % ntrials)
 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, fmt)
     npeaks = len(peakis)
     if npeaks == 0:
         nrnids[statei].append(
             nid)  # save nonresponsive nids, indexed by state
         continue  # this PSTH has no peaks, skip all subsequent measures
     rnids[statei].append(nid)  # save responsive nids, indexed by state
     rpsths[statei].append(psth)  # save responsive PSTH, indexed by state
     # calculate peak precision:
     widths = (ris - lis) * TRES * 1000  # ms
     psthswidths.append(widths)
     psthsts.append(peakis * TRES)  # sec
     psthsheights.append(psth[peakis] -
                         baseline)  # peak height above baseline
     #psthsheights.append(psth[peakis]) # peak height above 0
     lspikeis, rspikeis = ts.searchsorted(lis * TRES), ts.searchsorted(ris *
Example #6
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
     # calculate peak precision:
     widths = (ris - lis) * TRES * 1000 # ms
     peakwidths[state].append(widths)
     peakheights[state].append(psth[peakis] - baseline) # peak height above baseline
     #peakheights[state].append(psth[peakis]) # peak height above 0
     lspikeis, rspikeis = ts.searchsorted(lis*TRES), ts.searchsorted(ris*TRES)