class DMComparisonPeakRater(base.BaseRater): short_name = "dmcmppeak" long_name = "DM Comparison (Peak)" description = "Compute the ratio of peak height for the profile " \ "dedispersed at DM 0 divided by that for the profile " \ "dedispersed at the best-fit DM." version = 5 rat_cls = freq_vs_phase.FreqVsPhaseClass() def _compute_rating(self, cand): """Return a rating for the candidate. The rating value is the Peak of the DM=0 profile divided by the peak of the best-fit DM's profile. Input: cand: A Candidate object to rate. Output: value: The rating value. """ fvph = cand.freq_vs_phase fvph.dedisperse(DM=0) prof_dm0 = fvph.get_profile() peak_dm0 = np.amax(prof_dm0) - np.median(prof_dm0) fvph.dedisperse(DM=cand.pfd.bestdm) prof_bestdm = fvph.get_profile() peak_bestdm = np.amax(prof_bestdm) - np.median(prof_bestdm) return peak_dm0 / peak_bestdm
class DMComparisonStddevRater(base.BaseRater): short_name = "dmcmpstd" long_name = "DM Comparison (Stddev)" description = "Compute the ratio of std deviation for the profile " \ "dedispersed at DM 0 divided by that for the profile " \ "dedispersed at the best-fit DM." version = 5 rat_cls = freq_vs_phase.FreqVsPhaseClass() def _compute_rating(self, cand): """Return a rating for the candidate. The rating value is the stddev of the DM=0 profile divided by the stddev of the best-fit DM's profile. Input: cand: A Candidate object to rate. Output: value: The rating value. """ fvph = cand.get_from_cache('freq_vs_phase') pfd = cand.get_from_cache('pfd') fvph.dedisperse(DM=0) prof_dm0 = fvph.get_profile() stddev_dm0 = np.std(prof_dm0) fvph.dedisperse(DM=pfd.bestdm) prof_bestdm = fvph.get_profile() stddev_bestdm = np.std(prof_bestdm) return stddev_dm0 / stddev_bestdm
class DMComparisonChiSquareRater(base.BaseRater): short_name = "dmcmpchisqr" long_name = "DM Comparison (Chi Square)" description = "Compute the ratio of chi-square for the profile " \ "dedispersed at DM 0 divided by that for the profile " \ "dedispersed at the best-fit DM." version = 1 rat_cls = freq_vs_phase.FreqVsPhaseClass() def _compute_rating(self, cand): """Return a rating for the candidate. The rating value is the Chi-square of the DM=0 profile divided by the chi-square of the best-fit DM's profile. Input: cand: A Candidate object to rate. Output: value: The rating value. """ fvph = cand.get_from_cache('freq_vs_phase') pfd = cand.get_from_cache('pfd') prof_avg = np.sum(pfd.stats[:, :, 4][:pfd.npart]) prof_var = np.sum(pfd.stats[:, :, 5][:pfd.npart]) fvph.dedisperse(DM=0) prof_dm0 = fvph.get_profile() #chisqr_dm0 = presto.chisqr(prof_dm0, pfd.proflen, prof_avg, prof_var) # Below is adapted for presto v2.1 chisqr_dm0 = presto.chisqr(prof_dm0, prof_avg, prof_var) fvph.dedisperse(DM=pfd.bestdm) prof_bestdm = fvph.get_profile() #chisqr_bestdm = presto.chisqr(prof_bestdm, pfd.proflen, prof_avg, prof_var) # Below is adapted for presto v2.1 chisqr_bestdm = presto.chisqr(prof_bestdm, prof_avg, prof_var) return chisqr_dm0 / chisqr_bestdm
def main(): pfdfn = sys.argv[1] pfd = prepfold.pfd(pfdfn) cand = candidate.Candidate(pfd.topo_p1, pfd.bary_p1, pfd.bestdm, \ psr_utils.ra_to_rad(pfd.rastr)*psr_utils.RADTODEG, \ psr_utils.dec_to_rad(pfd.decstr)*psr_utils.RADTODEG, \ 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 from rating_classes import freq_vs_phase fvph = freq_vs_phase.FreqVsPhaseClass() fvph.add_data(cand) print "Added freq vs phase data to cand" pprint.pprint(cand.__dict__) print "-" * 10 pprint.pprint(cand.freq_vs_phase.__dict__) print "Check if freq_vs_phase rotates out and back to same array" orig = cand.freq_vs_phase.data.copy() orig_dm = cand.freq_vs_phase.curr_dm cand.freq_vs_phase.dedisperse(0) mod = cand.freq_vs_phase.data.copy() cand.freq_vs_phase.dedisperse(orig_dm) new = cand.freq_vs_phase.data.copy() print "Compare orig/mod" print(orig == mod).all() print "Compare mod/new" print(mod == new).all() print "Compare orig/new" print(orig == new).all() print "Compare with best prof" # Create best prof file print "show_pfd -noxwin %s" % cand.info['pfdfn'] subprocess.call("show_pfd -noxwin %s" % cand.info['pfdfn'], shell=True, stdout=open(os.devnull)) pfd_bestprof = np.loadtxt(os.path.split(cand.pfd.pfd_filename + ".bestprof")[-1], usecols=(1, )) cand.freq_vs_phase.dedisperse(cand.pfd.bestdm) fvph_prof = cand.freq_vs_phase.data.sum(axis=0).squeeze() print test_profiles(pfd_bestprof, fvph_prof, 1e-6) print "Testing dedispersion" for dm in np.random.randint(0, 1000, size=10): print "DM: %g" % dm, cand.freq_vs_phase.dedisperse(dm) fvph_prof = cand.freq_vs_phase.get_profile() cand.pfd.dedisperse(dm, doppler=1) cand.pfd.adjust_period() pfd_prof = cand.pfd.time_vs_phase().sum(axis=0).squeeze() print test_profiles(fvph_prof, pfd_prof, 1e-6) plt.figure(dm) plt.plot(fvph_prof, label="FvsPh") plt.plot(pfd_prof, label="PFD") plt.title("DM: %g" % dm) plt.legend(loc='best') plt.show()