def fit_spectrum(epos, pk_data, peak_height_fraction, bg_rois): import initElements_P3 import peak_param_determination as ppd # Define peaks to range ed = initElements_P3.initElements() # 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] # Determine the global background glob_bg_param = ppd.get_glob_bg(epos['m2q'], rois=bg_rois) # Range the peaks pk_params = ppd.get_peak_ranges(epos, pk_data['m2q'], peak_height_fraction=peak_height_fraction, glob_bg_param=0) return (pk_params, glob_bg_param, Ga1p_idxs, Ga2p_idxs)
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
# (0, 1, 0, ed['Ga'].isotopes[71][0]+ed['H'].isotopes[1][0]) # ], # dtype=[('N','i4'),('Ga','i4'),('Al','i4'),('m2q','f4')] ) # 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]:
# dtype=[('N','i4'),('Ga','i4'),('Al','i4'),('m2q','f4')] ) # 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.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]: