class MultiGaussGoodnessOfFitRater(base.BaseRater):
    short_name = "multigauss_goodness"
    long_name = "Multi-Gauss Goodness of Fit"
    description = "Fit the profile with multiple Gaussians and " \
                  "report the goodness of the fit (reduced " \
                  "chi-square."
    version = 1

    rat_cls = multigauss.MultipleGaussianProfileClass()

    def _compute_rating(self, cand):
        """
        """
        profile = utils.get_scaled_profile(cand.profile, cand.pfd.varprof)
        mgauss = cand.multigaussfit
        chi2 = mgauss.get_chisqr(profile)
        dof = mgauss.get_dof(len(profile))
        return chi2 / dof
示例#2
0
class PulseWidthRater(base.BaseRater):
    short_name = "pulsewidth"
    long_name = "Pulse Width Rating"
    description = "Fits a maximum of 5 Gaussian profile components and " \
                  "computes the contribution of DM Smearing and sampling " \
                  "time to the width of the narrowest component. Ideally, " \
                  "a real pulsar should have a rating < 1.0 (but the fits " \
                  "may not always be ideal!)."
    version = 1

    rat_cls = multigauss.MultipleGaussianProfileClass()

    def _compute_rating(self, cand):
        """Return a rating for the candidate. The rating value is the
            ratio of the width of the narrowest gaussian component 
            to the DM smearing.
        
            Input:
                cand: A Candidate object to rate.

            Output:
                value: The rating value.
        """
        pfd = cand.pfd
        mgauss = cand.multigaussfit
        ncomp = len(mgauss.components)
        if not ncomp:
            raise utils.RatingError("Bad number of components for single " \
                                    "gaussian fit (%d)" % ncomp)

        # Get the period
        period = pfd.bary_p1 or pfd.topo_p1
        if period is None:
            raise utils.RatingError("Bad period in PFD file (%f)" % period)
        f_ctr = (pfd.hifreq + pfd.lofreq) / 2.0
        dm_smear = psr_utils.dm_smear(pfd.bestdm, pfd.chan_wid, f_ctr)
        width_phs = np.sqrt(dm_smear**2 + pfd.dt**2) / period

        minfwhm = min([comp.fwhm for comp in mgauss.components])
        return width_phs / minfwhm
class NumberOfGaussiansRater(base.BaseRater):
    short_name = "numberofgaussians"
    long_name = "Number of Gaussians Rating"
    description = "The number of gaussians needed to obtain a statistically " \
                  "acceptable fit to the best profile. A maximum of 5 gaussians " \
                  "is used. An unsuccessful fit returns 0 gaussains."
    version = 1

    rat_cls = multigauss.MultipleGaussianProfileClass()

    def _compute_rating(self, cand):
        """Return a rating for the candidate. The rating value is the
            number of gaussian functions fit to the candidate's 
            profile.
        
            Input:
                cand: A Candidate object to rate.

            Output:
                value: The rating value.
        """
        mgauss = cand.multigaussfit
        return len(mgauss.components)
示例#4
0
    cand = candidate.read_pfd_file(pfdfn)

    print "Loaded %s" % cand.pfdfn
    print "    Best topo period (s): %f" % cand.topo_period
    print "    Best bary period (s): %f" % cand.bary_period
    print "    Best DM (cm^-3/pc): %f" % cand.dm
    print "    RA (J2000 - deg): %f" % cand.raj_deg
    print "    Dec (J2000 - deg): %f" % cand.decj_deg

    #print "-"*10
    #pprint.pprint(cand.__dict__)
    #print "-"*10

    mgauss.add_data(cand)

    print "Added multi-gaussian fit to cand"
    #pprint.pprint(cand.__dict__)
    #print "-"*10

    print cand.multigaussfit

    data = cand.profile.copy()
    data /= np.sqrt(cand.pfd.varprof)
    data -= data.mean()
    cand.multigaussfit.plot_comparison(data, True)


if __name__ == '__main__':
    mgauss = multigauss.MultipleGaussianProfileClass()
    main()