def get_vb_corr_ceria_tof(): fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_00504-v56.epos" epos = apt_fileio.read_epos_numpy(fn) red_epos = epos[100000::10] # Voltage and bowl correct ToF data p_volt = np.array([]) p_bowl = np.array([]) t_i = time.time() _, p_volt, p_bowl = do_voltage_and_bowl(red_epos, p_volt, p_bowl) print("time to voltage and bowl correct: " + str(time.time() - t_i) + " seconds") tof_vcorr = voltage_and_bowl.mod_full_voltage_correction( p_volt, epos['tof'], epos['v_dc']) tof_corr = voltage_and_bowl.mod_geometric_bowl_correction( p_bowl, tof_vcorr, epos['x_det'], epos['y_det']) return tof_corr[0:1000000]
def ceria_histo(): def shaded_plot(ax, x, y, idx, col_idx=None, min_val=None): if col_idx is None: col_idx = idx if min_val is None: min_val = np.min(y) cols = [ '#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf' ] xlim = ax.get_xlim() idxs = np.nonzero((x >= xlim[0]) & (x <= xlim[1])) ax.fill_between(x[idxs], y[idxs], min_val, color=cols[col_idx], linestyle='None', lw=0) # ax.plot(x,y+idx*sc, color='k') return fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_00504-v56.epos" epos = apt_fileio.read_epos_numpy(fn) red_epos = epos[100000::10] # Voltage and bowl correct ToF data p_volt = np.array([]) p_bowl = np.array([]) t_i = time.time() _, p_volt, p_bowl = do_voltage_and_bowl(red_epos, p_volt, p_bowl) print("time to voltage and bowl correct: " + str(time.time() - t_i) + " seconds") tof_vcorr = voltage_and_bowl.mod_full_voltage_correction( p_volt, epos['tof'], epos['v_dc']) tof_corr = voltage_and_bowl.mod_geometric_bowl_correction( p_bowl, tof_vcorr, epos['x_det'], epos['y_det']) m2q_roi = [10, 250] m2q_to_tof = 1025 / np.sqrt(172) tof_roi = [m2q_roi[0] * m2q_to_tof, m2q_roi[1] * m2q_to_tof] tof_roi = [200, 1200] cts_per_slice = 2**9 #m2q_roi = [0.9,190] # tof_roi = [0, 1000] t_start = time.time() pointwise_scales, piecewise_scales = scaling_correction.get_all_scale_coeffs( tof_corr, m2q_roi=tof_roi, cts_per_slice=cts_per_slice, max_scale=1.075) t_end = time.time() print('Total Time = ', t_end - t_start) # fake_tof_corr = fake_tof/np.sqrt(pointwise_scales) q_tof_corr = tof_corr / pointwise_scales OVERALL_CALIB_FACTOR = 0.9956265249773827 m2q_corr = OVERALL_CALIB_FACTOR * m2q_to_tof**-2 * q_tof_corr**2 m2q_vbcorr = OVERALL_CALIB_FACTOR * m2q_to_tof**-2 * tof_corr**2 fig = plt.figure(constrained_layout=True, figsize=(FIGURE_SCALE_FACTOR * 3.14961, FIGURE_SCALE_FACTOR * 3.14961), num=8, dpi=100) plt.clf() gs = plt.GridSpec(2, 4, figure=fig) ax0 = fig.add_subplot(gs[0, :]) # identical to ax1 = plt.subplot(gs.new_subplotspec((0, 0), colspan=3)) ax1 = fig.add_subplot(gs[1, 0:2]) #ax2 = fig.add_subplot(gs[1,1]) ax3 = fig.add_subplot(gs[1, 2:4]) dat = m2q_vbcorr user_bin_width = 0.02 user_xlim = [0, 200] ax0.set(xlim=user_xlim) dat = m2q_corr xs, ys = bin_dat(dat, isBinAligned=True, bin_width=user_bin_width, user_roi=user_xlim) shaded_plot(ax0, xs, 10 * (1 + ys), 1, min_val=10) dat = m2q_vbcorr xs, ys = bin_dat(dat, isBinAligned=True, bin_width=user_bin_width, user_roi=user_xlim) shaded_plot(ax0, xs, 1 + ys, 0, min_val=1) ax0.set(xlabel='m/z (Da)', ylabel='counts', xlim=user_xlim) ax0.set_yscale('log') ax0.set(ylim=[10, None]) # user_bin_width = 0.02 user_xlim = [75, 85] ax1.set(xlim=user_xlim) dat = m2q_corr xs, ys = bin_dat(dat, isBinAligned=True, bin_width=user_bin_width, user_roi=user_xlim) shaded_plot(ax1, xs, 10 * (1 + ys), 1, min_val=10) dat = m2q_vbcorr xs, ys = bin_dat(dat, isBinAligned=True, bin_width=user_bin_width, user_roi=user_xlim) shaded_plot(ax1, xs, 1 + ys, 0, min_val=1) ax1.set(xlabel='m/z (Da)', ylabel='counts', xlim=user_xlim) ax1.set_yscale('log') ax1.set(ylim=[10, None]) # # ##user_bin_width = 0.01 #user_xlim = [30,34] #ax2.set(xlim=user_xlim) # # #dat = m2q_corr #xs, ys = bin_dat(dat,isBinAligned=True,bin_width=user_bin_width,user_roi=user_xlim) #shaded_plot(ax2,xs,100*(1+ys),1,min_val=100) # # #dat = epos['m2q'] #xs, ys = bin_dat(dat,isBinAligned=True,bin_width=user_bin_width,user_roi=user_xlim) #shaded_plot(ax2,xs,1+ys,0,min_val=1) # # #ax2.set(xlabel='m/z (Da)', ylabel='counts', xlim=user_xlim) #ax2.set_yscale('log') # user_bin_width = 0.03 user_xlim = [154, 170] ax3.set(xlim=user_xlim) dat = m2q_corr xs, ys = bin_dat(dat, isBinAligned=True, bin_width=user_bin_width, user_roi=user_xlim) shaded_plot(ax3, xs, 10 * (1 + ys), 1, min_val=10) dat = m2q_vbcorr xs, ys = bin_dat(dat, isBinAligned=True, bin_width=user_bin_width, user_roi=user_xlim) shaded_plot(ax3, xs, 1 + ys, 0, min_val=1) ax3.set(xlabel='m/z (Da)', ylabel='counts', xlim=user_xlim) ax3.set_yscale('log') ax3.set(ylim=[10, 1e4]) ax3.set_xticks(np.arange(154, 170 + 1, 4)) fig.tight_layout() fig.savefig( r'Q:\users\bwc\APT\scale_corr_paper\Ceria_NUV_corrected_hist.pdf', format='pdf', dpi=600) return 0
# voltage and bowl correct ToF data. p_volt = np.array([1, 0]) p_volt = np.array([]) p_bowl = np.array([0.89964083, -0.43114144, -0.27484715, -0.25883824]) # only use singles for V+B # subsample down to 1 million ions for speedier computation vb_idxs = np.random.choice(epos_s.size, int(np.min([epos_s.size, 1000 * 1000])), replace=False) vb_epos = epos_s[vb_idxs] tof_sing_corr, p_volt, p_bowl = do_voltage_and_bowl(vb_epos, p_volt, p_bowl) tof_vcorr_fac = voltage_and_bowl.mod_full_voltage_correction( p_volt, np.ones_like(epos['tof']), epos['v_dc']) tof_bcorr_fac = voltage_and_bowl.mod_geometric_bowl_correction( p_bowl, np.ones_like(epos['tof']), epos['x_det'], epos['y_det']) # find the voltage and bowl coefficients for the doubles data tof_vcorr_fac_d = tof_vcorr_fac[doub_idxs] tof_bcorr_fac_d = tof_bcorr_fac[doub_idxs] # Find transform to m/z space m2q_corr, p_m2q = m2q_calib.align_m2q_to_ref_m2q(epos_s['m2q'], tof_sing_corr) epos['m2q'] = m2q_calib.mod_physics_m2q_calibration( p_m2q, mod_full_vb_correction(epos, p_volt, p_bowl)) plotting_stuff.plot_histo(epos['m2q'], fig_idx=1, user_xlim=[0, 250],
from voltage_and_bowl import do_voltage_and_bowl import voltage_and_bowl plt.close('all') fn = r'C:\Users\capli\Google Drive\NIST\pos_and_epos_files\GaN_manuscript\R20_07148-v01_vbm_corr.epos' epos = apt_fileio.read_epos_numpy(fn) # Voltage and bowl correct ToF data p_volt = np.array([]) p_bowl = np.array([]) tof_vbcorr, p_volt, p_bowl = do_voltage_and_bowl(epos,p_volt,p_bowl) tof_vcorr = voltage_and_bowl.mod_full_voltage_correction(p_volt,epos['tof'],epos['v_dc']) tof_bcorr = voltage_and_bowl.mod_geometric_bowl_correction(p_bowl,epos['tof'],epos['x_det'],epos['y_det']) epos_vb = epos.copy() epos_vb['tof'] = tof_vbcorr.copy() user_ylim=[670,740] # Plot raw fig = plt.figure(num=1) ax = fig.gca() delta = 3
fn = r"C:\Users\bwc\Documents\NetBeansProjects\R44_03200\recons\recon-v02\default\R44_03200-v02.epos" epos = apt_fileio.read_epos_numpy(fn) epos_red = epos[0::4] # Voltage and bowl correct ToF data p_volt = np.array([]) p_bowl = np.array([]) t_i = time.time() tof_corr, p_volt, p_bowl = do_voltage_and_bowl(epos_red,p_volt,p_bowl) print("time to voltage and bowl correct: "+str(time.time()-t_i)+" seconds") # Only apply bowl correction tof_bcorr = voltage_and_bowl.mod_geometric_bowl_correction(p_bowl,epos['tof'],epos['x_det'],epos['y_det']) tof_corr = voltage_and_bowl.mod_full_voltage_correction(p_volt,tof_bcorr,epos['v_dc']) laser_df = pd.read_csv(r'C:\Users\bwc\Documents\NetBeansProjects\R44_03200\R44_03200_LaserPositionHist.csv') power_df = pd.read_csv(r'C:\Users\bwc\Documents\NetBeansProjects\R44_03200\R44_03200_LaserPowerHist.csv')
def dummy(): # Voltage and bowl correct ToF data from voltage_and_bowl import do_voltage_and_bowl p_volt = np.array([]) p_bowl = np.array([]) tof_corr, p_volt, p_bowl = do_voltage_and_bowl(epos, p_volt, p_bowl) epos_vb = epos.copy() epos_vb['tof'] = tof_corr.copy() import voltage_and_bowl tof_vcorr = voltage_and_bowl.mod_full_voltage_correction( p_volt, epos['tof'], epos['v_dc']) epos_v = epos.copy() epos_v['tof'] = tof_vcorr.copy() tof_bcorr = voltage_and_bowl.mod_geometric_bowl_correction( p_bowl, epos['tof'], epos['x_det'], epos['y_det']) epos_b = epos.copy() epos_b['tof'] = tof_bcorr.copy() ROI = [0, None] ch = histogram_functions.corrhist(epos) fig1 = plt.figure(num=1) plt.clf() plt.imshow(np.log2(1 + ch)) plt.title('raw') fig1.gca().set_xlim(ROI[0], ROI[1]) fig1.gca().set_ylim(ROI[0], ROI[1]) ch = histogram_functions.corrhist(epos_v) fig2 = plt.figure(num=2) plt.clf() plt.imshow(np.log2(1 + ch)) plt.title('volt') fig2.gca().set_xlim(ROI[0], ROI[1]) fig2.gca().set_ylim(ROI[0], ROI[1]) ch = histogram_functions.corrhist(epos_b) fig3 = plt.figure(num=3) plt.clf() plt.imshow(np.log2(1 + ch)) plt.title('bowl') fig3.gca().set_xlim(ROI[0], ROI[1]) fig3.gca().set_ylim(ROI[0], ROI[1]) ch = histogram_functions.corrhist(epos_vb) fig4 = plt.figure(num=4) plt.clf() plt.imshow(np.log10(1 + ch)) plt.title('v+b') # fig4.gca().set_xlim(ROI[0],ROI[1]) # fig4.gca().set_ylim(ROI[0],ROI[1]) idxs = np.where(epos['ipp'] == 2)[0] fig5 = plt.figure(num=5) plt.clf() dts = np.abs(tof_corr[idxs] - tof_corr[idxs + 1]) plt.hist(dts, bins=np.arange(0, 2000, .5), label='deltaT') plt.hist(tof_corr[np.r_[idxs, idxs + 1]], bins=np.arange(0, 2000, .5), label='since t0') fig66 = plt.figure(num=66) plt.clf() dts = np.abs(tof_corr[idxs] - tof_corr[idxs + 1]) # sus = np.sqrt(tof_corr[idxs]**2+tof_corr[idxs+1]**2) # sus = np.fmax(tof_corr[idxs],tof_corr[idxs+1]) sus = (tof_corr[idxs] + tof_corr[idxs + 1]) / np.sqrt(2) plt.plot(sus, dts, '.', ms=1, alpha=1) # fig66.gca().axis('equal') fig66.gca().set_xlim(0, 7000) fig66.gca().set_ylim(-100, 800) return