Changes to single-pixel and subimage accessors

image
afw
Tags: #<Tag:0x00007ff62a789768> #<Tag:0x00007ff62a789628>

(Jim Bosch) #1

I’ve just merged the implementations of RFC-483 and RFC-486, which overhaul how __getitem__ and __setitem__ work on image-like objects.

I’ll post here with a link to complete documentation once it’s built (this evening with the next daily/weekly, I believe), but the summary is:

  • The single-pixel get and set methods have been removed; everything you could do with them can now be done with __getitem__ and __setitem__.
  • Image-like objects (Image, Mask, MaskedImage, Exposure) can be be indexed with pairs of (x, y) integers, pairs of (x, y) slices, Point2Is, and Box2Is.
  • The default origin in Python is now PARENT (i.e. xy0 is accounted for). Pass LOCAL as the last argument inside the square brackets to ignore xy0.
  • If you want to use negative indexes as an offset from the end, you must use LOCAL (as pixels may naturally have negative indices in PARENT).

(Robert Lupton) #2

Wouldn’t it be clearer to never allow negative indices? It’s quite easy to generate them by mistake if you’re pulling out sub-images at random points.


(Jim Bosch) #3

Wouldn’t it be clearer to never allow negative indices? It’s quite easy to generate them by mistake if you’re pulling out sub-images at random points.

It’d be clearer, but much less functional; it’s very nice to be able to refer to the boundaries of an image for e.g. masking purposes without having to manually subtract from the width and height. And we currently do that in lots of places, so I was loathe to rewrite all of that code. FWIW, this is actually a restriction from the previous behavior, which permitted negative indices for PARENT coordinates but interpreted them differently based on whether xy0 was negative (which seemed quite prone to accidental misuse to me).


(Jim Bosch) #4

Here is the promised documentation for the new functionality:

https://pipelines.lsst.io/v/d-2018-07-09/modules/lsst.afw.image/indexing-conventions.html