def load_coincidences_from_events(self): for (path, dirs, files) in os.walk(self.ldesrcdir): for fn in files: if self.fnpattern in fn and fn[0] != "." and fn[-4:] == ".npz": print os.path.join(path, fn) d = np.load(os.path.join(path, fn)) data = d["hhdata"] d.close() data = hht3.filter_timewindow(data, 0, mintime=0, maxtime=2400) data = hht3.filter_timewindow(data, 1, mintime=0, maxtime=2400) d, c = tpqi.coincidence_times(data, self.deltas) self.coincidences = tpqi.add_coincidence_times(self.coincidences, c)
def get_double_clicks(data,ch0_start=0, ch0_stop=700, ch1_start=0, ch1_stop=700): clicks=hht3.get_allclicks(data) clicks=hht3.filter_timewindow(clicks,0,ch0_start,ch0_stop) clicks=hht3.filter_timewindow(clicks,1,ch1_start,ch1_stop) clicks=np.vstack((clicks,np.zeros(4,dtype=np.uint32))) clicks=np.vstack((np.zeros(4,dtype=np.uint32),clicks)) delta_marker=clicks[1:,0]-clicks[:-1,0] double_click_idx=np.ravel(np.where(delta_marker==1)) triple_click_idx=np.ravel(np.where(delta_marker==0)) bad_idx=np.append(triple_click_idx,\ [triple_click_idx-np.ones(len(triple_click_idx),dtype=np.uint),\ triple_click_idx+np.ones(len(triple_click_idx),dtype=np.uint)]) valid_double_click_idx=np.setdiff1d(double_click_idx,bad_idx) valid_double_click_idx=np.sort(np.append(valid_double_click_idx,valid_double_click_idx+np.ones(len(valid_double_click_idx),dtype=np.uint))) return clicks[valid_double_click_idx]
def get_double_clicks(data,ch0_start=0, ch0_stop=700, ch1_start=0, ch1_stop=700): clicks=hht3.get_allclicks(data) clicks=hht3.filter_timewindow(clicks,0,ch0_start,ch0_stop) clicks=hht3.filter_timewindow(clicks,1,ch1_start,ch1_stop) clicks=np.vstack((clicks,np.zeros(4,dtype=np.uint32))) clicks=np.vstack((np.zeros(4,dtype=np.uint32),clicks)) delta_marker=clicks[1:,0]-clicks[:-1,0] double_click_idx=np.ravel(np.where(delta_marker==1)) triple_click_idx=np.ravel(np.where(delta_marker==0)) bad_idx=np.append(triple_click_idx,\ [triple_click_idx-np.ones(len(triple_click_idx),dtype=np.uint),\ triple_click_idx+np.ones(len(triple_click_idx),dtype=np.uint)]) valid_double_click_idx=np.setdiff1d(double_click_idx,bad_idx) valid_double_click_idx=np.sort(np.append(valid_double_click_idx,valid_double_click_idx+np.ones(len(valid_double_click_idx),dtype=np.uint))) return clicks[valid_double_click_idx]
def get_double_clicks_slow(hhdata, ch0_start=0, ch0_stop=700, ch1_start=0, ch1_stop=700): noof_double = 0 double_clicks = np.zeros(4,dtype=np.uint32) hhdata=hht3.get_allclicks(hhdata) hhdata=hht3.filter_timewindow(hhdata,0,ch0_start,ch0_stop) hhdata=hht3.filter_timewindow(hhdata,1,ch1_start,ch1_stop) for i in np.arange(len(hhdata)): try: if (hhdata[i,0]+1==(hhdata[i+1,0])): if (len(hhdata[np.where(hhdata[:,0]==hhdata[i,0])])==1 and\ len(hhdata[np.where(hhdata[:,0]==hhdata[i+1,0])])==1): double_clicks=np.vstack((double_clicks,hhdata[i])) double_clicks=np.vstack((double_clicks,hhdata[i+1])) except IndexError: pass if (len(np.shape(double_clicks))>1): double_clicks=double_clicks[1:] return double_clicks
def get_double_clicks_slow(hhdata, ch0_start=0, ch0_stop=700, ch1_start=0, ch1_stop=700): noof_double = 0 double_clicks = np.zeros(4,dtype=np.uint32) hhdata=hht3.get_allclicks(hhdata) hhdata=hht3.filter_timewindow(hhdata,0,ch0_start,ch0_stop) hhdata=hht3.filter_timewindow(hhdata,1,ch1_start,ch1_stop) for i in np.arange(len(hhdata)): try: if (hhdata[i,0]+1==(hhdata[i+1,0])): if (len(hhdata[np.where(hhdata[:,0]==hhdata[i,0])])==1 and\ len(hhdata[np.where(hhdata[:,0]==hhdata[i+1,0])])==1): double_clicks=np.vstack((double_clicks,hhdata[i])) double_clicks=np.vstack((double_clicks,hhdata[i+1])) except IndexError: pass if (len(np.shape(double_clicks))>1): double_clicks=double_clicks[1:] return double_clicks
def load_coincidences_from_events(self): for (path,dirs,files) in os.walk(self.ldesrcdir): for fn in files: if self.fnpattern in fn and fn[0] != '.' and fn[-4:] == '.npz': print os.path.join(path,fn) d = np.load(os.path.join(path, fn)) data = d['hhdata'] d.close() data = hht3.filter_timewindow(data, 0, mintime=0, maxtime=2400) data = hht3.filter_timewindow(data, 1, mintime=0, maxtime=2400) d,c = tpqi.coincidence_times(data, self.deltas) self.coincidences = tpqi.add_coincidence_times( self.coincidences, c)
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
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