Skip to content

Commit 7266d57

Browse files
committed
Add test for specific FB 2D basis element
1 parent 24643d1 commit 7266d57

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/test_FBbasis2D.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import numpy as np
66
from pytest import raises
7+
from scipy.special import jv
78

89
from aspire.basis import FBBasis2D
910
from aspire.image import Image
@@ -350,6 +351,42 @@ def testIndices(self):
350351

351352
i += 1
352353

354+
def testElement(self):
355+
ell = 1
356+
sgn = -1
357+
k = 2
358+
359+
indices = self.basis.indices()
360+
ells = indices["ells"]
361+
sgns = indices["sgns"]
362+
ks = indices["ks"]
363+
364+
g2d = grid_2d(self.L, dtype=self.dtype)
365+
mask = g2d["r"] < 1
366+
367+
r0 = self.basis.r0[k, ell]
368+
369+
im = np.zeros((self.L, self.L), dtype=self.dtype)
370+
im[mask] = jv(ell, g2d["r"][mask] * r0)
371+
im *= np.sqrt(2**2 / self.L**2)
372+
im *= 1 / (np.sqrt(np.pi) * np.abs(jv(ell + 1, r0)))
373+
374+
if sgn == 1:
375+
im *= np.sqrt(2) * np.cos(ell * g2d["phi"])
376+
else:
377+
im *= np.sqrt(2) * np.sin(ell * g2d["phi"])
378+
379+
coef_ref = np.zeros(self.basis.count, dtype=self.dtype)
380+
coef_ref[(ells == ell) & (sgns == sgn) & (ks == k)] = 1
381+
382+
im_ref = self.basis.evaluate(coef_ref)
383+
384+
coef = self.basis.expand(im)
385+
386+
# TODO: These tolerances should be tighter.
387+
self.assertTrue(np.allclose(im, im_ref, atol=1e-4))
388+
self.assertTrue(np.allclose(coef, coef_ref, atol=1e-4))
389+
353390
def testGaussianExpand(self):
354391
# Offset slightly
355392
x0 = 0.50

0 commit comments

Comments
 (0)