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
ppd.pretty_print_compositions(compositions,pk_data) # Plot the full spectrum xs, ys_sm = GaN_fun.bin_and_smooth_spectrum(epos=epos, user_roi=[0,150], bin_wid_mDa=30, smooth_wid_mDa=-1) fig = plt.figure(num=1) fig.set_size_inches(w=6.69, h=3) fig.clear() ax = fig.gca() ax.plot(xs, ys_sm, lw=1, label='full spec',color='k') glob_bg = ppd.physics_bg(xs,glob_bg_param) ax.plot(xs, glob_bg, lw=1, label='bg', alpha=1,color='r') ax.set_xlim(0,100) ax.set_ylim(1e1,5e4) ax.grid(b=True) ax.set(xlabel='m/z', ylabel='counts') ax.set_yscale('log') ax.legend() fig.tight_layout() fig.savefig('GaN_full_spectrum.pdf') fig.savefig('GaN_full_spectrum.jpg', dpi=300)
ppd.pretty_print_compositions(compositions, pk_data) # Plot the full spectrum xs, ys_sm = GaN_fun.bin_and_smooth_spectrum(epos=epos, user_roi=[0, 150], bin_wid_mDa=100, smooth_wid_mDa=-1) fig = plt.figure(num=1) fig.set_size_inches(w=3.5, h=2) fig.clear() ax = fig.gca() ax.plot(xs, ys_sm, lw=1, label='full spec', color='k') glob_bg = ppd.physics_bg(xs, glob_bg_param) ax.plot(xs, glob_bg, lw=1, label='bg', alpha=1, color='r') ax.set_xlim(0, 80) ax.set_ylim(1e1, 5e4) ax.grid(b=True) ax.set(xlabel='m/z', ylabel='counts') ax.set_yscale('log') ax.legend() fig.tight_layout() fig.savefig('AlGaN_full_spectrum.pdf') fig.savefig('AlGaN_full_spectrum.jpg', dpi=300) #### END BASIC ANALYSIS ####
def CSR_plot(run_number, comp_csr_fig_idx, spec_fig_num, multi_fig_num): # Read in data epos = GaN_fun.load_epos(run_number=run_number, epos_trim=[5000, 5000], fig_idx=plt.figure().number) pk_data = GaN_type_peak_assignments.GaN() 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, pk_data=pk_data, pk_params=pk_params, glob_bg_param=glob_bg_param, bg_frac=1, noise_threshhold=2) ppd.pretty_print_compositions(compositions, pk_data) # Plot the full spectrum xs, ys_sm = GaN_fun.bin_and_smooth_spectrum(epos=epos, user_roi=[0, 150], bin_wid_mDa=30, smooth_wid_mDa=-1) fig = plt.figure(num=spec_fig_num) ax = fig.gca() scale_factor = 1E4**next(counter) ax.plot(xs, scale_factor * (ys_sm + 1), lw=1, label=run_number) glob_bg = ppd.physics_bg(xs, glob_bg_param) ax.plot(xs, scale_factor * (glob_bg + 1), lw=1, label=run_number + ' (bg)', alpha=1) # Plot some detector hitmaps GaN_fun.create_det_hit_plots(epos, pk_data, pk_params, fig_idx=plt.figure().number) # Find the pole center and show it ax = plt.gcf().get_axes()[0] m2q_roi = [3, 100] sel_idxs = np.where((epos['m2q'] > m2q_roi[0]) & (epos['m2q'] < m2q_roi[1])) xc, yc = GaN_fun.mean_shift(epos['x_det'][sel_idxs], epos['y_det'][sel_idxs]) a_circle = plt.Circle((xc[-1], yc[-1]), 10, facecolor='none', edgecolor='k', lw=2, ls='-') ax.add_artist(a_circle) # Chop data up by Radius AND time time_chunk_centers, r_centers, idxs_list = GaN_fun.chop_data_rad_and_time( epos, [xc[-1], yc[-1]], time_chunk_size=2**16, N_ann_chunks=3) N_time_chunks = time_chunk_centers.size N_ann_chunks = r_centers.size # Charge state ratios csr = np.full([N_time_chunks, N_ann_chunks], -1.0) # Gallium atomic % and standard deviation (no bg) Ga_comp = np.full([N_time_chunks, N_ann_chunks], -1.0) Ga_comp_std = np.full([N_time_chunks, N_ann_chunks], -1.0) # Gallium atomic % and standard deviation (global bg) Ga_comp_glob = np.full([N_time_chunks, N_ann_chunks], -1.0) Ga_comp_std_glob = np.full([N_time_chunks, N_ann_chunks], -1.0) # Multiplicy hit_multiplicity = np.full([N_time_chunks, N_ann_chunks], -1.0) tot_cts = np.full([N_time_chunks, N_ann_chunks], -1.0) keys = list(pk_data.dtype.fields.keys()) keys.remove('m2q') Ga_idx = keys.index('Ga') for t_idx in np.arange(N_time_chunks): for a_idx in np.arange(N_ann_chunks): idxs = idxs_list[t_idx][a_idx] sub_epos = epos[idxs] bg_frac_roi = [120, 150] bg_frac = np.sum((sub_epos['m2q']>bg_frac_roi[0]) & (sub_epos['m2q']<bg_frac_roi[1])) \ / np.sum((epos['m2q']>bg_frac_roi[0]) & (epos['m2q']<bg_frac_roi[1])) cts, compositions, is_peak = GaN_fun.count_and_get_compositions( epos=sub_epos, pk_data=pk_data, pk_params=pk_params, glob_bg_param=glob_bg_param, bg_frac=bg_frac, noise_threshhold=2) csr[t_idx, a_idx] = np.sum(cts['total'][Ga2p_idxs] - cts['global_bg'][Ga2p_idxs]) / np.sum( cts['total'][Ga1p_idxs] - cts['global_bg'][Ga1p_idxs]) Ga_comp[t_idx, a_idx] = ppd.do_composition(pk_data, cts)[0][0][Ga_idx] Ga_comp_std[t_idx, a_idx] = ppd.do_composition(pk_data, cts)[0][1][Ga_idx] Ga_comp_glob[t_idx, a_idx] = ppd.do_composition(pk_data, cts)[2][0][Ga_idx] Ga_comp_std_glob[t_idx, a_idx] = ppd.do_composition(pk_data, cts)[2][1][Ga_idx] low_mz_idxs = np.where(sub_epos['m2q'] < 100)[0] hit_multiplicity[t_idx, a_idx] = np.sum( sub_epos[low_mz_idxs]['ipp'] != 1) / sub_epos[low_mz_idxs].size compositions = ppd.do_composition(pk_data, cts) # ppd.pretty_print_compositions(compositions,pk_data) # print('COUNTS IN CHUNK: ',np.sum(cts['total'])) tot_cts[t_idx, a_idx] = np.sum(cts['total']) fig = plt.figure(num=comp_csr_fig_idx) #fig.clear() ax = fig.gca() #ax.errorbar(csr.flatten(),Ga_comp.flatten(),yerr=Ga_comp_std.flatten(),fmt='.',capsize=4,label='det based (radial)') ax.errorbar(csr.flatten(), Ga_comp_glob.flatten(), yerr=Ga_comp_std_glob.flatten(), fmt='.', capsize=4, label=run_number) fig = plt.figure(num=multi_fig_num) #fig.clear() ax = fig.gca() ax.plot(csr.flatten(), hit_multiplicity.flatten(), '.', label=run_number) # Write data to console for copy/pasting print('CSR', '\t', 'Ga comp (glob bg)', '\t', 'Ga comp std (glob bg)') for i in np.arange(csr.size): print(csr.flatten()[i], '\t', Ga_comp_glob.flatten()[i], '\t', Ga_comp_std_glob.flatten()[i]) return fig
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'], np.array([0.5, (pk_param['amp'] + pk_param['off'])]), 'r--') ax.plot( np.array([1, 1]) * pk_param['post_bg'], np.array([0.5, (pk_param['amp'] + pk_param['off'])]), 'r--') ax.set_yscale('log') ax.set(ylim=[0.1, 1000]) glob_bg_param = ppd.fit_uncorr_bg(m2q_corr) glob_bg = ppd.physics_bg(xs_full_1mDa, glob_bg_param) #ax.clear() #ax.plot(xs_full_1mDa,ys_full_5mDa_sm,label='5 mDa smooth') ax.plot(xs_full_1mDa, ys_full_fwd_sm, label='fwd') ax.plot(xs_full_1mDa, ys_full_bwd_sm, label='bwd') ax.plot(xs_full_1mDa, glob_bg, label='glob_bg') ax.legend() stoich = np.c_[pk_data['N_at_ct'][pk_data['is_anal_pk'], None], pk_data['Ga_at_ct'][pk_data['is_anal_pk'], None]] cts = np.zeros((np.sum(pk_data['is_anal_pk']), 3)) - 1 for idx, pk_param in enumerate(pk_params): pre_pk_rng = [pk_param['pre_bg'] - 0.15, pk_param['pre_bg'] - 0.05]