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

1import numpy as np 

2import lsst.geom as geom 

3 

4import lsst.obs.lsst.phosim as obs_lsst_phosim 

5 

6from lsst.afw.cameraGeom import FOCAL_PLANE, PIXELS, TAN_PIXELS 

7from lsst.afw.cameraGeom import FIELD_ANGLE 

8 

9 

10__all__ = ["DMtoCameraPixelTransformer"] 

11 

12 

13class DMtoCameraPixelTransformer(object): 

14 

15 def __init__(self): 

16 self._camera = obs_lsst_phosim.PhosimMapper().camera 

17 

18 def getBBox(self, detector_name): 

19 """ 

20 Return the bounding box for the detector named by detector_name 

21 """ 

22 if not hasattr(self, '_bbox_cache'): 

23 self._bbox_cache = {} 

24 

25 if detector_name not in self._bbox_cache: 

26 dm_bbox = self._camera[detector_name].getBBox() 

27 dm_min = dm_bbox.getMin() 

28 dm_max = dm_bbox.getMax() 

29 cam_bbox = geom.Box2I(minimum=geom.Point2I(dm_min[1], dm_min[0]), 

30 maximum=geom.Point2I(dm_max[1], dm_max[0])) 

31 

32 self._bbox_cache[detector_name] = cam_bbox 

33 

34 return self._bbox_cache[detector_name] 

35 

36 def getCenterPixel(self, detector_name): 

37 """ 

38 Return the central pixel for the detector named by detector_name 

39 """ 

40 if not hasattr(self, '_center_pixel_cache'): 

41 self._center_pixel_cache = {} 

42 

43 if detector_name not in self._center_pixel_cache: 

44 centerPoint = self._camera[detector_name].getCenter(FOCAL_PLANE) 

45 centerPixel_dm = self._camera[detector_name].getTransform(FOCAL_PLANE, PIXELS).applyForward(centerPoint) 

46 centerPixel_cam = geom.Point2D(centerPixel_dm.getY(), centerPixel_dm.getX()) 

47 self._center_pixel_cache[detector_name] = centerPixel_cam 

48 

49 return self._center_pixel_cache[detector_name] 

50 

51 def cameraPixFromDMPix(self, dm_xPix, dm_yPix, chipName): 

52 """ 

53 Convert DM pixel coordinates into camera pixel coordinates 

54 

55 Parameters: 

56 ----------- 

57 dm_xPix -- the x pixel coordinate in the DM system (either 

58 a number or an array) 

59 

60 dm_yPix -- the y pixel coordinate in the DM system (either 

61 a number or an array) 

62 

63 chipName designates the names of the chips on which the pixel 

64 coordinates will be reckoned. Can be either single value, an array, or None. 

65 If an array, there must be as many chipNames as there are (RA, Dec) pairs. 

66 If a single value, all of the pixel coordinates will be reckoned on the same 

67 chip. If None, this method will calculate which chip each(RA, Dec) pair actually 

68 falls on, and return pixel coordinates for each (RA, Dec) pair on the appropriate 

69 chip. Default is None. 

70 

71 Returns 

72 ------- 

73 a 2-D numpy array in which the first row is the x pixel coordinate 

74 and the second row is the y pixel coordinate. These pixel coordinates 

75 are defined in the Camera team system, rather than the DM system. 

76 """ 

77 cam_yPix = dm_xPix 

78 

79 if isinstance(chipName, list) or isinstance(chipName, np.ndarray): 

80 cam_xPix = np.zeros(len(dm_xPix)) 

81 for ix, (det_name, yy) in enumerate(zip(chipName, dm_yPix)): 

82 cam_center_pix = self.getCenterPixel(det_name) 

83 cam_xPix[ix] = 2.0*cam_center_pix.getX() - yy 

84 else: 

85 cam_center_pix = self.getCenterPixel(chipName) 

86 cam_xPix = 2.0*cam_center_pix.getX() - dm_yPix 

87 

88 return cam_xPix, cam_yPix 

89 

90 def dmPixFromCameraPix(self, cam_x_pix, cam_y_pix, chipName): 

91 """ 

92 Convert pixel coordinates from the Camera Team system to the DM system 

93 

94 Parameters 

95 ---------- 

96 cam_x_pix -- the x pixel coordinate in the Camera Team system 

97 (can be either a float or a numpy array) 

98 

99 cam_y_pix -- the y pixel coordiantes in the Camera Team system 

100 (can be either a float or a numpy array) 

101 

102 chipName -- the name of the chip(s) on which the pixel coordinates 

103 are defined. This can be a list (in which case there should be one chip name 

104 for each (cam_xpix, cam_ypix) coordinate pair), or a single value (in which 

105 case, all of the (cam_xpix, cam_ypi) points will be reckoned on that chip). 

106 

107 Returns 

108 ------- 

109 dm_x_pix -- the x pixel coordinate(s) in the DM system (either 

110 a float or a numpy array) 

111 

112 dm_y_pix -- the y pixel coordinate(s) in the DM system (either 

113 a float or a numpy array) 

114 """ 

115 

116 dm_x_pix = cam_y_pix 

117 if isinstance(chipName, list) or isinstance(chipName, np.ndarray): 

118 center_pix_dict = {} 

119 dm_y_pix = np.zeros(len(cam_x_pix)) 

120 for ix, (det_name, xx) in enumerate(zip(chipName, cam_x_pix)): 

121 if det_name not in center_pix_dict: 

122 center_pix = self.getCenterPixel(det_name) 

123 center_pix_dict[det_name] = center_pix 

124 else: 

125 center_pix = center_pix_dict[det_name] 

126 dm_y_pix[ix] = 2.0*center_pix[0]-xx 

127 else: 

128 center_pix = self.getCenterPixel(chipName) 

129 dm_y_pix = 2.0*center_pix[0] - cam_x_pix 

130 

131 return dm_x_pix, dm_y_pix