wrapped_slices

Contents

wrapped_slices#

abtem.prism.utils.wrapped_slices(start, stop, n)[source]#

Two slices covering [start, stop) on a periodic axis of length n.

start may be any integer. Normalising it into [0, n) first leaves only two cases – the window fits, or it wraps once – which is what two slices can express.

The previous implementation assumed -n <= start < n and 0 < stop <= 2n and split on the raw values. For a window lying entirely in negative indices (stop <= 0) it produced slice(0, stop), which is Python’s negative indexing and selects n + stop elements rather than none, so the two pieces concatenated to n + size elements instead of size. The mis-shaped array then surfaced as a broadcast error frames away from here.

Raises:

RuntimeError – If stop - start > n. Two slices cannot cover more than one period; wrapped_crop_2d catches this and takes its general path.

Return type:

Tuple[slice, slice]