Beispiel #1
0
def main():
    import rating
    import harmonic_rating
    import pfd_ratings
    import profile_ratings
    import gaussian_ratings

    if options.where is not None:
        print "Using 'where clause':", options.where 

    D = rating.usual_database()
    rating.run(D,
               [gaussian_ratings.GaussianWidth(D), 
                gaussian_ratings.GaussianHeight(D), 
                gaussian_ratings.GaussianPhase(D), 
                gaussian_ratings.GaussianSignificance(D), 
                harmonic_rating.HarmonicRating(D), 
                profile_ratings.DutyCycle(D), 
                profile_ratings.PrepfoldSigmaRating(D), 
                pfd_ratings.RatioRating(D), 
                pfd_ratings.RatioRatingPeak(D), 
               ],
              where_clause=options.where,
              scramble=options.scramble,
              limit=options.n)
Beispiel #2
0
def compare_ratings(ratings):
    DBconn = rating.usual_database()
    DBcursor = MySQLdb.cursors.DictCursor(DBconn)

    ids = []
    for rr in ratings:
        if isinstance(rr,basestring):
            DBcursor.execute("SELECT * FROM rating_type_current_versions WHERE name=%s", rr)
            ids.append(DBcursor.fetchone()["rating_id"])
        else:
            r,v = rr
            DBcursor.execute("SELECT * FROM rating_types WHERE name=%s and version=%s", (r,v))
            ids.append(DBcursor.fetchone()["rating_id"])

    id1, id2 = ratings
    fields = ", ".join(["rating%d.value" % i for i in range(len(ids))])
    join = " JOIN ".join(["ratings AS rating%d" % i for i in range(len(ids))])
    ands = " AND ".join(["rating1.pdm_cand_id=rating%d.pdm_cand_id AND rating%d.rating_id = %%s" % (i,i) for i in range(len(ids))])

    command = "SELECT " + fields + " FROM " + join + " WHERE " + ands
    print command
    
    DBcursor.execute(command, ids)
    rs = []
    for match in DBcursor.fetchall():
        v = []
        for i in range(len(ids)):
            if not i:
                v.append(match["value"])
            else:
                v.append(match["rating%d.value" % i])
        rs.append(v)
    return rs
Beispiel #3
0
	# Un-dedispersed profile        
        p0 = pfd.time_vs_phase().sum(axis=0)
        p1 = profile_ratings.get_profile(cache, pfd)
        return np.std(p0)/np.std(p1)


class RatioRatingPeak(rating.DatabaseRater):
    def __init__(self,DBconn):
        rating.DatabaseRater.__init__(self,DBconn,version=5,
            name="Ratio Rating Peak",
            description="""Compare DM 0 and "best" DM

Computes the ratio of peak height for the profile dedispersed at
DM 0 divided by that for the profile dedispersed at the best-fit DM.
""",
            with_files=True)

    def rate_candidate(self, hdr, candidate, pfd, cache=None):
        
        p0 = pfd.time_vs_phase().sum(axis=0)
        p1 = profile_ratings.get_profile(cache, pfd)

        return (np.amax(p0)-np.median(p0))/(np.amax(p1)-np.median(p1))


if __name__=='__main__':
    D = rating.usual_database()
    rating.run(D, 
               [RatioRating(D),
               ])
def main():
    import upload_rating
    D = rating.usual_database()
    rating.run(D, [upload_rating.UploadRating(D)])
Beispiel #5
0
            description="""Determines whether candidates with nearly identical period are RFI based on their sky position.

	Compares each candidate with database of candidates. If the differences in RA and Dec. are both greater than 0.2 degrees, the fractional difference in period is computed. For fractional differences less than 0.001, the value is exponentiated by the number of candidates that fall within that 0.001.

In general, if a candidate gets a rating less than ~1e-4 it's very likely RFI.
 """,
            with_files=False)



    def rate_candidate(self, hdr, candidate, file=None):
        p = candidate["bary_period"]	# get candidate P_bary
	ra = hdr["ra_deg"]		# get candidate R.A.
   	decl = hdr["dec_deg"]		# get candidate Dec.
        pdiff_min = 10     



	c.execute("""SELECT pdm_candidates.period,headers.ra_deg,headers.dec_deg from pdm_candidates,headers where pdm_candidates.header_id=headers.header_id AND abs(pdm_candidates.period-%s)/(pdm_candidates.period+%s) < 0.0002 AND abs(ra_deg-%s) > 0.2 AND abs(dec_deg-%s) > 0.2;""", (p,p,ra,decl))


	results = c.fetchall()
	pdiff_min=3.0/(np.size(results)+1.0)


	return pdiff_min
	

if __name__=='__main__':
    PulsarRating(rating.usual_database()).run()
Beispiel #6
0
        self.plot("period","dm")
        pylab.gca().set_xscale("log")
        pylab.ylim(0,1000)
        pylab.xlim(1e-4,10)
        pylab.legend(loc="best")


    def plot(self,xaxis,yaxis):
        def p(s,sz,color,label=""):
            x,y = zip(*[(c[xaxis],c[yaxis]) for c in [self.candidates[id] for id in s]])
            print "%s: %d points" % (label, len(s))
            pylab.scatter(x,y,sz,color=color,edgecolor=color,facecolor=color,label=label)
        rated = self.rated_harmonic.union(self.rated_ratio)
        p(self.unclassified.difference(rated),1,"gray","unclassified")
        p(self.classified_notreal.difference(rated),1,"black","not real")
        p(self.classified_RFI.difference(rated),1,"red","RFI")
        p(self.rated_harmonic,1,"yellow","60 Hz")
        p(self.rated_ratio,1,"orange","stronger at DM 0")
        p(self.classified_maybe,1,"green","maybe")
        p(self.classified_real,2,"green","likely")
        p(self.classified_known,2,"blue","known")



if __name__=='__main__':
    rp = RatingPlotter(rating.usual_database())
    rp.run()
    rp.plot_p_vs_DM()
    rp.plot_p_vs_sigma()
    pylab.show()
Beispiel #7
0
pdm_cand_ids = {
    7891: "Known pulsar, bright nuller",
    7922: "Known pulsar, fainter",
    4441: "New pulsar, 487 ms",
    4443: "New pulsar, half frequency",
    21775: "RFI wrapped at nonzero DM",
    26526: "Narrowband RFI",
    759: "Just noise, no peak, 250 ms",
    31164: "Just noise, no peak, 12 ms",
}

def demo_rating(rating):
    for (n,i) in sorted([(n,i) for (i,n) in pdm_cand_ids.items()]):
        r = rating.rate_by_cand_id(i)
        print "\t%s:\t%g" % (n,r)

if __name__=='__main__':
    import rating
    import profile_ratings
    import harmonic_rating
    import pfd_ratings

    for R in [profile_ratings.GaussianWidth, profile_ratings.GaussianHeight, profile_ratings.PeakOverRMS,harmonic_rating.HarmonicRating, profile_ratings.DutyCycle, pfd_ratings.RatioRating]:
        r = R(rating.usual_database())
        print r.name
        demo_rating(r)