Skip to content

Move from hardcoded to logical downsampling tests #566

@chris-langfield

Description

@chris-langfield

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:

  1. Add a crop_2d method to aspire.utils(Add aspire.utils.coor_trans.crop_2d and move coor_trans objects to second-level API access #565)
  2. Replace hardcoded downsampling tests (where, for instance, the output is compared to a saved .npy file).
  3. Replace the downsampling method

For step 2, there are unit tests across multiple files that do not adequately test downsampling. See, e.g.

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),
)
)

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions