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)
def __init__(self,fn,t_gp): self.t_gp = t_gp fh = mark5b.open(fn, mode='rs', nchan=16, sample_rate=sample_rate, thread_ids=thread_ids, ref_mjd=57000) 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) self.d_dispersed = fh.read(size) #start_time = time.time() #print start_time self.process_data() #print time.time()-start_time self.process_output()
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 = mark5b.open(fn, mode='rs', nchan=16, sample_rate=sample_rate, thread_ids=thread_ids, ref_mjd=57000) 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 = fh.read(size) ft = np.fft.rfft(d, axis=0) # Second half of IFs have Fedge at top, need to subtract frequencies, # and not conjugate coherent phases f = fedge + np.fft.rfftfreq(d.shape[0], dt1)[:, np.newaxis] f[:,8:] = fedge[8:] - np.fft.rfftfreq(d.shape[0], dt1)[:, np.newaxis] ft[:,:8] *= dm(f[:,:8], fref, kind='complex').conj() ft[:,8:] *= dm(f[:,8:], fref, kind='complex') d = np.fft.irfft(ft, axis=0) # Channelize the data dchan = np.fft.rfft(d.reshape(-1, 2*nchan, 16), axis=1)
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 = mark5b.open(fn, mode='rs', nchan=16, sample_rate=sample_rate, thread_ids=thread_ids, ref_mjd=57000) for i in range(745): print('step %s of %s' % (i, 745)) fh.seek(i * step) t0 = fh.tell("time") print(t0.isot) d = pyfftw.empty_aligned((size, 16), dtype='float32') d[:] = fh.read(size) print('First FFT') ft = fft_object_a(d) #d = fh.read(size)