Example #1
0
def coincidence_times(data, deltas=range(-3,4), *arg, **kw):
    t0, t1 = hht3.get_clicks(data)

    if t0.shape == (4,0) or t1.shape == (4,0):
        return deltas, [ np.zeros((0,2)) for d in deltas ]

    c = []
    for delta in deltas:
        c.append(_coincidence_times(t0.astype(int), t1.astype(int), delta))

    return deltas, c
Example #2
0
def coincidence_times(data, deltas=range(-3,4), *arg, **kw):
    t0, t1 = hht3.get_clicks(data)

    if t0.shape == (4,0) or t1.shape == (4,0):
        return deltas, [ np.zeros((0,2)) for d in deltas ]

    c = []
    for delta in deltas:
        c.append(_coincidence_times(t0.astype(int), t1.astype(int), delta))

    return deltas, c
Example #3
0
def coincidences_from_folder(path, ch0window=(0,500), ch1window=(0,500), *arg, **kw):
    
    npzfiles = [ f for f in os.listdir(os.path.join(workingpath, path)) \
            if ( os.path.splitext(f)[1] == '.npz' and 'alldata' in f and f[:1] != '.') ]
   
    sync_range = kw.pop('sync_range', range(1, 301))
    ret = kw.pop('ret', True)
   
    totalhist=np.array([0,0], dtype=np.uint32)
    #totalhist = np.array([], dtype=int)
    for i,f in enumerate(npzfiles):
        print ''
        print 'file', f

        # brute force for now: ignore the first file of each measurement.
        # if os.path.splitext(f)[0][-3:] == '-0':
        #     print 'IGNORED; FIND BETTER WAY...'
        #     continue

        base = path
        d = np.load(os.path.join(workingpath, path, f))
        raw = d['data'].astype(np.uint)
        d.close()

        data = hht3.decode(raw)
        data, ofls = hht3.filter_overflows(data)
        
        # print 'filter on timewindow'
        data = hht3.filter_timewindow(data, 0, mintime=ch0window[0], maxtime=ch0window[1])
        data = hht3.filter_timewindow(data, 1, mintime=ch1window[0], maxtime=ch1window[1])
        if len(data) == 0:
            continue

        data = hht3.filter_decreasing_syncs(data)
        if len(data) == 0:
            continue

        # print 'filter counts on markers'
        data = filter_markers(data, sync_range=sync_range)
        if len(data) == 0:
            continue
        
        t0, t1 = hht3.get_clicks(data)


        # print 'extract coincidences'
        #deltas, c = coincidences(data, *arg, **kw)

        #print '* Coincidences for %s:' % f, [ len(_c) for _c in c ]
        #print ''

        totalhist= totalhist+np.array([len(t0),len(t1)])
        print totalhist
        #totalhist = add_coincidences(totalhist, c)
    
    p = os.path.join(workingpath, '%s_coincidences_syncs_%d-%d_ch0_%d-%d_ch1_%d-%d' % \
                (base, sync_range[0], sync_range[-1], ch0window[0], ch0window[1], ch1window[0], ch1window[1]))

    np.savez(p, deltas=deltas, coincidences=totalhist)
    plot_g2(deltas, totalhist, savepath=p+'.png', 
        title='%s; windows: %d-%d, %d-%d; syncs: %d-%d' % (path, 
            ch0window[0], ch0window[1], ch1window[0], ch1window[1], sync_range[0], sync_range[-1]))

    if ret:
        return deltas, totalhist
Example #4
0
def coincidences_from_folder(path, ch0window=(0,500), ch1window=(0,500), *arg, **kw):
    
    npzfiles = [ f for f in os.listdir(os.path.join(workingpath, path)) \
            if ( os.path.splitext(f)[1] == '.npz' and 'alldata' in f and f[:1] != '.') ]
   
    sync_range = kw.pop('sync_range', range(1, 301))
    ret = kw.pop('ret', True)
   
    totalhist=np.array([0,0], dtype=np.uint32)
    #totalhist = np.array([], dtype=int)
    for i,f in enumerate(npzfiles):
        print ''
        print 'file', f

        # brute force for now: ignore the first file of each measurement.
        # if os.path.splitext(f)[0][-3:] == '-0':
        #     print 'IGNORED; FIND BETTER WAY...'
        #     continue

        base = path
        d = np.load(os.path.join(workingpath, path, f))
        raw = d['data'].astype(np.uint)
        d.close()

        data = hht3.decode(raw)
        data, ofls = hht3.filter_overflows(data)
        
        # print 'filter on timewindow'
        data = hht3.filter_timewindow(data, 0, mintime=ch0window[0], maxtime=ch0window[1])
        data = hht3.filter_timewindow(data, 1, mintime=ch1window[0], maxtime=ch1window[1])
        if len(data) == 0:
            continue

        data = hht3.filter_decreasing_syncs(data)
        if len(data) == 0:
            continue

        # print 'filter counts on markers'
        data = filter_markers(data, sync_range=sync_range)
        if len(data) == 0:
            continue
        
        t0, t1 = hht3.get_clicks(data)


        # print 'extract coincidences'
        #deltas, c = coincidences(data, *arg, **kw)

        #print '* Coincidences for %s:' % f, [ len(_c) for _c in c ]
        #print ''

        totalhist= totalhist+np.array([len(t0),len(t1)])
        print totalhist
        #totalhist = add_coincidences(totalhist, c)
    
    p = os.path.join(workingpath, '%s_coincidences_syncs_%d-%d_ch0_%d-%d_ch1_%d-%d' % \
                (base, sync_range[0], sync_range[-1], ch0window[0], ch0window[1], ch1window[0], ch1window[1]))

    np.savez(p, deltas=deltas, coincidences=totalhist)
    plot_g2(deltas, totalhist, savepath=p+'.png', 
        title='%s; windows: %d-%d, %d-%d; syncs: %d-%d' % (path, 
            ch0window[0], ch0window[1], ch1window[0], ch1window[1], sync_range[0], sync_range[-1]))

    if ret:
        return deltas, totalhist