Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

# 

# LSST Data Management System 

# Copyright 2008, 2009, 2010 LSST Corporation. 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <http://www.lsstcorp.org/LegalNotices/>. 

# 

import lsst.geom 

from . import copyDetector 

 

__ALL__ = ['assembleAmplifierImage', 'assembleAmplifierRawImage', 

'updateAmpGeometryForAssembledCcd'] 

 

# dict of doFlip: slice 

_SliceDict = { 

False: slice(None, None, 1), 

True: slice(None, None, -1), 

} 

 

 

def _insertPixelChunk(outView, inView, amplifier, hasArrays): 

# For the sake of simplicity and robustness, this code does not short-circuit the case flipX=flipY=False. 

# However, it would save a bit of time, including the cost of making numpy array views. 

# If short circuiting is wanted, do it here. 

 

xSlice = _SliceDict[amplifier.getRawFlipX()] 

ySlice = _SliceDict[amplifier.getRawFlipY()] 

if hasArrays: 

# MaskedImage 

inArrList = inView.getArrays() 

outArrList = outView.getArrays() 

else: 

inArrList = [inView.getArray()] 

outArrList = [outView.getArray()] 

 

for inArr, outArr in zip(inArrList, outArrList): 

# y,x because numpy arrays are transposed w.r.t. afw Images 

outArr[:] = inArr[ySlice, xSlice] 

 

 

def assembleAmplifierImage(destImage, rawImage, amplifier): 

"""!Assemble the amplifier region of an image from a raw image 

 

@param[in,out] destImage assembled image (lsst.afw.image.Image or MaskedImage); 

the region amplifier.getBBox() is overwritten with the assembled amplifier image 

@param[in] rawImage raw image (same type as destImage) 

@param[in] amplifier amplifier geometry: lsst.afw.cameraGeom.Amplifier with raw amplifier info 

 

@throw RuntimeError if: 

- image types do not match 

- amplifier has no raw amplifier info 

""" 

if not amplifier.getHasRawInfo(): 

raise RuntimeError("amplifier must contain raw amplifier info") 

if type(destImage.Factory) != type(rawImage.Factory): # noqa E721 

raise RuntimeError("destImage type = %s != %s = rawImage type" % 

type(destImage.Factory).__name__, type(rawImage.Factory).__name__) 

inView = rawImage.Factory(rawImage, amplifier.getRawDataBBox()) 

outView = destImage.Factory(destImage, amplifier.getBBox()) 

 

_insertPixelChunk(outView, inView, amplifier, 

hasattr(rawImage, "getArrays")) 

 

 

def assembleAmplifierRawImage(destImage, rawImage, amplifier): 

"""!Assemble the amplifier region of a raw CCD image 

 

For most cameras this is a no-op: the raw image already is an assembled CCD image. 

However, it is useful for camera such as LSST for which each amplifier image is a separate image. 

 

@param[in,out] destImage CCD image (lsst.afw.image.Image or MaskedImage); 

the region amplifier.getRawAmplifier().getBBox() is overwritten with the raw amplifier image 

@param[in] rawImage raw image (same type as destImage) 

@param[in] amplifier amplifier geometry: lsst.afw.cameraGeom.Amplifier with raw amplifier info 

 

@throw RuntimeError if: 

- image types do not match 

- amplifier has no raw amplifier info 

""" 

if not amplifier.getHasRawInfo(): 

raise RuntimeError("amplifier must contain raw amplifier info") 

if type(destImage.Factory) != type(rawImage.Factory): # noqa E721 

raise RuntimeError("destImage type = %s != %s = rawImage type" % 

type(destImage.Factory).__name__, type(rawImage.Factory).__name__) 

inBBox = amplifier.getRawBBox() 

inView = rawImage.Factory(rawImage, inBBox) 

outBBox = amplifier.getRawBBox() 

outBBox.shift(amplifier.getRawXYOffset()) 

outView = destImage.Factory(destImage, outBBox) 

 

_insertPixelChunk(outView, inView, amplifier, 

hasattr(rawImage, "getArrays")) 

 

 

def makeUpdatedDetector(ccd): 

"""Return a Detector that has had the definitions of amplifier geometry updated post assembly 

""" 

ampInfoCatalog = ccd.getAmpInfoCatalog().copy(deep=True) 

 

for amp in ampInfoCatalog: 

assert amp.getHasRawInfo() 

 

bbox = amp.getRawBBox() 

awidth, aheight = bbox.getDimensions() 

# 

# Figure out how far flipping the amp LR and/or TB offsets the bboxes 

# 

boxMin0 = bbox.getMin() # initial position of rawBBox's LLC corner 

if amp.getRawFlipX(): 

bbox.flipLR(awidth) 

if amp.getRawFlipY(): 

bbox.flipTB(aheight) 

shift = boxMin0 - bbox.getMin() 

 

for bboxName in ("", 

"HorizontalOverscan", 

"Data", 

"VerticalOverscan", 

"Prescan"): 

bbox = getattr(amp, "getRaw%sBBox" % bboxName)() 

if amp.getRawFlipX(): 

bbox.flipLR(awidth) 

if amp.getRawFlipY(): 

bbox.flipTB(aheight) 

bbox.shift(amp.getRawXYOffset() + shift) 

 

getattr(amp, "setRaw%sBBox" % bboxName)(bbox) 

# 

# All of these have now been transferred to the per-amp geometry 

# 

amp.setRawXYOffset(lsst.geom.ExtentI(0, 0)) 

amp.setRawFlipX(False) 

amp.setRawFlipY(False) 

 

return copyDetector(ccd, ampInfoCatalog)