/
test_presto_python.py
167 lines (154 loc) · 5.24 KB
/
test_presto_python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import numpy as np
import presto
import os
import matplotlib.pyplot as plt
print "Testing FFT stuff...",
N = 20
x = np.random.standard_normal(N)
nx = presto.rfft(presto.rfft(x, -1), 1)
assert(np.allclose(x, nx, atol=1e-6))
print "success"
print "Testing FFTW call...",
cx = np.random.standard_normal(N).astype(np.complex64)
ncx = np.array(cx, copy=1)
presto.fftwcall(cx, -1)
presto.fftwcall(cx, 1)
assert(np.allclose(cx/N, ncx, atol=1e-6))
print "success"
print "Testing tablesixstepfft call...",
cx = np.random.standard_normal(N).astype(np.complex64)
ncx = np.array(cx, copy=1)
presto.tablesixstepfft(cx, -1)
presto.tablesixstepfft(cx, 1)
assert(np.allclose(cx/N, ncx, atol=1e-6))
print "success"
print "Testing reading infiles...",
x = presto.read_inffile("1937_DM71.02_zerodm.inf", verbose=False)
assert(x.telescope=="GBT")
assert(x.mjd_i==55267)
assert(x.dt==8.192e-05)
assert(x.numonoff==1)
assert(x.analyzer=="sransom")
print "success"
print "Testing writing infiles...",
x.analyzer="test"
x.name="xxx"
x.dt=0.125
presto.write_inffile(x, verbose=False)
y = presto.read_inffile("xxx", verbose=False)
assert(y.analyzer=="test")
assert(y.bary==0)
assert(y.numonoff==1)
assert(y.dt==0.125)
os.remove("xxx.inf")
print "success"
print "Testing allocation and freeing of memory...",
for ii in range(1024):
a = presto.gen_fvect(1024 * 32768)
del a
for ii in range(1024):
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...",
orb = presto.orbitparams()
orb.p = 10000.0
orb.e = 0.1
orb.x = 1.0
orb.t = 1234.0
orb.w = np.radians(75.0)
orb.pd = orb.wd = 0.0
E0 = presto.keplers_eqn(orb.t+0.0, orb.p, orb.e, 1e-15)
E1 = presto.keplers_eqn(orb.t+100.0, orb.p, orb.e, 1e-15)
E2 = presto.keplers_eqn(orb.t+200.0, orb.p, orb.e, 1e-15)
E3 = presto.keplers_eqn(orb.t+300.0, orb.p, orb.e, 1e-15)
Es = np.asarray([E0, E1, E2, E3])
Es_check = np.asarray([ 0.85050653, 0.9175909,
0.9842971, 1.05061346])
assert(np.allclose(Es, Es_check))
Es_new = presto.dorbint(E0, 4, 100.0, orb)
assert(np.allclose(Es_new, Es_check))
presto.E_to_v(Es, orb)
Vs_check = np.asarray([-112.15558594, -122.45299212,
-131.9991447, -140.76659065])
assert(np.allclose(Es, Vs_check))
print "\nTODO: fix inconsistent omega units of deg vs rad!!"
orb.w = 75.0
minv, maxv = presto.binary_velocity(300.0, orb)
minv *= presto.SOL/1000.0
maxv *= presto.SOL/1000.0
assert(round(minv-Vs_check.min(), 7)==0)
assert(round(maxv-Vs_check.max(), 7)==0)
print "success"
print "Testing Fourier response generation...",
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)])
nn = numbetween * bins_per_side * 2;
rresp = presto.gen_r_response(0.0, numbetween, nn)
zresp = presto.gen_z_response(0.0, numbetween, nn, z)
wresp = presto.gen_w_response(0.0, numbetween, nn, z, w)
pr = presto.spectralpower(rresp)
pz = presto.spectralpower(zresp)
pw = presto.spectralpower(wresp)
rs = np.arange(float(nn))/numbetween - bins_per_side
if 0:
plt.plot(rs, pr, 'b-')
plt.plot(rs, pz, 'g-')
plt.plot(rs, pw, 'r-')
plt.show()
assert(rs[nn/2]==0.0)
assert(pr[nn/2]==1.0)
assert(round(pz[nn/2]-0.227675, 6)==0)
assert(round(pw[nn/2]-0.019467, 6)==0)
print "success"
print "Testing angle functions...",
dd1 = 15.25
dd2 = presto.dms2rad(*presto.deg2dms(dd1))*presto.RADTODEG
assert(round(dd1-dd2, 12)==0)
dd1 = -0.5
dd2 = presto.dms2rad(*presto.deg2dms(dd1))*presto.RADTODEG
assert(round(dd1-dd2, 12)==0)
hh1 = 12.125
hh2 = presto.hms2rad(*presto.hours2hms(hh1))*presto.RADTODEG/15.0
assert(round(hh1-hh2, 12)==0)
hh1 = -0.5
hh2 = presto.hms2rad(*presto.hours2hms(hh1))*presto.RADTODEG/15.0
assert(round(hh1-hh2, 12)==0)
ang = presto.sphere_ang_diff(10.0*presto.DEGTORAD, 10.0*presto.DEGTORAD,
50.0*presto.DEGTORAD, -10.0*presto.DEGTORAD)
assert(round(160334.960*presto.ARCSEC2RAD-ang, 7)==0)
print "success"
print "Testing get_baryv (barycenter)...",
vavg1 = presto.get_baryv("18:24:32.9520", "-24:52:12.0000",
56421.44222222222222, 214.5386496, obs="GB")
vavg2 = -7.2069293455783169e-05
assert(round(vavg1-vavg2, 10)==0)
print "success"