Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/aspire/source/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,6 +1751,12 @@ def __init__(
f" Original error: {str(e)}"
)

# Now that we are an `Image`, check stack is 1D
if im.stack_ndim != 1:
raise RuntimeError(
"`ArrayImageSource` expects a single stack axis, received shape {im.shape}."
)

super().__init__(
L=im.resolution,
n=im.n_images,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_array_image_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,14 @@ def test_dtype_passthrough(dtype):
np.testing.assert_equal(src.images[:].dtype, dtype)
np.testing.assert_equal(src.amplitudes.dtype, dtype)
np.testing.assert_equal(src.offsets.dtype, dtype)


def test_stack_1d_only():
d = np.empty((2, 3, 4, 4))
img = Image(d)

with raises(RuntimeError, match=r"expects a single stack axis"):
_ = ArrayImageSource(d)

with raises(RuntimeError, match=r"expects a single stack axis"):
_ = ArrayImageSource(img)
Loading