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

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

# 

# LSST Data Management System 

# Copyright 2014 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/>. 

# 

from lsst.pex.exceptions import InvalidParameterError 

import lsst.geom 

from .cameraGeomLib import FOCAL_PLANE, PIXELS 

from .detectorCollection import DetectorCollection 

from .pupil import PupilFactory 

 

 

class Camera(DetectorCollection): 

"""!A collection of Detectors plus additional coordinate system support 

 

Camera.transform transforms points from one camera coordinate system to another. 

 

Camera.getTransform returns a transform between camera coordinate systems. 

 

Camera.findDetectors finds all detectors overlapping a specified point. 

""" 

 

def __init__(self, name, detectorList, transformMap, pupilFactoryClass=PupilFactory): 

"""!Construct a Camera 

 

@param[in] name name of camera 

@param[in] detectorList a sequence of detectors in index order 

@param[in] transformMap a TransformMap that at least supports 

FOCAL_PLANE and FIELD_ANGLE coordinates 

@param[in] pupilFactoryClass a PupilFactory class for this camera 

[default: afw.cameraGeom.PupilFactory] 

""" 

self._name = name 

self._transformMap = transformMap 

self._nativeCameraSys = FOCAL_PLANE 

self._pupilFactoryClass = pupilFactoryClass 

super(Camera, self).__init__(detectorList) 

 

def getName(self): 

"""!Return the camera name 

""" 

return self._name 

 

def getPupilFactory(self, visitInfo, pupilSize, npix, **kwargs): 

"""!Construct a PupilFactory. 

 

@param[in] visitInfo VisitInfo object for a particular exposure. 

@param[in] pupilSize Size in meters of constructed Pupil array. 

Note that this may be larger than the actual 

diameter of the illuminated pupil to 

accommodate zero-padding. 

@param[in] npix Constructed Pupils will be npix x npix. 

@param[in] kwargs Other keyword arguments for the pupil factory 

""" 

return self._pupilFactoryClass(visitInfo, pupilSize, npix, **kwargs) 

 

@property 

def telescopeDiameter(self): 

return self._pupilFactoryClass.telescopeDiameter 

 

def _getTransformFromOneTransformMap(self, fromSys, toSys): 

"""!Get a transform from one TransformMap 

 

`fromSys` and `toSys` must both be present in the same transform map, 

but that transform map may be from any detector or this camera object. 

 

@param[in] fromSys Camera coordinate system of `position` 

input points 

@param[in] toSys Camera coordinate system of returned point(s) 

 

@return an lsst.afw.geom.TransformPoint2ToPoint2 that transforms from 

`fromSys` to `toSys` in the forward direction 

 

@throws lsst.pex.exceptions.InvalidParameterError if no transform is 

available. This includes the case that fromSys specifies a known 

detector and toSys specifies any other detector (known or unknown) 

@throws KeyError if an unknown detector is specified 

""" 

if fromSys.hasDetectorName(): 

det = self[fromSys.getDetectorName()] 

return det.getTransformMap().getTransform(fromSys, toSys) 

elif toSys.hasDetectorName(): 

det = self[toSys.getDetectorName()] 

return det.getTransformMap().getTransform(fromSys, toSys) 

else: 

return self.getTransformMap().getTransform(fromSys, toSys) 

 

def findDetectors(self, point, cameraSys): 

"""!Find the detectors that cover a point in any camera system 

 

@param[in] point position to use in lookup (lsst.geom.Point2D) 

@param[in] cameraSys camera coordinate system of `point` 

@return a list of zero or more Detectors that overlap the specified point 

""" 

# convert `point` to the native coordinate system 

transform = self._getTransformFromOneTransformMap(cameraSys, self._nativeCameraSys) 

nativePoint = transform.applyForward(point) 

 

detectorList = [] 

for detector in self: 

nativeToPixels = detector.getTransform(self._nativeCameraSys, PIXELS) 

pointPixels = nativeToPixels.applyForward(nativePoint) 

if lsst.geom.Box2D(detector.getBBox()).contains(pointPixels): 

detectorList.append(detector) 

return detectorList 

 

def findDetectorsList(self, pointList, cameraSys): 

"""!Find the detectors that cover a list of points in any camera system 

 

@param[in] pointList a list of points (lsst.geom.Point2D) 

@param[in] cameraSys the camera coordinate system of the points in `pointList` 

@return a list of lists; each list contains the names of all detectors 

which contain the corresponding point 

""" 

 

# transform the points to the native coordinate system 

transform = self._getTransformFromOneTransformMap(cameraSys, self._nativeCameraSys) 

nativePointList = transform.applyForward(pointList) 

 

detectorList = [] 

for i in range(len(pointList)): 

detectorList.append([]) 

 

for detector in self: 

pixelSys = detector.makeCameraSys(PIXELS) 

transform = detector.getTransformMap().getTransform(self._nativeCameraSys, pixelSys) 

detectorPointList = transform.applyForward(nativePointList) 

box = lsst.geom.Box2D(detector.getBBox()) 

for i, pt in enumerate(detectorPointList): 

if box.contains(pt): 

detectorList[i].append(detector) 

 

return detectorList 

 

def getTransform(self, fromSys, toSys): 

"""!Get a transform from one CameraSys to another 

 

@param[in] fromSys From CameraSys 

@param[in] toSys To CameraSys 

@return an lsst.afw.geom.TransformPoint2ToPoint2 that transforms from 

`fromSys` to `toSys` in the forward direction 

 

@throws lsst.pex.exceptions.InvalidParameterError if no transform is 

available. 

@throws KeyError if an unknown detector is specified 

""" 

# Cameras built via makeCameraFromConfig or makeCameraFromPath 

# should now have all coordinate systems available in their 

# transformMap. 

try: 

return self.getTransformMap().getTransform(fromSys, toSys) 

except InvalidParameterError: 

pass 

# Camera must have been constructed an in an unusual way (which we 

# still support for backwards compatibility). 

# All transform maps should know about the native coordinate system 

fromSysToNative = self._getTransformFromOneTransformMap(fromSys, self._nativeCameraSys) 

nativeToToSys = self._getTransformFromOneTransformMap(self._nativeCameraSys, toSys) 

return fromSysToNative.then(nativeToToSys) 

 

def getTransformMap(self): 

"""!Obtain the transform registry. 

 

@return a TransformMap 

 

@note: TransformRegistries are immutable, so this should be safe. 

""" 

return self._transformMap 

 

def transform(self, points, fromSys, toSys): 

"""!Transform a point or list of points from one camera coordinate system 

to another 

 

@param[in] points an lsst.geom.Point2D or list of Point2D 

@param[in] fromSys Transform from this CameraSys 

@param[in] toSys Transform to this CameraSys 

@return `points` transformed to `toSys` (an lsst.geom.Point2D 

or list of Point2D) 

""" 

transform = self.getTransform(fromSys, toSys) 

return transform.applyForward(points)