diff --git a/PeakOTron.py b/PeakOTron.py index 081b885e6167f7673f1c07f757d6dfe2f9f88333..bf9ab2e3fd380f46b436a80c2a5c379c7955bd8a 100644 --- a/PeakOTron.py +++ b/PeakOTron.py @@ -1482,7 +1482,10 @@ class PeakOTron: idxs_peaks, _ = find_peaks(density_bgsub, distance=kwargs["peak_dist_nG"]*G_fft) - + if(len(idxs_peaks)<2): + raise Exception("Less than 2 peaks found in spectrum. Spectrum cannot be fitted.") + + ######################################################################################################## ## Find peaks widths with scipy 'peak_widths'. 'peak_rel_height' is used to find the appropriate width criterion. ######################################################################################################## @@ -1532,6 +1535,9 @@ class PeakOTron: idxs_peaks = idxs_peaks[_idxs_sort] idxs_peak_widths = idxs_peak_widths[_idxs_sort] + + if(len(idxs_peaks)<2): + raise Exception("Less than 2 peaks found in spectrum. Spectrum cannot be fitted.") ######################################################################################################## ## Calculate and store bin statistic information. @@ -1725,9 +1731,55 @@ class PeakOTron: mu_DCR = DCR*(kwargs["t_0"] + kwargs["t_gate"]) ######################################################################################################## - ## Store results in the class for fitting/reference. + ## Check for nans and correct as necessary. ######################################################################################################## + if(np.isnan(Q_0)): + if(self._verbose): + print("Q_0 returned nan in prefit. Setting Q_0 to 1 bin"): + Q_0 = 1 + dQ_0 = 0.1 + + if(np.isnan(G)): + if(self._verbose): + print("G returned nan in prefit. Setting G to 1 bin"): + G = 1 + dG = 0.1 + + if(np.isnan(mu)): + if(self._verbose): + print("mu returned nan in prefit. Setting mu to 1 p.e."): + mu = 1 + dmu = 0.1 + + if(np.isnan(lbda)): + if(self._verbose): + print("lbda returned nan in prefit. Setting lbda to 1e-2."): + lbda = 1e-2 + dlbda = 0.1 + + + if(np.isnan(sigma_0)): + if(self._verbose): + print("sigma_0 returned nan in prefit. Setting sigma_0 to 1 bin."): + sigma_0 = 1 + dsigma_0 = 0.1 + + if(np.isnan(sigma_1)): + if(self._verbose): + print("sigma_0 returned nan in prefit. Setting sigma_1 to 1 bin."): + sigma_1 = 1 + dsigma_1 = 0.1 + + if(np.isnan(DCR)): + if(self._verbose): + print("DCR returned nan in prefit. Setting DCR to 1e-9 GHz."): + DCR = 1e-9 + dDCR = 1e-2 + + ######################################################################################################## + ## Store results in the class for fitting/reference. + ######################################################################################################## self._hist_data["data"] = data self._hist_data["bw"] = bw