|
3 | 3 | from unittest import TestCase |
4 | 4 |
|
5 | 5 | import numpy as np |
| 6 | +from scipy.special import jv |
6 | 7 |
|
7 | 8 | from aspire.basis import FFBBasis2D |
8 | 9 | from aspire.image import Image |
@@ -263,6 +264,47 @@ def testFFBBasis2DExpand(self): |
263 | 264 | ) |
264 | 265 | ) |
265 | 266 |
|
| 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 | + |
266 | 308 | def testRotate(self): |
267 | 309 | # Now low res (8x8) had problems; |
268 | 310 | # better with odd (7x7), but still not good. |
|
0 commit comments