|
4 | 4 |
|
5 | 5 | import numpy as np |
6 | 6 | from pytest import raises |
| 7 | +from scipy.special import jv |
7 | 8 |
|
8 | 9 | from aspire.basis import FBBasis2D |
9 | 10 | from aspire.image import Image |
@@ -350,6 +351,42 @@ def testIndices(self): |
350 | 351 |
|
351 | 352 | i += 1 |
352 | 353 |
|
| 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 | + |
353 | 390 | def testGaussianExpand(self): |
354 | 391 | # Offset slightly |
355 | 392 | x0 = 0.50 |
|
0 commit comments