def reject_inf(wav_info, ts): ch = wav_info['id'] pos = wav_info['file_pos'] if ch not in reject_inf.valid: try: inf = np.loadtxt(reject_inf.prefix + '.inf.' + str(ch), skiprows=1) ninf0 = len(inf) inf, = sort_uniq(inf[:,0].astype('int'), inf) ninf1 = len(inf) if ninf1 != ninf0: print 'Ch:', ch, '\tchange in size: %d -> %d' % (ninf0, ninf1) reject_inf.valid[ch] = hash_tbl([int(l) for l in inf[:,0]]) except IOError, e: print '*** Bad channel?:', e reject_inf.valid[ch] = hash_tbl([])
def cluster(wav_info, ts): ch = wav_info['id'] pos = wav_info['file_pos'] if ch not in cluster.valid: try: # -- load and sort in terms of inf[:,0] inf = np.loadtxt(cluster.prefix_inf + '.inf.' + str(ch), skiprows=1) clu = np.loadtxt(cluster.prefix_clu + '.clu.' + str(ch), skiprows=1).astype('int') assert len(inf) == len(clu) ninf0 = len(inf) inf, clu = sort_uniq(inf[:,0].astype('int'), inf, clu) ninf1 = len(inf) if ninf1 != ninf0: print 'Ch:', ch, '\tchange in size: %d -> %d' % (ninf0, ninf1) cluster.valid[ch] = hash_tbl([int(l) for l in inf[:,0]]) # get the "nicer" cluster id (clu_ref: reference cluster id's) if cluster.prefix_clu_all == None: clu_ref = clu else: clu_ref = load_superset(cluster.prefix_clu, cluster.prefix_clu_all, ch) nclu, ucid = get_standard_cid(clu_ref, clu, nmax=cluster.nmax) # -- check bad ISIs nbad = [] nspk = [] for cid in range(nclu): ii = np.nonzero(cid == clu)[0] isi = np.diff(np.sort(inf[ii,1])) nbad.append(np.sum(isi < BAD_ISI)) nspk.append(len(ii)) # -- done cluster.ucid[ch] = ucid cluster.nbad[ch] = nbad cluster.nspk[ch] = nspk cluster.nclu[ch] = nclu cluster.clu[ch] = list(clu) print 'Ch:', ch, '\t#Spk:', nspk, ' #Bad:', nbad, ' Unsorted ID:', ucid except IOError, e: print '*** Bad channel?:', e cluster.valid[ch] = hash_tbl([])