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], user_bin_width=0.03) import GaN_fun pk_data = GaN_type_peak_assignments.GaN_with_H() bg_rois = [[0.4, 0.9]] pk_params, glob_bg_param, Ga1p_idxs, Ga2p_idxs = GaN_fun.fit_spectrum( epos=epos, pk_data=pk_data, peak_height_fraction=0.05, bg_rois=bg_rois) cts, compositions, is_peak = GaN_fun.count_and_get_compositions( epos=epos, pk_data=pk_data, pk_params=pk_params, glob_bg_param=glob_bg_param,
def __main__(): plt.close('all') # # Load data fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_00504-v56.epos" fn = r"\\cfs2w.campus.nist.gov\647\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_04472-v02_allVfromAnn.epos" #fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\R20_07148-v01_vbm_corr.epos" #fn = r"D:\Users\clifford\Documents\Python Scripts\NIST_DATA\R20_07094-v03.epos" #fn = r"D:\Users\clifford\Documents\Python Scripts\NIST_DATA\R45_04472-v03.epos" #fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07263-v02.epos" #fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07080-v01.epos" #fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07086-v01.epos" #fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07276-v03.epos" # fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_04472-v03.epos" #fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_04472-v02.epos" # fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\R20_07148-v01.epos" # Mg doped # fn = fn[:-5]+'_vbm_corr.epos' epos = apt_fileio.read_epos_numpy(fn) # plotting_stuff.plot_TOF_vs_time(epos['m2q'],epos,1,clearFigure=True,user_ylim=[0,150]) # epos = epos[0:2**20] cts_per_slice=2**10 m2q_roi = [0.8,75] import time t_start = time.time() pointwise_scales,piecewise_scales = get_all_scale_coeffs(epos['m2q'], m2q_roi=m2q_roi, cts_per_slice=cts_per_slice, max_scale=1.15) t_end = time.time() print('Total Time = ',t_end-t_start) # Plot histogram in log space lys_corr = np.log(epos['m2q'])-np.log(pointwise_scales) N,x_edges,ly_edges = create_histogram(lys_corr,y_roi=m2q_roi,cts_per_slice=cts_per_slice) # fig = plt.figure(figsize=(8,8)) # plt.imshow(np.log1p(np.transpose(N)), aspect='auto', interpolation='none', # extent=extents(x_edges) + extents(ly_edges), origin='lower') # # Compute corrected data m2q_corr = epos['m2q']/pointwise_scales # Plot data uncorrected and corrected TEST_PEAK = 32 ax = plotting_stuff.plot_TOF_vs_time(epos['m2q'],epos,111,clearFigure=True,user_ylim=[0,75]) ax.plot(pointwise_scales*TEST_PEAK) plotting_stuff.plot_TOF_vs_time(m2q_corr,epos,222,clearFigure=True,user_ylim=[0,75]) # Plot histograms uncorrected and corrected plotting_stuff.plot_histo(m2q_corr,333,user_xlim=[0, 75],user_bin_width=0.01) plotting_stuff.plot_histo(epos['m2q'],333,user_xlim=[0, 75],clearFigure=False,user_bin_width=0.01) # epos['m2q'] = m2q_corr # apt_fileio.write_epos_numpy(epos,'Q:\\NIST_Projects\\EUV_APT_IMS\\BWC\\GaN epos files\\R20_07148-v01_vbmq_corr.epos') _, ys = bin_dat(m2q_corr,isBinAligned=True,bin_width=0.01,user_roi=[0,75]) print(np.sum(np.square(ys))) return 0
# custom imports import apt_fileio import plotting_stuff import initElements_P3 import peak_param_determination as ppd from histogram_functions import bin_dat # Read in data fn = r'C:\Users\capli\Downloads\JAVASS_R44_03187-v01.epos' epos = apt_fileio.read_epos_numpy(fn) plotting_stuff.plot_histo(epos['m2q'],1) isSingle = np.nonzero(epos['ipp'] == 1) ed = initElements_P3.initElements() pk_data = np.array( [ (1, ed['Si'].isotopes[28][0]/2), (1, ed['Si'].isotopes[29][0]/2), (1, ed['Si'].isotopes[30][0]/2), (1, ed['Si'].isotopes[28][0]), (1, ed['Si'].isotopes[29][0]), (1, ed['Si'].isotopes[30][0])], dtype=[('Si','i4'),('m2q','f4')] ) pk_params = ppd.get_peak_ranges(epos,pk_data['m2q'],peak_height_fraction=0.01)
p_volt = np.array([]) p_bowl = np.array([]) # 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) # 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) import GaN_fun pk_data = GaN_type_peak_assignments.GaN_with_H() bg_rois=[[0.4,0.9]] pk_params, glob_bg_param, Ga1p_idxs, Ga2p_idxs = GaN_fun.fit_spectrum( epos=epos, pk_data=pk_data, peak_height_fraction=0.1, bg_rois=bg_rois) cts, compositions, is_peak = GaN_fun.count_and_get_compositions( epos=epos,
# 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, p_volt, p_bowl) print("time to voltage and bowl correct: " + str(time.time() - t_i) + " seconds") # Find c and t0 for ToF data based on aligning to reference spectrum m2q_corr, p_m2q = m2q_calib.align_m2q_to_ref_m2q(ref_epos['m2q'], tof_corr, nom_voltage=np.mean( epos['v_dc'])) print(p_m2q) plotting_stuff.plot_histo(ref_epos['m2q'], 4, user_label='ref') plotting_stuff.plot_histo(m2q_corr[m2q_corr.size // 2:-1], 4, clearFigure=False, user_label='[c,t0] corr') xs, ys = bin_dat(tof_corr, isDensity=True, bin_width=0.25) bg_lvl = np.mean(ys[(xs > 1000) & (xs < 3500)]) idxs = np.nonzero((xs > 200) & (xs < 1000)) xs = xs[idxs] ys = ys[idxs] fig = plt.figure(num=113)
ed = initElements_P3.initElements() ref_pk_m2qs = np.array([ ed['H'].isotopes[1][0], ed['Si'].isotopes[28][0] / 3, ed['Si'].isotopes[28][0] / 2, ed['O'].isotopes[16][0] / 1, (ed['Si'].isotopes[28][0] + ed['O'].isotopes[16][0]) / 2, ed['O'].isotopes[16][0] * 2, (ed['Si'].isotopes[28][0] + ed['O'].isotopes[16][0]) / 1, (ed['Si'].isotopes[28][0] + 2 * ed['O'].isotopes[16][0]) / 1 ]) # Perform 'linearization' m2q calibration m2q_corr2 = m2q_calib.calibrate_m2q_by_peak_location(m2q_corr_q, ref_pk_m2qs) # Plot the reference spectrum, (c, t0) corr spectrum and linearized spectrum # to confirm that mass calibration went ok plotting_stuff.plot_histo(ref_epos['m2q'], fig_idx=4, user_label='ref') plotting_stuff.plot_histo(m2q_corr_q, fig_idx=4, clearFigure=False, user_label='[c,t0] corr') ax = plotting_stuff.plot_histo(m2q_corr2, 4, clearFigure=False, user_label='linearized') for ref_pk_m2q in ref_pk_m2qs: ax.plot(ref_pk_m2q * np.ones(2), np.array([1, 1e4]), 'k--') # Save the data as a new epos file epos['m2q'] = m2q_corr2 new_fn = fn[:-5] + '_vbmq_corr.epos' apt_fileio.write_epos_numpy(epos, new_fn)
def __main__(): plt.close('all') # # Load data fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_00504-v56.epos" #fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\R20_07148-v01_vbm_corr.epos" #fn = r"D:\Users\clifford\Documents\Python Scripts\NIST_DATA\R20_07094-v03.epos" #fn = r"D:\Users\clifford\Documents\Python Scripts\NIST_DATA\R45_04472-v03.epos" #fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07263-v02.epos" #fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07080-v01.epos" #fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07086-v01.epos" #fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07276-v03.epos" # fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_04472-v03.epos" #fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_04472-v02.epos" # fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\R20_07148-v01.epos" # Mg doped # fn = fn[:-5]+'_vbm_corr.epos' epos = apt_fileio.read_epos_numpy(fn) # plotting_stuff.plot_TOF_vs_time(epos['m2q'],epos,1,clearFigure=True,user_ylim=[0,150]) epos = epos[0:2**20] cts_per_slice = 2**10 #m2q_roi = [0.9,190] m2q_roi = [0.8, 80] # m2q_roi = [60,100] import time t_start = time.time() pointwise_scales, piecewise_scales = get_all_scale_coeffs( epos['m2q'], m2q_roi=m2q_roi, cts_per_slice=cts_per_slice, max_scale=1.15) t_end = time.time() print('Total Time = ', t_end - t_start) # Plot histogram in log space lys_corr = np.log(epos['m2q']) - np.log(pointwise_scales) N, x_edges, ly_edges = create_histogram(lys_corr, y_roi=m2q_roi, cts_per_slice=cts_per_slice) fig = plt.figure(figsize=(8, 8)) plt.imshow(np.log1p(np.transpose(N)), aspect='auto', interpolation='none', extent=extents(x_edges) + extents(ly_edges), origin='lower') # Compute corrected data m2q_corr = epos['m2q'] / pointwise_scales # Plot data uncorrected and corrected TEST_PEAK = 32 ax = plotting_stuff.plot_TOF_vs_time(epos['m2q'], epos, 111, clearFigure=True, user_ylim=[0, 150]) ax.plot(pointwise_scales * TEST_PEAK) plotting_stuff.plot_TOF_vs_time(m2q_corr, epos, 222, clearFigure=True, user_ylim=[0, 150]) # Plot histograms uncorrected and corrected plotting_stuff.plot_histo(m2q_corr, 333, user_xlim=[0, 150]) plotting_stuff.plot_histo(epos['m2q'], 333, user_xlim=[0, 150], clearFigure=False) #import pandas as pd # # #fig = plt.figure(figsize=(8,8)) #ax = fig.gca() # #df = pd.read_csv(r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_04472_LaserPositionHist.csv") #ax.plot(df['Ion Sequence Number'],df['Laser X Position (mic)']) #ax.plot(df['Ion Sequence Number'],df['Laser Y Position (mic)']) #ax.plot(df['Ion Sequence Number'],df['Laser Z Position (mic)']) # #ax.clear() #ax.plot(pointwise_scales) #ax.grid() #ax.plot(np.convolve(np.diff(epos['v_dc']),np.ones(101)/101,mode='same')+1) ##ax.plot(np.convolve(np.diff(epos['v_dc']),np.ones(1)/1,mode='same')+1) # # #wall_time = np.cumsum(epos['pslep'])/500000.0 # #dt = ppd.moving_average(np.diff(wall_time),n=512) #ra = 1/dt # #fig = plt.figure(figsize=(8,8)) #ax = fig.gca() #ax.plot(ra) # #dsc_pointwise = np.r_[np.diff(pointwise_scales),0] # ##ax.plot(dsc_pointwise*10000000) # #ax.plot((pointwise_scales-1)*100000/3) # #ax.plot((pointwise_scales-1)*100/3) # # #fig = plt.gcf() #ax = fig.gca() # dsc = np.r_[np.diff(piecewise_scales), 0] #fig = plt.figure(figsize=(8,8)) #ax = fig.gca() #ax.plot(dsc) #fig = plt.figure(figsize=(8,8)) #ax = fig.gca() ax.hist(dsc, bins=64, range=[-0.01, 0.01]) dsc_cut = scipy.stats.trimboth(dsc, 0.025) outlier_lims = [ np.mean(dsc_cut) - 7 * np.std(dsc_cut), np.mean(dsc_cut) + 7 * np.std(dsc_cut) ] epos['m2q'] = m2q_corr #apt_fileio.write_epos_numpy(epos,'Q:\\NIST_Projects\\EUV_APT_IMS\\BWC\\GaN epos files\\R20_07148-v01_vbmq_corr.epos') return 0
markersize=1, marker='.', markeredgecolor='tab:blue') ax.set(xlabel='ion index (thousands)', ylabel='ToF (ns)', ylim=user_ylim) ax_twin = ax.twinx() ax_twin.plot(np.arange(0,epos.size,STEP )/1000,epos['v_dc'][0::STEP ], color='tab:orange', lw=2) ax_twin.set(ylabel='V_dc') fig.savefig('APT_Soft_volt.png') # Plot raw ax = plotting_stuff.plot_histo(epos['tof'],fig_idx=3,user_label='raw tof', user_bin_width=0.25, user_xlim=[0,1000]) # Plot raw ax = plotting_stuff.plot_histo(tof_vbcorr,fig_idx=3,user_label='V+B corrected tof', user_bin_width=0.25, user_xlim=[0,1000], clearFigure=False) ax.set(ylim=[5e1,1e6]) plt.gcf().savefig('APT_Soft_corr_histos.png') fig = plt.figure(num=3) ax = fig.gca() delta = 3 # Plot x cut STEP = 10 ax.plot(np.arange(0,epos.size,STEP )/1000,tof_bcorr[0::STEP ],'.',
csr = np.full(len(idxs_list), -1.0) Ga_comp = np.full(len(idxs_list), -1.0) Ga_comp_std = np.full(len(idxs_list), -1.0) Ga_comp_glob = np.full(len(idxs_list), -1.0) Ga_comp_std_glob = np.full(len(idxs_list), -1.0) keys = list(pk_data.dtype.fields.keys()) keys.remove('m2q') Ga_idx = keys.index('Ga') for loop_idx, idxs in enumerate(idxs_list): sub_epos = epos[idxs[0]:idxs[1]] plotting_stuff.plot_histo(sub_epos['m2q'], 321, user_xlim=[0, 275], user_bin_width=0.1, user_label=loop_idx) plt.waitforbuttonpress() # r = np.sqrt(sub_epos['x_det']**2+sub_epos['y_det']**2) # sub_idxs = np.nonzero(r>=0) # cts = ppd.do_counting(sub_epos[sub_idxs],pk_params,glob_bg_param) # # tot_bg_ct = epos['m2q'][(epos['m2q']>=80) & (epos['m2q']<=120)].size # sub_bg_ct = sub_epos['m2q'][(sub_epos['m2q']>=80) & (sub_epos['m2q']<=120)].size # # loc_bg_param = glob_bg_param*sub_bg_ct/tot_bg_ct glob_bg_param_chunk = ppd.get_glob_bg(sub_epos['m2q'], rois=bg_rois) cts = ppd.do_counting(sub_epos, pk_params, glob_bg_param_chunk) Ga_comp[loop_idx] = ppd.do_composition(pk_data, cts)[0][0][Ga_idx]
label='Y') #ax.set_xlim(start_idx,epos.size) ax.set_ylim(85,90) ax.set_ylim(0,1000) fig.tight_layout() plotting_stuff.plot_histo(epos['m2q'],131131,user_label='raw') plotting_stuff.plot_histo(epos['m2q']/pointwise_scales,131131,user_label='corr',clearFigure=False) cts_per_slice=2**12 import time t_start = time.time() pointwise_scales,piecewise_scales = sel_align_m2q_log_xcorr_v2.get_all_scale_coeffs(epos['m2q'], m2q_roi=[0.8,80], cts_per_slice=cts_per_slice, max_scale=1.15) t_end = time.time() print('Total Time = ',t_end-t_start)
ref_pk_m2qs = np.array([ ed['H'].isotopes[1][0], 2 * ed['H'].isotopes[1][0], (1 / 2) * ed['N'].isotopes[14][0], ed['N'].isotopes[14][0], 2 * ed['N'].isotopes[14][0], (1 / 2) * ed['Ga'].isotopes[69][0], (1 / 2) * ed['Ga'].isotopes[71][0], ed['Ga'].isotopes[69][0], ed['Ga'].isotopes[71][0] ]) # Perform 'linearization' m2q calibration m2q_corr2 = m2q_calib.calibrate_m2q_by_peak_location(m2q_corr, ref_pk_m2qs) # Plot the reference spectrum, (c, t0) corr spectrum and linearized spectrum # to confirm that mass calibration went ok user_xlim = [0, 150] plotting_stuff.plot_histo(ref_epos['m2q'], 4, user_label='ref', user_xlim=user_xlim) plotting_stuff.plot_histo(m2q_corr, 4, clearFigure=False, user_label='[c,t0] corr', user_xlim=user_xlim) ax = plotting_stuff.plot_histo(m2q_corr2, 4, clearFigure=False, user_label='linearized', user_xlim=user_xlim) for ref_pk_m2q in ref_pk_m2qs: ax.plot(ref_pk_m2q * np.ones(2), np.array([1, 1e4]), 'k--') # Save the data as a new epos file
scales_short = 10.0**((shifts0 + shifts1) * (y_edges[1] - y_edges[0])) fig = plt.figure(figsize=(8, 8)) ax = fig.gca() ax.plot(scales_short, 'o-') m2q_corr = epos['m2q'] / scales plotting_stuff.plot_TOF_vs_time(m2q_corr, epos, 111, clearFigure=True, user_ylim=[0, 150]) plotting_stuff.plot_histo(m2q_corr, 222, user_xlim=[0, 200]) plotting_stuff.plot_histo(epos['m2q'], 222, user_xlim=[0, 200], clearFigure=False) # #dsc = np.r_[np.diff(scales_short),0] #fig = plt.figure(figsize=(8,8)) #ax = fig.gca() #ax.plot(dsc) # #fig = plt.figure(figsize=(8,8)) #ax = fig.gca() # #ax.hist(dsc,bins=512,range=[-0.01,0.01])
ax.axis('equal') ax.axis('square') ax.set_xlabel('x') ax.set_ylabel('y') vc = np.sqrt(5000) / np.sqrt(epos['v_dc']) plotting_stuff.plot_TOF_vs_time(epos['tof'] / vc, epos, 1, user_ylim=[0, 5000]) # Find transform to m/z space epos_R44['m2q'], p_m2q_R44 = m2q_calib.align_m2q_to_ref_m2q( ref_epos['m2q'], mod_full_vb_correction(epos_R44, p_volt_R44, p_bowl_R44)) epos_R20['m2q'], p_m2q_R20 = m2q_calib.align_m2q_to_ref_m2q( ref_epos['m2q'], mod_full_vb_correction(epos_R20, p_volt_R20, p_bowl_R20)) plotting_stuff.plot_histo(epos_R44['m2q'], fig_idx=1, user_label='R44', scale_factor=1 / epos_R44.size) plotting_stuff.plot_histo(epos_R20['m2q'], fig_idx=1, user_label='R20', clearFigure=False, scale_factor=1 / epos_R20.size) # Make a correlation histogram of doubles epos_vb_R44 = epos_R44.copy() epos_vb_R44['tof'] = np.sqrt(1e4 * epos_R44['m2q']) edges, ch = corrhist(epos_vb_R44, roi=[0, 1000], delta=1) centers = (edges[1:] + edges[:-1]) / 2.0 fig2 = plt.figure(num=3)
bin_dat(q_tof[1::2], isBinAligned=True, bin_width=0.1, user_roi=tof_roi)[1]) plt.plot(x, y, label='ref2') plt.figure(32132313) pointwise_scales, piecewise_scales = scaling_correction.get_all_scale_coeffs( varying_tof, m2q_roi=tof_roi, cts_per_slice=2**6, max_scale=1.075, delta_ly=1e-4) ax = plotting_stuff.plot_histo(q_tof, 4, user_xlim=[0, 800], user_bin_width=0.1, user_label='orig') ax = plotting_stuff.plot_histo(varying_tof, 4, clearFigure=False, user_xlim=[0, 800], user_bin_width=0.1, user_label='messed') ax = plotting_stuff.plot_histo(varying_tof / pointwise_scales, 4, clearFigure=False, user_xlim=[0, 800], user_bin_width=0.1, user_label='messed')
'R20_18160-v01.epos', 'R20_18161-v01.epos', 'R20_18162-v01.epos' ] fold = "GaN epos files" fig = plt.figure(1) fig.clf() ax = fig.gca() for i in range(len(fns)): epos = apt_fileio.read_epos_numpy(fold + "\\" + fns[i]) plotting_stuff.plot_histo( epos['m2q'], 1, user_label=fns[i], clearFigure=False, user_xlim=[0, 100], user_bin_width=0.03, scale_factor=10**i, user_color=None, ) CSR = [0.038, 0.005, 0.1, 0.09, 0.24, 0.01] N = [34.1, 17, 41.5, 40.5, 49.7, 23.2] Ga = [65.9, 83, 58.5, 59.5, 53.3, 76.8] fig = plt.figure(5) plt.plot(CSR, Ga, 'ko', label="Ga") plt.plot(CSR, N, 'rs', label="N") plt.xscale('log') plt.legend() #fn = fold+"\\"+'R20_18161-v01.epos'