lsst.afw  14.0-17-gfc02bf727
pupil.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2017 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 from __future__ import absolute_import, division, print_function
23 
24 __all__ = ['PupilFactory', 'Pupil']
25 
26 import numpy as np
27 
28 
29 class Pupil(object):
30  """!Pupil obscuration function.
31  """
32 
33  def __init__(self, illuminated, size, scale):
34  """!Construct a Pupil
35 
36  @param[in] illuminated 2D numpy array indicating which parts of
37  the pupil plane are illuminated.
38  @param[in] size Size of pupil plane array in meters. Note
39  that this may be larger than the actual
40  diameter of the illuminated pupil to
41  accommodate zero-padding.
42  @param[in] scale Sampling interval of pupil plane array in
43  meters.
44  """
45  self.illuminated = illuminated
46  self.size = size
47  self.scale = scale
48 
49 
50 class PupilFactory(object):
51  """!Pupil obscuration function factory for use with Fourier optics.
52  """
53 
54  def __init__(self, visitInfo, pupilSize, npix):
55  """!Construct a PupilFactory.
56 
57  @param[in] visitInfo VisitInfo object for a particular exposure.
58  @param[in] pupilSize Size in meters of constructed Pupil array.
59  Note that this may be larger than the actual
60  diameter of the illuminated pupil to
61  accommodate zero-padding.
62  @param[in] npix Constructed Pupils will be npix x npix.
63  """
64  self.visitInfo = visitInfo
65  self.pupilSize = pupilSize
66  self.npix = npix
67  self.pupilScale = pupilSize/npix
68  u = (np.arange(npix, dtype=np.float64) - (npix - 1)/2) * self.pupilScale
69  self.u, self.v = np.meshgrid(u, u)
70 
71  def getPupil(self, point):
72  """!Calculate a Pupil at a given point in the focal plane.
73 
74  @param point Point2D indicating focal plane coordinates.
75  @returns Pupil
76  """
77  raise NotImplementedError(
78  "PupilFactory not implemented for this camera")
79 
80  @staticmethod
81  def _pointLineDistance(p0, p1, p2):
82  """Compute the right-angle distance between the points given by `p0`
83  and the line that passes through `p1` and `p2`.
84 
85  @param[in] p0 2-tuple of numpy arrays (x,y coords)
86  @param[in] p1 2-tuple of scalars (x,y coords)
87  @param[in] p2 2-tuple of scalars (x,y coords)
88  @returns numpy array of distances; shape congruent to p0[0]
89  """
90  x0, y0 = p0
91  x1, y1 = p1
92  x2, y2 = p2
93  dy21 = y2 - y1
94  dx21 = x2 - x1
95  return np.abs(dy21*x0 - dx21*y0 + x2*y1 - y2*x1)/np.hypot(dy21, dx21)
96 
97  def _fullPupil(self):
98  """Make a fully-illuminated Pupil.
99 
100  @returns Pupil
101  """
102  illuminated = np.ones(self.u.shape, dtype=np.bool)
103  return Pupil(illuminated, self.pupilSize, self.pupilScale)
104 
105  def _cutCircleInterior(self, pupil, p0, r):
106  """Cut out the interior of a circular region from a Pupil.
107 
108  @param[in,out] pupil Pupil to modify in place
109  @param[in] p0 2-tuple indicating region center
110  @param[in] r Circular region radius
111  """
112  r2 = (self.u - p0[0])**2 + (self.v - p0[1])**2
113  pupil.illuminated[r2 < r**2] = False
114 
115  def _cutCircleExterior(self, pupil, p0, r):
116  """Cut out the exterior of a circular region from a Pupil.
117 
118  @param[in,out] pupil Pupil to modify in place
119  @param[in] p0 2-tuple indicating region center
120  @param[in] r Circular region radius
121  """
122  r2 = (self.u - p0[0])**2 + (self.v - p0[1])**2
123  pupil.illuminated[r2 > r**2] = False
124 
125  def _cutRay(self, pupil, p0, angle, thickness):
126  """Cut out a ray from a Pupil.
127 
128  @param[in,out] pupil Pupil to modify in place
129  @param[in] p0 2-tuple indicating ray starting point
130  @param[in] angle Ray angle measured CCW from +x.
131  @param[in] thickness Thickness of cutout
132  """
133  angleRad = angle.asRadians()
134  # the 1 is arbitrary, just need something to define another point on
135  # the line
136  p1 = (p0[0] + 1, p0[1] + np.tan(angleRad))
137  d = PupilFactory._pointLineDistance((self.u, self.v), p0, p1)
138  pupil.illuminated[(d < 0.5*thickness) &
139  ((self.u - p0[0])*np.cos(angleRad) +
140  (self.v - p0[1])*np.sin(angleRad) >= 0)] = False
def __init__(self, visitInfo, pupilSize, npix)
Construct a PupilFactory.
Definition: pupil.py:54
Pupil obscuration function.
Definition: pupil.py:29
def getPupil(self, point)
Calculate a Pupil at a given point in the focal plane.
Definition: pupil.py:71
Pupil obscuration function factory for use with Fourier optics.
Definition: pupil.py:50
def __init__(self, illuminated, size, scale)
Construct a Pupil.
Definition: pupil.py:33