def steel():

    # Load and subsample data (for easier processing)
    fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R44_02203-v01.epos"
    epos = apt_fileio.read_epos_numpy(fn)
    epos = epos[100000::10]

    # 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")

    # Only apply bowl correction
    tof_bcorr = voltage_and_bowl.mod_geometric_bowl_correction(
        p_bowl, epos['tof'], epos['x_det'], epos['y_det'])

    # Plot histogram for steel
    fig = plt.figure(figsize=(FIGURE_SCALE_FACTOR * 3.14961,
                              FIGURE_SCALE_FACTOR * 3.14961),
                     num=1,
                     dpi=100)
    plt.clf()
    ax1, ax2 = fig.subplots(2, 1, sharex=True)

    N, x_edges, y_edges = create_histogram(tof_bcorr,
                                           y_roi=[400, 600],
                                           cts_per_slice=2**9,
                                           delta_y=0.25)
    im = plot_2d_histo(ax1, N, x_edges, y_edges)
    #    plt.colorbar(im)
    ax1.set(ylabel='flight time (ns)')

    ax1twin = ax1.twinx()
    ax1twin.plot(epos['v_dc'],
                 '-',
                 linewidth=2,
                 color=mcd.XKCD_COLORS['xkcd:white'])
    ax1twin.set(ylabel='applied voltage (volts)',
                ylim=[0, 6000],
                xlim=[0, 400000])

    N, x_edges, y_edges = create_histogram(tof_corr,
                                           y_roi=[425, 475],
                                           cts_per_slice=2**9,
                                           delta_y=0.25)
    im = plot_2d_histo(ax2, N, x_edges, y_edges)
    #    plt.colorbar(im)

    ax2.set(xlabel='ion sequence', ylabel='corrected flight time (ns)')

    fig.tight_layout()

    fig.savefig(r'Q:\users\bwc\APT\scale_corr_paper\metal_not_wandering.pdf',
                format='pdf',
                dpi=600)

    return 0
Beispiel #2
0
def load_epos(run_number, epos_trim, fig_idx=-1):
    import GaN_data_paths
    import apt_fileio

    #    fn = GaN_data_paths.get_epos_path(run_number=run_number)
    #    fn = fn.rsplit(sep='.', maxsplit=1)[0]+'_vbm_corr.epos'
    #    fn = r"GaN epos files\R20_18162-v01_vbm_corr.epos"
    fn = "GaN epos files\\" + run_number + "-v01_vbm_corr.epos"
    epos = apt_fileio.read_epos_numpy(fn)

    # Plot m2q vs event index and show the current ROI selection
    roi_event_idxs = np.arange(epos_trim[0], epos.size - epos_trim[1])

    if fig_idx > 0:
        ax = plotting_stuff.plot_m2q_vs_time(epos['m2q'],
                                             epos,
                                             fig_idx=fig_idx)
        ax.plot(roi_event_idxs[0] * np.ones(2), [0, 1200], '--k')
        ax.plot(roi_event_idxs[-1] * np.ones(2), [0, 1200], '--k')
        ax.set_title('roi selected to start analysis')

    sub_epos = epos[roi_event_idxs]

    print('ROI includes the following % of events: ',
          sub_epos.size / epos.size)

    return sub_epos
