|
| 1 | +from unittest import TestCase |
| 2 | + |
| 3 | +import numpy as np |
| 4 | + |
| 5 | +from aspire.basis.ffb_2d import FFBBasis2D |
| 6 | +from aspire.denoising.denoiser_cov2d import DenoiserCov2D |
| 7 | +from aspire.operators.filters import RadialCTFFilter, ScalarFilter |
| 8 | +from aspire.source.simulation import Simulation |
| 9 | + |
| 10 | + |
| 11 | +class BatchedRotCov2DTestCase(TestCase): |
| 12 | + def testMSE(self): |
| 13 | + # need larger numbers of images and higher resolution for good MSE |
| 14 | + dtype = np.float32 |
| 15 | + img_size = 64 |
| 16 | + num_imgs = 1024 |
| 17 | + noise_var = 0.1848 |
| 18 | + noise_filter = ScalarFilter(dim=2, value=noise_var) |
| 19 | + filters = [ |
| 20 | + RadialCTFFilter(5, 200, defocus=d, Cs=2.0, alpha=0.1) |
| 21 | + for d in np.linspace(1.5e4, 2.5e4, 7) |
| 22 | + ] |
| 23 | + # set simulation object |
| 24 | + sim = Simulation( |
| 25 | + L=img_size, |
| 26 | + n=num_imgs, |
| 27 | + unique_filters=filters, |
| 28 | + offsets=0.0, |
| 29 | + amplitudes=1.0, |
| 30 | + dtype=dtype, |
| 31 | + noise_filter=noise_filter, |
| 32 | + ) |
| 33 | + imgs_clean = sim.projections() |
| 34 | + |
| 35 | + # Specify the fast FB basis method for expending the 2D images |
| 36 | + ffbbasis = FFBBasis2D((img_size, img_size), dtype=dtype) |
| 37 | + denoiser = DenoiserCov2D(sim, ffbbasis, noise_var) |
| 38 | + denoised_src = denoiser.denoise(batch_size=64) |
| 39 | + imgs_denoised = denoised_src.images(0, num_imgs) |
| 40 | + # Calculate the normalized RMSE of the estimated images. |
| 41 | + nrmse_ims = (imgs_denoised - imgs_clean).norm() / imgs_clean.norm() |
| 42 | + |
| 43 | + self.assertTrue(nrmse_ims < 0.25) |
0 commit comments