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]) if (convals.max() < 1.5): # Using relative contours print "Using relative contours.." pow_contours = convals * maxvals[-1] else:
#r = N/4.0 + 0.5 # average freq over "observation" 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
#r = N/4.0 + 0.5 # average freq over "observation" rint = num.floor(r) 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'
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]) if (convals.max() < 1.5): # Using relative contours print "Using relative contours.." pow_contours = convals * maxvals[-1] else: