Exemple #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."
Exemple #2
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."
Exemple #3
0
    3: 1.0 / 12,
    4: 1.0 / 12,
    5: 1.0 / 60,
    6: 1.0 / 60
}

# The following are for the lowest harmonic
zmax = 20
dr = drs[numharm]
dz = dr * 4.0
numrs = int(round(4 * zmax / dr))
numzs = int(round(2 * zmax / dz)) + 1

infilenm = sys.argv[1]
infile = open(infilenm, 'rb')
idata = infodata(infilenm[:-4] + ".inf")
idata.T = idata.N * idata.dt

ctrr = int(round(float(sys.argv[2]) * idata.T))
startr = int(ctrr - numrs / 2 * dr)
ctrfreq = ctrr / idata.T

ffdps = []
maxvals = []
maxargs = []

for harmnum in range(1, numharm + 1):
    print("Computing harmonic", harmnum)
    ldr = dr * harmnum
    ldz = dz * harmnum
    lor = startr * harmnum