Coverage for python/lsst/afw/image/slicing.py : 95%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
"""Separate the actual slice from origin arguments to __getitem__ or __setitem__, using PARENT for the origin if it is not provided.
Parameter --------- sliceArgs : `tuple`, `Box2I`, or `Point2I` The first argument passed to an image-like object's ``__getitem__`` or ``__setitem__``.
Returns ------- sliceArgs : `tuple`, `Box2I`, or `Point2I` The original sliceArgs passed in, with any ImageOrigin argument stripped off. origin : `ImageOrigin` Enum value that sets whether or not to consider xy0 in positions.
See interpretSliceArgs for more information.
Intended primarily for internal use by `supportSlicing()`. """ # Args are already a tuple that includes the origin. else: else: # Args are a tuple that does not include the origin; add it to make origin explicit.
"""Handle negative indices passed to image accessors.
When negative indices are used in LOCAL coordinates, we interpret them as relative to the upper bounds of the array, as in regular negative indexing in Python.
Using negative indices in PARENT coordinates is not allowed unless passed via a `Point2I` or `Box2I`; the potential for confusion between actual negative indices (when ``xy0 < 0``) and offsets relative to the upper bounds of the array is too great.
Parameters ---------- index : `int` or `None` 1-d pixel index to interpret, as given by a caller to an image-like object's ``__getitem__`` or ``__setitem__``. size : `int` Size of the image in the dimension corresponding to ``index``. origin : `ImageOrigin` Enum value that sets whether or not to consider xy0 in positions. default : `int` Index to return if `index` is None.
Returns ------- index : `int` If ``origin==PARENT``, either the given ``index`` or ``default``. If ``origin==LOCAL``, an equivalent index guaranteed to be nonnegative.
Intended primarily for internal use by `supportSlicing()`. """ else: raise IndexError("Negative indices are not permitted with the PARENT origin. " "Use LOCAL to use negative to index relative to the end, " "and Point2I or Box2I indexing to access negative pixels " "in PARENT coordinates.")
"""Transform a tuple of slice objects into a Box2I, correctly handling negative indices.
see `interpretSliceArgs` for a description of parameters
Returns ------- box : `Box2I` or `None` A box to use to create a subimage, or None if the slice refers to a scalar. index: `tuple` or `None` An ``(x, y)`` tuple of integers, or None if the slice refers to a box. origin : `ImageOrigin` Enum indicating whether to account for xy0. """
raise ValueError("Slices with steps are not supported in image indexing.")
"""Transform arguments to __getitem__ or __setitem__ to a standard form.
Parameters ---------- sliceArgs : `tuple`, `Box2I`, or `Point2I` Slice arguments passed directly to `__getitem__` or `__setitem__`. bboxGetter : callable Callable that accepts an ImageOrigin enum value and returns the appropriate image bounding box. Usually the bound getBBox method of an Image, Mask, or MaskedImage object.
Returns ------- x : int or slice Index or slice in the x dimension y : int or slice Index or slice in the y dimension origin : `ImageOrigin` Either `PARENT` (coordinates respect XY0) or LOCAL (coordinates do not respect XY0) """ else:
handleNegativeIndex(x.stop, bbox.getWidth(), origin, default=bbox.getEndX())) handleNegativeIndex(y.stop, bbox.getHeight(), origin, default=bbox.getEndY()))
raise TypeError("Mixed indices of the form (int, slice) are not supported for images.")
"""Convert slicing format to numpy
LSST `afw` image-like objects use an `[x,y]` coordinate convention, accept `Point2I` and `Box2I` objects for slicing, and slice relative to the bounding box `XY0` location; while python and numpy use the convention `[y,x]` with no `XY0`, so this method converts the `afw` indices or slices into numpy indices or slices
Parameters ---------- sliceArgs: `sequence`, `Point2I` or `Box2I` An `(xIndex, yIndex)` pair, or a single `(xIndex,)` tuple, where `xIndex` and `yIndex` can be a `slice` or `int`, or list of `int` objects, and if only a single `xIndex` is given, a `Point2I` or `Box2I`. bboxGetter : callable Callable that accepts an ImageOrigin enum value and returns the appropriate image bounding box. Usually the bound getBBox method of an Image, Mask, or MaskedImage object.
Returns ------- y: `int` or `slice` Index or `slice` in the y dimension x: `int` or `slice` Index or `slice` in the x dimension bbox: `Box2I` Bounding box of the image. If `bbox` is `None` then the result is a point and not a subset of an image. """ # Use a common slicing algorithm as single band images
else: raise ValueError("Unrecognized value for origin")
# Use a local bounding box Extent2I(x.stop-x.start, y.stop-y.start)) else:
"""Support image slicing """
"""Return an object of this type """
"""Return a deep copy of self"""
else: |