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 

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

4from lsst.afw.cameraGeom import FIELD_ANGLE 

5from lsst.sims.coordUtils import lsst_camera 

6 

7 

8__all__ = ["DMtoCameraPixelTransformer"] 

9 

10 

11class DMtoCameraPixelTransformer(object): 

12 

13 def __init__(self): 

14 self._camera = lsst_camera() 

15 

16 def getBBox(self, detector_name): 

17 """ 

18 Return the bounding box for the detector named by detector_name 

19 """ 

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

21 self._bbox_cache = {} 

22 

23 if detector_name not in self._bbox_cache: 

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

25 dm_min = dm_bbox.getMin() 

26 dm_max = dm_bbox.getMax() 

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

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

29 

30 self._bbox_cache[detector_name] = cam_bbox 

31 

32 return self._bbox_cache[detector_name] 

33 

34 def getCenterPixel(self, detector_name): 

35 """ 

36 Return the central pixel for the detector named by detector_name 

37 """ 

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

39 self._center_pixel_cache = {} 

40 

41 if detector_name not in self._center_pixel_cache: 

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

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

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

45 self._center_pixel_cache[detector_name] = centerPixel_cam 

46 

47 return self._center_pixel_cache[detector_name] 

48 

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

50 """ 

51 Convert DM pixel coordinates into camera pixel coordinates 

52 

53 Parameters: 

54 ----------- 

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

56 a number or an array) 

57 

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

59 a number or an array) 

60 

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

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

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

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

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

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

67 chip. Default is None. 

68 

69 Returns 

70 ------- 

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

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

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

74 """ 

75 cam_yPix = dm_xPix 

76 

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

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

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

80 cam_center_pix = self.getCenterPixel(det_name) 

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

82 else: 

83 cam_center_pix = self.getCenterPixel(chipName) 

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

85 

86 return cam_xPix, cam_yPix 

87 

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

89 """ 

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

91 

92 Parameters 

93 ---------- 

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

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

96 

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

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

99 

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

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

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

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

104 

105 Returns 

106 ------- 

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

108 a float or a numpy array) 

109 

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

111 a float or a numpy array) 

112 """ 

113 

114 dm_x_pix = cam_y_pix 

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

116 center_pix_dict = {} 

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

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

119 if det_name not in center_pix_dict: 

120 center_pix = self.getCenterPixel(det_name) 

121 center_pix_dict[det_name] = center_pix 

122 else: 

123 center_pix = center_pix_dict[det_name] 

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

125 else: 

126 center_pix = self.getCenterPixel(chipName) 

127 dm_y_pix = 2.0*center_pix[0] - cam_x_pix 

128 

129 return dm_x_pix, dm_y_pix