Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Baum committed Jan 10, 2021
1 parent 8511615 commit 078a020
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
numpy>=1.1
numpy>=1.19
scipy>=1.5.4
matplotlib>=3.3.3
1 change: 0 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ python test_associated_legendre.py

cd ../spherical-harmonic
python test_spherical_harmonic.py
python test_noise.py

cd ../../
2 changes: 2 additions & 0 deletions tests/chebyshev/test_bvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def cheby_bvp_test(xa, xb, pts, aderiv, ideriv, bderiv, va, vb, F, S, xextra=Non
#test the boundary value convergence
err, xs, qexs, qsps = cheby_bvp_test(xa, xb, pts, ad, id, bd, va, vb, F, S, xextra)

assert err[-1] < 1e-10

figa, axa = plt.subplots(1,1)
figb, axb = plt.subplots(1,1)

Expand Down
2 changes: 2 additions & 0 deletions tests/chebyshev/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def cheby_coef_test(xa, xb, pts, F, da=None, db=None, xextra=None):
#now test simple interpolation
err, xs, coefs = cheby_coef_test(xa, xb, pts, F)

assert err[-1] < 1e-25

figa, axa = plt.subplots(1,1)
figb, axb = plt.subplots(1,1)

Expand Down
6 changes: 4 additions & 2 deletions tests/legendre/test_associated_legendre.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ def test_ddlegen_theta(nmax, N=100, h=1e-2):
plt.show()

print('testing analytical evaluation of first derivatives of associated Legendres')
test_dlegen_theta(20)
err, fig, ax = test_dlegen_theta(20)
assert np.nanmax(err) < 1e-5
plt.show()

print('testing analytical evaluation of second derivative of associated Legendres')
test_ddlegen_theta(20)
err, fig, ax = test_ddlegen_theta(20)
assert np.nanmax(err) < 1e-2
plt.show()
23 changes: 16 additions & 7 deletions tests/spherical-harmonic/test_spherical_harmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
sys.path.insert(0, join('..', '..'))
from orthopoly.spherical_harmonic import *

#plt.style.use('dark_background')
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.style.use('dark_background')
#plt.rc('text', usetex=True)
#plt.rc('font', family='serif')

#-------------------------------------------------------------------------------
#FUNCTIONS
Expand Down Expand Up @@ -141,8 +141,8 @@ def test_grad_sph_har(ntest=100, nmax=100, h=1e-4):
idx = np.random.randint(1, len(yn), ntest)
for i in idx:
n, m = yn[i], ym[i]
t = pi*np.random.rand()
p = 2*pi*np.random.rand()
t = pi*np.random.rand()*(1 - 1e-6) + 1e-6
p = 2*pi*np.random.rand()*(1 - 1e-6) + 1e-6
dt, dp = grad_sph_har(t, p, n, m)
tg = np.linspace(t - 2*h, t + 2*h, 5)
pg = np.linspace(p - 2*h, p + 2*h, 5)
Expand All @@ -162,6 +162,11 @@ def test_grad_sph_har(ntest=100, nmax=100, h=1e-4):
n, m, t, p, terr, perr = (np.array(n), np.array(m), np.array(t),
np.array(p), np.array(terr), np.array(perr))

print('max terr = %g' % max(terr))
assert max(terr) < 1e-4
print('max perr = %g' % max(perr))
assert max(perr) < 1e-4

fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(8,5))
ax1.semilogy(t[terr > 1e-20], terr[terr > 1e-20], '.')
ax1.set_xlabel(r'$\theta$')
Expand Down Expand Up @@ -222,8 +227,8 @@ def test_lap_sph_har(ntest=200, nmax=100, h=1e-4):
idx = np.random.randint(1, len(yn), ntest)
for i in idx:
n, m = yn[i], ym[i]
t = pi*np.random.rand()
p = 2*pi*np.random.rand()
t = pi*np.random.rand()*(1 - 1e-6) + 1e-6
p = 2*pi*np.random.rand()*(1 - 1e-6) + 1e-6
lap = lap_sph_har(t, p, n, m)
tg = np.linspace(t - 2*h, t + 2*h, 5)
pg = np.linspace(p - 2*h, p + 2*h, 5)
Expand All @@ -240,6 +245,9 @@ def test_lap_sph_har(ntest=200, nmax=100, h=1e-4):
n, m, t, p, err = zip(*res)
n, m, t, p, err = (np.array(n), np.array(m), np.array(t), np.array(p), np.array(err))

print('max err = %g' % max(err))
assert max(err) < 1e-4

fig, ax = plt.subplots(1,1)
r = ax.scatter(p[err > 1e-20], t[err > 1e-20], c=np.log10(err[err > 1e-20]))
cb = plt.colorbar(r, ax=ax)
Expand Down Expand Up @@ -269,6 +277,7 @@ def test_lap_sph_har(ntest=200, nmax=100, h=1e-4):

print('testing orthonormality of spherical harmonics')
err = test_sph_har_orthonormal(3)
assert err < 1e-13
print('maximum absolute error is %g' % err)

print('plotting spherical harmonics')
Expand Down

0 comments on commit 078a020

Please sign in to comment.