MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / snip_method_numba

Function snip_method_numba

pyxrf/core/map_processing.py:1154–1357  ·  view source on GitHub ↗

Use snip algorithm to obtain background. The code of this function is borrowed from scikit-beam and changed to to work with numba. Parameters ---------- spectrum : array intensity spectrum e_off : float energy calibration, such as e_off + e_lin * energy

(
    spectrum,
    e_off,
    e_lin,
    e_quad,
    xmin=0,
    xmax=4096,
    epsilon=2.96,
    width=0.5,
    decrease_factor=np.sqrt(2),
    spectral_binning=None,
    con_val=None,
    iter_num=None,
    width_threshold=0.5,
)

Source from the content-addressed store, hash-verified

1152
1153@jit(nopython=True, nogil=True)
1154def snip_method_numba(
1155 spectrum,
1156 e_off,
1157 e_lin,
1158 e_quad,
1159 xmin=0,
1160 xmax=4096,
1161 epsilon=2.96,
1162 width=0.5,
1163 decrease_factor=np.sqrt(2),
1164 spectral_binning=None,
1165 con_val=None,
1166 iter_num=None,
1167 width_threshold=0.5,
1168):
1169 """
1170 Use snip algorithm to obtain background.
1171
1172 The code of this function is borrowed from scikit-beam and changed to
1173 to work with numba.
1174
1175 Parameters
1176 ----------
1177 spectrum : array
1178 intensity spectrum
1179 e_off : float
1180 energy calibration, such as e_off + e_lin * energy + e_quad * energy^2
1181 e_lin : float
1182 energy calibration, such as e_off + e_lin * energy + e_quad * energy^2
1183 e_quad : float
1184 energy calibration, such as e_off + e_lin * energy + e_quad * energy^2
1185 xmin : float, optional
1186 smallest index to define the range
1187 xmax : float, optional
1188 largest index to define the range
1189 epsilon : float, optional
1190 energy to create a hole-electron pair
1191 for Ge 2.96, for Si 3.61 at 300K
1192 needs to double check this value
1193 width : int, optional
1194 window size to adjust how much to shift background
1195 decrease_factor : float, optional
1196 gradually decrease of window size, default as sqrt(2)
1197 spectral_binning : float, optional
1198 bin the data into different size
1199 con_val : int, optional
1200 size of scipy.signal.boxcar to convolve the spectrum.
1201
1202 Default value is controlled by the keys `con_val_no_bin`
1203 and `con_val_bin` in the defaults dictionary, depending
1204 on if spectral_binning is used or not
1205
1206 iter_num : int, optional
1207 Number of iterations.
1208
1209 Default value is controlled by the keys `iter_num_no_bin`
1210 and `iter_num_bin` in the defaults dictionary, depending
1211 on if spectral_binning is used or not

Callers 9

verify_fit_outputMethod · 0.90
verify_roi_outputMethod · 0.90
test_snip_method_numbaFunction · 0.90
calculate_profileFunction · 0.85
get_backgroundMethod · 0.85
save_fitted_figFunction · 0.85
update_imgFunction · 0.85
fit_per_line_nnlsFunction · 0.85

Calls 2

convolveFunction · 0.85
_clipFunction · 0.85

Tested by 3

verify_fit_outputMethod · 0.72
verify_roi_outputMethod · 0.72
test_snip_method_numbaFunction · 0.72