def count_and_get_compositions(epos, pk_data, pk_params, glob_bg_param, bg_frac=1, noise_threshhold=2): import peak_param_determination as ppd # Count the peaks, local bg, and global bg cts = ppd.do_counting(epos, pk_params, glob_bg_param) cts['local_bg'] = cts['local_bg'] * bg_frac cts['global_bg'] = cts['global_bg'] * bg_frac # Test for peak S/N and throw out craptastic peaks B = np.max(np.c_[cts['local_bg'][:, None], cts['global_bg'][:, None]], 1)[:, None] T = cts['total'][:, None] S = T - B std_S = np.sqrt(T + B) # Make up a threshold for peak detection... for the most part this won't matter # since weak peaks don't contribute to stoichiometry much... except for Mg! is_peak = S > (noise_threshhold * np.sqrt(2 * B)) for idx, ct in enumerate(cts): if not is_peak[idx]: for i in np.arange(len(ct)): ct[i] = 0 # Calculate compositions compositions = ppd.do_composition(pk_data, cts) return (cts, compositions, is_peak)
# Define which peaks to use for CSR calcs Ga1p_m2qs = [ed['Ga'].isotopes[69][0], ed['Ga'].isotopes[71][0]] Ga2p_m2qs = [ed['Ga'].isotopes[69][0] / 2, ed['Ga'].isotopes[71][0] / 2] Ga1p_idxs = [np.argmin(np.abs(m2q - pk_data['m2q'])) for m2q in Ga1p_m2qs] Ga2p_idxs = [np.argmin(np.abs(m2q - pk_data['m2q'])) for m2q in Ga2p_m2qs] # Range the peaks pk_params = ppd.get_peak_ranges(epos, pk_data['m2q'], peak_height_fraction=0.1) # Determine the global background glob_bg_param = ppd.get_glob_bg(epos['m2q']) # Count the peaks, local bg, and global bg cts = ppd.do_counting(epos, pk_params, glob_bg_param) # Test for peak S/N and throw out craptastic peaks B = np.max(np.c_[cts['local_bg'][:, None], cts['global_bg'][:, None]], 1)[:, None] T = cts['total'][:, None] S = T - B std_S = np.sqrt(T + B) # Make up a threshold for peak detection... for the most part this won't matter # since weak peaks don't contribute to stoichiometry much... except for Mg! is_peak = S > 2 * np.sqrt(2 * B) for idx, ct in enumerate(cts): if not is_peak[idx]: for i in np.arange(len(ct)): ct[i] = 0
Ga1p_m2qs = [ed['Ga'].isotopes[69][0], ed['Ga'].isotopes[71][0]] Ga2p_m2qs = [ed['Ga'].isotopes[69][0] / 2, ed['Ga'].isotopes[71][0] / 2] Ga1p_idxs = [np.argmin(np.abs(m2q - pk_data['m2q'])) for m2q in Ga1p_m2qs] Ga2p_idxs = [np.argmin(np.abs(m2q - pk_data['m2q'])) for m2q in Ga2p_m2qs] # Range the peaks pk_params = ppd.get_peak_ranges(epos, pk_data['m2q'], peak_height_fraction=0.1) # Determine the global background #glob_bg_param = ppd.fit_uncorr_bg(epos['m2q'],fit_roi=[3.5,6.5]) bg_rois = [[3.5, 6.5], [90, 110]] glob_bg_param = ppd.get_glob_bg(epos['m2q'], rois=bg_rois) # Count the peaks, local bg, and global bg cts = ppd.do_counting(epos, pk_params, glob_bg_param) # Test for peak S/N and throw out craptastic peaks B = np.max(np.c_[cts['local_bg'][:, None], cts['global_bg'][:, None]], 1)[:, None] T = cts['total'][:, None] S = T - B std_S = np.sqrt(T + B) # Make up a threshold for peak detection... for the most part this won't matter # since weak peaks don't contribute to stoichiometry much... except for Mg! is_peak = S > 2 * np.sqrt(2 * B) for idx, ct in enumerate(cts): if not is_peak[idx]: for i in np.arange(len(ct)): ct[i] = 0
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) glob_bg_param = ppd.get_glob_bg(epos['m2q'], rois=[[24,27]]) cts = ppd.do_counting(epos,pk_params,glob_bg_param) # Test for peak S/N and throw out craptastic peaks B = np.max(np.c_[cts['local_bg'][:,None],cts['global_bg'][:,None]],1)[:,None] T = cts['total'][:,None] S = T-B std_S = np.sqrt(T+B) # Make up a threshold for peak detection... for the most part this won't matter # since weak peaks don't contribute to stoichiometry much... except for Mg! is_peak = S>1*np.sqrt(2*B) for idx, ct in enumerate(cts): if not is_peak[idx]: for i in np.arange(len(ct)): ct[i] = 0