Beispiel #1
0
 def __init__(self, fits_filenm):
     self.fits_filenm = fits_filenm
     self.basefilenm = fits_filenm[:fits_filenm.find(".fits")]
     self.dsbasefilenm = fits_filenm[:fits_filenm.rfind("_")]
     fitshandle=pyfits.open(fits_filenm)
     self.MJD = fitshandle[0].header['STT_IMJD']+fitshandle[0].header['STT_SMJD']/86400.0+fitshandle[0].header['STT_OFFS']/86400.0
     self.nchans = fitshandle[0].header['OBSNCHAN']
     self.ra_string = fitshandle[0].header['RA']
     self.dec_string = fitshandle[0].header['DEC']
     self.str_coords = "J"+"".join(self.ra_string.split(":")[:2])
     self.str_coords += "".join(self.dec_string.split(":")[:2])
     self.nbits=fitshandle[0].header['BITPIX']
     
     self.raw_N=fitshandle[1].header['NAXIS2']*fitshandle[1].header['NSBLK']
     self.dt=fitshandle[1].header['TBIN']*1000000
     self.raw_T = self.raw_N * self.dt
     self.N = raw_N
     if self.dt == 163.84:
       self.N=self.N/2
     self.T = self.N * self.dt
     self.srcname=fitshandle[0].header['SRC_NAME']
     # Determine the average barycentric velocity of the observation
     self.baryv = presto.get_baryv(self.ra_string, self.dec_string,
                                   self.MJD, self.T, obs="GB")
     # Where to dump all the results
     # Directory structure is under the base_output_directory
     # according to base/MJD/filenmbase/beam
     self.outputdir = os.path.join(base_output_dir,
                                   str(int(self.MJD)),
                                   self.srcname)
     # Figure out which host we are processing on
     self.hostname = socket.gethostname()
     # The fraction of the data recommended to be masked by rfifind
     self.masked_fraction = 0.0
     # Initialize our timers
     self.rfifind_time = 0.0
     self.downsample_time = 0.0
     self.dedispersing_time = 0.0
     self.FFT_time = 0.0
     self.lo_accelsearch_time = 0.0
     self.hi_accelsearch_time = 0.0
     self.singlepulse_time = 0.0
     self.sifting_time = 0.0
     self.folding_time = 0.0
     self.total_time = 0.0
     # Inialize some candidate counters
     self.num_sifted_cands = 0
     self.num_folded_cands = 0
     self.num_single_cands = 0
Beispiel #2
0
 def __init__(self, fil_filenm):
     self.fil_filenm = fil_filenm
     self.basefilenm = fil_filenm[:fil_filenm.find(".fil")]
     filhdr, hdrlen = sigproc.read_header(fil_filenm)
     self.MJD = filhdr['tstart']
     self.nchans = filhdr['nchans']
     self.ra_rad = sigproc.ra2radians(filhdr['src_raj'])
     self.ra_string = pu.coord_to_string(*pu.rad_to_hms(self.ra_rad))
     self.dec_rad = sigproc.dec2radians(filhdr['src_dej'])
     self.dec_string = pu.coord_to_string(*pu.rad_to_dms(self.dec_rad))
     self.str_coords = "J"+"".join(self.ra_string.split(":")[:2])
     if self.dec_rad >= 0.0:  self.str_coords += "+"
     self.str_coords += "".join(self.dec_string.split(":")[:2])
     self.az = filhdr['az_start']
     self.el = 90.0-filhdr['za_start']
     fillen = os.stat(fil_filenm)[6]
     self.raw_N = (fillen-hdrlen)/(filhdr['nbits']/8)/filhdr['nchans']
     self.dt = filhdr['tsamp']
     self.raw_T = self.raw_N * self.dt
     self.N = orig_N
     self.T = self.N * self.dt
     # Determine the average barycentric velocity of the observation
     self.baryv = presto.get_baryv(self.ra_string, self.dec_string,
                                   self.MJD, self.T, obs="GB")
     # Where to dump all the results
     # Directory structure is under the base_output_directory
     # according to base/MJD/filenmbase/beam
     self.outputdir = os.path.join(base_output_dir,
                                   str(int(self.MJD)),
                                   self.str_coords)
     # Figure out which host we are processing on
     self.hostname = socket.gethostname()
     # The fraction of the data recommended to be masked by rfifind
     self.masked_fraction = 0.0
     # Initialize our timers
     self.rfifind_time = 0.0
     self.downsample_time = 0.0
     self.dedispersing_time = 0.0
     self.FFT_time = 0.0
     self.lo_accelsearch_time = 0.0
     self.hi_accelsearch_time = 0.0
     self.singlepulse_time = 0.0
     self.sifting_time = 0.0
     self.folding_time = 0.0
     self.total_time = 0.0
     # Inialize some candidate counters
     self.num_sifted_cands = 0
     self.num_folded_cands = 0
     self.num_single_cands = 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=0,
                      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=' + repr(pM) + ' count=' + repr(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')
        if options.wmax > 0:
            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 +
                      '_JERK_%d.txtcand' % options.wmax)
            myexecute('cp ' + outname + '_JERK_%d ' % options.wmax +
                      options.outdir)
            myexecute('cp ' + outname + '_JERK_%d.cand ' % options.wmax +
                      options.outdir)
        else:
            myexecute(
                'accelsearch -sigma %.2f -zmax %d -numharm %d -flo %f -fhi %f '
                % (options.sigma, options.zmax, options.numharm, options.flo,
                   options.fhi) + outname + '.fft')
            myexecute('rm ' + outname + '.fft ' + outname +
                      '_ACCEL_%d.txtcand' % options.zmax)
            myexecute('cp ' + outname + '_ACCEL_%d ' % options.zmax +
                      options.outdir)
            myexecute('cp ' + outname + '_ACCEL_%d.cand ' % options.zmax +
                      options.outdir)
        myexecute('cp ' + outname + '.inf ' + options.outdir)
        num = num + 1
        point = point + int(options.nM * options.frac)
