Esempio n. 1
0
def plot_spectrum_gory_detail(epos, user_roi, pk_params, bg_rois,
                              glob_bg_param, is_peak, fig_idx):
    from histogram_functions import bin_dat
    import peak_param_determination as ppd

    xs, ys = bin_dat(epos['m2q'], user_roi=user_roi, isBinAligned=True)
    #ys_sm = ppd.do_smooth_with_gaussian(ys,30)
    ys_sm = ppd.moving_average(ys, 30)

    glob_bg = ppd.physics_bg(xs, glob_bg_param)

    fig = plt.figure(num=fig_idx)
    fig.clear()
    ax = fig.gca()

    ax.plot(xs, ys_sm, label='hist')
    ax.plot(xs, glob_bg, label='global bg')

    ax.set(xlabel='m/z (Da)', ylabel='counts')
    ax.grid()
    fig.tight_layout()
    fig.canvas.manager.window.raise_()
    ax.set_yscale('log')
    ax.legend()

    for idx, pk_param in enumerate(pk_params):

        if is_peak[idx]:
            ax.plot(
                np.array([1, 1]) * pk_param['pre_rng'],
                np.array([0.5, (pk_param['amp'] + pk_param['off'])]), 'k--')
            ax.plot(
                np.array([1, 1]) * pk_param['post_rng'],
                np.array([0.5, (pk_param['amp'] + pk_param['off'])]), 'k--')
            ax.plot(
                np.array([1, 1]) * pk_param['pre_bg_rng'],
                np.array([0.5, (pk_param['amp'] + pk_param['off'])]), 'm--')
            ax.plot(
                np.array([1, 1]) * pk_param['post_bg_rng'],
                np.array([0.5, (pk_param['amp'] + pk_param['off'])]), 'm--')

            ax.plot(
                np.array([pk_param['pre_bg_rng'], pk_param['post_bg_rng']]),
                np.ones(2) * pk_param['loc_bg'], 'g--')
        else:
            ax.plot(
                np.array([1, 1]) * pk_param['x0_mean_shift'],
                np.array([0.5, (pk_param['amp'] + pk_param['off'])]), 'r--')

    for roi in bg_rois:
        xbox = np.array([roi[0], roi[0], roi[1], roi[1]])
        ybox = np.array([0.1, np.max(ys_sm) / 10, np.max(ys_sm) / 10, 0.1])

        ax.fill(xbox, ybox, 'b', alpha=0.2)

    plt.pause(0.1)

    return None
Esempio n. 2
0
def bin_and_smooth_spectrum(epos, user_roi, bin_wid_mDa=30, smooth_wid_mDa=-1):
    from histogram_functions import bin_dat
    import peak_param_determination as ppd

    xs, ys = bin_dat(epos['m2q'],
                     user_roi=user_roi,
                     isBinAligned=True,
                     bin_width=bin_wid_mDa / 1000.0)
    if smooth_wid_mDa > 0:
        ys_sm = ppd.moving_average(ys, smooth_wid) * smooth_wid
    else:
        ys_sm = ys
    return (xs, ys_sm)
Esempio n. 3
0
print('Total Ranged Global Background Ions: ' + str(np.sum(cts['global_bg'])))
print('Total Ions: ' + str(epos.size))

print('Overall CSR (no bg)    : ' +
      str(np.sum(cts['total'][Ga2p_idxs]) / np.sum(cts['total'][Ga1p_idxs])))
print('Overall CSR (local bg) : ' + str(
    (np.sum(cts['total'][Ga2p_idxs]) - np.sum(cts['local_bg'][Ga2p_idxs])) /
    (np.sum(cts['total'][Ga1p_idxs]) - np.sum(cts['local_bg'][Ga1p_idxs]))))
print('Overall CSR (global bg): ' + str(
    (np.sum(cts['total'][Ga2p_idxs]) - np.sum(cts['global_bg'][Ga2p_idxs])) /
    (np.sum(cts['total'][Ga1p_idxs]) - np.sum(cts['global_bg'][Ga1p_idxs]))))

# Plot all the things
xs, ys = bin_dat(epos['m2q'], user_roi=[0.5, 100], isBinAligned=True)
#ys_sm = ppd.do_smooth_with_gaussian(ys,10)
ys_sm = ppd.moving_average(ys, 10)

glob_bg = ppd.physics_bg(xs, glob_bg_param)

fig = plt.figure(num=100)
fig.clear()
ax = fig.gca()

ax.plot(xs, ys_sm, label='hist')
ax.plot(xs, glob_bg, label='global bg')

ax.set(xlabel='m/z (Da)', ylabel='counts')
ax.grid()
fig.tight_layout()
fig.canvas.manager.window.raise_()
ax.set_yscale('log')
#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()
print('Total Time = ', t_end - t_start)

# Compute corrected data
m2q_corr = epos['m2q'] / pointwise_scales

wall_time = np.cumsum(epos['pslep']) / 10000.0
wall_time = np.cumsum(epos['pslep']) / 500000.0

dt = ppd.moving_average(np.diff(wall_time), n=512)
ra = 1 / dt

pks = [14, 16, 32.2, 44.3, 60.3]
#pks = [14,16,32,44,60]
wid = 1

mask = None
for pk in pks:
    if mask is None:
        mask = np.abs(m2q_corr - pk) <= wid / 2
    else:
        mask = mask | (np.abs(m2q_corr - pk) <= wid / 2)

fig = plt.figure(num=111)
ax = fig.gca()