def sio2_R20():

    fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R20_07080-v01.epos"
    epos = apt_fileio.read_epos_numpy(fn)
    #    epos = epos[25000:]
    epos = epos[:400000]

    # 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")

    # Only apply bowl correction
    tof_bcorr = voltage_and_bowl.mod_geometric_bowl_correction(
        p_bowl, epos['tof'], epos['x_det'], epos['y_det'])

    # Plot histogram for sio2
    fig = plt.figure(figsize=(FIGURE_SCALE_FACTOR * 3.14961,
                              FIGURE_SCALE_FACTOR * 3.14961),
                     num=4,
                     dpi=100)
    plt.clf()
    ax1, ax2 = fig.subplots(2, 1, sharex=True)

    N, x_edges, y_edges = create_histogram(tof_bcorr,
                                           y_roi=[320, 380],
                                           cts_per_slice=2**9,
                                           delta_y=.25)
    plot_2d_histo(ax1, N, x_edges, y_edges)
    ax1.set(ylabel='flight time (ns)')

    ax1twin = ax1.twinx()
    ax1twin.plot(epos['v_dc'],
                 '-',
                 linewidth=2,
                 color=mcd.XKCD_COLORS['xkcd:white'])
    ax1twin.set(ylabel='applied voltage (volts)',
                ylim=[0000, 5000],
                xlim=[0, 400000])

    N, x_edges, y_edges = create_histogram(tof_corr,
                                           y_roi=[320, 380],
                                           cts_per_slice=2**9,
                                           delta_y=.25)
    plot_2d_histo(ax2, N, x_edges, y_edges)
    ax2.set(xlabel='ion sequence', ylabel='corrected flight time (ns)')

    fig.tight_layout()

    fig.savefig(r'SiO2_EUV_wandering.pdf', format='pdf', dpi=600)

    return 0
    def get_vb_corr_sio2_tof():
        fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_04472-v03.epos"
        epos = apt_fileio.read_epos_numpy(fn)
        epos = epos[25000:]
        epos = epos[:400000]

        # 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)
        return tof_corr
    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 __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
Beispiel #7
0
from histogram_functions import bin_dat
import scipy.interpolate
import image_registration.register_images

#import sel_align_m2q_log_xcorr

from voltage_and_bowl import do_voltage_and_bowl
import voltage_and_bowl

import colorcet as cc
import matplotlib._color_data as mcd

fn = r'Q:\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\R20_07148-v01.epos'
#fn = r'Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07080-v01_vbmq_corr.epos'
epos = apt_fileio.read_epos_numpy(fn)

sing_tof = epos['tof'][epos['ipp'] == 1]
sing_m2q = epos['m2q'][epos['ipp'] == 1]
sing_x = epos['x_det'][epos['ipp'] == 1]
sing_y = epos['y_det'][epos['ipp'] == 1]
sing_ipp = epos['ipp'][epos['ipp'] == 1]

fig = plt.figure(num=10)
plt.clf()
ax = fig.gca()

#ax.plot(sing_tof[0:-1],sing_tof[1:],',')
ax.plot(sing_m2q[0:-1], sing_m2q[1:], ',')

from matplotlib.colors import LogNorm
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
Beispiel #9
0
from histogram_functions import bin_dat

