Skip to content

Commit ef3a0c2

Browse files
committed
_projection_pixel_size. test projections and clean_images.
1 parent 999199d commit ef3a0c2

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

src/aspire/source/simulation.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def __init__(
124124
f"`pixel_size`: {pixel_size} does not match volume pixel_size: {self.vols.pixel_size}."
125125
" Setting `pixel_size` to user provided value: {pixel_size}."
126126
)
127-
self._original_pixel_size = pixel_size
127+
self._projection_pixel_size = pixel_size
128128

129129
# Infer the details from volume when possible.
130130
super().__init__(
@@ -283,7 +283,7 @@ def _projections(self, indices):
283283
im_k = self.vols[k - 1].project(rot_matrices=rot)
284284
im[idx_k, :, :] = im_k.asnumpy()
285285

286-
return Image(im, pixel_size=self.pixel_size)
286+
return Image(im, pixel_size=self._projection_pixel_size)
287287

288288
@property
289289
def clean_images(self):
@@ -329,16 +329,13 @@ def _images(self, indices, clean_images=False):
329329
return self.generation_pipeline.forward(im, indices)
330330

331331
def _apply_sim_filters(self, im, indices):
332-
# Use original pixel_size when applying filters.
333-
im.pixel_size = self._original_pixel_size
334-
335332
im = self._apply_filters(
336333
im,
337334
self.sim_filters,
338335
self.filter_indices[indices],
339336
)
340337

341-
# Recover correct pixel_size
338+
# Assign correct pixel_size
342339
im.pixel_size = self.pixel_size
343340

344341
return im

tests/test_simulation.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,38 @@ def test_cached_image_accessors():
702702
)
703703

704704

705+
def test_projections_and_clean_images_downsample():
706+
"""
707+
Test `projections` and `clean_images` post downsample.
708+
`projections` should remain unaltered and `clean_images` should
709+
be resized with adjusted pixel_size.
710+
"""
711+
n = 10
712+
L = 32
713+
L_ds = 21
714+
px_sz = 1.23
715+
ctf = [RadialCTFFilter(1.5e4)]
716+
717+
src = Simulation(
718+
L=L,
719+
n=n,
720+
C=1,
721+
noise_adder=WhiteNoiseAdder(var=0.123),
722+
unique_filters=ctf,
723+
pixel_size=px_sz,
724+
)
725+
726+
src_ds = src.downsample(L_ds)
727+
728+
# Check pixel_size
729+
np.testing.assert_allclose(src_ds.projections[:].pixel_size, px_sz)
730+
np.testing.assert_allclose(src_ds.clean_images[:].pixel_size, px_sz * L / L_ds)
731+
732+
# Check image size
733+
np.testing.assert_allclose(src_ds.projections[:].shape[-1], L)
734+
np.testing.assert_allclose(src_ds.clean_images[:].shape[-1], L_ds)
735+
736+
705737
def test_save_overwrite(caplog):
706738
"""
707739
Test that the overwrite flag behaves as expected.

0 commit comments

Comments
 (0)