LSST Applications g04a91732dc+146a938ab0,g07dc498a13+80b84b0d75,g0fba68d861+0decac7526,g1409bbee79+80b84b0d75,g1a7e361dbc+80b84b0d75,g1fd858c14a+f6e422e056,g20f46db602+483a84333a,g21d47ad084+4a6cd485de,g35bb328faa+fcb1d3bbc8,g42c1b31a95+a1301e4c20,g4d39ba7253+9b833be27e,g4e0f332c67+5d362be553,g53246c7159+fcb1d3bbc8,g60b5630c4e+9b833be27e,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g8852436030+790117df0f,g89139ef638+80b84b0d75,g8d6b6b353c+9b833be27e,g9125e01d80+fcb1d3bbc8,g989de1cb63+80b84b0d75,g9f33ca652e+9c6b68d7f3,ga9baa6287d+9b833be27e,gaaedd4e678+80b84b0d75,gabe3b4be73+1e0a283bba,gb1101e3267+9f3571abad,gb58c049af0+f03b321e39,gb90eeb9370+691e4ab549,gc741bbaa4f+5f483edd21,gcf25f946ba+790117df0f,gd24842266e+c54cdbdbd2,gd315a588df+5b65d88fe4,gd6cbbdb0b4+c8606af20c,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+c99546153d,ge278dab8ac+932305ba37,ge82c20c137+76d20ab76d,w.2025.10
LSST Data Management Base Package
|
You can use the C++ APIs to manipulate images and bits of images from python, e.g.
sets a 4x10
portion of image im
to 100 (I used im.Factory
to avoid repeating afwImage.ImageF
, rendering the code non-generic). I can't simply say sim
=
100
as that'd make sim
an integer rather than setting the pixel values to 100. I used an Image, but a Mask or a MaskedImage would work too (and I can create a sub-Exposure, although I can't assign to it).
This syntax gets boring fast.
We accordingly added some syntactic sugar at the swig level. I can write the preceeding example as:
i.e. create a subimage and assign to it. afw's image slices are always shallow (but you can clone
them as we shall see).
Note that the order is [x, y]
**. This is consistent with our C++ code (e.g. it's PointI(x, y)
), but different from numpy's matrix-like [row, column]
.
This opens up various possiblities; the following all work:
You might expect to be able to say print
im
[0,20] but you won't get what you expect (it's an image, not a pixel value); say print
float(im[0,20])
instead.
The one remaining thing that you can't do it make a deep copy (the left-hand-side has to pre-exist), but fortunately
works.
You will remember that the previous section used [x, y]
whereas numpy uses [row, column]
which is different; you have been warned.
You can achieve similar effects using numpy
. For example, after creating im
as above, I can use getArray
to return a view of the image (i.e. the numpy object shares memory with the C++ object), so:
will also set a sub-image's value (but a different sub-image from im[1:5, 2:8]
). You can do more complex operations using numpy
syntax, e.g.
which is very convenient, although there's a good chance that you'll be creating temporaries the size of im
.