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)
| 50 | |
| 51 | |
| 52 | def 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 | |
| 80 | def fit_spectrum(data, ref_spectra, *, method="nnls", axis=0, maxiter=100, rate=0.2, epsilon=1e-30): |
no outgoing calls
no test coverage detected