Skip to content

Replace saved ribosome volume with Gaussian blobs for testing #600

@chris-langfield

Description

@chris-langfield

Many tests rely on the saved 70S ribosome volume, e.g.

def testDownsample(self):
# Data files re-used from test_preprocess
vols = Volume(np.load(os.path.join(DATA_DIR, "clean70SRibosome_vol.npy")))
resv = Volume(np.load(os.path.join(DATA_DIR, "clean70SRibosome_vol_down8.npy")))
result = vols.downsample((8, 8, 8))
self.assertTrue(np.allclose(result, resv))

However, we should replace these with self-contained tests based on gaussian volumes, and test mathematical properties rather than compare to hardcoded files. Good examples are below:

def testWhiten(self):
noise_estimator = AnisotropicNoiseEstimator(self.sim)
self.sim.whiten(noise_estimator.filter)
imgs_wt = self.sim.images(start=0, num=self.n).asnumpy()
# calculate correlation between two neighboring pixels from background
corr_coef = np.corrcoef(
imgs_wt[:, self.L - 1, self.L - 1], imgs_wt[:, self.L - 2, self.L - 1]
)
# correlation matrix should be close to identity
self.assertTrue(np.allclose(np.eye(2), corr_coef, atol=1e-1))

# Check individual grid points
self.assertTrue(
np.allclose(
imgs_org[:, 32, 32],
imgs_ds[:, 16, 16],
atol=utest_tolerance(self.dtype),
)
)
# check resolution
self.assertTrue(np.allclose(max_resolution, imgs_ds.shape[1]))
# check energy conservation after downsample
self.assertTrue(
np.allclose(
anorm(imgs_org.asnumpy(), axes=(1, 2)) / self.L,
anorm(imgs_ds.asnumpy(), axes=(1, 2)) / max_resolution,
atol=utest_tolerance(self.dtype),
)
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    CIContinuous Integration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions