Skip to content

Commit 0182f7c

Browse files
committed
test src.downsample.pixel_size == src.img.downsample.pixel_size
1 parent 06dfaf8 commit 0182f7c

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/aspire/source/relion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(
4343
:param data_folder: Path to folder w.r.t which all relative paths to .mrcs files are resolved.
4444
If None, the folder corresponding to filepath is used.
4545
:param pixel_size: The pixel size of the images in angstroms. By default, pixel size is
46-
populated from the STAR file if relevant metadata fields exist, otherwise set to 1.
46+
populated from the STAR file if relevant metadata fields exist.
4747
:param B: the envelope decay of the CTF in inverse square angstrom (Default 0)
4848
:param n_workers: Number of threads to spawn to read referenced .mrcs files (Default -1 to auto detect)
4949
:param max_rows: Maximum number of rows in STAR file to read. If None, all rows are read.

tests/test_downsample.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,21 +317,27 @@ def test_downsample_offsets(dtype, res):
317317

318318
def test_pixel_size():
319319
"""
320-
Test downsampling is rescaling the `pixel_size` attribute.
320+
Test downsampling is rescaling the `pixel_size` attribute for both Images
321+
and ImageSource objects.
321322
"""
322323
# Image sizes in pixels
323324
L = 8 # original
324325
dsL = 5 # downsampled
326+
n = 10 # num images
325327

326-
# Construct a small test Image
327-
img = Image(np.random.random((1, L, L)).astype(DTYPE, copy=False), pixel_size=1.23)
328+
# Construct small test ImageSource and Image instances
329+
src = Simulation(L=L, n=n)
330+
img = src.images[:]
328331

329-
# Downsample the image
330-
result = img.downsample(dsL)
332+
# Confirm the pixel size is scaled properly in both cases
333+
np.testing.assert_approx_equal(
334+
src.downsample(dsL).pixel_size,
335+
src.pixel_size * L / dsL,
336+
err_msg="Incorrect pixel size.",
337+
)
331338

332-
# Confirm the pixel size is scaled
333339
np.testing.assert_approx_equal(
334-
result.pixel_size,
340+
img.downsample(dsL).pixel_size,
335341
img.pixel_size * L / dsL,
336342
err_msg="Incorrect pixel size.",
337343
)

0 commit comments

Comments
 (0)