lsst.afw g5dde539398+b655ba634f
Loading...
Searching...
No Matches
Functions | Variables
lsst.afw.image._image._slicing Namespace Reference

Functions

def splitSliceArgs (sliceArgs)
 
def handleNegativeIndex (index, size, origin, default)
 
def translateSliceArgs (sliceArgs, bboxGetter)
 
def interpretSliceArgs (sliceArgs, bboxGetter)
 
def imageIndicesToNumpy (sliceArgs, bboxGetter)
 
def supportSlicing (cls)
 

Variables

 Factory
 
 clone
 

Function Documentation

◆ handleNegativeIndex()

def lsst.afw.image._image._slicing.handleNegativeIndex (   index,
  size,
  origin,
  default 
)
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()`.

Definition at line 65 of file _slicing.py.

◆ imageIndicesToNumpy()

def lsst.afw.image._image._slicing.imageIndicesToNumpy (   sliceArgs,
  bboxGetter 
)
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.

Definition at line 202 of file _slicing.py.

◆ interpretSliceArgs()

def lsst.afw.image._image._slicing.interpretSliceArgs (   sliceArgs,
  bboxGetter 
)
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)

Definition at line 147 of file _slicing.py.

◆ splitSliceArgs()

def lsst.afw.image._image._slicing.splitSliceArgs (   sliceArgs)
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()`.

Definition at line 28 of file _slicing.py.

◆ supportSlicing()

def lsst.afw.image._image._slicing.supportSlicing (   cls)
Support image slicing

Definition at line 265 of file _slicing.py.

◆ translateSliceArgs()

def lsst.afw.image._image._slicing.translateSliceArgs (   sliceArgs,
  bboxGetter 
)
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.

Definition at line 111 of file _slicing.py.

Variable Documentation

◆ clone

lsst.afw.image._image._slicing.clone

Definition at line 278 of file _slicing.py.

◆ Factory

lsst.afw.image._image._slicing.Factory

Definition at line 273 of file _slicing.py.