Esempio n. 1
0
def BasebandProcess(ar_data, band, SR, dt, N, DN, offset, i, dd_coh, ngate):
    print('ar_data', ar_data)
    fh = mark4.open(ar_data,
                    'rs',
                    ntrack=64,
                    decade=2010,
                    sample_rate=SR,
                    thread_ids=[2 * band, 2 * band + 1])
    fh.seek(offset + i * (N - DN))
    t0 = fh.tell(unit='time')
    print('t0', t0)
    t1 = t0.mjd
    print('t1', t1)
    print('N-DN', N - DN)
    print('dt', dt)
    print('ngate', ngate)
    # note ph is equilibrium to ((ph)*P0) / (P0/ngate) % ngate
    ph, ncycle = FindPhase(t0, N - DN, dt, ngate)
    ph %= ngate
    print('ph3', ph)
    z = fh.read(N)
    z = rfft(z, axis=0, **_fftargs)
    z *= dd_coh[..., np.newaxis]
    z = irfft(z, axis=0, **_fftargs)[:-DN]
    z = z.astype(np.float32)
    z = z * z
    return ph, z
Esempio n. 2
0
def FindOffset(ar_data, SR):
    from astropy.time import Time
    fh = mark4.open(ar_data, 'rs', ntrack=64, decade=2010, sample_rate=SR)
    t0 = fh.time0
    offset_time = Time(math.ceil(t0.unix), format='unix', precision=9)
    offset = fh.seek(offset_time)
    t00 = np.float128(offset_time.mjd)  # previous: isot
    print('offset', offset)
    print('t00', t00)
    return offset, t00
Esempio n. 3
0
    def open(self, fname):
        """Open data with appropriate baseband reader"""

        if self.dtype == 'vdif':
            self.fh = vdif.open(fname, mode='rs', sample_rate=self.sample_rate)

        if self.dtype == 'mark4':
            self.fh = mark4.open(fname, mode='rs', decade=2010, ntrack=self.ntrack,
                                 sample_rate=self.sample_rate, thread_ids=self.thread_ids)

        if self.dtype == 'mark5b':
            self.fh = mark5b.open(fname, mode='rs', nchan=self.nIF, ref_mjd=57000,
                                  sample_rate=self.sample_rate, thread_ids=self.thread_ids)
Esempio n. 4
0
    def open(self, fname):
        """Open data with appropriate baseband reader"""

        if self.dtype == 'vdif':
            self.fh = vdif.open(fname, mode='rs', sample_rate=self.sample_rate)

        if self.dtype == 'mark4':
            self.fh = mark4.open(fname,
                                 mode='rs',
                                 decade=2010,
                                 ntrack=self.ntrack,
                                 sample_rate=self.sample_rate,
                                 thread_ids=self.thread_ids)

        if self.dtype == 'mark5b':
            self.fh = mark5b.open(fname,
                                  mode='rs',
                                  nchan=self.nIF,
                                  ref_mjd=57000,
                                  sample_rate=self.sample_rate,
                                  thread_ids=self.thread_ids)
Esempio n. 5
0
            dang = (d * f * (1./fref-1./f)**2) * u.cycle
            if kind == 'phase':
                return dang
            elif kind == 'complex':
                return np.exp(dang.to(u.rad).value * 1j)

        raise ValueError("kind not one of 'delay', 'phase', or 'complex'")


print("Pre-Calculating De-Dispersion Phases")
dm = DispersionMeasure(dm)
dd = dm(f, fref, kind='complex').conj()

if __name__ == '__main__':
    print('Reading...')
    fh = mark4.open(fn, mode='rs', decade=2010, ntrack=64,
                    sample_rate=sample_rate, thread_ids=thread_ids)
    offset_gp = ((t_gp - fh.tell(unit='time')).to(u.s).value *
                 fh.frames_per_second * fh.samples_per_frame)
    fh.seek(int(offset_gp) - size // 2)

    d = pyfftw.empty_aligned((2**25,6), dtype='float32')
    d[:] = fh.read(size)
    print('First FFT')
    ft = fft_object_a(d)
    print('De-Dispersing')
    ft *= dd
    print('Second FFT')
    d = pyfftw.empty_aligned((2**24+1,6), dtype='complex64')
    d[:] = ft
    data = fft_object_b(d)
    plt.ion()
fdir = '/scratch/p/pen/simardda/B1133/gk049c/ar/'
fname = sys.argv[1]
output_name = fname[:-4]

# Load Data
frequency = np.array([[320.25], [320.25], [336.25], [336.25]]) * u.MHz
sideband = np.array([[-1, -1], [1, 1], [-1, -1], [1, 1]])
polarization = ['R', 'L']
dispersion_measure = 4.84066 * u.pc / u.cm**3
polyco_file = 'B1133_ar_polycopolyco_new.dat'
fullpol = False
print("Parameters set")

# Creating stream reader. For other formats, such as vdif, use vdif.open(...)
fh = mark4.open(fdir + fname, 'rs', decade=2010)
rh = Reshape(fh, (4, 2))
dt = TimeDelta(10, format='sec')

# Rounding Time
start = Time(rh.time)
start_time_str = start.iso.__str__()
new_time = Time(start_time_str, precision = -1)
new_time_str = new_time.iso.__str__()
start_time = Time(new_time_str) + dt

print("Opened stream reader with sample shape:", rh.sample_shape)
print("Starting at time:", start_time)

# Initial waterfall interpretor
WF = sr.Fold(rh, dispersion_measure, frequency, sideband, polyco_file, polarization, fullpol,start=start_time, nthreads=1)
Esempio n. 7
0
            return d * (1./f**2 - 1./fref**2)
        else:
            dang = (d * f * (1./fref-1./f)**2) * u.cycle
            if kind == 'phase':
                return dang
            elif kind == 'complex':
                return np.exp(dang.to(u.rad).value * 1j)

        raise ValueError("kind not one of 'delay', 'phase', or 'complex'")


dm = DispersionMeasure(dm)


if __name__ == '__main__':
    fh = mark4.open(fn, mode='rs', decade=2010, ntrack=64,
                    sample_rate=sample_rate, thread_ids=thread_ids)

    # Compute offset to have giant pulse in middle of data chunk
    offset_gp = ((t_gp - fh.tell(unit='time')).to(u.s).value *
                 fh.frames_per_second * fh.samples_per_frame)

    # Go to that offset, read "size" number of samples
    fh.seek(int(offset_gp) - size // 2)
    d = fh.read(size)

    # For coherent de-dispersion, FT to frequency space 
    # apply de-dispersion delay as phase rotation
    ft = np.fft.rfft(d, axis=0)
    f = fedge + np.fft.rfftfreq(d.shape[0], dt1)[:, np.newaxis]
    ft *= dm(f, fref, kind='complex').conj()
    d = np.fft.irfft(ft, axis=0)