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

Function rfactor

pyxrf/core/fitting.py:52–77  ·  view source on GitHub ↗

r""" Computes R-factor based on two spectra Parameters ---------- spectrum_experimental : ndarray spectrum data on which fitting is performed (N elements) spectrum_fit : ndarray fitted spectrum (weighted sum of spectrum components, N elements) Returns -

(spectrum_experimental, spectrum_fit)

Source from the content-addressed store, hash-verified

50
51
52def rfactor(spectrum_experimental, spectrum_fit):
53 r"""
54 Computes R-factor based on two spectra
55
56 Parameters
57 ----------
58 spectrum_experimental : ndarray
59 spectrum data on which fitting is performed (N elements)
60
61 spectrum_fit : ndarray
62 fitted spectrum (weighted sum of spectrum components, N elements)
63
64 Returns
65 -------
66 float, the value of R-factor
67 """
68
69 # Compute R-factor
70 dif = spectrum_experimental - spectrum_fit
71 dif_sum = np.sum(np.abs(dif), axis=0)
72 data_sum = np.sum(np.abs(spectrum_experimental), axis=0)
73
74 # Avoid accidental division by zero (or a very small number)
75 data_sum = np.clip(data_sum, a_min=1e-30, a_max=None)
76
77 return dif_sum / data_sum
78
79
80def fit_spectrum(data, ref_spectra, *, method="nnls", axis=0, maxiter=100, rate=0.2, epsilon=1e-30):

Callers 2

rfactor_computeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected