示例#1
0
def convert_tim_to_dat(tim):
    """Convert a SIGPROC time series .tim file to a
        PRESTO .dat time series

        Input:
            tim: The SIGPROC .tim time series file to convert.

        Output:
            datfn: The PRESTO .dat time series file
    """
    if not tim.endswith(".tim"):
        raise ValueError("Was expecting a file name ending with '.tim'. "
                         "Got: %s" % tim)
    path, fn = os.path.split(tim)
    basenm = fn[:-4]
    outfn = os.path.join(path, basenm + ".dat")
    hdr, hdrlen = sigproc.read_header(tim)
    N = sigproc.samples_per_file(tim, hdr, hdrlen)
    Ndone = 0
    status = -1
    with open(tim, 'rb') as inff, open(outfn, 'wb') as outff:
        inff.seek(hdrlen)
        data = np.fromfile(inff, dtype='float32', count=BLOCKSIZE)
        while data.size:
            data.tofile(outff)
            Ndone += data.size
            data = np.fromfile(inff, dtype='float32', count=BLOCKSIZE)
            newstatus = int(100.0 * Ndone / N)
            if newstatus > status:
                sys.stdout.write(" %d %%\r" % newstatus)
                sys.stdout.flush()
                status = newstatus
    return outfn
示例#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
示例#3
0
def main():
    for tim in args.timfiles:
        print("Working on %s" % tim)

        if args.write_dat:
            try:
                datfn = convert_tim_to_dat(tim)
                print("    Wrote PRESTO time series: %s" % datfn)
            except ValueError as e:
                sys.stderr.write("Error encountered when converting on %s" %
                                 tim)
                sys.stderr.write(str(e))
        else:
            datfn = tim[-3:] + "dat"
        hdr, hdrlen = sigproc.read_header(tim)
        inffn = write_inf_file(datfn, hdr, hdrlen)
        print("    Wrote info data: %s" % inffn)
示例#4
0
                print("1st_file_samps = ", first_file_subints)
                print("numfiles       = ", numfiles)
            break
        else:
            accum_subints += subints_per_file[ii]

    # Now make a command line option for guppidrift2fil.py
    tmpfilenm = "tmp%d.fil" % random.randint(0, 2**30)
    cmd = "guppidrift2fil.py --skip=%d --nsubint=%d -o %s " % \
          (skip, raw_N, tmpfilenm)
    for goodfile in infilenms[ii:ii + numfiles]:
        cmd += "%s " % goodfile
        print(cmd)
    os.system(cmd)

    # Now read the header to determine what the correct filename
    # should be.  Use that to rename the fil file.

    filhdr, hdrlen = sigproc.read_header(tmpfilenm)
    MJDi = int(filhdr['tstart'])
    ra_rad = sigproc.ra2radians(filhdr['src_raj'])
    ra_string = pu.coord_to_string(*pu.rad_to_hms(ra_rad))
    dec_rad = sigproc.dec2radians(filhdr['src_dej'])
    dec_string = pu.coord_to_string(*pu.rad_to_dms(dec_rad))
    str_coords = "".join(ra_string.split(":")[:2])
    if dec_rad >= 0.0: str_coords += "+"
    str_coords += "".join(dec_string.split(":")[:2])
    filfilenm = "GBT350drift_%d_%s.fil" % (MJDi, str_coords)
    os.rename(tmpfilenm, filfilenm)
    print("Renamed '%s' to '%s'." % (tmpfilenm, filfilenm))
示例#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