Exemplo n.º 1
0
    def savedat(self, fname, withnoise=True):
        """
        Save a presto-readable .dat file (with a corresponding .inf file)
        containing the time series.

        fname: filename without suffix, to be used for .inf and .dat files
        """
        inf = infodata()
        inf.name = fname
        inf.telescope = 'NA'
        inf.instrument = 'NA'
        inf.object = self.profile.pars['PSR']
        inf.observer = 'NA'
        inf.mjd_i = self.start.day_int
        inf.mjd_f = self.start.day_frac
        inf.bary = int(self.bary)
        inf.N = self.nbins
        inf.dt = self.tres
        inf.band = 'Radio'
        inf.filt = 'NA'
        inf.analyzer = 'NA'
        inf.notes = 'Completely fake data set.'

        print "Writing %s.dat and %s.inf..." % (fname, fname)

        # round since .dat files use integers
        if withnoise:
            write_dat(np.round(self.ts_pulses+self.ts_noise), fname)
        else:
            write_dat(np.round(self.ts_pulses), fname)
        writeinf(inf)

        print "Done."
Exemplo n.º 2
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."
Exemplo n.º 3
0
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("")
os.system(command)
os.remove(outfile)
Exemplo n.º 4
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)
Exemplo n.º 5
0
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 ""
os.system(command)
os.remove(outfile)
Exemplo n.º 6
0
def multi_psr_ts(psr_list, amp_list, start, tres, noise, length, fname,\
                 fpath='.', obs=-1, zero=0.):
    """
    fname: no extension
    fpath: directory to place dat and inf files into
    psr_list: iterable set of psrProfile objects
    amp_list: corresponding list of pulse heights as fraction of noise sigma
      (if no noise is present, values are simply used as heights)
    start: start time as MJD object
    noise: sigma of white noise in time series
    """
    amp_list = np.array(amp_list)
    if noise: amp_list *= noise

    nbins = int(np.ceil(length/tres))
    if nbins % 2: nbins -= 1

    chunk_nbins = 2**22
    chunk_length = chunk_nbins * tres
    
    n_full_chunks = nbins / chunk_nbins
    extra_nbins = nbins % chunk_nbins

    # So we can correctly print which chunk we're on:
    if extra_nbins: n_chunks = n_full_chunks + 1
    else: n_chunks = n_full_chunks

    outfile = open("%s/%s.dat" % (fpath, fname), 'w')

    for chunk_ii in range(n_full_chunks):
        chunk_start = start + chunk_ii*(chunk_length/86400.)
        print "Writing time series chunk %d of %d to %s.dat..." % (chunk_ii+1,\
            n_chunks, fname)
        write_to_dat(outfile, psr_list, amp_list, chunk_start, tres, noise,\
            chunk_nbins, obs, zero)
        print "Time series chunk complete."

    if extra_nbins:
        chunk_start = start + n_full_chunks*(chunk_length/86400.)
        print "Writing time series chunk %d of %d to %s.dat..." % (n_chunks,\
            n_chunks, fname)
        write_to_dat(outfile, psr_list, amp_list, chunk_start, tres, noise,\
            extra_nbins, obs, zero)
        print "Time series chunk complete."

    outfile.close()

    print "Writing %s.inf..." % fname
    inf = infodata()
    inf.name = fname
    inf.telescope = 'NA'
    inf.instrument = 'NA'
    inf.object = 'NA' 
    inf.observer = 'NA'
    inf.mjd_i = start.day_int
    inf.mjd_f = start.day_frac
    inf.bary = 1
    inf.N = nbins
    inf.dt = tres
    inf.band = 'Radio'
    inf.filt = 'NA'
    inf.analyzer = 'NA'
    inf.notes = 'Completely fake data set.'
    writeinf(inf)

    print "Done."