bcych / BiCEP_GUI

GUI for using the BiCEP method (Cych et al, 2021) on paleointensity data.
5 stars 3 forks source link

SVD did not converge error #3

Closed ltauxe closed 2 years ago

ltauxe commented 2 years ago

On the jupyterhub.earthref.org website, the keeps happening using the attached file: LinAlgError Traceback (most recent call last) ~/BiCEP_GUI/BiCEP_functions.py in get_site_dist(a) 1603 model=model_circle_fast 1604 -> 1605 thellierData[site_wid.value].BiCEP_fit(model=model) 1606 fit=thellierData[site_wid.value].fit 1607 display_sampler_diags(fit)

~/BiCEP_GUI/BiCEP_functions.py in BiCEP_fit(self, n_samples, priorstd, model, **kwargs) 361 if specimen.active==True: 362 specimen.save_changes() --> 363 minPTRM,minNRM,PTRMmax,k,phi,dist_to_edge,sigma,PTRMS,NRMS=specimen.BiCEP_prep() 364 NRM0=specimen.NRM0 365 minPTRMs.append(minPTRM)

~/BiCEP_GUI/BiCEP_functions.py in BiCEP_prep(self) 793 #We perform the Taubin least squares circle fit to get values close to the Bayesian maximum likelihood to initialize our MCMC sampler at, this makes sampling a lot easier than initializing at a random point (which may have infinitely low probability). 794 --> 795 x_c,y_c,R,sigma=TaubinSVD(PTRMS,NRMS) #Calculate x_c,y_c and R 796 dist_to_edge=abs(np.sqrt(x_c2+y_c2)-R) #Calculate D (dist_to_edge) 797 phi=np.radians(np.degrees(np.arctan(y_c/x_c))%180)

~/BiCEP_GUI/BiCEP_functions.py in TaubinSVD(x, y) 74 Z0 = (Z - Zmean)/(2. * np.sqrt(Zmean)) 75 ZXY = np.array([Z0, X, Y]).T ---> 76 U, S, V = np.linalg.svd(ZXY, full_matrices=False) # 77 V = V.transpose() 78 A = V[:,2]

/opt/tljh/user/lib/python3.6/site-packages/numpy/linalg/linalg.py in svd(a, full_matrices, compute_uv) 1548 1549 signature = 'D->DdD' if isComplexType(t) else 'd->ddd' -> 1550 u, s, vh = gufunc(a, signature=signature, extobj=extobj) 1551 u = u.astype(result_t, copy=False) 1552 s = s.astype(_realType(result_t), copy=False)

/opt/tljh/user/lib/python3.6/site-packages/numpy/linalg/linalg.py in _raise_linalgerror_svd_nonconvergence(err, flag) 96 97 def _raise_linalgerror_svd_nonconvergence(err, flag): ---> 98 raise LinAlgError("SVD did not converge") 99 100 def _raise_linalgerror_lstsq(err, flag):

LinAlgError: SVD did not converge BiCEP.zip

bcych commented 2 years ago

BiCEP uses a modified version of the TaubinSVD best fitting circle function (used to calculate k) as an initial value for the fit to the data. If the SVD doesn't converge then there's likely something wrong with the input data, and this should fail the curvature calculation in PmagPy as well. I believe this particular case was related to an error in anisotropy tensor calculation, so it should be fixed now.

bcych commented 2 years ago

Fixed in the latest commit. This was a complicated issue in which the cooling rate correction was pulling NaN values from the samples table and then applying these to the data, causing the TaubinSVD problems. An additional issue where the cooling rate correction was pulling zero field cooling rate measurements from the measurements table was also fixed.