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

import os.path 

import lsst.geom 

from lsst.afw.table import AmpInfoCatalog 

from .cameraGeomLib import FOCAL_PLANE, FIELD_ANGLE, PIXELS, TAN_PIXELS, ACTUAL_PIXELS, CameraSys, \ 

Detector, DetectorType, Orientation, TransformMap 

from .camera import Camera 

from .makePixelToTanPixel import makePixelToTanPixel 

from .pupil import PupilFactory 

 

__all__ = ["makeCameraFromPath", "makeCameraFromCatalogs", 

"makeDetector", "copyDetector"] 

 

cameraSysList = [FIELD_ANGLE, FOCAL_PLANE, PIXELS, TAN_PIXELS, ACTUAL_PIXELS] 

cameraSysMap = dict((sys.getSysName(), sys) for sys in cameraSysList) 

 

 

def makeDetector(detectorConfig, ampInfoCatalog, focalPlaneToField): 

"""!Make a Detector instance from a detector config and amp info catalog 

 

@param detectorConfig config for this detector (an lsst.pex.config.Config) 

@param ampInfoCatalog amplifier information for this detector (an lsst.afw.table.AmpInfoCatalog) 

@param focalPlaneToField FOCAL_PLANE to FIELD_ANGLE Transform 

@return detector (an lsst.afw.cameraGeom.Detector) 

""" 

orientation = makeOrientation(detectorConfig) 

pixelSizeMm = lsst.geom.Extent2D( 

detectorConfig.pixelSize_x, detectorConfig.pixelSize_y) 

transforms = makeTransformDict(detectorConfig.transformDict.transforms) 

transforms[FOCAL_PLANE] = orientation.makePixelFpTransform(pixelSizeMm) 

 

llPoint = lsst.geom.Point2I(detectorConfig.bbox_x0, detectorConfig.bbox_y0) 

urPoint = lsst.geom.Point2I(detectorConfig.bbox_x1, detectorConfig.bbox_y1) 

bbox = lsst.geom.Box2I(llPoint, urPoint) 

 

tanPixSys = CameraSys(TAN_PIXELS, detectorConfig.name) 

transforms[tanPixSys] = makePixelToTanPixel( 

bbox=bbox, 

orientation=orientation, 

focalPlaneToField=focalPlaneToField, 

pixelSizeMm=pixelSizeMm, 

) 

 

args = [ 

detectorConfig.name, 

detectorConfig.id, 

DetectorType(detectorConfig.detectorType), 

detectorConfig.serial, 

bbox, 

ampInfoCatalog, 

orientation, 

pixelSizeMm, 

transforms, 

] 

crosstalk = detectorConfig.getCrosstalk(len(ampInfoCatalog)) 

55 ↛ 56line 55 didn't jump to line 56, because the condition on line 55 was never true if crosstalk: 

args.append(crosstalk) 

return Detector(*args) 

 

 

def copyDetector(detector, ampInfoCatalog=None): 

"""!Return a copy of a Detector 

 

@param detector The Detector to clone 

@param ampInfoCatalog The ampInfoCatalog to use; default use original 

 

N.b. No deep copies are made; the input transformDict is used unmodified 

""" 

if ampInfoCatalog is None: 

ampInfoCatalog = detector.getAmpInfoCatalog() 

 

tm = detector.getTransformMap() 

native = detector.getNativeCoordSys() 

transformDict = dict() 

for cs in tm: 

if cs != native: 

transformDict[cs] = tm.getTransform(native, cs) 

 

return Detector(detector.getName(), detector.getId(), detector.getType(), 

detector.getSerial(), detector.getBBox(), 

ampInfoCatalog, detector.getOrientation(), detector.getPixelSize(), 

transformDict, detector.getCrosstalk()) 

 

 

def makeOrientation(detectorConfig): 

"""!Make an Orientation instance from a detector config 

 

@param detectorConfig config for this detector (an lsst.pex.config.Config) 

@return orientation (an lsst.afw.cameraGeom.Orientation) 

""" 

offset = lsst.geom.Point2D(detectorConfig.offset_x, detectorConfig.offset_y) 

refPos = lsst.geom.Point2D(detectorConfig.refpos_x, detectorConfig.refpos_y) 

yaw = lsst.geom.Angle(detectorConfig.yawDeg, lsst.geom.degrees) 

pitch = lsst.geom.Angle(detectorConfig.pitchDeg, lsst.geom.degrees) 

roll = lsst.geom.Angle(detectorConfig.rollDeg, lsst.geom.degrees) 

return Orientation(offset, refPos, yaw, pitch, roll) 

 

 

def makeTransformDict(transformConfigDict): 

"""!Make a dictionary of CameraSys: lsst.afw.geom.Transform from a config dict. 

 

@param transformConfigDict an lsst.pex.config.ConfigDictField from an lsst.afw.geom.Transform 

registry; keys are camera system names. 

@return a dict of CameraSys or CameraSysPrefix: lsst.afw.geom.Transform 

""" 

resMap = dict() 

if transformConfigDict is not None: 

for key in transformConfigDict: 

transform = transformConfigDict[key].transform.apply() 

resMap[CameraSys(key)] = transform 

return resMap 

 

 

def makeCameraFromPath(cameraConfig, ampInfoPath, shortNameFunc, 

pupilFactoryClass=PupilFactory): 

"""!Make a Camera instance from a directory of ampInfo files 

 

The directory must contain one ampInfo fits file for each detector in cameraConfig.detectorList. 

The name of each ampInfo file must be shortNameFunc(fullDetectorName) + ".fits". 

 

@param[in] cameraConfig an instance of CameraConfig 

@param[in] ampInfoPath path to ampInfo data files 

@param[in] shortNameFunc a function that converts a long detector name to a short one 

@param[in] pupilFactoryClass class to attach to camera; default afw.cameraGeom.PupilFactory 

@return camera (an lsst.afw.cameraGeom.Camera) 

""" 

ampInfoCatDict = dict() 

for detectorConfig in cameraConfig.detectorList.values(): 

shortName = shortNameFunc(detectorConfig.name) 

ampCatPath = os.path.join(ampInfoPath, shortName + ".fits") 

ampInfoCatalog = AmpInfoCatalog.readFits(ampCatPath) 

ampInfoCatDict[detectorConfig.name] = ampInfoCatalog 

 

return makeCameraFromCatalogs(cameraConfig, ampInfoCatDict, pupilFactoryClass) 

 

 

def makeCameraFromCatalogs(cameraConfig, ampInfoCatDict, 

pupilFactoryClass=PupilFactory): 

"""!Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog 

 

@param[in] cameraConfig an instance of CameraConfig 

@param[in] ampInfoCatDict a dictionary of detector name: AmpInfoCatalog 

@param[in] pupilFactoryClass class to attach to camera; default afw.cameraGeom.PupilFactory 

@return camera (an lsst.afw.cameraGeom.Camera) 

""" 

nativeSys = cameraSysMap[cameraConfig.transformDict.nativeSys] 

transformDict = makeTransformDict(cameraConfig.transformDict.transforms) 

focalPlaneToField = transformDict[FIELD_ANGLE] 

transformMap = TransformMap(nativeSys, transformDict) 

 

detectorList = [] 

for detectorConfig in cameraConfig.detectorList.values(): 

ampInfoCatalog = ampInfoCatDict[detectorConfig.name] 

 

detectorList.append(makeDetector( 

detectorConfig=detectorConfig, 

ampInfoCatalog=ampInfoCatalog, 

focalPlaneToField=focalPlaneToField, 

)) 

 

return Camera(cameraConfig.name, detectorList, transformMap, pupilFactoryClass)