Coverage for python/lsst/cbp/computeHolePositions.py: 21%

23 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-25 02:29 -0800

1# This file is part of cbp. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

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

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

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

12# (at your option) any later version. 

13# 

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

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

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21"""computeHolePositions function: compute hole positions for a CBP mask.""" 

22 

23__all__ = ["computeHolePositions"] 

24 

25import math 

26 

27from lsst.geom import Point2D 

28from lsst.afw.cameraGeom import PIXELS, FIELD_ANGLE 

29from .coordUtils import fieldAngleToVector, vectorToFieldAngle 

30 

31 

32def computeHolePositions(detectorNames, detectorPositions, cameraGeom, cbpFlipX, cbpFocalLength): 

33 """Compute hole positions for a CBP mask. 

34 

35 Given the desired locations of one or more spots on each detector, 

36 and assuming the telescope and CBP are pointing directly at each other, 

37 compute hole positions for a CBP mask. 

38 

39 Parameters 

40 ---------- 

41 detectorNames : `iterable` of `str`, or None, 

42 List of detector names; if None, use all detectors in ``cameraGeom``, 

43 sorted by name. 

44 detectorPositions : `iterable` of pair of `float` 

45 Detector x, y positions (pixels). 

46 Note that the center of a 1000x1000 pixel detector is (499.5, 499.5) 

47 cameraGeom : `lsst.afw.cameraGeom.Camera` 

48 Camera geometry. 

49 cbpFlipX : `bool` 

50 Is the CBP focal plane flipped? 

51 

52 Returns 

53 ------- 

54 holePositions : `list` of `tuple` of pair of `float` 

55 CBP mask x, y hole positions mm. 

56 

57 Notes 

58 ----- 

59 This code assumes that all detectors have approximately the same 

60 dimensions and orientation. This restriction should suffice for LSST 

61 because the two kinds of CCDs it uses have very similar dimensions. 

62 However, it will not do for HSC because that has very rectangular 

63 CCDs and some are 90 degrees from the others. 

64 """ 

65 holePositions = [] 

66 pixelPosList = [Point2D(*val) for val in detectorPositions] 

67 if detectorNames is None: 

68 detectorNames = sorted(list(cameraGeom.getNameIter())) 

69 for detectorName in detectorNames: 

70 detector = cameraGeom[detectorName] 

71 pixelSys = detector.makeCameraSys(PIXELS) 

72 pixelsToFieldAngle = cameraGeom.getTransform(pixelSys, FIELD_ANGLE) 

73 telFieldAngleList = pixelsToFieldAngle.applyForward(pixelPosList) 

74 for telFieldAngle in telFieldAngleList: 

75 # Compute hole positions for when the telescope and CBP 

76 # are pointing at each other; 

77 # thus CBP pupil vector = telescope pupil vector with z negated. 

78 # This is simply a shortcut for setting telAzAlt and cbpAzAlt, 

79 # then transforming vectors from tel pupil to base, 

80 # then from base to CBP pupil. 

81 telVector = fieldAngleToVector(telFieldAngle, False) 

82 cbpVector = (telVector[0], telVector[1], -telVector[2]) 

83 cbpFieldAngle = vectorToFieldAngle(cbpVector, cbpFlipX) 

84 holePos = tuple(math.tan(ang) * cbpFocalLength for ang in cbpFieldAngle) 

85 holePositions.append(holePos) 

86 return holePositions