class GaussianHeightRater(base.BaseRater): short_name = "gaussheight" long_name = "Gaussian Height Rating" description = "Compute the height of the best-fit Gaussian divided " \ "by the RMS of the post-fit residuals. The function " \ "being fit is not actually a Gaussian, it's a von Mises " \ "distribution (exp(k*cos(theta)))" version = 6 rat_cls = gaussian.GaussianProfileClass() def _compute_rating(self, cand): """Return a rating for the candidate. The rating value is the amplitude of the von Mises function fit to the candidate's profile divided by the RMS of the post-fit residuals. Input: cand: A Candidate object to rate. Output: value: The rating value. """ nbins = len(cand.profile) resids = cand.profile-cand.gaussfit.histogram(nbins) rms = resids.std() return cand.gaussfit.amplitude(nbins)/rms
class GaussianSignificanceRater(base.BaseRater): short_name = "gausssig" long_name = "Gaussian Significance Rating" description = "Compute the significance of the best-fit Gaussian. " \ "The function being fit is not actually a Gaussian, " \ "it's a von Mises distribution (exp(k*cos(theta)))" version = 2 rat_cls = gaussian.GaussianProfileClass() def _compute_rating(self, cand): """Return a rating for the candidate. The rating value is the amplitude of the von Mises function fit to the candidate's profile divided by the RMS of the post-fit residuals. Input: cand: A Candidate object to rate. Output: value: The rating value. """ nbins = len(cand.profile) std = np.sqrt(np.mean(np.var(cand.pfd.profs,axis=-1))) * \ np.sqrt(cand.pfd.nsub*cand.pfd.npart) return cand.gaussfit.amplitude(nbins) / \ (std/np.sqrt(max(cand.gaussfit.fwhm()/(1.0/nbins), 1)))
class GaussianWidthRater(base.BaseRater): short_name = "gausswidth" long_name = "Gaussian Width Rating" description = "Compute the full width at half maxiumum of the best-fit " \ "Gaussian. The function being fit is not actually a " \ "Gaussian, it's a von Mises distribution " \ "(exp(k*cos(theta)))" version = 5 rat_cls = gaussian.GaussianProfileClass() def _compute_rating(self, cand): """Return a rating for the candidate. The rating value is the FWHM of the von Mises function fit to the candidate's profile. Input: cand: A Candidate object to rate. Output: value: The rating value. """ return cand.gaussfit.fwhm()
class GaussianPhaseRater(base.BaseRater): short_name = "gaussphase" long_name = "Gaussian Phase Rating" description = "Compute the phase of the best-fit Gaussian. The function " \ "being fit is not actually a Gaussian, it's a von Mises " \ "distribution (exp(k*cos(theta)))" version = 5 rat_cls = gaussian.GaussianProfileClass() def _compute_rating(self, cand): """Return a rating for the candidate. The rating value is the phase of the von Mises function fit to the candidate's profile. Input: cand: A Candidate object to rate. Output: value: The rating value. """ return cand.gaussfit.mu
xs = np.linspace(0.0, 1.0, n, endpoint=False) G = gauss._compute_data(cand) print "k: %g, log(k): %g" % (G.k, np.log10(G.k)) test_ks = np.logspace(np.log10(G.k)-2, np.log10(G.k)+1, 1e3) #test_ks = np.exp(np.linspace(np.log(1e-1),np.log(1e3),1e3)) plt.figure(1) resids = [gauss._rms_residual(k,data) for k in test_ks] plt.loglog(test_ks,resids,color="green", label="_nolabel_") #plt.axvline(true_k,color="red", label="true k") best_k = test_ks[np.argmin(resids)] plt.axvline(best_k,color="green", label="best k") plt.axvline(G.k,color="cyan", label="k from fit") plt.ylabel("RMS of residuals") plt.xlabel("Value of k used (i.e. held fixed) when fitting") plt.legend(loc="best") plt.figure(2) mue, ae, be = gauss._fit_all_but_k(best_k, data) #plt.plot(xs, true_prof, color="red", label="true") plt.plot(xs, data, color="black", label="data") plt.plot(xs, (ae*utils.vonmises_histogram(best_k,mue,n)+be), color="green", label="exhaustive best fit") plt.plot(xs, G.histogram(n), color="cyan", label="best fit") plt.legend(loc="best") plt.show() if __name__=='__main__': gauss = gaussian.GaussianProfileClass() main()