LSSTApplications  16.0-11-g09ed895+2,16.0-11-g12e47bd,16.0-11-g9bb73b2+6,16.0-12-g5c924a4+6,16.0-14-g9a974b3+1,16.0-15-g1417920+1,16.0-15-gdd5ca33+1,16.0-16-gf0259e2,16.0-17-g31abd91+7,16.0-17-g7d7456e+7,16.0-17-ga3d2e9f+13,16.0-18-ga4d4bcb+1,16.0-18-gd06566c+1,16.0-2-g0febb12+21,16.0-2-g9d5294e+69,16.0-2-ga8830df+6,16.0-20-g21842373+7,16.0-24-g3eae5ec,16.0-28-gfc9ea6c+4,16.0-29-ge8801f9,16.0-3-ge00e371+34,16.0-4-g18f3627+13,16.0-4-g5f3a788+20,16.0-4-ga3eb747+10,16.0-4-gabf74b7+29,16.0-4-gb13d127+6,16.0-49-g42e581f7+6,16.0-5-g27fb78a+7,16.0-5-g6a53317+34,16.0-5-gb3f8a4b+87,16.0-6-g9321be7+4,16.0-6-gcbc7b31+42,16.0-6-gf49912c+29,16.0-7-gd2eeba5+51,16.0-71-ge89f8615e,16.0-8-g21fd5fe+29,16.0-8-g3a9f023+20,16.0-8-g4734f7a+1,16.0-8-g5858431+3,16.0-9-gf5c1f43+8,master-gd73dc1d098+1,w.2019.01
LSSTDataManagementBasePackage
assembleImage.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 import lsst.geom
23 from . import copyDetector
24 
25 __ALL__ = ['assembleAmplifierImage', 'assembleAmplifierRawImage',
26  'updateAmpGeometryForAssembledCcd']
27 
28 # dict of doFlip: slice
29 _SliceDict = {
30  False: slice(None, None, 1),
31  True: slice(None, None, -1),
32 }
33 
34 
35 def _insertPixelChunk(outView, inView, amplifier, hasArrays):
36  # For the sake of simplicity and robustness, this code does not short-circuit the case flipX=flipY=False.
37  # However, it would save a bit of time, including the cost of making numpy array views.
38  # If short circuiting is wanted, do it here.
39 
40  xSlice = _SliceDict[amplifier.getRawFlipX()]
41  ySlice = _SliceDict[amplifier.getRawFlipY()]
42  if hasArrays:
43  # MaskedImage
44  inArrList = inView.getArrays()
45  outArrList = outView.getArrays()
46  else:
47  inArrList = [inView.getArray()]
48  outArrList = [outView.getArray()]
49 
50  for inArr, outArr in zip(inArrList, outArrList):
51  # y,x because numpy arrays are transposed w.r.t. afw Images
52  outArr[:] = inArr[ySlice, xSlice]
53 
54 
55 def assembleAmplifierImage(destImage, rawImage, amplifier):
56  """!Assemble the amplifier region of an image from a raw image
57 
58  @param[in,out] destImage assembled image (lsst.afw.image.Image or MaskedImage);
59  the region amplifier.getBBox() is overwritten with the assembled amplifier image
60  @param[in] rawImage raw image (same type as destImage)
61  @param[in] amplifier amplifier geometry: lsst.afw.cameraGeom.Amplifier with raw amplifier info
62 
63  @throw RuntimeError if:
64  - image types do not match
65  - amplifier has no raw amplifier info
66  """
67  if not amplifier.getHasRawInfo():
68  raise RuntimeError("amplifier must contain raw amplifier info")
69  if type(destImage.Factory) != type(rawImage.Factory): # noqa E721
70  raise RuntimeError("destImage type = %s != %s = rawImage type" %
71  type(destImage.Factory).__name__, type(rawImage.Factory).__name__)
72  inView = rawImage.Factory(rawImage, amplifier.getRawDataBBox())
73  outView = destImage.Factory(destImage, amplifier.getBBox())
74 
75  _insertPixelChunk(outView, inView, amplifier,
76  hasattr(rawImage, "getArrays"))
77 
78 
79 def assembleAmplifierRawImage(destImage, rawImage, amplifier):
80  """!Assemble the amplifier region of a raw CCD image
81 
82  For most cameras this is a no-op: the raw image already is an assembled CCD image.
83  However, it is useful for camera such as LSST for which each amplifier image is a separate image.
84 
85  @param[in,out] destImage CCD image (lsst.afw.image.Image or MaskedImage);
86  the region amplifier.getRawAmplifier().getBBox() is overwritten with the raw amplifier image
87  @param[in] rawImage raw image (same type as destImage)
88  @param[in] amplifier amplifier geometry: lsst.afw.cameraGeom.Amplifier with raw amplifier info
89 
90  @throw RuntimeError if:
91  - image types do not match
92  - amplifier has no raw amplifier info
93  """
94  if not amplifier.getHasRawInfo():
95  raise RuntimeError("amplifier must contain raw amplifier info")
96  if type(destImage.Factory) != type(rawImage.Factory): # noqa E721
97  raise RuntimeError("destImage type = %s != %s = rawImage type" %
98  type(destImage.Factory).__name__, type(rawImage.Factory).__name__)
99  inBBox = amplifier.getRawBBox()
100  inView = rawImage.Factory(rawImage, inBBox)
101  outBBox = amplifier.getRawBBox()
102  outBBox.shift(amplifier.getRawXYOffset())
103  outView = destImage.Factory(destImage, outBBox)
104 
105  _insertPixelChunk(outView, inView, amplifier,
106  hasattr(rawImage, "getArrays"))
107 
108 
110  """Return a Detector that has had the definitions of amplifier geometry updated post assembly
111  """
112  ampInfoCatalog = ccd.getAmpInfoCatalog().copy(deep=True)
113 
114  for amp in ampInfoCatalog:
115  assert amp.getHasRawInfo()
116 
117  bbox = amp.getRawBBox()
118  awidth, aheight = bbox.getDimensions()
119  #
120  # Figure out how far flipping the amp LR and/or TB offsets the bboxes
121  #
122  boxMin0 = bbox.getMin() # initial position of rawBBox's LLC corner
123  if amp.getRawFlipX():
124  bbox.flipLR(awidth)
125  if amp.getRawFlipY():
126  bbox.flipTB(aheight)
127  shift = boxMin0 - bbox.getMin()
128 
129  for bboxName in ("",
130  "HorizontalOverscan",
131  "Data",
132  "VerticalOverscan",
133  "Prescan"):
134  bbox = getattr(amp, "getRaw%sBBox" % bboxName)()
135  if amp.getRawFlipX():
136  bbox.flipLR(awidth)
137  if amp.getRawFlipY():
138  bbox.flipTB(aheight)
139  bbox.shift(amp.getRawXYOffset() + shift)
140 
141  getattr(amp, "setRaw%sBBox" % bboxName)(bbox)
142  #
143  # All of these have now been transferred to the per-amp geometry
144  #
145  amp.setRawXYOffset(lsst.geom.ExtentI(0, 0))
146  amp.setRawFlipX(False)
147  amp.setRawFlipY(False)
148 
149  return copyDetector(ccd, ampInfoCatalog)
def copyDetector(detector, ampInfoCatalog=None)
table::Key< int > type
Definition: Detector.cc:164
def assembleAmplifierImage(destImage, rawImage, amplifier)
Assemble the amplifier region of an image from a raw image.
def assembleAmplifierRawImage(destImage, rawImage, amplifier)
Assemble the amplifier region of a raw CCD image.