Exemple #1
0
def PRESTOsp(fil_file, dmlo, dmhi, base_name, snr_cut, mask_file, basename):

    print "Running PRESTO with %f to %f DM range" % (lodm, hidm)
    if mask_file:
        cmd = "prepsubband %s -lodm %f -numdms %d -dmstep 1 -mask %s -o prepsubband" % (
            fil_file, dmlo, dmhi - dmlo, mask_file)
    else:
        cmd = "prepsubband %s -lodm %f -numdms %d -dmstep 1 -o prepsubband" % (
            fil_file, dmlo, dmhi - dmlo)

    os.system(cmd)

    #Run single pulse search on the .dat files
    tbin = 0.4  # Seconds. Time window to compare candidates
    nhits_max = 500
    dm_min = dmlo
    dm_max = dmhi

    fullfile = '%s_full.txt' % basename
    allfile = '%s_all.txt' % basename
    tmp_file = '%s_FRBcand.txt' % basename

    cmd = "single_pulse_search.py prepsubband*.dat"

    os.system(cmd)

    cmd = "cat prepsubband*.singlepulse > All_cand.singlepulse"
    os.system(cmd)
    cand_file = "All_cand.singlepulse"
    sys.path.insert(0,
                    '/home/vgajjar/SP_search_wrapper/PulsarSearch/robert_sp/')
    import sp_cand_find as sp
    cands = sp.cands_from_file(cand_file, 0)
    print("%d total candidates" % len(cands))
    cands = sp.find_duplicates(cands, tbin, 1000.0)

    sp.write_cands(fullfile, cands)
    ndupes = np.array([dd.nhits for dd in cands])
    yy = np.where((ndupes > 0) & (ndupes <= nhits_max))[0]
    #print len(yy)
    all_cands = [cands[ii] for ii in yy]
    sp.write_cands(allfile, all_cands)

    dms = np.array([dd.dm for dd in cands])
    snrs = np.array([dd.sigma for dd in cands])
    xx = np.where((ndupes > 0) & (ndupes <= nhits_max) & (dms >= dm_min)
                  & (dms <= dm_max) & (snrs >= snr_cut))[0]
    gcands = [cands[ii] for ii in xx]

    print("%d good candidates" % len(gcands))
    if (len(gcands)):
        sp.write_cands(tmp_file, gcands)
    else:
        print "Nothing to plot"
    sp.make_nhits_plot(ndupes, nhits_max, basename)
    return gcands
Exemple #2
0
def PRESTOsp(fil_file, dmlo, dmhi, outdir, snr_cut, zerodm, mask_file,
             base_name, nosearch):

    print "Running PRESTO with %f to %f DM range" % (lodm, hidm)

    #prepsubband can only take 500 DMs to  dedisperse
    dmr = int(500)

    #DM Step
    dmstep = 1

    if not nosearch:
        cmd = "rm *.dat prepsub*.inf *.singlepulse"
        os.system(cmd)

    if zerodm:
        if mask_file:
            cmd = "prepsubband %s -lodm 0 -numdms 1 -dmstep 1 -mask %s -o prepsubband" % (
                fil_file, mask_file)
        else:
            cmd = "prepsubband %s -lodm 0 -numdms 1 -dmstep 1 -o prepsubband" % (
                fil_file)

        #if not nosearch: os.system(cmd)
        os.system(cmd)

    for d in range(int(dmlo), int(dmhi), dmr):
        if (d + dmr > dmhi): dmhi1 = dmhi
        else: dmhi1 = d + dmr
        if (d > 1000): dmstep = dmstep + 1
        if mask_file:
            cmd = "prepsubband %s -lodm %f -numdms %d -dmstep %d -mask %s -o prepsubband" % (
                fil_file, d, dmhi1 - d, dmstep, mask_file)
        else:
            cmd = "prepsubband %s -lodm %f -numdms %d -dmstep %d -o prepsubband" % (
                fil_file, d, dmhi1 - d, dmstep)
        if not nosearch: os.system(cmd)

    #Run single pulse search on the .dat files
    tint = 1  # Seconds. Time window to compare candidates
    nhits_max = 12000
    dm_min = 530
    dm_max = 630

    fullfile = '%s_orig_cand.txt' % base_name
    allfile = '%s_clean_cand.txt' % base_name
    tmp_file = '%s_FRBcand.txt' % base_name

    cmd = "single_pulse_search.py -m 0.01 -b -t %f prepsubband*.dat" % (
        snr_cut)

    if not nosearch: os.system(cmd)

    cmd = "cat prepsubband*.singlepulse > All_cand.singlepulse"
    os.system(cmd)
    cand_file = "All_cand.singlepulse"
    sys.path.insert(0,
                    '/home/vgajjar/SP_search_wrapper/PulsarSearch/robert_sp/')
    import sp_cand_find as sp
    cands = sp.cands_from_file(cand_file, 0)
    print("%d total candidates" % len(cands))
    cands = sp.find_duplicates(cands, tint, 1000.0)

    if (len(cands)):
        if zerodm:
            zdm = []
            dupdms = np.array([dd.dupes_dms for dd in cands])
            for i, d in enumerate(dupdms):
                if (0.0 not in d): zdm.append(i)
            cands = [cands[ii] for ii in zdm]

        sp.write_cands(fullfile, cands)
        ndupes = np.array([dd.nhits for dd in cands])
        #print 	dupes
        yy = np.where((ndupes > 0) & (ndupes <= nhits_max))[0]
        #print len(yy)
        all_cands = [cands[ii] for ii in yy]
        if len(all_cands): sp.write_cands(allfile, all_cands)

        dms = np.array([dd.dm for dd in cands])
        snrs = np.array([dd.sigma for dd in cands])
        xx = np.where((ndupes > 0) & (ndupes <= nhits_max) & (dms >= dm_min)
                      & (dms <= dm_max) & (snrs >= snr_cut))[0]
        gcands = [cands[ii] for ii in xx]

        print("%d good candidates" % len(gcands))
        if (len(gcands)):
            sp.write_cands(tmp_file, gcands)
            sp.make_nhits_plot(ndupes, nhits_max, base_name)
        else:
            print "Nothing to plot"
    else:
        gcands = []

    return gcands