22__all__ = [
'assembleAmplifierImage',
'assembleAmplifierRawImage',
23 'makeUpdatedDetector',
'AmplifierIsolator']
27 False: slice(
None,
None, 1),
28 True: slice(
None,
None, -1),
37 xSlice = _SliceDict[amplifier.getRawFlipX()]
38 ySlice = _SliceDict[amplifier.getRawFlipY()]
39 if hasattr(inView,
"image"):
40 inArrList = (inView.image.array, inView.mask.array, inView.variance.array)
41 outArrList = (outView.image.array, outView.mask.array, outView.variance.array)
43 inArrList = [inView.array]
44 outArrList = [outView.array]
46 for inArr, outArr
in zip(inArrList, outArrList):
48 outArr[:] = inArr[ySlice, xSlice]
51def assembleAmplifierImage(destImage, rawImage, amplifier):
52 """Assemble the amplifier region of an image from a raw image.
57 Assembled image; the region amplifier.getBBox()
is overwritten
with
58 the assembled amplifier image.
60 Raw image (same type
as destImage).
62 Amplifier geometry,
with raw amplifier info.
67 Raised
if image types do
not match
or amplifier has no raw amplifier info.
69 if type(destImage.Factory) !=
type(rawImage.Factory):
70 raise RuntimeError(f
"destImage type = {type(destImage.Factory).__name__} != "
71 f
"{type(rawImage.Factory).__name__} = rawImage type")
72 inView = rawImage.Factory(rawImage, amplifier.getRawDataBBox())
73 outView = destImage.Factory(destImage, amplifier.getBBox())
78def assembleAmplifierRawImage(destImage, rawImage, amplifier):
79 """Assemble the amplifier region of a raw CCD image.
81 For most cameras this is a no-op: the raw image already
is an assembled
83 However, it
is useful
for camera such
as LSST
for which each amplifier
84 image
is a separate image.
89 CCD Image; the region amplifier.getRawAmplifier().getBBox()
90 is overwritten
with the raw amplifier image.
92 Raw image (same type
as destImage).
94 Amplifier geometry
with raw amplifier info
99 Raised
if image types do
not match
or amplifier has no raw amplifier info.
101 if type(destImage.Factory) !=
type(rawImage.Factory):
102 raise RuntimeError(f
"destImage type = {type(destImage.Factory).__name__} != "
103 f
"{type(rawImage.Factory).__name__} = rawImage type")
104 inBBox = amplifier.getRawBBox()
105 inView = rawImage.Factory(rawImage, inBBox)
106 outBBox = amplifier.getRawBBox()
107 outBBox.shift(amplifier.getRawXYOffset())
108 outView = destImage.Factory(destImage, outBBox)
114 """Return a Detector that has had the definitions of amplifier geometry
115 updated post assembly.
119 ccd : `lsst.afw.image.Detector`
120 The detector to copy and update.
122 builder = ccd.rebuild()
123 for amp
in builder.getAmplifiers():
125 return builder.finish()
129 """A class that can extracts single-amplifier subimages from trimmed or
130 untrimmed assembled images and transforms them to a particular orientation
134 generally just use the `apply`
class method. Other methods can be used to
135 implement subimage loads of on on-disk images (e.g. formatter classes
in
136 ``obs_base``)
or obtain subsets
from other image classes.
140 amplifier : `Amplifier`
141 Amplifier object that identifies the amplifier to load
and sets the
142 orientation
and offset of the returned subimage.
144 Bounding box of the assembled parent image. This must be equal to
145 either ``parent_detector.getBBox()``
or
146 ``parent_detector.getRawBBox()``; which one
is used to determine
147 whether the parent image (
and hence the amplifier subimages)
is
149 parent_detector : `Detector`
150 Detector object that describes the parent image.
153 def __init__(self, amplifier, parent_bbox, parent_detector):
164 f
"The given amplifier's trimmed bounding box ({self._amplifier.getBBox()}) is not the "
165 "same as the trimmed bounding box of the same amplifier in the parent image "
166 f
"({self._parent_amplifier.getBBox()})."
173 "The given amplifier's subregions are fundamentally incompatible with those of the "
174 "parent image's amplifier."
179 """The bounding box of the target amplifier in the parent image
188 """Transform an already-extracted subimage to match the orientation
189 and offset of the target amplifier.
193 subimage : image-like
200 transformed : image-like
201 Transformed image of the same type
as ``subimage``.
204 if hasattr(subimage,
"getMaskedImage"):
208 result = subimage.clone()
209 result.setMaskedImage(
211 subimage.getMaskedImage(),
223 result.setXY0(self.
_amplifier.getBBox().getMin())
229 """Create a single-amplifier detector that describes the transformed
234 detector : `Detector`
235 Detector object with a single amplifier, a trimmed bounding box
236 equal to the amplifier
's trimmed bounding box, and no crosstalk.
242 detector.unsetCrosstalk()
243 return detector.finish()
246 def apply(cls, parent_exposure, amplifier):
247 """Obtain a single-amplifier `lsst.afw.image.Exposure` subimage that
248 masquerades as full-detector image
for a single-amp detector.
253 Parent image to obtain a subset
from.
254 `~lsst.afw.image.Exposure.getDetector` must
not return `
None`.
255 amplifier : `Amplifier`
256 Target amplifier
for the subimage. May differ
from the amplifier
257 obtained by ``parent_exposure.getDetector()[amplifier.getName()]``
258 only by flips
and differences
in `~Amplifier.getRawXYOffset`.
263 Exposure subimage
for the target amplifier,
with the
264 orientation
and XY0 described by that amplifier,
and a single-amp
265 detector holding a copy of that amplifier.
269 Because we use the target amplifier
's bounding box as the bounding box
270 of the detector attached to the returned exposure, other exposure
271 components that are passed through unmodified (e.g. the WCS) should
272 still be valid for the single-amp exposure after it
is trimmed
and
273 "assembled". Unlike most trimmed+assembled images, however, it will
274 have a nonzero XY0,
and code that (incorrectly!) does
not pay attention
277 instance = cls(amplifier, parent_bbox=parent_exposure.getBBox(),
278 parent_detector=parent_exposure.getDetector())
279 result = instance.transform_subimage(parent_exposure[instance.subimage_bbox])
280 result.setDetector(instance.make_detector())
__init__(self, amplifier, parent_bbox, parent_detector)
apply(cls, parent_exposure, amplifier)
transform_subimage(self, subimage)
Geometry and electronic information about raw amplifier images.
A class to contain the data, WCS, and other information needed to describe an image of the sky.
A class to represent a 2-dimensional array of pixels.
Represent a 2-dimensional array of bitmask pixels.
A class to manipulate images, masks, and variance as a single object.
An integer coordinate rectangle.
_insertPixelChunk(outView, inView, amplifier)