Beispiel #4
0
print("Testing angle functions...", end=' ')
dd1 = 15.25
dd2 = presto.dms2rad(*presto.deg2dms(dd1))*presto.RADTODEG
assert(round(dd1-dd2, 12)==0)
dd1 = -0.5
dd2 = presto.dms2rad(*presto.deg2dms(dd1))*presto.RADTODEG
assert(round(dd1-dd2, 12)==0)
hh1 = 12.125
hh2 = presto.hms2rad(*presto.hours2hms(hh1))*presto.RADTODEG/15.0
assert(round(hh1-hh2, 12)==0)
hh1 = -0.5
hh2 = presto.hms2rad(*presto.hours2hms(hh1))*presto.RADTODEG/15.0
assert(round(hh1-hh2, 12)==0)
ang = presto.sphere_ang_diff(10.0*presto.DEGTORAD, 10.0*presto.DEGTORAD,
                             50.0*presto.DEGTORAD, -10.0*presto.DEGTORAD)
assert(round(160334.960*presto.ARCSEC2RAD-ang, 7)==0)
print("success")

# Only run this test if TEMPO is available
envval = os.getenv("TEMPO")
if envval is not None:
    print("Testing get_baryv (barycenter)...", end=' ')
    vavg1 = presto.get_baryv("18:24:32.9520", "-24:52:12.0000",
                             56421.44222222222222, 214.5386496, obs="GB")
    vavg2 = -7.2069293455783169e-05
    assert(round(vavg1-vavg2, 10)==0)
    print("success")
else:
    print("Skipping test of presto.get_baryv() since TEMPO not set.")

Beispiel #5
0
 def __init__(self, fil_filenm):
     self.fil_filenm = fil_filenm
     self.basefilenm = fil_filenm.rstrip(".fil")
     self.beam = int(self.basefilenm[-1])
     filhdr, self.hdrlen = sigproc.read_header(fil_filenm)
     self.orig_filenm = filhdr['rawdatafile']
     self.MJD = filhdr['tstart']
     self.nchans = filhdr['nchans']
     self.ra_rad = sigproc.ra2radians(filhdr['src_raj'])
     self.ra_string = psr_utils.coord_to_string(\
         *psr_utils.rad_to_hms(self.ra_rad))
     self.dec_rad = sigproc.dec2radians(filhdr['src_dej'])
     self.dec_string = psr_utils.coord_to_string(\
         *psr_utils.rad_to_dms(self.dec_rad))
     self.az = filhdr['az_start']
     self.el = 90.0 - filhdr['za_start']
     self.BW = abs(filhdr['foff']) * filhdr['nchans']
     self.dt = filhdr['tsamp']
     self.orig_N = sigproc.samples_per_file(fil_filenm, filhdr, self.hdrlen)
     self.orig_T = self.orig_N * self.dt
     self.N = psr_utils.choose_N(self.orig_N)
     self.T = self.N * self.dt
     # Update the RA and DEC from the database file if required
     newposn = read_db_posn(self.orig_filenm, self.beam)
     if newposn is not None:
         self.ra_string, self.dec_string = newposn
         # ... and use them to update the filterbank file
         fix_fil_posn(fil_filenm, self.hdrlen, self.ra_string,
                      self.dec_string)
     # Determine the average barycentric velocity of the observation
     self.baryv = presto.get_baryv(self.ra_string,
                                   self.dec_string,
                                   self.MJD,
                                   self.T,
                                   obs="AO")
     # Where to dump all the results
     # Directory structure is under the base_output_directory
     # according to base/MJD/filenmbase/beam
     self.outputdir = os.path.join(base_output_directory,
                                   str(int(self.MJD)), self.basefilenm[:-2],
                                   str(self.beam))
     # Figure out which host we are processing on
     self.hostname = socket.gethostname()
     # The fraction of the data recommended to be masked by rfifind
     self.masked_fraction = 0.0
     # Initialize our timers
     self.rfifind_time = 0.0
     self.downsample_time = 0.0
     self.subbanding_time = 0.0
     self.dedispersing_time = 0.0
     self.FFT_time = 0.0
     self.lo_accelsearch_time = 0.0
     self.hi_accelsearch_time = 0.0
     self.singlepulse_time = 0.0
     self.sifting_time = 0.0
     self.folding_time = 0.0
     self.total_time = 0.0
     # Inialize some candidate counters
     self.num_sifted_cands = 0
     self.num_folded_cands = 0
     self.num_single_cands = 0