LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
assembleImage.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division
2 #
3 # LSST Data Management System
4 # Copyright 2008, 2009, 2010 LSST Corporation.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 import itertools
24 
25 __ALL__ = ['assembleAmplifierImage', 'assembleAmplifierRawImage']
26 
27 # dict of doFlip: slice
28 _SliceDict = {
29  False: slice(None,None,1),
30  True: slice(None,None,-1),
31 }
32 
33 def _insertPixelChunk(outView, inView, amplifier, hasArrays):
34  # For the sake of simplicity and robustness, this code does not short-circuit the case flipX=flipY=False.
35  # However, it would save a bit of time, including the cost of making numpy array views.
36  # If short circuiting is wanted, do it here.
37 
38  xSlice = _SliceDict[amplifier.getRawFlipX()]
39  ySlice = _SliceDict[amplifier.getRawFlipY()]
40  if hasArrays:
41  # MaskedImage
42  inArrList = inView.getArrays()
43  outArrList = outView.getArrays()
44  else:
45  inArrList = [inView.getArray()]
46  outArrList = [outView.getArray()]
47 
48  for inArr, outArr in itertools.izip(inArrList, outArrList):
49  outArr[:] = inArr[ySlice, xSlice] # y,x because numpy arrays are transposed w.r.t. afw Images
50 
51 def assembleAmplifierImage(destImage, rawImage, amplifier):
52  """!Assemble the amplifier region of an image from a raw image
53 
54  @param[in,out] destImage assembled image (lsst.afw.image.Image or MaskedImage);
55  the region amplifier.getBBox() is overwritten with the assembled amplifier image
56  @param[in] rawImage raw image (same type as destImage)
57  @param[in] amplifier amplifier geometry: lsst.afw.cameraGeom.Amplifier with raw amplifier info
58 
59  @throw RuntimeError if:
60  - image types do not match
61  - amplifier has no raw amplifier info
62  """
63  if not amplifier.getHasRawInfo():
64  raise RuntimeError("amplifier must contain raw amplifier info")
65  if type(destImage.Factory) != type(rawImage.Factory):
66  raise RuntimeError("destImage type = %s != %s = rawImage type" % \
67  type(destImage.Factory).__name__, type(rawImage.Factory).__name__)
68  inView = rawImage.Factory(rawImage, amplifier.getRawDataBBox(), False)
69  outView = destImage.Factory(destImage, amplifier.getBBox(), False)
70 
71  _insertPixelChunk(outView, inView, amplifier, hasattr(rawImage, "getArrays"))
72 
73 def assembleAmplifierRawImage(destImage, rawImage, amplifier):
74  """!Assemble the amplifier region of a raw CCD image
75 
76  For most cameras this is a no-op: the raw image already is an assembled CCD image.
77  However, it is useful for camera such as LSST for which each amplifier image is a separate image.
78 
79  @param[in,out] destImage CCD image (lsst.afw.image.Image or MaskedImage);
80  the region amplifier.getRawAmplifier().getBBox() is overwritten with the raw amplifier image
81  @param[in] rawImage raw image (same type as destImage)
82  @param[in] amplifier amplifier geometry: lsst.afw.cameraGeom.Amplifier with raw amplifier info
83 
84  @throw RuntimeError if:
85  - image types do not match
86  - amplifier has no raw amplifier info
87  """
88  if not amplifier.getHasRawInfo():
89  raise RuntimeError("amplifier must contain raw amplifier info")
90  if type(destImage.Factory) != type(rawImage.Factory):
91  raise RuntimeError("destImage type = %s != %s = rawImage type" % \
92  type(destImage.Factory).__name__, type(rawImage.Factory).__name__)
93  inBBox = amplifier.getRawBBox()
94  inView = rawImage.Factory(rawImage, inBBox, False)
95  outBBox = amplifier.getRawBBox()
96  outBBox.shift(amplifier.getRawXYOffset())
97  outView = destImage.Factory(destImage, outBBox, False)
98 
99  _insertPixelChunk(outView, inView, amplifier, hasattr(rawImage, "getArrays"))
def assembleAmplifierRawImage
Assemble the amplifier region of a raw CCD image.
def assembleAmplifierImage
Assemble the amplifier region of an image from a raw image.