Skip to content

Commit

Permalink
Updated python test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
scottransom committed Nov 12, 2019
1 parent c7e036f commit 8236dc1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
22 changes: 14 additions & 8 deletions tests/test_max_rzw_harmonics.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import sys
import time
import numpy as np
from presto import presto
from numpy.random import standard_normal as norm
from numpy.random import uniform
import time
from presto import presto

if sys.version_info[0]<3:
clk = time.clock
else:
clk = time.perf_counter

N = 2**17
noiseamp = 1.0
Expand Down Expand Up @@ -36,7 +42,7 @@

offset = uniform(-1.0, 1.0, 3) * np.array([0.5, 2.0, 20.0]) / (0.5 * numharm)

a = time.clock()
a = clk()
if (numharm > 1):
[maxpow, rmax, zmax, rds] = presto.maximize_rz_harmonics(ft, r+offset[0],
z+offset[1], numharm,
Expand All @@ -45,10 +51,10 @@
[maxpow, rmax, zmax, rd] = presto.maximize_rz(ft, r+offset[0],
z+offset[1],
norm=1.0)
rztime += time.clock() - a
rztime += clk() - a
rzerrs[n] = (maxpow/numharm - theo_max_pow) / theo_max_pow, rmax - r, zmax - z

a = time.clock()
a = clk()
if (numharm > 1):
[maxpow, rmax, zmax, wmax, rds] = presto.maximize_rzw_harmonics(ft, r+offset[0],
z+offset[1],
Expand All @@ -59,11 +65,11 @@
z+offset[1],
w+offset[2],
norm=1.0)
rzwtime += time.clock() - a
rzwtime += clk() - a
rzwerrs[n] = (maxpow/numharm - theo_max_pow) / theo_max_pow, rmax - r, zmax - z, wmax - w

print("Time for rz: %s".format(rztime / numtrials))
print("Time for rzw: %s".format(rzwtime / numtrials))
print("Time for rz: %f" % (rztime / numtrials))
print("Time for rzw: %f" % (rzwtime / numtrials))

print("rzerrs:")
print(" avg: %6.3f %6.3f %6.3f" % tuple(rzerrs.mean(axis=0)))
Expand Down
10 changes: 3 additions & 7 deletions tests/test_presto_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

here = path.dirname(__file__)



print("Testing FFT stuff...", end=' ')
N = 20
x = np.random.standard_normal(N)
Expand Down Expand Up @@ -66,9 +64,7 @@
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)
assert(round(psr.orb.p-8834.534998272, 7)==0)
print("success")

print("Testing spectralpower and spectralphase...", end=' ')
Expand Down Expand Up @@ -121,7 +117,6 @@
numbetween = 16
z = 5.0
w = 40.0
# Should use w_resp_halfwidth() for this. Need to update that!
bins_per_side = max([presto.r_resp_halfwidth(presto.LOWACC), \
presto.z_resp_halfwidth(z, presto.LOWACC), \
presto.w_resp_halfwidth(z, w, presto.LOWACC)])
Expand All @@ -133,7 +128,8 @@
pz = presto.spectralpower(zresp)
pw = presto.spectralpower(wresp)
rs = np.arange(float(nn))/numbetween - bins_per_side
if 0:
if False:
import matplotlib.pyplot as plt
plt.plot(rs, pr, 'b-')
plt.plot(rs, pz, 'g-')
plt.plot(rs, pw, 'r-')
Expand Down

0 comments on commit 8236dc1

Please sign in to comment.