Skip to content
Open
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
4 changes: 3 additions & 1 deletion hexrd/core/imageseries/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ def _toarray(

def _alloc_buffer(ims: ImageInput, nf: int) -> np.ndarray:
"""Allocate buffer to save as many full frames as possible"""
shp, dt = ims.shape, ims.dtype
# Some adapters (e.g. fch5) report shape as an ndarray, which would
# broadcast-add with (nf,) instead of concatenating.
shp, dt = tuple(ims.shape), ims.dtype
framesize = shp[0] * shp[1] * dt.itemsize
nf = np.minimum(nf, np.floor(STATS_BUFFER / framesize).astype(int))
bshp = (nf,) + shp
Expand Down
7 changes: 7 additions & 0 deletions tests/core/imageseries/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ def test_alloc_buffer(mock_ims):
buf = stats._alloc_buffer(mock_ims, 10)
assert buf.shape == (10, 4, 4)

# An ndarray shape (as the fch5 adapter reports) must concatenate,
# not broadcast-add
mock_ims.shape = np.array([4, 4])
with patch('hexrd.core.imageseries.stats.STATS_BUFFER', 1000):
buf = stats._alloc_buffer(mock_ims, 10)
assert buf.shape == (10, 4, 4)


def test_toarray_buffering(mock_ims):
arr = stats._toarray(mock_ims, 10)
Expand Down
Loading