Example #1
0
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
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
Example #3
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
Example #4
0
    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]
Example #5
0
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
Example #6
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
Example #7
0
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
Example #8
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
Example #9
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
Example #10
0
epos_d = epos[doub_idxs]

# 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))
ax = plotting_stuff.plot_TOF_vs_time(epos['tof'], epos, 1)
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')
epos = epos[roi_event_idxs]

# Compute some extra information from epos information
wall_time = np.cumsum(epos['pslep']) / 10000.0
pulse_idx = np.arange(0, epos.size)
isSingle = np.nonzero(epos['ipp'] == 1)

# 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)
#
import sel_align_m2q_log_xcorr
pointwise_scales, piecewise_scales = sel_align_m2q_log_xcorr.get_all_scale_coeffs(
    m2q_corr, m2q_roi=[0.5, 75], cts_per_slice=2**8, max_scale=1.15)
# Compute corrected data
m2q_corr_q = m2q_corr / pointwise_scales

# Convert back to tof
tof_corr_q = np.sqrt(m2q_corr_q / (p_m2q[0] * 1e-4)) + p_m2q[1]
Example #12
0
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
Example #13
0
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
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)