Two solutions of quadratic equation in ARC region
pyimgalgos/src/FiberAngles.py
y = funcy_l1_v1(x, phi_deg, bet_deg, DoR=390/913.27, sgnrt=1.) # or ... sgnrt=-1.)
wide range of x:
narrow range of x:
pyimgalgos/src/FiberAngles.py
y = funcy_l0(x, phi_deg, bet_deg)
Problem with two roots is resolved for EQU region; sign of the root is selected the same as sign of parameter B;
Example of how to apply fit to data using absolute errors on peak position, get fit parameters with errors, estimate fit quality.
cxif5315/proc-cxif5315-r0169-peaks-from-file-v4.py, v5, v6
from scipy.optimize import curve_fit from scipy.stats import chi2 xn = np.array([pk.x/L for pk in sp.lst_equ_evt_peaks], dtype=np.double) yn = np.array([pk.y/L for pk in sp.lst_equ_evt_peaks], dtype=np.double) en = np.array([pk.csigma*sp.PIXEL_SIZE/L for pk in sp.lst_equ_evt_peaks], dtype=np.double) #en = np.array([max(pk.rsigma,pk.csigma)*sp.PIXEL_SIZE/L for pk in sp.lst_equ_evt_peaks], dtype=np.double) p0 = [-3.2,-16.0] # phi, beta angle central values popt, pcov = curve_fit(funcy, xn, yn, p0, en, absolute_sigma=True) sp.fib_chi2 = np.sum(((funcy(xn, *popt) - yn) / en)**2) sp.fib_ndof = len(xn) - 1 sp.fib_prob = chi2.sf(sp.fib_chi2, sp.fib_ndof, loc=0, scale=1) |
For 2-peak events fit does not have any freedom - curve can exactly be fitted to 3 points (including origin); chi2=0 and probability is always 1.
For >2-peak events chi2 and probability show some distribution.
After phi-beta fit peaks are saved in the file with name like
result/peak-fit-cxif5315-r0169-2016-04-04T16:16:38.txt
Comparing to regular peak parameters this file has extended data for each peak by
... fit-phi fit-beta phi-err beta-err fit-chi2 ndof fit-prob ... 1.30 -42.98 3.800454 10.236941 0.000000 1 1.000000 ... -4.75 -23.85 0.265462 1.212093 1.734365 3 0.629321 |
To load this file use helper classes |