Coverage for python/lsst/cbp/beamInfo.py: 32%
46 statements
« prev ^ index » next coverage.py v6.4, created at 2022-06-02 03:44 -0700
« prev ^ index » next coverage.py v6.4, created at 2022-06-02 03:44 -0700
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"""BeamInfo class: information about a beam at the telescope."""
23__all__ = ["BeamInfo"]
25import numpy as np
27from lsst.geom import Point2D
28from lsst.afw.cameraGeom import PIXELS, FOCAL_PLANE, FIELD_ANGLE
31class BeamInfo:
32 """Information about a beam at the telescope.
34 Note that this is information about the fiducial position
35 of the beam; it tell you nothing about the rest of the beam.
36 Thus, for instance, a broad beam may easily
37 have some light on a detector even if ``isVisible`` is False.
39 Parameters
40 ----------
41 cameraGeom : `lsst.afw.cameraGeom.Camera`
42 Camera geometry
43 name : `str`
44 Beam name
45 holePos : pair of `float`
46 Hole position on CBP mask (x, y mm)
47 isOnPupil : `bool`
48 See `fields`_ below
49 isOnFocalPlane : `bool`
50 See `fields`_ below
51 focalPlanePos : pair of `float`
52 See `fields`_ below
53 pupilPos : pair of `float`
54 See `fields`_ below
55 focalFieldAngle : pair of `float`
56 See `fields`_ below
57 pupilFieldAngle : pair of `float`
58 See `fields`_ below
60 Notes
61 -----
62 .. _fields:
64 **Attributes**
66 name : `str`
67 Name of beam.
68 holePos : pair of `float`
69 Position of hole on CBP mask (x, y mm).
70 isOnPupil : `bool`
71 True if the beam is likely on the pupil and not obscured
72 by the secondary.
73 isOnFocalPlane : `bool`
74 True if the beam is likely on the focal plane.
76 This is independent of ``isOnPupil``; both must be true
77 for light from the beam to be on the focal plane.
78 focalPlanePos : `lsst.geom.Point2D`
79 Telescope :ref:`focal plane <lsst.cbp.focal_plane>` position
80 of beam (x, y mm).
81 focalFieldAngle : `lsst.geom.Point2D`
82 :ref:`Focal plane field angle <lsst.cbp.focal_plane_field_angle>`
83 of beam (x, y rad).
84 pupilFieldAngle : `lsst.geom.Point2D`
85 :ref:`Pupil field angle <lsst.cbp.pupil_field_angle>`
86 of beam (x, y rad).
87 pupilPos : `lsst.geom.Point2D`
88 Telescope :ref:`pupil plane position <lsst.cbp.pupil_position>`
89 of beam (x, y mm).
91 """
93 def __init__(self, cameraGeom, name, holePos, isOnPupil, isOnFocalPlane, focalPlanePos, pupilPos,
94 focalFieldAngle, pupilFieldAngle):
95 self._cameraGeom = cameraGeom
96 self.name = name
97 self.holePos = holePos
98 self.isOnPupil = isOnPupil
99 self.isOnFocalPlane = isOnFocalPlane
100 self.focalPlanePos = Point2D(*focalPlanePos)
101 self.focalFieldAngle = Point2D(*focalFieldAngle)
102 self.pupilFieldAngle = Point2D(*pupilFieldAngle)
103 self.pupilPos = Point2D(*pupilPos)
104 fieldAngleToFocalPlane = self._cameraGeom.getTransform(FIELD_ANGLE, FOCAL_PLANE)
105 self.focalPlanePos = fieldAngleToFocalPlane.applyForward(self.focalFieldAngle)
106 self._isOnDetector = None
107 self._detector = None
109 @property
110 def isOnDetector(self):
111 """Is the spot from the beam on a detector?
112 """
113 if self._isOnDetector is None:
114 self._findDetector()
115 return self._isOnDetector
117 @property
118 def isVisible(self):
119 """Is light from the beam visible on a detector?
120 """
121 return self.isOnPupil and self.isOnDetector
123 @property
124 def detectorPos(self):
125 """The position of the spot on the detector, or (nan, nan)
126 if `isOnDetector` is False.
127 """
128 if not self.isOnDetector:
129 return Point2D(np.nan, np.nan)
130 pixelSys = self._detector.makeCameraSys(PIXELS)
131 focalPlaneToPixels = self._cameraGeom.getTransform(FOCAL_PLANE, pixelSys)
132 return focalPlaneToPixels.applyForward(self.focalPlanePos)
134 @property
135 def detectorName(self):
136 """The name of the detector that the beam falls on,
137 or None if isOnDetector is False.
138 """
139 if not self.isOnDetector:
140 return None
141 return self._detector.getName()
143 def _findDetector(self):
144 detectors = self._cameraGeom.findDetectors(self.focalFieldAngle, FIELD_ANGLE)
145 if not detectors:
146 self._isOnDetector = False
147 else:
148 self._detector = detectors[0]
149 self._isOnDetector = True