fns = [
    'R20_18155-v01.epos', 'R20_18156-v01.epos', 'R20_18157-v01.epos',
    '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)
def sio2_R45_corr():

    fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_04472-v03.epos"
    epos = apt_fileio.read_epos_numpy(fn)
    epos = epos[25000:]
    epos = epos[:400000]

    # 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")

    #    fake_tof = np.sqrt((296/312)*epos['m2q']/1.393e-4)

    m2q_roi = [0.8, 80]

    m2q_to_tof = 613 / np.sqrt(59)

    tof_roi = [m2q_roi[0] * m2q_to_tof, m2q_roi[1] * m2q_to_tof]

    cts_per_slice = 2**7
    #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

    #    m2q_corr = epos['m2q']/pointwise_scales

    # Plot histogram for sio2
    fig = plt.figure(figsize=(FIGURE_SCALE_FACTOR * 3.14961,
                              FIGURE_SCALE_FACTOR * 3.14961),
                     num=6,
                     dpi=100)
    plt.clf()
    ax1, ax2 = fig.subplots(2, 1, sharex=True)

    N, x_edges, y_edges = create_histogram(tof_corr,
                                           y_roi=[280, 360],
                                           cts_per_slice=2**9,
                                           delta_y=.25)
    im = plot_2d_histo(ax1, N, x_edges, y_edges)
    plt.colorbar(im)

    ax1.set(ylabel='flight time (ns)')

    ax1twin = ax1.twinx()
    ax1twin.plot(pointwise_scales,
                 '-',
                 linewidth=1,
                 color=mcd.XKCD_COLORS['xkcd:white'])
    ax1twin.set(ylabel='correction factor, c',
                ylim=[0.98, 1.2],
                xlim=[0, 400000])

    N, x_edges, y_edges = create_histogram(q_tof_corr,
                                           y_roi=[280, 360],
                                           cts_per_slice=2**9,
                                           delta_y=.25)
    im = plot_2d_histo(ax2, N, x_edges, y_edges)
    plt.colorbar(im)

    ax2.set(xlabel='ion sequence', ylabel='corrected flight time (ns)')

    fig.tight_layout()
    fig.savefig(r'Q:\users\bwc\APT\scale_corr_paper\SiO2_NUV_corrected.pdf',
                format='pdf',
                dpi=600)

    return 0
def corr_idea():

    fig = plt.figure(num=5)
    plt.close(fig)
    fig = plt.figure(constrained_layout=True,
                     figsize=(FIGURE_SCALE_FACTOR * 3.14961,
                              FIGURE_SCALE_FACTOR * 1.5 * 3.14961),
                     num=5,
                     dpi=100)

    gs = fig.add_gridspec(3, 1)

    ax2 = fig.add_subplot(gs[:2, :])
    ax1 = fig.add_subplot(gs[2, :])

    def shaded_plot(ax, x, y, idx, col_idx=None):
        if col_idx is None:
            col_idx = idx
        sc = 50
        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] + idx * sc, (idx - 0.005) * sc,
                        color=cols[col_idx])
        #    ax.plot(x,y+idx*sc, color='k')
        return

    fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_04472-v02_allVfromAnn.epos"
    epos = apt_fileio.read_epos_numpy(fn)
    epos = epos[25000:]

    # 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")

    # Plot histogram for sio2
    #    fig = plt.figure(figsize=(2*3.14961,2*3.14961),num=654321,dpi=100)
    #    plt.clf()
    #    ax2 = fig.subplots(1,1)
    N, x_edges, y_edges = create_histogram(tof_corr,
                                           y_roi=[80, 400],
                                           cts_per_slice=2**10,
                                           delta_y=0.0625)
    #ax1.imshow(np.log10(1+1*np.transpose(N)), aspect='auto',
    #           extent=extents(x_edges) + extents(y_edges), origin='lower', cmap=cc.cm.CET_L8,
    #           interpolation='bilinear')

    event_idx_range_ref = [0, 0 + 1024]
    event_idx_range_mov = [124000, 124000 + 1024]

    x_centers = edges_to_centers(x_edges)
    idxs_ref = (x_centers >= event_idx_range_ref[0]) & (x_centers <=
                                                        event_idx_range_ref[1])
    idxs_mov = (x_centers >= event_idx_range_mov[0]) & (x_centers <=
                                                        event_idx_range_mov[1])

    ref_hist = np.sum(N[idxs_ref, :], axis=0)
    mov_hist = np.sum(N[idxs_mov, :], axis=0)

    y_centers = edges_to_centers(y_edges)

    ax2.set(xlim=[290, 320])

    N, x_edges, y_edges = create_histogram(0.98 * tof_corr,
                                           y_roi=[80, 400],
                                           cts_per_slice=2**10,
                                           delta_y=0.0625)
    mov_hist = np.sum(N[idxs_mov, :], axis=0)

    shaded_plot(ax2, y_centers, mov_hist, 2, 2)

    N, x_edges, y_edges = create_histogram(0.99 * tof_corr,
                                           y_roi=[80, 400],
                                           cts_per_slice=2**10,
                                           delta_y=0.0625)
    mov_hist = np.sum(N[idxs_mov, :], axis=0)

    shaded_plot(ax2, y_centers, ref_hist, 3, 3)
    shaded_plot(ax2, y_centers, mov_hist, 1, 1)

    N, x_edges, y_edges = create_histogram(1.0 * tof_corr,
                                           y_roi=[80, 400],
                                           cts_per_slice=2**10,
                                           delta_y=0.0625)
    mov_hist = np.sum(N[idxs_mov, :], axis=0)

    shaded_plot(ax2, y_centers, mov_hist, 0, col_idx=0)

    cs = np.linspace(0.975, 1.005, 256)
    dp = np.zeros_like(cs)
    for idx, c in enumerate(cs):
        N, x_edges, y_edges = create_histogram(c * tof_corr,
                                               y_roi=[80, 400],
                                               cts_per_slice=2**10,
                                               delta_y=0.0625)
        mov_hist = np.sum(N[idxs_mov, :], axis=0)
        dp[idx] = np.sum(
            (mov_hist / np.sum(mov_hist)) * (ref_hist / np.sum(ref_hist)))

    ax1.set(xlim=[0.975, 1.005], ylim=[-0.1, 1.1])

    f = scipy.interpolate.interp1d(cs, dp / np.max(dp))

    cols = [
        '#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b',
        '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'
    ]

    xq = [0.98, 0.99017, 1.0]
    for idx in [0, 1, 2]:
        ax1.plot(xq[idx], f(xq[idx]), 'o', markersize=14, color=cols[2 - idx])

    ax1.plot(cs, dp / np.max(dp), 'k')

    ax1.set_xlabel('correction factor, c')
    ax1.set_ylabel('dot product (norm)')

    ax2.set_xlabel('corrected time of flight (ns)')
    ax2.set_ylabel('counts')
    plt.pause(0.1)
    fig.tight_layout()

    fig.savefig(r'Q:\users\bwc\APT\scale_corr_paper\correction_idea.pdf',
                format='pdf',
                dpi=600)

    return 0
def sio2_R44():

    fn = r"C:\Users\bwc\Documents\NetBeansProjects\R44_03200\recons\recon-v02\default\R44_03200-v02.epos"
    epos = apt_fileio.read_epos_numpy(fn)

    # 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")

    # Only apply bowl correction
    tof_bcorr = voltage_and_bowl.mod_geometric_bowl_correction(
        p_bowl, epos['tof'], epos['x_det'], epos['y_det'])

    # Plot histogram for sio2
    fig = plt.figure(figsize=(FIGURE_SCALE_FACTOR * 3.14961,
                              FIGURE_SCALE_FACTOR * 3.14961),
                     num=3,
                     dpi=100)
    plt.clf()
    ax1, ax2 = fig.subplots(2, 1, sharex=True)

    roi = [1400000, 1800000]

    N, x_edges, y_edges = create_histogram(tof_bcorr[roi[0]:roi[1]],
                                           y_roi=[300, 310],
                                           cts_per_slice=2**7,
                                           delta_y=.2)
    im = plot_2d_histo(ax1, N, x_edges, y_edges)
    plt.colorbar(im)

    ax1.set(ylabel='flight time (ns)')

    ax1twin = ax1.twinx()
    ax1twin.plot(epos['v_dc'][roi[0]:roi[1]],
                 '-',
                 linewidth=2,
                 color=mcd.XKCD_COLORS['xkcd:white'])
    ax1twin.set(ylabel='applied voltage (volts)',
                ylim=[0000, 7000],
                xlim=[0, None])

    N, x_edges, y_edges = create_histogram(tof_corr[roi[0]:roi[1]],
                                           y_roi=[300, 310],
                                           cts_per_slice=2**7,
                                           delta_y=0.2)
    im = plot_2d_histo(ax2, N, x_edges, y_edges)
    plt.colorbar(im)

    ax2.set(xlabel='ion sequence', ylabel='corrected flight time (ns)')

    ax2.set_xlim(0, roi[1] - roi[0])

    fig.tight_layout()
    fig.savefig(r'Q:\users\bwc\APT\scale_corr_paper\Figure_R44NUV.pdf',
                format='pdf',
                dpi=600)

    return 0
import m2q_calib
import plotting_stuff
import initElements_P3

import peak_param_determination as ppd

from histogram_functions import bin_dat
from voltage_and_bowl import do_voltage_and_bowl

plt.close('all')

# Read in template spectrum
#ref_fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07263-v02.epos"
ref_fn = r'C:\Users\capli\Google Drive\NIST\pos_and_epos_files\SiO2_Nov092020\R20_07276-v03.epos'

ref_epos = apt_fileio.read_epos_numpy(ref_fn)
#ref_epos = ref_epos[130000:]

# Read in data
#fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07263-v02.epos" # 25 K
#fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07080-v01.epos" # 50 K
#fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07086-v01.epos" # 125 K
#fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07276-v03.epos" # 150 K
fn = r'C:\Users\capli\Google Drive\NIST\pos_and_epos_files\SiO2_Nov092020\R44_03376-v01.epos'

epos = apt_fileio.read_epos_numpy(fn)
#epos = epos[epos.size//2:-1]

# Plot TOF vs event index and show the current ROI selection
#roi_event_idxs = np.arange(1000,epos.size-1000)
roi_event_idxs = np.arange(epos.size)
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
import scipy.interpolate

plt.close('all')

nuv_fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\R45_data\R45_04472-v03.epos"

#euv_fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07263-v02.epos"
euv_fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07080-v01.epos"
#euv_fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07086-v01.epos"
#euv_fn = r"Q:\NIST_Projects\EUV_APT_IMS\BWC\Final EPOS for APL Mat Paper\R20_07276-v03.epos"

#epos = apt_fileio.read_epos_numpy(nuv_fn)
#plotting_stuff.plot_TOF_vs_time(epos['m2q'],epos,1,clearFigure=True,user_ylim=[0,150])

epos = apt_fileio.read_epos_numpy(euv_fn)
#epos = apt_fileio.read_epos_numpy(nuv_fn)
plotting_stuff.plot_TOF_vs_time(epos['m2q'],
                                epos,
                                1,
                                clearFigure=True,
                                user_ylim=[0, 80])

cts_per_slice = 2**10
#m2q_roi = [0.9,190]
m2q_roi = [0.8, 80]
import time
t_start = time.time()
pointwise_scales, piecewise_scales = sel_align_m2q_log_xcorr.get_all_scale_coeffs(
    epos['m2q'], m2q_roi=m2q_roi, cts_per_slice=cts_per_slice, max_scale=1.15)
t_end = time.time()
def testing():
    
    # 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"C:\Users\bwc\Documents\NetBeansProjects\R44_03115\recons\recon-v02\default\R44_03115-v02.epos"
    
    epos = apt_fileio.read_epos_numpy(fn)
#    epos = epos[0:1000000]    
    
    epos1 = epos[0:-1:2]
    epos2 = epos[1::2]


    
    
    N_lower = 8
    N_upper = 16
    N = N_upper-N_lower+1
    slicings = np.logspace(N_lower,N_upper,N,base=2)
    
    
    opt_res = np.zeros(N)
    time_res = np.zeros(N)

    for idx,cts_per_slice in enumerate(slicings):
        m2q_roi = [0.9,180]
        
        import time
        t_start = time.time()
        pointwise_scales,piecewise_scales = get_all_scale_coeffs(epos1['m2q'],
                                                                 m2q_roi=m2q_roi,
                                                                 cts_per_slice=cts_per_slice,
                                                                 max_scale=1.15)
        t_end = time.time()
        time_res[idx] = t_end-t_start
        print('Total Time = ',time_res[idx])
        
        
        # Compute corrected data
        m2q_corr = epos2['m2q']/pointwise_scales
            
        _, ys = bin_dat(m2q_corr,isBinAligned=True,bin_width=0.01,user_roi=[0,250])
    
        opt_res[idx] = chi2(ys)
