def estimate_rz(psr, T, show=0, device='/XWIN'): """ estimate_rz(psr, T, show=0, device='/XWIN'): Return estimates of a pulsar's average Fourier freq ('r') relative to its nominal Fourier freq as well as its Fourier f-dot ('z') in bins, of a pulsar. 'psr' is a psrparams structure describing the pulsar. 'T' is the length of the observation in sec. 'show' if true, displays plots of 'r' and 'z'. 'device' if the device to plot to if 'show' is true. """ startE = keplers_eqn(psr.orb.t, psr.orb.p, psr.orb.e, 1.0E-15) numorbpts = int(T / psr.orb.p + 1.0) * 1024 + 1 dt = T / (numorbpts - 1) E = dorbint(startE, numorbpts, dt, psr.orb) z = z_from_e(E, psr, T) r = T/p_from_e(E, psr) - T/psr.p if show: times = np.arange(numorbpts) * dt Pgplot.plotxy(r, times, labx = 'Time', \ laby = 'Fourier Frequency (r)', device=device) if device=='/XWIN': print 'Press enter to continue:' i = raw_input() Pgplot.nextplotpage() Pgplot.plotxy(z, times, labx = 'Time', laby = 'Fourier Frequency Derivative (z)', device=device) Pgplot.closeplot() return r.mean(), z.mean()
def estimate_rz(psr, T, show=0, device='/XWIN'): """ estimate_rz(psr, T, show=0, device='/XWIN'): Return estimates of a pulsar's average Fourier freq ('r') relative to its nominal Fourier freq as well as its Fourier f-dot ('z') in bins, of a pulsar. 'psr' is a psrparams structure describing the pulsar. 'T' is the length of the observation in sec. 'show' if true, displays plots of 'r' and 'z'. 'device' if the device to plot to if 'show' is true. """ startE = keplers_eqn(psr.orb.t, psr.orb.p, psr.orb.e, 1.0E-15) numorbpts = int(T / psr.orb.p + 1.0) * 1024 + 1 dt = T / (numorbpts - 1) E = dorbint(startE, numorbpts, dt, psr.orb) z = z_from_e(E, psr, T) r = T / p_from_e(E, psr) - T / psr.p if show: times = Num.arange(numorbpts) * dt Pgplot.plotxy(r, times, labx = 'Time', \ laby = 'Fourier Frequency (r)', device=device) if device == '/XWIN': print 'Press enter to continue:' i = raw_input() Pgplot.nextplotpage() Pgplot.plotxy(z, times, labx='Time', laby='Fourier Frequency Derivative (z)', device=device) Pgplot.closeplot() return r.mean(), z.mean()
def kuiper_uniform_test(data, output=0): """ kuiper_uniform_test(data, output=0): Conduct a Kuiper test on the data. The data must be values within [0,1) (e.g. phases from a periodicity search). They will be compared to a uniform distribution. The return value is the probability that the data is uniformly distributed. """ sdata = num.asarray(data) N = sdata.size sdata.sort() f0 = num.arange(N, dtype=num.float64)/N fn = (num.arange(N, dtype=num.float64)+1.0)/N Dp = (fn - sdata).max() Dm = (sdata - f0).max() D = Dp + Dm P = kuiper_prob(D, N) if (output): xs = (num.arange(N+3, dtype=num.float64)/(N+2.0)).repeat(2)[1:-1] ys = num.concatenate((num.asarray([0.0]), sdata, num.asarray([1.0]))).repeat(2) Pgplot.plotxy(ys, xs, rangex=[-0.03, 1.03], rangey=[-0.03, 1.03], aspect=1.0, labx="Fraction of Data", laby="Cumulative Value", width=2) Pgplot.plotxy(num.asarray([0.0, 1.0]), num.asarray([0.0, 1.0]), width=1) Pgplot.closeplot() print("Max distance between the cumulative distributions (D) = %.5g" % D) print("Prob the data is from the specified distrbution (P) = %.3g" % P) return (D, P)
def kuiper_uniform_test(data, output=0): """ kuiper_uniform_test(data, output=0): Conduct a Kuiper test on the data. The data must be values within [0,1) (e.g. phases from a periodicity search). They will be compared to a uniform distribution. The return value is the probability that the data is uniformly distributed. """ sdata = num.asarray(data) N = sdata.size sdata.sort() f0 = num.arange(N, dtype=num.float64)/N fn = (num.arange(N, dtype=num.float64)+1.0)/N Dp = (fn - sdata).max() Dm = (sdata - f0).max() D = Dp + Dm P = kuiper_prob(D, N) if (output): xs = (num.arange(N+3, dtype=num.float64)/(N+2.0)).repeat(2)[1:-1] ys = num.concatenate((num.asarray([0.0]), sdata, num.asarray([1.0]))).repeat(2) Pgplot.plotxy(ys, xs, rangex=[-0.03, 1.03], rangey=[-0.03, 1.03], aspect=1.0, labx="Fraction of Data", laby="Cumulative Value", width=2) Pgplot.plotxy(num.asarray([0.0, 1.0]), num.asarray([0.0, 1.0]), width=1) Pgplot.closeplot() print "Max distance between the cumulative distributions (D) = %.5g" % D print "Prob the data is from the specified distrbution (P) = %.3g" % P return (D, P)
# Powers averaged over orb.t as a function of orb.w pwrs_w = zeros((orbsperpt[ctype], numbins), Float32) for ct in range(orbsperpt[ctype]): wb = ct * 180.0 / orbsperpt[ctype] if debugout: print('wb = '+repr(wb)) psr = psrparams_from_list([pp, Pb, xb, ecc[ctype], wb, 0.0]) for i in range(numffts): psr.orb.t = i * Tfft tmppwrs = spectralpower(gen_bin_response(0.0, numbetween, psr.p, Tfft, psr.orb, numbins)) if debugout: print(' tb = '+repr(psr.orb.t)+' Max pow = '+\ repr(max(tmppwrs))) if showplots: Pgplot.plotxy(tmppwrs) Pgplot.closeplot() pwrs_w[ct] = pwrs_w[ct] + tmppwrs if showsumplots: Pgplot.plotxy(pwrs_w[ct], title='power(w) averaged over orb.t') Pgplot.closeplot() pwrs_w = pwrs_w / numffts max_avg_pow = average(maximum.reduce(pwrs_w,1)) if showsumplots: Pgplot.plotxy(add.reduce(pwrs_w), title='power(w) averaged over orb.t') Pgplot.closeplot() tim = clock() - stim if debugout: print('Time for this point was ',tim, ' s.') file.write('%8.6f %10.5f %10d %13.9f\n' % \ (pp, Tfft, int(Tfft/dt), max_avg_pow)) file.flush()
template -= min(template) template /= max(template) # Rotate it so that it becomes a "true" template according to FFTFIT shift, eshift, snr, esnr, b, errb, ngood = measure_phase( template, template) template = psr_utils.fft_rotate(template, shift) # Determine the off-pulse bins if bkgd_vals is not None: Pgplot.plotxy(template, labx="Phase bins") Pgplot.plotxy(template[bkgd_vals], Num.arange(numbins)[bkgd_vals], line=None, symbol=2, color='red') Pgplot.closeplot() offpulse_inds = bkgd_vals onpulse_inds = set(Num.arange(numbins)) - set(bkgd_vals) else: offpulse_inds = Num.compress(template <= bkgd_cutoff, Num.arange(numbins)) onpulse_inds = Num.compress(template > bkgd_cutoff, Num.arange(numbins)) Pgplot.plotxy(template) Pgplot.plotxy([bkgd_cutoff, bkgd_cutoff], [0.0, numbins], color='red') Pgplot.closeplot() # If the number of bins in the offpulse section is < 10% of the total # use the statistics in the .pfd file to set the RMS if (len(offpulse_inds) < 0.1 * numbins): print( "Number of off-pulse bins to use for RMS is too low. Using .pfd stats."