def split(rawfolder, file_contains='LDE', print_status=False, *arg, **kw): windows = kw.pop('windows', [1, 2]) ch0maxtime = kw.pop('ch0maxtime', 700) ch1maxtime = kw.pop('ch1maxtime', 700) allfiles = [ f for f in os.listdir(rawfolder) if file_contains in f and \ f[:1] != '.' and f[-4:] == '.npz' ] lastidx = len(allfiles) # we don't have too much data left over, so can use this approach finaldata = np.zeros((0, 4), dtype=np.uint) windowdata = [np.zeros((0, 4), dtype=np.uint) for w in windows] sync_of = 0 for i, f in enumerate(allfiles): if print_status: print 'file %d (%d) ...' % (i + 1, len(allfiles)) fp = os.path.join(rawfolder, f) data = hht3.data_from_file(fp, ch0_lastbin=ch0maxtime, ch1_lastbin=ch1maxtime, *arg, **kw) if len(data) == 0: continue data[:, 0] += sync_of + 100 sync_of = data[-1, 0] + 1 data = hht3.filter_counts_on_marker(data, 1, windows) if len(data) == 0: continue _windowdata = [] for w in windows: _wd = hht3.filter_counts_on_marker(data, 1, [w]) _wd = hht3.delete_markers(_wd, 1) _windowdata.append(_wd) data = hht3.delete_markers(data, 1) finaldata = np.vstack((finaldata, data)) for i, w in enumerate(windows): windowdata[i] = np.vstack((windowdata[i], _windowdata[i])) ret = [finaldata] ret.extend(windowdata) return tuple(ret)
def split(rawfolder, file_contains='LDE', print_status=False, *arg, **kw): windows = kw.pop('windows', [1,2]) ch0maxtime = kw.pop('ch0maxtime', 700) ch1maxtime = kw.pop('ch1maxtime', 700) allfiles = [ f for f in os.listdir(rawfolder) if file_contains in f and \ f[:1] != '.' and f[-4:] == '.npz' ] lastidx = len(allfiles) # we don't have too much data left over, so can use this approach finaldata = np.zeros((0,4), dtype=np.uint) windowdata = [ np.zeros((0,4), dtype=np.uint) for w in windows ] sync_of = 0 for i,f in enumerate(allfiles): if print_status: print 'file %d (%d) ...' % (i+1, len(allfiles)) fp = os.path.join(rawfolder, f) data = hht3.data_from_file(fp, ch0_lastbin=ch0maxtime, ch1_lastbin=ch1maxtime, *arg, **kw) if len(data) == 0: continue data[:,0] += sync_of + 100 sync_of = data[-1,0] + 1 data = hht3.filter_counts_on_marker(data, 1, windows) if len(data) == 0: continue _windowdata = [] for w in windows: _wd = hht3.filter_counts_on_marker(data, 1, [w]) _wd = hht3.delete_markers(_wd,1) _windowdata.append(_wd) data = hht3.delete_markers(data, 1) finaldata = np.vstack((finaldata, data)) for i,w in enumerate(windows): windowdata[i] = np.vstack((windowdata[i], _windowdata[i])) ret = [finaldata] ret.extend(windowdata) return tuple(ret)
def filter_markers(data, sync_range=range(1,301), delete=True): data = hht3.filter_counts_on_marker(data, 1, sync_range) if len(data) > 0 and delete: print 'delete markers' data = hht3.delete_markers(data, 1) return data
def get_hhpludata(hhdata): hhpludata = hht3.filter_counts_on_marker(hhdata, 2, [-1,0]) hhpludata1 = hht3.filter_counts_on_marker(hhdata, 2, [-1]) hhpludata2 = hht3.filter_counts_on_marker(hhdata, 2, [0]) # some sanity checks if (len(hhpludata)==0): print 'no valid hhpludata' else: print '' print 'HH SSROs: %d' % len(hhpludata[ np.logical_and(hhpludata[:,3]==1, hhpludata[:,2]==2)]) print '' print 'counts + PLU: %d' % len(hhpludata[hhpludata[:,3]==0]) print 'counts in window 1 + PLU: %d' % len(hhpludata1[hhpludata1[:,3]==0]) print 'counts in window 2 + PLU: %d' % len(hhpludata2[hhpludata2[:,3]==0]) return hhpludata, hhpludata1, hhpludata2
def prepare_correlations(datfolder, datfile='hh_prefiltered_events.npz'): # HH data d = np.load(os.path.join(datfolder, datfile)) hhdata = d['data'] d.close() hhpludat = hht3.filter_counts_on_marker(hhdata, 2, [-1,0]) hhpludat1 = hht3.filter_counts_on_marker(hhdata, 2, [-1]) hhpludat2 = hht3.filter_counts_on_marker(hhdata, 2, [0]) ### some sanity checks print '' print 'HH SSROs: %d' % len(hhpludat[ np.logical_and(hhpludat[:,3]==1, hhpludat[:,2]==2)]) print '' print 'counts + PLU: %d' % len(hhpludat[hhpludat[:,3]==0]) print 'counts in window 1 + PLU: %d' % len(hhpludat1[hhpludat1[:,3]==0]) print 'counts in window 2 + PLU: %d' % len(hhpludat2[hhpludat2[:,3]==0]) return hhpludat
def prepare_correlations(datfolder, datfile='hh_prefiltered_events.npz'): # HH data d = np.load(os.path.join(datfolder, datfile)) hhdata = d['data'] d.close() hhpludat = hht3.filter_counts_on_marker(hhdata, 2, [-1, 0]) hhpludat1 = hht3.filter_counts_on_marker(hhdata, 2, [-1]) hhpludat2 = hht3.filter_counts_on_marker(hhdata, 2, [0]) ### some sanity checks print '' print 'HH SSROs: %d' % len(hhpludat[np.logical_and(hhpludat[:, 3] == 1, hhpludat[:, 2] == 2)]) print '' print 'counts + PLU: %d' % len(hhpludat[hhpludat[:, 3] == 0]) print 'counts in window 1 + PLU: %d' % len(hhpludat1[hhpludat1[:, 3] == 0]) print 'counts in window 2 + PLU: %d' % len(hhpludat2[hhpludat2[:, 3] == 0]) return hhpludat
def plot_counts_vs_time(windowdata, savepath, window=1, bins=700, save_prefix='', save_postfix=''): gated = hht3.filter_counts_on_marker(windowdata, 2, [window - 2]) print 'length of window data = ', len(windowdata) fig = plt.figure() t0, t1 = hht3.get_click_times(windowdata) h0y, h0x = np.histogram(t0, bins=bins, range=(0, bins - 1)) h1y, h1x = np.histogram(t1, bins=bins, range=(0, bins - 1)) g_t0, g_t1 = hht3.get_click_times(gated) g_h0y, g_h0x = np.histogram(g_t0, bins=bins, range=(0, bins - 1)) g_h1y, g_h1x = np.histogram(g_t1, bins=bins, range=(0, bins - 1)) ax = plt.subplot(121) ax.semilogy(g_h0x[:-1], g_h0y, color='g', label='ch0 gated') ax.semilogy(h0x[:-1], h0y, label='ch0', color='b') ax.set_xlabel('Bins') ax.legend() ax = plt.subplot(122) ax.semilogy(h1x[:-1], h1y, label='ch1') ax.semilogy(g_h1x[:-1], g_h1y, label='ch1 gated') ax.set_xlabel('Bins') ax.legend() plt.suptitle('Clicks after optical pulse, window %d' % window) fig.savefig(os.path.join(savepath,'%shistogram_window%s%s.pdf' % \ (save_prefix,window,save_postfix))) np.savez(os.path.join(savepath, 'histogram_window%s.npz' % window), window_number=window, window_data=windowdata, ch0=h0y, ch0_xaxis=h0x[:-1], ch0_gated=g_h0y, ch0_gated_xaxis=g_h0x[:-1], ch1=h1y, ch1_xaxis=h1x[:-1], ch1_gated=g_h1y, ch1_gated_xaxis=g_h1x[:-1]) return True
def plot_counts_vs_time(windowdata, savepath, window=1, bins=700, save_prefix='', save_postfix=''): gated = hht3.filter_counts_on_marker(windowdata, 2, [window-2]) print 'length of window data = ',len(windowdata) fig = plt.figure() t0, t1 = hht3.get_click_times(windowdata) h0y, h0x = np.histogram(t0, bins=bins, range=(0,bins-1)) h1y, h1x = np.histogram(t1, bins=bins, range=(0,bins-1)) g_t0, g_t1 = hht3.get_click_times(gated) g_h0y, g_h0x = np.histogram(g_t0, bins=bins, range=(0,bins-1)) g_h1y, g_h1x = np.histogram(g_t1, bins=bins, range=(0,bins-1)) ax = plt.subplot(121) ax.semilogy(g_h0x[:-1], g_h0y, color = 'g', label='ch0 gated') ax.semilogy(h0x[:-1], h0y, label='ch0', color = 'b') ax.set_xlabel('Bins') ax.legend() ax = plt.subplot(122) ax.semilogy(h1x[:-1], h1y, label='ch1') ax.semilogy(g_h1x[:-1], g_h1y, label='ch1 gated') ax.set_xlabel('Bins') ax.legend() plt.suptitle('Clicks after optical pulse, window %d' % window) fig.savefig(os.path.join(savepath,'%shistogram_window%s%s.pdf' % \ (save_prefix,window,save_postfix))) np.savez(os.path.join(savepath, 'histogram_window%s.npz'%window), window_number = window, window_data = windowdata, ch0 = h0y, ch0_xaxis = h0x[:-1], ch0_gated = g_h0y, ch0_gated_xaxis = g_h0x[:-1], ch1 = h1y, ch1_xaxis = h1x[:-1], ch1_gated = g_h1y, ch1_gated_xaxis = g_h1x[:-1]) return True
def prepare(datfolder, rawfolder, *arg, **kw): global setup ############################# #### LOAD ADWIN LT1 DATA #### ############################# # load adwin autodata fn = os.path.join(datfolder, ADWINLT1FOLDER+('-%.'+str(DATIDXDIGITS)+'d') % DATIDX, ADWINDATAFN) d = np.load(fn) noof_SSROs_adwin_LT1 = d['get_noof_SSROs'] noof_SSRO_triggers_LT1 = d['get_noof_SSRO_triggers'] d.close() ############################# #### LOAD ADWIN LT2 DATA #### ############################# sn = os.path.join(datfolder, ADWINLT2FOLDER+('-%.'+str(DATIDXDIGITS)+'d') % DATIDX, ADWINDATAFN) s = np.load(sn) noof_PLU_markers = s['get_noof_PLU_markers'] noof_SSROs_adwin_LT2 = s['get_noof_SSROs'] s.close() ############################################ ### LOADING SSRO DATA### ############################################ fn = os.path.join(datfolder, DATFILEBASE+('-%.'+str(DATIDXDIGITS)+'d.npz') % DATIDX) d = np.load(fn) SSROs_adwin_LT1 = d['adwin_lt1_SSRO'] SSROs_adwin_LT2 = d['adwin_lt2_SSRO'] ############################################ ### COMPENSATING A MISMATCH IN SSRO DATA ### ############################################ #filling up SSROs_adwin_lt1 with -1 where LT2 missed a PLU SSROs_adwin_LT1, added_idxs = correct_ssro_mismatch(SSROs_adwin_LT1, SSROs_adwin_LT2, noof_PLU_markers,noof_SSROs_adwin_LT1, noof_SSROs_adwin_LT2) ###################################### ###################################### ###################################### if setup == 'lt2': CRs_adwin = d['adwin_lt2_CR'] else: CRs_adwin = d['adwin_lt1_CR'] d.close() # load HH data hh_prefiltered, window1, window2 = split(rawfolder, *arg, **kw) hhpludat = hht3.filter_counts_on_marker( hh_prefiltered, 2, [-1,0]) np.savez(os.path.join(datfolder, 'hh_prefiltered_events'), data=hh_prefiltered) np.savez(os.path.join(datfolder, 'window1_events'), data=window1) np.savez(os.path.join(datfolder, 'window2_events'), data=window2) # more preparations SSROs_adwin_LT1 = SSROs_adwin_LT1[:noof_SSRO_triggers_LT1+added_idxs] SSROs_adwin_LT2 = SSROs_adwin_LT2[:noof_PLU_markers] if setup == 'lt1': CRs_adwin = CRs_adwin[:noof_SSRO_triggers_LT1] ###################################### ###################################### ###################################### print 'PLU markers on adwin lt2:', noof_PLU_markers print '\nLength of ADwin LT1 SSRO array after addition: '\ , len(SSROs_adwin_LT1) print 'Length of ADwin LT2 SSRO array: ', len(SSROs_adwin_LT2) ###################################### ###################################### ###################################### ### first some sanity checks invalid_SSROs_adwin = np.where(SSROs_adwin_LT1==-1)[0] \ if setup =='lt1' else np.where(SSROs_adwin_LT2==-1)[0] print '' print 'adwin detected SSROs: %d' % \ (noof_SSRO_triggers_LT1 if setup=='lt1' else noof_PLU_markers) print ' thereof invalid: %d' % len(invalid_SSROs_adwin) print 'HH SSROs: %d' % len(hhpludat[ np.logical_and(hhpludat[:,3]==1, hhpludat[:,2]==2)]) print '' ### plot counts if(kw.get('do_plot',False)): plot_counts_vs_time(window1, datfolder, window=1) plot_counts_vs_time(window2, datfolder, window=2) ret = SSROs_adwin_LT1 if setup=='lt1' else SSROs_adwin_LT2 return ret
def filter_PLU(data, mchan=2): filtered = hht3.filter_counts_on_marker(data, mchan, delta_syncs=[0]) return filtered
def prepare(datfolder, rawfolder, *arg, **kw): global setup ############################# #### LOAD ADWIN LT1 DATA #### ############################# # load adwin autodata fn = os.path.join( datfolder, ADWINLT1FOLDER + ('-%.' + str(DATIDXDIGITS) + 'd') % DATIDX, ADWINDATAFN) d = np.load(fn) noof_SSROs_adwin_LT1 = d['get_noof_SSROs'] noof_SSRO_triggers_LT1 = d['get_noof_SSRO_triggers'] d.close() ############################# #### LOAD ADWIN LT2 DATA #### ############################# sn = os.path.join( datfolder, ADWINLT2FOLDER + ('-%.' + str(DATIDXDIGITS) + 'd') % DATIDX, ADWINDATAFN) s = np.load(sn) noof_PLU_markers = s['get_noof_PLU_markers'] noof_SSROs_adwin_LT2 = s['get_noof_SSROs'] s.close() ############################################ ### LOADING SSRO DATA### ############################################ fn = os.path.join( datfolder, DATFILEBASE + ('-%.' + str(DATIDXDIGITS) + 'd.npz') % DATIDX) d = np.load(fn) SSROs_adwin_LT1 = d['adwin_lt1_SSRO'] SSROs_adwin_LT2 = d['adwin_lt2_SSRO'] ############################################ ### COMPENSATING A MISMATCH IN SSRO DATA ### ############################################ #filling up SSROs_adwin_lt1 with -1 where LT2 missed a PLU SSROs_adwin_LT1, added_idxs = correct_ssro_mismatch( SSROs_adwin_LT1, SSROs_adwin_LT2, noof_PLU_markers, noof_SSROs_adwin_LT1, noof_SSROs_adwin_LT2) ###################################### ###################################### ###################################### if setup == 'lt2': CRs_adwin = d['adwin_lt2_CR'] else: CRs_adwin = d['adwin_lt1_CR'] d.close() # load HH data hh_prefiltered, window1, window2 = split(rawfolder, *arg, **kw) hhpludat = hht3.filter_counts_on_marker(hh_prefiltered, 2, [-1, 0]) np.savez(os.path.join(datfolder, 'hh_prefiltered_events'), data=hh_prefiltered) np.savez(os.path.join(datfolder, 'window1_events'), data=window1) np.savez(os.path.join(datfolder, 'window2_events'), data=window2) # more preparations SSROs_adwin_LT1 = SSROs_adwin_LT1[:noof_SSRO_triggers_LT1 + added_idxs] SSROs_adwin_LT2 = SSROs_adwin_LT2[:noof_PLU_markers] if setup == 'lt1': CRs_adwin = CRs_adwin[:noof_SSRO_triggers_LT1] ###################################### ###################################### ###################################### print 'PLU markers on adwin lt2:', noof_PLU_markers print '\nLength of ADwin LT1 SSRO array after addition: '\ , len(SSROs_adwin_LT1) print 'Length of ADwin LT2 SSRO array: ', len(SSROs_adwin_LT2) ###################################### ###################################### ###################################### ### first some sanity checks invalid_SSROs_adwin = np.where(SSROs_adwin_LT1==-1)[0] \ if setup =='lt1' else np.where(SSROs_adwin_LT2==-1)[0] print '' print 'adwin detected SSROs: %d' % \ (noof_SSRO_triggers_LT1 if setup=='lt1' else noof_PLU_markers) print ' thereof invalid: %d' % len(invalid_SSROs_adwin) print 'HH SSROs: %d' % len(hhpludat[np.logical_and(hhpludat[:, 3] == 1, hhpludat[:, 2] == 2)]) print '' ### plot counts if (kw.get('do_plot', False)): plot_counts_vs_time(window1, datfolder, window=1) plot_counts_vs_time(window2, datfolder, window=2) ret = SSROs_adwin_LT1 if setup == 'lt1' else SSROs_adwin_LT2 return ret