-
Notifications
You must be signed in to change notification settings - Fork 26
Closed
Labels
Description
As part of #140 we are replacing the 2D downsampling method Image.downsample() with a MATLAB port. The plan is to do this in three steps:
- Add a
crop_2dmethod toaspire.utils(Addaspire.utils.coor_trans.crop_2dand movecoor_transobjects to second-level API access #565) - Replace hardcoded downsampling tests (where, for instance, the output is compared to a saved
.npyfile). - Replace the downsampling method
For step 2, there are unit tests across multiple files that do not adequately test downsampling. See, e.g.
ASPIRE-Python/tests/test_simulation.py
Lines 87 to 98 in 3223d6c
| def testSimulationImagesDownsample(self): | |
| # The simulation already generates images of size 8 x 8; Downsampling to resolution 8 should thus have no effect | |
| self.sim.downsample(8) | |
| images = self.sim.clean_images(0, 512).asnumpy() | |
| self.assertTrue( | |
| np.allclose( | |
| images, | |
| np.load(os.path.join(DATA_DIR, "sim_clean_images.npy")), | |
| rtol=1e-2, | |
| atol=utest_tolerance(self.sim.dtype), | |
| ) | |
| ) |
ASPIRE-Python/tests/test_starfile_stack.py
Lines 59 to 76 in 3223d6c
| def testImageDownsample(self): | |
| self.src.downsample(16) | |
| first_image = self.src.images(0, 1)[0] | |
| self.assertEqual(first_image.shape, (16, 16)) | |
| def testImageDownsampleAndWhiten(self): | |
| self.src.downsample(16) | |
| self.src.whiten(noise_filter=ScalarFilter(dim=2, value=0.02450909546680349)) | |
| first_whitened_image = self.src.images(0, 1)[0] | |
| self.assertTrue( | |
| np.allclose( | |
| first_whitened_image, | |
| np.load( | |
| os.path.join(DATA_DIR, "starfile_image_0_whitened.npy") | |
| ).T, # RCOPT | |
| atol=1e-6, | |
| ) | |
| ) |
Some of these tests mix testing the downsampling algorithm and output itself with the behavior of the object being tested (e.g. a class). I think it would make sense to create a test_downsample.py to contain tests that do actual validation of the downsampling.