def toafft(toas, freqs, days=0): if days: toas = (toas - toas[0]) * 86400.0 else: toas = toas - toas[0] twid = zeros(len(freqs), 'D') twid.imag = -2.0 * pi * freqs return spectralpower(add.reduce(exp(\ multiply.outer(toas, twid)))) / len(toas)
print "Computing harmonic", harmnum ldr = dr * harmnum ldz = dz * harmnum lor = startr * harmnum loz = 0.0 - (numzs-1)/2 * ldz rs = N.arange(numrs) * ldr + lor zs = N.arange(numzs) * ldz + loz if harmnum==1: rs0, zs0 = rs[:], zs[:] lo_file_r = int(rs.min()) - 1000 hi_file_r = int(rs.max()) + 1000 # Read and normalize the raw spectrum infile.seek(lo_file_r * 8, 0) fftamps = fread(infile, hi_file_r-lo_file_r+1, 'F') fftpows = spectralpower(fftamps) pownorm = 1.0 / (1.442695 * N.median(fftpows)) fftamps *= sqrt(pownorm) ffd = ffdot_plane(fftamps, lor-lo_file_r, ldr, numrs, loz, ldz, numzs) ffd_pows = (ffd * ffd.conj()).real ffdps.append(ffd_pows) if (harmnum==1): sumpows = N.zeros_like(ffd_pows) sumpows += ffd_pows argmax = ffd_pows.argmax() maxvals.append(ffd_pows.max()) maxargs.append((argmax / numrs, argmax % numrs)) print " Maximum power for harmonic %d = %.2f"%(harmnum, maxvals[-1])
a = presto.gen_cvect(1024 * 16384) del a print "success" print "Testing psrparams and orbitparams stuff...", psr = presto.psrepoch("J0737-3039A", 56000.0, verbose=False) assert(round(psr.dm-48.92, 7)==0) # This needs to change when we start using the actual psrcat.db file print "\nTODO: fix the precision of the values in the catalog!!" assert(round(psr.orb.p-8838.72, 7)==0) #assert(round(psr.orb.p-8834.534998272, 7)==0) print "success" print "Testing spectralpower and spectralphase...", a = np.arange(5.0) + complex(0.0, 1.0) assert(np.allclose(presto.spectralpower(a), np.arange(5.0)**2.0 + 1)) assert(np.allclose(presto.spectralphase(a), np.array([90., 45., 26.56505203, 18.43494797, 14.03624344]))) print "success" print "Testing vector shifting / rotation...", a = np.arange(4, dtype=np.float32) presto.frotate(a, 1) assert(np.allclose(a, np.array([1, 2, 3, 0]))) a = np.arange(4, dtype=np.float64) presto.drotate(a, 1) assert(np.allclose(a, np.array([1, 2, 3, 0]))) print "success" print "Testing orbit integration stuff...",
print ' Orbit z =', \ presto.TWOPI*psr.orb.x/psr.p print '' # Create the data set cand = presto.orbitparams() m = 0 comb = presto.gen_bin_response(0.0, 1, psr.p, T, psr.orb , presto.LOWACC, m) ind = len(comb) # The follwoing is performed automatically in gen_bin_resp() now # m = (ind / 2 + 10) * numbetween data = Numeric.zeros(3 * ind, 'F') data[ind:2*ind] = comb if showplots and not parallel: Pgplot.plotxy(presto.spectralpower(data), color='red', title='Data', labx='Fourier Frequency', laby='Relative Power') a = raw_input("Press enter to continue...") Pgplot.nextplotpage(1) # Perform the loops over the Keplarian parameters for job in range(numjobs): if parallel: myjob = work[myid] else: myjob = work[job] if myjob=='p': Dd = Dp psrref = psr.orb.p if myjob=='x':
print ' Orbit z =', \ presto.TWOPI*psr.orb.x/psr.p print '' # Create the data set cand = presto.orbitparams() m = 0 comb = presto.gen_bin_response(0.0, 1, psr.p, T, psr.orb , presto.LOWACC, m) ind = len(comb) # The follwoing is performed automatically in gen_bin_resp() now # m = (ind / 2 + 10) * numbetween data = Numeric.zeros(3 * ind, 'F') data[ind:2*ind] = comb if showplots and not parallel: Pgplot.plotxy(presto.spectralpower(data), color='red', title='Data', labx='Fourier Frequency', laby='Relative Power') a = raw_input("Press enter to continue...") Pgplot.nextplotpage(1) # Perform the loops over the Keplerian parameters for job in range(numjobs): if parallel: myjob = work[myid] else: myjob = work[job] if myjob=='p': Dd = Dp psrref = psr.orb.p if myjob=='x':
a = presto.gen_cvect(1024 * 16384) del a print "success" print "Testing psrparams and orbitparams stuff...", psr = presto.psrepoch("J0737-3039A", 56000.0, verbose=False) assert (round(psr.dm - 48.92, 7) == 0) # This needs to change when we start using the actual psrcat.db file print "\nTODO: fix the precision of the values in the catalog!!" assert (round(psr.orb.p - 8838.72, 7) == 0) #assert(round(psr.orb.p-8834.534998272, 7)==0) print "success" print "Testing spectralpower and spectralphase...", a = np.arange(5.0) + complex(0.0, 1.0) assert (np.allclose(presto.spectralpower(a), np.arange(5.0)**2.0 + 1)) assert (np.allclose( presto.spectralphase(a), np.array([90., 45., 26.56505203, 18.43494797, 14.03624344]))) print "success" print "Testing vector shifting / rotation...", a = np.arange(4, dtype=np.float32) presto.frotate(a, 1) assert (np.allclose(a, np.array([1, 2, 3, 0]))) a = np.arange(4, dtype=np.float64) presto.drotate(a, 1) assert (np.allclose(a, np.array([1, 2, 3, 0]))) print "success" print "Testing orbit integration stuff...",
dr = 1.0 / 32.0 dz = 0.18 np = 512 # number of pixels across for f-fdot image z = 0.0 # average fourier f-dot w = 0.0 # fourier freq double deriv noise = 0.0 #noise = 4*num.random.standard_normal(N) us = num.arange(N, dtype=num.float64) / N # normalized time coordinate r0 = r - 0.5 * z + w / 12.0 # Make symmetric for all z and w z0 = z - 0.5 * w phss = 2.0 * num.pi * (us * (us * (us * w / 6.0 + z0 / 2.0) + r0)) ft = presto.rfft(num.cos(phss) + noise) ffdot = presto.ffdot_plane(ft, rint - np / 2 * dr, dr, np, 0.0 - np / 2 * dz, dz, np) pffdot = presto.spectralpower(ffdot.flat) theo_max_pow = N**2.0 / 4.0 frp = max(pffdot) / theo_max_pow # Fraction of recovered power print("Fraction of recovered signal power = %f" % frp) # print "Raw power should be ~%.2e" % theo_max_pow pffdot = pffdot / theo_max_pow pffdot.shape = (np, np) rs = num.arange(np) * dr - np / 2 * dr zs = num.arange(np) * dz - np / 2 * dz rgx = num.asarray([rs[0], rs[np - 1]]) rgy = num.asarray([zs[0], zs[np - 1]]) freqcut = pffdot[np / 2, :] fdotcut = pffdot[:, np / 2] image = 'antirainbow' device = 'ffdot_combined.eps/VCPS'
print(' Orbit Fourier Freq =', T / psr.orb.p) print(' Orbit z =', \ presto.TWOPI*psr.orb.x/psr.p) print('') # Create the data set cand = presto.orbitparams() m = 0 comb = presto.gen_bin_response(0.0, 1, psr.p, T, psr.orb, presto.LOWACC, m) ind = len(comb) # The follwoing is performed automatically in gen_bin_resp() now # m = (ind / 2 + 10) * numbetween data = Numeric.zeros(3 * ind, 'F') data[ind:2 * ind] = comb if showplots and not parallel: Pgplot.plotxy(presto.spectralpower(data), color='red', title='Data', labx='Fourier Frequency', laby='Relative Power') a = input("Press enter to continue...") Pgplot.nextplotpage(1) # Perform the loops over the Keplerian parameters for job in range(numjobs): if parallel: myjob = work[myid] else: myjob = work[job] if myjob == 'p': Dd = Dp
us = num.arange(N, dtype=num.float64) / N # normalized time coordinate r0 = r - 0.5 * z + w / 12.0 # Make symmetric for all z and w z0 = z - 0.5 * w phss = 2.0 * num.pi * (us * (us * (us * w / 6.0 + z0 / 2.0) + r0)) ft = presto.rfft(num.cos(phss) + noise) a = time.clock() vol = presto.fdotdot_vol(ft, rint - np / 2 * dr, dr, np, 0.0 - np / 2 * dz, dz, np, 0.0 - np / 2 * dw, dw, np) print "First jerk vol took %.3f s" % (time.clock() - a) a = time.clock() vol = presto.fdotdot_vol(ft, rint - np / 2 * dr, dr, np, 0.0 - np / 2 * dz, dz, np, 0.0 - np / 2 * dw, dw, np) print "Second jerk vol took %.3f s" % (time.clock() - a) pvol = presto.spectralpower(vol.flat) theo_max_pow = N**2.0 / 4.0 frp = max(pvol) / theo_max_pow # Fraction of recovered power print "Fraction of recovered signal power = %f" % frp [maxpow, rmax, zmax, rd] = presto.maximize_rz(ft, r + num.random.standard_normal(1)[0] / 5.0, z + num.random.standard_normal(1)[0], norm=1.0) print r, rmax, z, zmax, theo_max_pow, maxpow # print "Raw power should be ~%.2e" % theo_max_pow pvol = pvol / theo_max_pow pvol.shape = (np, np, np) rs = num.arange(np) * dr - np / 2 * dr zs = num.arange(np) * dz - np / 2 * dz ws = num.arange(np) * dw - np / 2 * dw
rint = num.floor(r) dr = 1.0/32.0 dz = 0.18 np = 512 # number of pixels across for f-fdot image z = 10.0 # average fourier f-dot w = -40.0 # fourier freq double deriv noise = 0.0 noise = 1.0*norm(N) us = num.arange(N, dtype=num.float64) / N # normalized time coordinate r0 = r - 0.5 * z + w / 12.0 # Make symmetric for all z and w z0 = z - 0.5 * w phss = 2.0 * num.pi * (us * (us * (us * w/6.0 + z0/2.0) + r0)) ft = presto.rfft(num.cos(phss)+noise) ffdot = presto.ffdot_plane(ft, rint-np/2*dr, dr, np, 0.0-np/2*dz, dz, np) pffdot = presto.spectralpower(ffdot.flat) theo_max_pow = N**2.0/4.0 frp = max(pffdot) / theo_max_pow # Fraction of recovered power print "Fraction of recovered signal power = %f" % frp a = time.clock() [maxpow, rmax, zmax, rd] = presto.maximize_rz(ft, r+norm(1)[0]/5.0, z+norm(1)[0], norm=1.0) print "Time for rz:", time.clock()-a print r, rmax, z, zmax, theo_max_pow, maxpow a = time.clock() [maxpow, rmax, zmax, wmax, rd] = presto.maximize_rzw(ft, r+norm(1)[0]/5.0, z+norm(1)[0], w+norm(1)[0]*5.0, norm=1.0) print "Time for rzw:", time.clock()-a print r, rmax, z, zmax, w, wmax, theo_max_pow, maxpow
print "Computing harmonic", harmnum ldr = dr * harmnum ldz = dz * harmnum lor = startr * harmnum loz = 0.0 - (numzs - 1) / 2 * ldz rs = N.arange(numrs) * ldr + lor zs = N.arange(numzs) * ldz + loz if harmnum == 1: rs0, zs0 = rs[:], zs[:] lo_file_r = int(rs.min()) - 1000 hi_file_r = int(rs.max()) + 1000 # Read and normalize the raw spectrum infile.seek(lo_file_r * 8, 0) fftamps = N.fromfile(infile, 'F', hi_file_r - lo_file_r + 1) fftpows = spectralpower(fftamps) pownorm = 1.0 / (1.442695 * N.median(fftpows)) fftamps *= sqrt(pownorm) ffd = ffdot_plane(fftamps, lor - lo_file_r, ldr, numrs, loz, ldz, numzs) ffd_pows = (ffd * ffd.conj()).real ffdps.append(ffd_pows) if (harmnum == 1): sumpows = N.zeros_like(ffd_pows) sumpows += ffd_pows argmax = ffd_pows.argmax() maxvals.append(ffd_pows.max()) maxargs.append((argmax / numrs, argmax % numrs)) print " Maximum power for harmonic %d = %.2f" % (harmnum, maxvals[-1])
r0 = r - 0.5 * z + w / 12.0 # Make symmetric for all z and w z0 = z - 0.5 * w phss = 2.0 * num.pi * (us * (us * (us * w/6.0 + z0/2.0) + r0)) ft = presto.rfft(num.cos(phss)+noise) a = time.clock() vol = presto.fdotdot_vol(ft, rint-np/2*dr, dr, np, 0.0-np/2*dz, dz, np, 0.0-np/2*dw, dw, np) print "First jerk vol took %.3f s" % (time.clock()-a) a = time.clock() vol = presto.fdotdot_vol(ft, rint-np/2*dr, dr, np, 0.0-np/2*dz, dz, np, 0.0-np/2*dw, dw, np) print "Second jerk vol took %.3f s" % (time.clock()-a) pvol = presto.spectralpower(vol.flat) theo_max_pow = N**2.0/4.0 frp = max(pvol) / theo_max_pow # Fraction of recovered power print "Fraction of recovered signal power = %f" % frp [maxpow, rmax, zmax, rd] = presto.maximize_rz(ft, r+num.random.standard_normal(1)[0]/5.0, z+num.random.standard_normal(1)[0], norm=1.0) print r, rmax, z, zmax, theo_max_pow, maxpow # print "Raw power should be ~%.2e" % theo_max_pow pvol = pvol / theo_max_pow pvol.shape = (np, np, np) rs = num.arange(np) * dr - np/2*dr zs = num.arange(np) * dz - np/2*dz ws = num.arange(np) * dw - np/2*dw rgx = num.asarray([rs[0], rs[np-1]]) rgy = num.asarray([zs[0], zs[np-1]])
from presto import spectralpower from periodogram import * from time import clock file = 'rosat_crab_3k.toa' toas = ravel(readColumns(file, '#')) toas = (toas - toas[0]) * 86400.0 T = toas[-1] - toas[0] df = 1.0 / (10.0 * T) p0 = 0.033468239225/2 numf = 100000 lof = 1.0 / p0 - df * numf / 2.0 freqs = arange(numf) * df + lof beg = clock() mypows = spectralpower(toafft(toas, len(toas), lof, df, numf)) end = clock() print ' TOAFFT took ', end-beg, ' sec. (%d freqs/sec)' % (numf/(end-beg)) beg = clock() pows = periodogram(ones(len(toas), 'd'), toas, len(toas), lof, df, numf) end = clock() print 'periodogram took ', end-beg, ' sec. (%d freqs/sec)' % (numf/(end-beg)) def toafft(toas, freqs, days=0): if days: toas = (toas - toas[0]) * 86400.0 else: toas = toas - toas[0] twid = zeros(len(freqs), 'D') twid.imag = -2.0 * pi * freqs return spectralpower(add.reduce(exp(\