LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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"))