Skip to content

Commit 8e09642

Browse files
committed
First attempt at testElement for FFB2D
1 parent 7faf923 commit 8e09642

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/test_FFBbasis2D.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from unittest import TestCase
44

55
import numpy as np
6+
from scipy.special import jv
67

78
from aspire.basis import FFBBasis2D
89
from aspire.image import Image
@@ -263,6 +264,47 @@ def testFFBBasis2DExpand(self):
263264
)
264265
)
265266

267+
def testElement(self):
268+
ell = 1
269+
sgn = -1
270+
k = 2
271+
272+
indices = self.basis.indices()
273+
ells = indices["ells"]
274+
sgns = indices["sgns"]
275+
ks = indices["ks"]
276+
277+
g2d = grid_2d(self.L, dtype=self.dtype)
278+
mask = g2d["r"] < 1
279+
280+
r0 = self.basis.r0[k, ell]
281+
282+
r = g2d["r"] * self.L / 4
283+
284+
im = np.zeros((self.L, self.L), dtype=self.dtype)
285+
im[mask] = (
286+
(-1) ** k
287+
* np.sqrt(np.pi)
288+
* r0
289+
* jv(ell, 2 * np.pi * r[mask])
290+
/ ((2 * np.pi * r[mask]) ** 2 - r0**2)
291+
)
292+
293+
if sgn == 1:
294+
im *= np.sqrt(2) * np.cos(ell * g2d["phi"])
295+
else:
296+
im *= np.sqrt(2) * np.sin(ell * g2d["phi"])
297+
298+
coef_ref = np.zeros(self.basis.count, dtype=self.dtype)
299+
coef_ref[(ells == ell) & (sgns == sgn) & (ks == k)] = 1
300+
301+
im_ref = self.basis.evaluate(coef_ref).asnumpy()[0]
302+
303+
coef = self.basis.expand(im)
304+
305+
self.assertTrue(np.allclose(im, im_ref, atol=1e-1))
306+
self.assertTrue(np.allclose(coef, coef_ref, atol=1e-1))
307+
266308
def testRotate(self):
267309
# Now low res (8x8) had problems;
268310
# better with odd (7x7), but still not good.

0 commit comments

Comments
 (0)