def pkmb_prepdata(optlist, file, filenum):
    # Runs prepdata and returns a tuple containg number of points
    # written, time per point, and starting time (MJD)
    outfile = optlist['o'] + ` filenum `
    command = 'prepdata -pkmb -nobary -dm '+optlist['dm']+' -o '+\
              outfile+' '+file
    print ""
    print command
    print ""
    os.system(command)
    inf = presto.read_inffile(outfile)
    return (int(inf.N), inf.dt, inf.mjd_i + inf.mjd_f)
Exemple #2
0
def pkmb_prepdata(optlist, file, filenum):
    # Runs prepdata and returns a tuple containg number of points
    # written, time per point, and starting time (MJD)
    outfile = optlist['o']+repr(filenum)
    command = 'prepdata -pkmb -nobary -dm '+optlist['dm']+' -o '+\
              outfile+' '+file
    print("")
    print(command)
    print("")
    os.system(command)
    inf = presto.read_inffile(outfile)
    return (int(inf.N), inf.dt, inf.mjd_i+inf.mjd_f)
Exemple #3
0
def multi_psr_ts_add(psr_list, amp_list, in_fname, out_fname, in_fpath='.',\
    out_fpath='.'):
    """
    edit of multi_psr_ts to allow adding to existing datfile...
    in_fname and out_fname: no extension
    amp_list: amps as fraction of time series 1-sigma noise level

    NOTE: Should be edited so that it doesn't read and also write the whole
        time series in one big chunk, more like how multi_psr_ts now works.
    """
    in_inffile = read_inffile('%s/%s' % (in_fpath, in_fname))

    nbins = in_inffile.N
    tres = in_inffile.dt
    length = nbins*tres
    start = MJD(in_inffile.mjd_i, in_inffile.mjd_f)

    full_ts = load_dat('%s/%s' % (in_fpath, in_fname))

    amp_list = np.array(amp_list)
    noise = np.std(full_ts)
    amp_list *= noise

    for ii in range(len(psr_list)):
        ts = TimeSeries(psr_list[ii], amp_list[ii], start, tres, 0, length)
        full_ts += ts.ts_pulses
    
    print "Writing %s.dat and %s.inf..." % (out_fname, out_fname)

    write_dat(np.round(full_ts), '%s/%s' % (out_fpath, out_fname))

    inf = in_inffile
    inf.name = out_fname
    inf.observer = 'Nobody (edited data)'
    inf.analyzer = 'Nobody (edited data)'
    inf.notes = 'Edited file %s.dat' % in_fname
    writeinf(inf)

    print "Done."
Exemple #4
0
    hdr += prep_double("src_raj", inf.ra_h*10000.0 + inf.ra_m*100.0 + inf.ra_s)
    if inf.dec_d > 0.0:
        hdr += prep_double("src_dej", inf.dec_d*10000.0 + inf.dec_m*100.0 + inf.dec_s)
    else:
        hdr += prep_double("src_dej", inf.dec_d*10000.0 - inf.dec_m*100.0 - inf.dec_s)
    hdr += prep_int("nbits", 32)
    hdr += prep_int("nifs", 1)
    hdr += prep_int("nchans", 1)
    hdr += prep_double("fch1", inf.freq)
    hdr += prep_double("foff", 1)
    hdr += prep_double("tstart", inf.mjd_i + inf.mjd_f)
    hdr += prep_double("tsamp", inf.dt)
    hdr += prep_double("refdm", inf.dm)
    hdr += prep_string("HEADER_END")
    return hdr

if __name__ == "__main__":
    if len(sys.argv)==1:
        print "\nusage:  dat2tim.py file.dat\n"
        sys.exit()
    if sys.argv[1].endswith(".dat"):
        basefilenm = sys.argv[1][:sys.argv[1].rfind(".dat")]
    else:
        basefilenm = sys.argv[1]
    inf = presto.read_inffile(basefilenm)
    outfile = open(basefilenm+".tim", "wb")
    outfile.write(infodata_to_sigproc_header(inf))
    outfile.close()
    # Do this the simple (but kludgey) way
    os.system("cat %s >> %s"%(sys.argv[1], basefilenm+".tim"))
Exemple #5
0
print("\n\n**** Joining files...\n\n")

outfile = optlist['o']+'0.dat'
for filenum in range(1, len(files)):
    infile = optlist['o']+repr(filenum)+'.dat'
    command = 'cat '+infile+' >> '+outfile
    print("")
    print(command)
    print("")
    os.system(command)
    os.remove(infile)
    os.remove(optlist['o']+repr(filenum)+'.inf')

# Adjust infofile for the pasted data set

inf = presto.read_inffile(optlist['o']+'0')
inf.N = os.stat(outfile)[6] / 4
presto.writeinf(inf)

# Run prepdata on the big file to barycenter it

print("\n\n**** Barycentering...\n\n")

if (numout):
    command = ('prepdata -numout '+repr(numout)+' -o '+
               optlist['o']+' '+outfile)
else:
    command = ('prepdata -o '+optlist['o']+' '+outfile)
print("")
print(command)
print("")
ncx = np.array(cx, copy=1)
presto.fftwcall(cx, -1)
presto.fftwcall(cx, 1)
assert(np.allclose(cx/N, ncx, atol=1e-6))
print "success"

print "Testing tablesixstepfft call...",
cx = np.random.standard_normal(N).astype(np.complex64)
ncx = np.array(cx, copy=1)
presto.tablesixstepfft(cx, -1)
presto.tablesixstepfft(cx, 1)
assert(np.allclose(cx/N, ncx, atol=1e-6))
print "success"

print "Testing reading infiles...",
x = presto.read_inffile("1937_DM71.02_zerodm.inf", verbose=False)
assert(x.telescope=="GBT")
assert(x.mjd_i==55267)
assert(x.dt==8.192e-05)
assert(x.numonoff==1)
assert(x.analyzer=="sransom")
print "success"

print "Testing writing infiles...",
x.analyzer="test"
x.name="xxx"
x.dt=0.125
presto.write_inffile(x, verbose=False)
y = presto.read_inffile("xxx", verbose=False)
assert(y.analyzer=="test")
assert(y.bary==0)
ncx = np.array(cx, copy=1)
presto.fftwcall(cx, -1)
presto.fftwcall(cx, 1)
assert (np.allclose(cx / N, ncx, atol=1e-6))
print "success"

print "Testing tablesixstepfft call...",
cx = np.random.standard_normal(N).astype(np.complex64)
ncx = np.array(cx, copy=1)
presto.tablesixstepfft(cx, -1)
presto.tablesixstepfft(cx, 1)
assert (np.allclose(cx / N, ncx, atol=1e-6))
print "success"

print "Testing reading infiles...",
x = presto.read_inffile("1937_DM71.02_zerodm.inf", verbose=False)
assert (x.telescope == "GBT")
assert (x.mjd_i == 55267)
assert (x.dt == 8.192e-05)
assert (x.numonoff == 1)
assert (x.analyzer == "sransom")
print "success"

print "Testing writing infiles...",
x.analyzer = "test"
x.name = "xxx"
x.dt = 0.125
presto.write_inffile(x, verbose=False)
y = presto.read_inffile("xxx", verbose=False)
assert (y.analyzer == "test")
assert (y.bary == 0)
Exemple #8
0
                           inf.dec_d * 10000.0 + inf.dec_m * 100.0 + inf.dec_s)
    else:
        hdr += prep_double("src_dej",
                           inf.dec_d * 10000.0 - inf.dec_m * 100.0 - inf.dec_s)
    hdr += prep_int("nbits", 32)
    hdr += prep_int("nifs", 1)
    hdr += prep_int("nchans", 1)
    hdr += prep_double("fch1", inf.freq)
    hdr += prep_double("foff", 1)
    hdr += prep_double("tstart", inf.mjd_i + inf.mjd_f)
    hdr += prep_double("tsamp", inf.dt)
    hdr += prep_double("refdm", inf.dm)
    hdr += prep_string("HEADER_END")
    return hdr


if __name__ == "__main__":
    if len(sys.argv) == 1:
        print "\nusage:  dat2tim.py file.dat\n"
        sys.exit()
    if sys.argv[1].endswith(".dat"):
        basefilenm = sys.argv[1][:sys.argv[1].rfind(".dat")]
    else:
        basefilenm = sys.argv[1]
    inf = presto.read_inffile(basefilenm)
    outfile = open(basefilenm + ".tim", "wb")
    outfile.write(infodata_to_sigproc_header(inf))
    outfile.close()
    # Do this the simple (but kludgey) way
    os.system("cat %s >> %s" % (sys.argv[1], basefilenm + ".tim"))
Exemple #9
0
def main():
    usage = "usage: %prog [options]"
    parser = OptionParser(usage)
    parser.add_option("-n",
                      "--number",
                      type="int",
                      dest="nM",
                      default=40,
                      help="Number of points in each chunk (millions)")
    parser.add_option("-o",
                      "--outdir",
                      type="string",
                      dest="outdir",
                      default=".",
                      help="Output directory to store results")
    parser.add_option("-d",
                      "--workdir",
                      type="string",
                      dest="workdir",
                      default=".",
                      help="Working directory for search")
    parser.add_option("-l",
                      "--flo",
                      type="float",
                      dest="flo",
                      default=10.0,
                      help="Low frequency (Hz) to search")
    parser.add_option("-f",
                      "--frac",
                      type="float",
                      dest="frac",
                      default=0.5,
                      help="Fraction to overlap")
    parser.add_option("-x",
                      "--fhi",
                      type="float",
                      dest="fhi",
                      default=10000.0,
                      help="High frequency (Hz) to search")
    parser.add_option("-z",
                      "--zmax",
                      type="int",
                      dest="zmax",
                      default=160,
                      help="Maximum fourier drift (bins) to search")
    parser.add_option("-w",
                      "--wmax",
                      type="int",
                      dest="wmax",
                      default=400,
                      help="Maximum fourier drift deriv (bins) to search")
    parser.add_option("-a",
                      "--numharm",
                      type="int",
                      dest="numharm",
                      default=4,
                      help="Number of harmonics to sum when searching")
    parser.add_option("-s",
                      "--sigma",
                      type="float",
                      dest="sigma",
                      default=2.0,
                      help="Cutoff sigma to consider a candidate")
    (options, args) = parser.parse_args()
    if (options.outdir[-1] != "/"):
        options.outdir = options.outdir + "/"
    if (options.workdir != '.'):
        chdir(options.workdir)
    if (options.nM >= 1000000):
        if (options.nM % 1000000):
            print "If you specify --num nM to be > 1000000, it must be divisible by 1000000."
            exit(1)
    else:
        options.nM *= 1000000
    short_nM = options.nM / 1000000

    # The basename of the data files
    if argv[1].endswith(".dat"):
        basename = "../" + argv[1][:-4]
    else:
        basename = "../" + argv[1]

    # Get the bird file (the first birdie file in the directory!)
    birdname = glob("../*.birds")
    if birdname:
        birdname = birdname[0]

    outnamebase = options.outdir + basename[3:]
    inf = read_inffile(basename)
    idata = infodata.infodata(basename + ".inf")
    N = inf.N
    t0i = inf.mjd_i
    t0f = inf.mjd_f
    num = 0
    point = 0
    T = options.nM * inf.dt / 86400.0
    baryv = get_baryv(idata.RA, idata.DEC, idata.epoch, T, obs='GB')
    print "Baryv = ", baryv
    inf.N = options.nM
    inf.numonoff = 0
    nM = options.nM / 1000000
    while (point + options.nM < N):
        pM = point / 1000000
        outname = basename[3:] + '_%03dM' % nM + '_%02d' % num
        stdout.write('\n' + outname + '\n\n')
        inf.name = outname
        tstartf = inf.mjd_f + num * T * options.frac
        if (tstartf > 1.0):
            tstartf = tstartf - 1.0
            inf.mjd_i = inf.mjd_i + 1
        inf.mjd_f = tstartf
        writeinf(inf)
        myexecute('dd if=' + basename + '.dat of=' + outname +
                  '.dat bs=4000000 skip=' + ` pM ` + ' count=' + ` nM `)
        myexecute('realfft ' + outname + '.dat')
        myexecute('rm -f ' + outname + '.dat')
        myexecute('cp ' + birdname + ' ' + outname + '.birds')
        myexecute('makezaplist.py ' + outname + '.birds')
        myexecute('rm -f ' + outname + '.birds')
        myexecute('zapbirds -zap -zapfile ' + outname +
                  '.zaplist -baryv %g ' % baryv + outname + '.fft')
        myexecute('rm -f ' + outname + '.zaplist')
        myexecute(
            'accelsearch -sigma %.2f -zmax %d -wmax %d -numharm %d -flo %f -fhi %f '
            % (options.sigma, options.zmax, options.wmax, options.numharm,
               options.flo, options.fhi) + outname + '.fft')
        myexecute('rm ' + outname + '.fft ' + outname +
                  '_ACCEL_%d.txtcand' % options.zmax)
        myexecute('cp ' + outname + '.inf ' + options.outdir)
        num = num + 1
        point = point + int(options.nM * options.frac)
print "\n\n**** Joining files...\n\n"

outfile = optlist['o'] + '0.dat'
for filenum in xrange(1, len(files)):
    infile = optlist['o'] + ` filenum ` + '.dat'
    command = 'cat ' + infile + ' >> ' + outfile
    print ""
    print command
    print ""
    os.system(command)
    os.remove(infile)
    os.remove(optlist['o'] + ` filenum ` + '.inf')

# Adjust infofile for the pasted data set

inf = presto.read_inffile(optlist['o'] + '0')
inf.N = os.stat(outfile)[6] / 4
presto.writeinf(inf)

# Run prepdata on the big file to barycenter it

print "\n\n**** Barycentering...\n\n"

if (numout):
    command = ('prepdata -numout ' + ` numout ` + ' -o ' + optlist['o'] + ' ' +
               outfile)
else:
    command = ('prepdata -o ' + optlist['o'] + ' ' + outfile)
print ""
print command
print ""