#        ys = ys/np.sum(ys)
#        opt_res[idx] = np.sum(np.square(ys))
#        opt_res[idx] = test_1d_vec(m2q_corr[(m2q_corr>0.8) & (m2q_corr<80)])
        print(opt_res[idx])
        
    print(slicings)
    print(opt_res/np.max(opt_res))
    print(time_res)
    
    
    
    fig = plt.figure(num=666)
    fig.clear()
    ax = fig.gca()

    ax.plot(tmpx,tmpy,'s-', 
            markersize=8,label='SiO2')

    ax.plot(slicings,opt_res/np.max(opt_res),'o-', 
            markersize=8,label='ceria')
    ax.set(xlabel='N (events per chunk)', ylabel='compactness metric (normalized)')
    ax.set_xscale('log')    

    
    ax.legend()
       
    ax.set_xlim(5,1e5)
    ax.set_ylim(0.15, 1.05)


    fig.tight_layout()
    
    
    return 0   
def sio2_R45_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)

        sc = 150
        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_04472-v03.epos"
    epos = apt_fileio.read_epos_numpy(fn)
    epos = epos[25000:]
    epos = epos[:400000]

    # 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")

    #    fake_tof = np.sqrt((296/312)*epos['m2q']/1.393e-4)

    m2q_roi = [0.8, 80]

    m2q_to_tof = 613 / np.sqrt(59)

    tof_roi = [m2q_roi[0] * m2q_to_tof, m2q_roi[1] * m2q_to_tof]

    cts_per_slice = 2**7
    #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 = 1.0047693561704287

    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=7,
                     dpi=100)
    plt.clf()

    gs = plt.GridSpec(2, 3, 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])

    dat = m2q_vbcorr
    user_bin_width = 0.02
    user_xlim = [0, 65]
    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, 100 * (1 + ys), 1, min_val=100)

    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')

    #    user_bin_width = 0.02
    user_xlim = [13, 19]
    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, 100 * (1 + ys), 1, min_val=100)

    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')

    #
    #
    ##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.01
    user_xlim = [58, 64]
    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, 100 * (1 + ys), 1, min_val=100)

    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')

    ax0.set(ylim=[1, None])
    ax1.set(ylim=[1, None])
    #    ax2.set(ylim=[1,None])
    ax3.set(ylim=[1, None])

    fig.tight_layout()

    fig.savefig(
        r'Q:\users\bwc\APT\scale_corr_paper\SiO2_NUV_corrected_hist.pdf',
        format='pdf',
        dpi=600)

    return 0
Beispiel #18
0
#    return index.reshape(-1, k)

def cartesian_product(arrays):
    ndim = len(arrays)
    return np.stack(np.meshgrid(*arrays), axis=-1).reshape(-1, ndim)





plt.close('all')

fn_R44 = r'C:\Users\capli\Google Drive\NIST\pos_and_epos_files\MgO\R44_03636-v01.epos'
fn_R20 = r'C:\Users\capli\Google Drive\NIST\pos_and_epos_files\MgO\R20_08084-v01.epos'

ref_epos = apt_fileio.read_epos_numpy(fn_R44)

epos_R20 = apt_fileio.read_epos_numpy(fn_R20)
epos_R20 = epos_R20[20000:]
epos_R44 = apt_fileio.read_epos_numpy(fn_R44)

# voltage and bowl correct ToF data.  
p_volt = np.array([])
p_bowl = np.array([ 0.89964083, -0.43114144, -0.27484715, -0.25883824])


_, p_volt_R44, p_bowl_R44 = do_voltage_and_bowl(epos_R44[epos_R44['ipp']==1],p_volt,p_bowl)        
_, p_volt_R20, p_bowl_R20 = do_voltage_and_bowl(epos_R20[epos_R20['ipp']==1],p_volt,p_bowl)   


# Find transform to m/z space