def getphase(fname, ang): print "Getting phase from: ", fname dat, attribs, cf = bu.getdata(os.path.join(path, fname)) xdat, ydat = rotate_data(dat[:, data_columns[0]], dat[:, data_columns[1]], ang) #xdat = sp.filtfilt(b, a, xdat) xdat = np.append(xdat, np.zeros(fsamp / fdrive)) corr2 = np.correlate(xdat, dat[:, drive_column]) maxv = np.argmax(corr2) cf.close() if (plot_phase): plt.figure() plt.plot(corr2) plt.figure() xdat_filt = sp.filtfilt(b, a, xdat) drive_filt = sp.filtfilt(b, a, dat[:, drive_column]) plt.plot(xdat_filt / np.max(xdat_filt), label='x') plt.plot(drive_filt / np.max(drive_filt), label='drive') plt.legend() plt.show() print maxv return maxv
def getangle(fname): print "Getting angle from: ", fname num_angs = 100 dat, attribs, cf = bu.getdata(os.path.join(path, fname)) pow_arr = np.zeros((num_angs,2)) ang_list = np.linspace(-np.pi/2.0, np.pi/2.0, num_angs) for i,ang in enumerate(ang_list): rot_x, rot_y = rotate_data(dat[:,data_columns[0]], dat[:,data_columns[1]], ang) pow_arr[i, :] = [np.std(rot_x), np.std(rot_y)] best_ang = ang_list[ np.argmax(pow_arr[:,0]) ] print "Best angle [deg]: %f" % (best_ang*180/np.pi) cf.close() if(plot_angle): plt.figure() plt.plot(ang_list, pow_arr[:,0], label='x') plt.plot(ang_list, pow_arr[:,1], label='y') plt.xlabel("Rotation angle") plt.ylabel("RMS at drive freq.") plt.legend() ## also plot rotated time stream rot_x, rot_y = rotate_data(dat[:,data_columns[0]], dat[:,data_columns[1]], best_ang) plt.figure() plt.plot(rot_x) plt.plot(rot_y) plt.plot(dat[:, drive_column] * np.max(rot_x)/np.max(dat[:,drive_column])) plt.show() return best_ang
def getangle(fname): print "Getting angle from: ", fname num_angs = 100 dat, attribs, cf = bu.getdata(os.path.join(path, fname)) pow_arr = np.zeros((num_angs, 2)) ang_list = np.linspace(-np.pi / 2.0, np.pi / 2.0, num_angs) for i, ang in enumerate(ang_list): rot_x, rot_y = rotate_data(dat[:, data_columns[0]], dat[:, data_columns[1]], ang) pow_arr[i, :] = [np.std(rot_x), np.std(rot_y)] best_ang = ang_list[np.argmax(pow_arr[:, 0])] print "Best angle [deg]: %f" % (best_ang * 180 / np.pi) cf.close() if (plot_angle): plt.figure() plt.plot(ang_list, pow_arr[:, 0], label='x') plt.plot(ang_list, pow_arr[:, 1], label='y') plt.xlabel("Rotation angle") plt.ylabel("RMS at drive freq.") plt.legend() ## also plot rotated time stream rot_x, rot_y = rotate_data(dat[:, data_columns[0]], dat[:, data_columns[1]], best_ang) plt.figure() plt.plot(rot_x) plt.plot(rot_y) plt.plot(dat[:, drive_column] * np.max(rot_x) / np.max(dat[:, drive_column])) plt.show() return best_ang
def profile(fname, ends=100, stage_cal=8., data_column=5, make_plot=False, p0=[30, 30, .001], ortho_column=[18, 17, 19]): '''takes raw data makes profile and fits to gaussian to determine beam center. returns beam center and position on orthogonal beam axis''' dat, attribs, f = bu.getdata(fname) dat = dat[ends:-ends, :] stage_column, ortho_column = get_stage_column(attribs) dat[:, stage_column] *= stage_cal dat[:, ortho_column] *= stage_cal f.close() bp, yp, ep = cu.sbin_pn(dat[:, stage_column], dat[:, data_column], bin_size=.1, vel_mult=1.) bn, yn, en = cu.sbin_pn(dat[:, stage_column], dat[:, data_column], bin_size=.1, vel_mult=-1.) profp = np.abs(np.gradient(yp, bp)) profn = np.abs(np.gradient(yn, bn)) poptp, pcovp = curve_fit(gauss_beam, bp[10:-10], profp[10:-10], p0=p0) poptn, pcovn = curve_fit(gauss_beam, bn[10:-10], profn[10:-10], p0=p0) if make_plot: plt.semilogy(bp, profp, 'o') plt.semilogy(bp, gauss_beam(bp, *poptp), 'r') plt.semilogy(bn, profn, 'o') plt.semilogy(bn, gauss_beam(bn, *poptn), 'k') plt.show() return np.mean([poptn[0], poptp[0]]), np.mean(dat[:, ortho_column])
def profile(fname, ends = 100, stage_cal = 8.): dat, attribs, f = bu.getdata(fname) dat = dat[ends:-ends, :] dat[:, stage_column]*=stage_cal f.close() b, a = sig.butter(3, 0.25) int_filt = sig.filtfilt(b, a, dat[:, data_column]) proft = np.gradient(int_filt) stage_filt = sig.filtfilt(b, a, dat[:, stage_column]) dir_sign = np.sign(np.gradient(stage_filt)) b, y, e = spatial_bin(dat[dir_sign<0, stage_column], proft[dir_sign<0]) return b, y, e
def profile(fname, ends=100, stage_cal=8.): dat, attribs, f = bu.getdata(fname) dat = dat[ends:-ends, :] dat[:, stage_column] *= stage_cal f.close() b, a = sig.butter(3, 0.25) int_filt = sig.filtfilt(b, a, dat[:, data_column]) proft = np.gradient(int_filt) stage_filt = sig.filtfilt(b, a, dat[:, stage_column]) dir_sign = np.sign(np.gradient(stage_filt)) b, y, e = spatial_bin(dat[dir_sign < 0, stage_column], proft[dir_sign < 0]) return b, y, e
def getphase(fname): print "Getting phase from: ", fname dat, attribs, cf = bu.getdata(os.path.join(path, fname)) fsamp = attribs["Fsamp"] xdat = dat[:,data_columns[1]] xdat = np.append(xdat, np.zeros( int(fsamp/fdrive) )) corr2 = np.correlate(xdat,dat[:,drive_column]) maxv = np.argmax(corr2) cf.close() print maxv return maxv
def getphase(fname): print "Getting phase from: ", fname dat, attribs, cf = bu.getdata(os.path.join(path, fname)) fsamp = attribs["Fsamp"] xdat = dat[:,data_columns[1]] xdat = np.append(xdat, np.zeros( int(fsamp/fdrive) )) corr2 = np.correlate(xdat,dat[:,drive_column]) maxv = np.argmax(corr2) cf.close() print maxv return maxv
def getdata(fname, maxv): print "Processing ", fname dat, attribs, cf = bu.getdata(os.path.join(path, fname)) if (len(attribs) > 0): fsamp = attribs["Fsamp"] xdat = dat[:, data_columns[1]] lentrace = len(xdat) ## zero pad one cycle corr_full = bu.corr_func(dat[:, drive_column], xdat, fsamp, fdrive) return corr_full[0], np.max(corr_full)
def getdata(fname, maxv): print "Processing ", fname dat, attribs, cf = bu.getdata(os.path.join(path, fname)) if( len(attribs) > 0 ): fsamp = attribs["Fsamp"] xdat = dat[:,data_columns[1]] lentrace = len(xdat) ## zero pad one cycle corr_full = bu.corr_func( dat[:,drive_column], xdat, fsamp, fdrive) return corr_full[0], np.max(corr_full)
def profile(fname, ends = 5000, stage_cal = 8., data_column = 6, stage_column = 19): dat, attribs, f = bu.getdata(fname) dat = dat[ends:-ends, :] dat[:, stage_column]*=stage_cal #plt.plot(dat[:, data_column]) #plt.show() f.close() b, a = sig.butter(3, 0.25) int_filt = sig.filtfilt(b, a, dat[:, data_column]) stage_filt = sig.filtfilt(b, a, dat[:, stage_column]) v = np.gradient(stage_filt) b = np.abs(v) > 1e-4 b2 = np.gradient(stage_filt)>0 proft = np.gradient(int_filt[b])/v[b] #dir_sign = np.sign(np.gradient(stage_filt)) b, y, e = spatial_bin(dat[:, stage_column][b], proft) return b, y, e
def profile(fname, ends = 100, stage_cal = 8., stage_column = 17.): dat, attribs, f = bu.getdata(fname) dat = dat[ends:-ends, :] if 'xsweep' in fname: stage_column = 17 sign = 1.0 elif 'ysweep' in fname: stage_column = 18 if 'left' in fname: sign = 1.0 elif 'right' in fname: sign = -1.0 else: sign = 1.0 #elif 'zsweep' in fname: #stage_column = 19 dat[:,stage_column]*=stage_cal h = attribs["stage_settings"][2]*cant_cal f.close() b, a = sig.butter(1, 1) if '2016' in fname: int_filt = sig.filtfilt(b, a, dat[:, data_column2]) else: int_filt = sig.filtfilt(b, a, dat[:, data_column]) #plt.plot(int_filt) #fft = np.fft.rfft(int_filt) #freqs = np.fft.rfftfreq(len(int_filt), d=1./5000) #plt.figure() #plt.loglog(freqs, fft * fft.conj()) #plt.show() proft = np.gradient(int_filt)- OFFSET stage_filt = sig.filtfilt(b, a, dat[:, stage_column]) dir_sign = np.sign(np.gradient(stage_filt)) * sign xvec = dat[:,stage_column] yvec = (proft - proft * dir_sign) * 0.5 - (proft + proft * dir_sign) * 0.5 #plt.plot(xvec, yvec) #plt.show() b, y, e = spatial_bin(xvec, yvec) #plt.errorbar(b, y, e) #plt.show() if INVERT: y = -1.*y return b, y, e, h
def getdata(fname, maxv): print "Processing ", fname dat, attribs, cf = bu.getdata(os.path.join(path, fname)) if (len(attribs) > 0): fsamp = attribs["Fsamp"] xdat = dat[:, data_columns[1]] lentrace = len(xdat) ## zero pad one cycle MinusDC = dat[:, drive_column] corr_full = bu.corr_func(MinusDC - np.median(MinusDC), xdat, fsamp, fdrive) #plt.figure() #plt.plot( xdat) #plt.plot(dat[:,drive_column]) #plt.show() return corr_full[0], np.max(corr_full)
def test(fname): print "Getting phase from: ", fname dat, attribs, cf = bu.getdata(os.path.join(path, fname)) f = h5py.File(os.path.join(path, fname),'r') dset = f['beads/data/pos_data'] fsamp = attribs["Fsamp"] xdat = dat[:,data_columns[1]] xdat = np.append(xdat, np.zeros( int(fsamp/fdrive) )) driver = butter_bandpass_filter(dat[:,drive_column], li, ls, fsamp, order=3)/np.max( butter_bandpass_filter(dat[:,drive_column], li, ls, fsamp, order=3)) Ddriver = np.gradient(driver)/np.max(np.gradient(driver)) driver2F = driver*Ddriver/np.max(np.abs(driver*Ddriver)) corr2 = np.correlate(xdat,driver*Ddriver) maxv = np.argmax(corr2) Fs = dset.attrs['Fsamp'] xpsd, freqs = matplotlib.mlab.psd(dat[:, drive_column]-numpy.mean(dat[:, drive_column]), Fs = Fs, NFFT = NFFT) driverpsd, freqs = matplotlib.mlab.psd(driver-numpy.mean(driver), Fs = Fs, NFFT = NFFT) Ddriverpsd, freqs = matplotlib.mlab.psd(Ddriver-numpy.mean(Ddriver), Fs = Fs, NFFT = NFFT) driverpsd2F, freqs = matplotlib.mlab.psd(driver2F-numpy.mean(driver2F), Fs = Fs, NFFT = NFFT) cf.close() return [driverpsd, xpsd, freqs, Ddriverpsd, driverpsd2F, driver2F, driver, dat[:,drive_column]/np.max(dat[:,drive_column])]
def getphase(fname, ang): print "Getting phase from: ", fname dat, attribs, cf = bu.getdata(os.path.join(path, fname)) xdat, ydat = rotate_data(dat[:,data_columns[0]], dat[:,data_columns[1]], ang) #xdat = sp.filtfilt(b, a, xdat) xdat = np.append(xdat, np.zeros( fsamp/fdrive )) corr2 = np.correlate(xdat,dat[:,drive_column]) maxv = np.argmax(corr2) cf.close() if(plot_phase): plt.figure() plt.plot( corr2 ) plt.figure() xdat_filt = sp.filtfilt(b,a,xdat) drive_filt = sp.filtfilt(b,a,dat[:,drive_column]) plt.plot( xdat_filt/np.max( xdat_filt ), label='x') plt.plot( drive_filt/np.max( drive_filt ), label='drive' ) plt.legend() plt.show() print maxv return maxv
import h5py import matplotlib import matplotlib.pyplot as plt import os import scipy.signal as sp import scipy.optimize as opt import bead_util as bu import numpy as np refname = r"C:\Data\20150908\Bead2\mod_template\urmbar_xyzcool.h5" dat, attribs, _ = bu.getdata(refname) ## first find the phase of the drive signal b, a = sp.butter(3, 0.1) cdrive = np.abs(dat[:, 7] - np.mean(dat[:, 7])) #cdrive = dat[:,3] cdrive = sp.filtfilt(b, a, cdrive) cdrive -= np.mean(cdrive) cdat = dat[:, 6] def ffn(x, p0, p1, p2): return p0 * np.sin(2 * np.pi * p1 * xx + p2) ## fit to a sin xx = np.arange(len(cdrive)) spars = [np.std(cdrive) * 2, 6.05e-4, 0]
flist = sorted(glob.glob(os.path.join(data_dir, "*.h5")), key=sort_fun) avg_dict = {} elec_list = [ 3, ] ##[1,2,3,4,5,6] dcol_list = [0, 1, 2] tot_dat = np.zeros([len(flist), len(elec_list), len(dcol_list), 3]) for fidx, f in enumerate(flist): cpos = sort_fun(f) print("Vdc = ", cpos) cdat, attribs, _ = bu.getdata(f) Fs = attribs['Fsamp'] #cpsd, freqs = mlab.psd(cdat[:, 1]-np.mean(cdat[:,1]), Fs = Fs, NFFT = NFFT) ## take correlation with drive and drive^2 for eidx, elec in enumerate(elec_list): for didx, dcol in enumerate(dcol_list): response = cdat[:, dcol] drive = cdat[:, 9 + elec] drive2 = drive**2 drive2 -= np.mean(drive2)
import h5py import matplotlib import matplotlib.pyplot as plt import os import scipy.signal as sp import scipy.optimize as opt import bead_util as bu import numpy as np refname = r"C:\Data\20150908\Bead2\mod_template\urmbar_xyzcool.h5" dat, attribs, _ = bu.getdata(refname) ## first find the phase of the drive signal b,a = sp.butter(3,0.1) cdrive = np.abs(dat[:,7]-np.mean(dat[:,7])) #cdrive = dat[:,3] cdrive = sp.filtfilt( b, a, cdrive) cdrive -= np.mean(cdrive) cdat = dat[:,6] def ffn(x, p0, p1, p2): return p0*np.sin( 2*np.pi*p1*xx + p2 ) ## fit to a sin xx = np.arange(len(cdrive)) spars = [np.std(cdrive)*2, 6.05e-4, 0] bf, bc = opt.curve_fit( ffn, xx, cdrive, p0=spars ) #bf, bc = spars, ""
import numpy as np import bead_util as bu import matplotlib.pyplot as plt import os fname = r"allon_drive_pxi6259_chan0_10000mV_41Hz.h5" path = "/data/20140620/xtalk" channels = np.array([1, 2, 3, 4, 5, 6]) drive_column = -1 dat, attribs, f = bu.getdata(os.path.join(path, fname)) corrs = [] corrmaxs = [] for i in range(7): if i != drive_column: corrmax = np.max( bu.corr_func(dat[:, drive_column], dat[:, i], attribs['Fsamp'], attribs['drive_freq'], filt=True)) sub_corrs = bu.corr_blocks(dat[:, drive_column], dat[:, i], attribs['Fsamp'], attribs['drive_freq'], filt=True, N_blocks=3)
] tot_dat = np.zeros([len(flist), 5]) tot_dat_pts = [] for fidx, f in enumerate(dclist): cpos = f ##sort_fun(f) print("Vdc = ", cpos) cflist = glob.glob(os.path.join(data_dir, "*elec0_%dmV*.h5" % cpos)) tot_corr_dr = [] tot_corr_dr2 = [] for f2 in cflist: cdat, attribs, fhand = bu.getdata(f2) if (len(cdat) == 0): print("Empty file, skipping: ", f2) continue Fs = attribs['Fsamp'] drive_freq = attribs['electrode_settings'][16] fhand.close() NFFT = bu.prev_pow_2(len(cdat[:, 1])) cpsd, freqs = mlab.psd(cdat[:, 1] - np.mean(cdat[:, 1]), Fs=Fs, NFFT=NFFT) # plt.figure() # plt.loglog(freqs, cpsd)
import numpy as np import bead_util as bu import matplotlib.pyplot as plt import os fname = r"allon_drive_pxi6259_chan0_10000mV_41Hz.h5" path = "/data/20140620/xtalk" channels = np.array([1, 2, 3, 4, 5, 6]) drive_column = -1 dat, attribs, f = bu.getdata(os.path.join(path, fname)) corrs = [] corrmaxs = [] for i in range(7): if i != drive_column: corrmax = np.max(bu.corr_func(dat[:, drive_column], dat[:, i], attribs['Fsamp'], attribs['drive_freq'], filt = True)) sub_corrs = bu.corr_blocks(dat[:, drive_column], dat[:, i], attribs['Fsamp'], attribs['drive_freq'], filt = True, N_blocks = 3) corrs.append(sub_corrs) corrmaxs.append(corrmax) plt.figure() corrs = np.array(corrs)
def sort_fun(s): vstr = re.findall("-?\d+mVdc.h5", s)[0] return float(vstr[:-7]) flist = sorted(glob.glob(os.path.join(path, name)), key=sort_fun) col_list = ['k', 'b', 'r', 'g', 'm', 'c', 'y'] drive_freq_list = [] corr_mat = np.zeros((len(flist), len(data_cols), len(electrode_cols), 2)) dc_list = np.zeros(len(flist)) for fidx, f in enumerate(flist): dat, attribs, cf = bu.getdata(f) if (len(dat) == 0): print "Warning, couldn't get data for: ", f fsamp = attribs["Fsamp"] print "Working on file: ", f if len(drive_freq_list) == 0: ## get the frequency for each drive channel if (plot_freqs): plt.figure() for j, elec in enumerate(electrode_cols): cpsd = np.abs(np.fft.rfft(dat[:, elec] - np.mean(dat[:, elec])))**2 cfreqs = np.fft.rfftfreq(len(dat[:, elec]), d=1. / fsamp)
import bead_util as bu import numpy as np import os import matplotlib bpv = 2.0**15/10. pipb = 1./1000. muppi = 1.0639/4. mupv = muppi*pipb*bpv path = "/data/20170606/bead2_2" fname0 = "2mbar_nocool1kbppi.h5" fname1 = "2mbar_zcool1kbppi.h5" dat0, attribs0, f0 = bu.getdata(os.path.join(path, fname0)) Fs = attribs0["Fsamp"] f0.close() dat1, attribs1, f1 = bu.getdata(os.path.join(path, fname1)) Fs = attribs1["Fsamp"] f1.close() def plt_zpos(dat, Fs, mupv, n_plt): n = len(dat[:, 0]) t = np.arange(0, n/Fs, 1./Fs) plt.plot(t[:n_plt], dat0[:n_plt, 2]*mupv) plt.xlabel("time[s]") plt.ylabel("displacement[um]") plt.show()
import bead_util as bu import glob import os from scipy import signal import scipy import matplotlib data_path = '/data/20170531/int_calib' files = glob.glob(os.path.join(data_path + '/*.h5')) bppi = 100. adcbits = 2**15 bpv = adcbits/10. mupv = 80./10. mupc = 0.532 data0, attribs, f = bu.getdata(files[0]) f.close() z = mupc*(data0[:, 2] - np.mean(data0[:, 2]))*(bpv/bppi)*0.5 cant_z = (data0[:, 17] - np.mean(data0[:, 17]))*mupv b, a = signal.butter(4, 0.001, btype = 'high') #z = signal.filtfilt(b, a, z) def scale(s): #finds sum square error difference after scaling data return np.sum((s*z-cant_z)**2) res = scipy.optimize.minimize_scalar(scale) t = np.linspace(0., 10., 50000) res.x = 1.
def getdata(fname, maxv, ang, gain): print "Processing ", fname dat, attribs, cf = bu.getdata(os.path.join(path, fname)) ## make sure file opened correctly if( len(dat) == 0 ): return {} dat[:, drive_column] *= gain if( len(attribs) > 0 ): fsamp = attribs["Fsamp"] drive_amplitude = attribs["drive_amplitude"] xdat, ydat = rotate_data(dat[:,data_columns[0]], dat[:,data_columns[1]], ang) drive_amp = np.sqrt(2)*np.std(dat[:,drive_column]) if( remove_laser_noise ): laser_good = bu.laser_reject(dat[:, laser_column], 60., 90., 4e-6, 100, fsamp, False) else: laser_good = np.ones_like(dat[:, laser_column]) > 0 corr_full = bu.corr_func(dat[:,drive_column], xdat, fsamp, fdrive, good_pts=laser_good) corr = corr_full[ maxv ] corr_max = np.max(corr_full) corr_max_pos = np.argmax(corr_full) xpsd, freqs = matplotlib.mlab.psd(xdat, Fs = fsamp, NFFT = NFFT) #ypsd, freqs = matplotlib.mlab.psd(ydat, Fs = fsamp, NFFT = NFFT) max_bin = np.argmin( np.abs( freqs - fdrive ) ) ref_bin = np.argmin( np.abs( freqs - fref ) ) ## also correlate signal with drive squared dsq = dat[:,drive_column]**2 dsq -= np.mean(dsq) sq_amp = np.sqrt(2)*np.std( dsq ) ## only normalize by one factor of the squared amplitude corr_sq_full = bu.corr_func(dsq*sq_amp, xdat, fsamp, fdrive) corr_sq_max = np.max(corr_sq_full) corr_sq_max_pos = np.argmax(corr_sq_full) xoff = sp.filtfilt(boff, aoff, xdat) if(False): plt.figure() plt.plot( xdat ) plt.plot( dat[:, drive_column] ) plt.figure() plt.plot( corr_full ) plt.show() ctime = attribs["time"] ## is this a calibration file? cdir,_ = os.path.split(fname) is_cal = cdir == cal_path curr_scale = 1.0 ## make a dictionary containing the various calculations out_dict = {"corr_t0": corr, "max_corr": [corr_max, corr_max_pos], "max_corr_sq": [corr_sq_max, corr_sq_max_pos], "psd": np.sqrt(xpsd[max_bin]), "ref_psd": np.sqrt(xpsd[ref_bin]), "temps": attribs["temps"], "time": bu.labview_time_to_datetime(ctime), "num_flashes": attribs["num_flashes"], "is_cal": is_cal, "drive_amp": drive_amp} cf.close() return out_dict
def getdata(fname, maxv, ang, gain): print "Processing ", fname dat, attribs, cf = bu.getdata(os.path.join(path, fname)) ## make sure file opened correctly if (len(dat) == 0): return {} dat[:, drive_column] *= gain if (len(attribs) > 0): fsamp = attribs["Fsamp"] drive_amplitude = attribs["drive_amplitude"] xdat, ydat = rotate_data(dat[:, data_columns[0]], dat[:, data_columns[1]], ang) drive_amp = np.sqrt(2) * np.std(dat[:, drive_column]) if (remove_laser_noise): laser_good = bu.laser_reject(dat[:, laser_column], 60., 90., 4e-6, 100, fsamp, False) else: laser_good = np.ones_like(dat[:, laser_column]) > 0 corr_full = bu.corr_func(dat[:, drive_column], xdat, fsamp, fdrive, good_pts=laser_good) corr = corr_full[maxv] corr_max = np.max(corr_full) corr_max_pos = np.argmax(corr_full) xpsd, freqs = matplotlib.mlab.psd(xdat, Fs=fsamp, NFFT=NFFT) #ypsd, freqs = matplotlib.mlab.psd(ydat, Fs = fsamp, NFFT = NFFT) max_bin = np.argmin(np.abs(freqs - fdrive)) ref_bin = np.argmin(np.abs(freqs - fref)) ## also correlate signal with drive squared dsq = dat[:, drive_column]**2 dsq -= np.mean(dsq) sq_amp = np.sqrt(2) * np.std(dsq) ## only normalize by one factor of the squared amplitude corr_sq_full = bu.corr_func(dsq * sq_amp, xdat, fsamp, fdrive) corr_sq_max = np.max(corr_sq_full) corr_sq_max_pos = np.argmax(corr_sq_full) xoff = sp.filtfilt(boff, aoff, xdat) if (False): plt.figure() plt.plot(xdat) plt.plot(dat[:, drive_column]) plt.figure() plt.plot(corr_full) plt.show() ctime = attribs["time"] ## is this a calibration file? cdir, _ = os.path.split(fname) is_cal = cdir == cal_path curr_scale = 1.0 ## make a dictionary containing the various calculations out_dict = { "corr_t0": corr, "max_corr": [corr_max, corr_max_pos], "max_corr_sq": [corr_sq_max, corr_sq_max_pos], "psd": np.sqrt(xpsd[max_bin]), "ref_psd": np.sqrt(xpsd[ref_bin]), "temps": attribs["temps"], "time": bu.labview_time_to_datetime(ctime), "num_flashes": attribs["num_flashes"], "is_cal": is_cal, "drive_amp": drive_amp } cf.close() return out_dict