23 __all__ = [
'PupilFactory',
'Pupil']
29 """!Pupil obscuration function. 35 @param[in] illuminated 2D numpy array indicating which parts of 36 the pupil plane are illuminated. 37 @param[in] size Size of pupil plane array in meters. Note 38 that this may be larger than the actual 39 diameter of the illuminated pupil to 40 accommodate zero-padding. 41 @param[in] scale Sampling interval of pupil plane array in 50 """!Pupil obscuration function factory for use with Fourier optics. 53 def __init__(self, visitInfo, pupilSize, npix):
54 """!Construct a PupilFactory. 56 @param[in] visitInfo VisitInfo object for a particular exposure. 57 @param[in] pupilSize Size in meters of constructed Pupil array. 58 Note that this may be larger than the actual 59 diameter of the illuminated pupil to 60 accommodate zero-padding. 61 @param[in] npix Constructed Pupils will be npix x npix. 67 u = (np.arange(npix, dtype=np.float64) - (npix - 1)/2) * self.
pupilScale 68 self.u, self.
v = np.meshgrid(u, u)
71 """!Calculate a Pupil at a given point in the focal plane. 73 @param point Point2D indicating focal plane coordinates. 76 raise NotImplementedError(
77 "PupilFactory not implemented for this camera")
80 def _pointLineDistance(p0, p1, p2):
81 """Compute the right-angle distance between the points given by `p0` 82 and the line that passes through `p1` and `p2`. 84 @param[in] p0 2-tuple of numpy arrays (x,y coords) 85 @param[in] p1 2-tuple of scalars (x,y coords) 86 @param[in] p2 2-tuple of scalars (x,y coords) 87 @returns numpy array of distances; shape congruent to p0[0] 94 return np.abs(dy21*x0 - dx21*y0 + x2*y1 - y2*x1)/np.hypot(dy21, dx21)
97 """Make a fully-illuminated Pupil. 101 illuminated = np.ones(self.u.shape, dtype=np.bool)
104 def _cutCircleInterior(self, pupil, p0, r):
105 """Cut out the interior of a circular region from a Pupil. 107 @param[in,out] pupil Pupil to modify in place 108 @param[in] p0 2-tuple indicating region center 109 @param[in] r Circular region radius 111 r2 = (self.u - p0[0])**2 + (self.
v - p0[1])**2
112 pupil.illuminated[r2 < r**2] =
False 114 def _cutCircleExterior(self, pupil, p0, r):
115 """Cut out the exterior of a circular region from a Pupil. 117 @param[in,out] pupil Pupil to modify in place 118 @param[in] p0 2-tuple indicating region center 119 @param[in] r Circular region radius 121 r2 = (self.u - p0[0])**2 + (self.
v - p0[1])**2
122 pupil.illuminated[r2 > r**2] =
False 124 def _cutRay(self, pupil, p0, angle, thickness):
125 """Cut out a ray from a Pupil. 127 @param[in,out] pupil Pupil to modify in place 128 @param[in] p0 2-tuple indicating ray starting point 129 @param[in] angle Ray angle measured CCW from +x. 130 @param[in] thickness Thickness of cutout 132 angleRad = angle.asRadians()
135 p1 = (p0[0] + 1, p0[1] + np.tan(angleRad))
136 d = PupilFactory._pointLineDistance((self.u, self.
v), p0, p1)
137 pupil.illuminated[(d < 0.5*thickness) &
138 ((self.u - p0[0])*np.cos(angleRad) +
139 (self.
v - p0[1])*np.sin(angleRad) >= 0)] =
False 141 def _centerPupil(self, pupil):
142 """Center the illuminated portion of the pupil in array. 144 @param[in,out] pupil Pupil to modify in place 146 def center(arr, axis):
147 smash = np.sum(arr, axis=axis)
148 w = np.where(smash)[0]
149 return int(0.5*(np.min(w)+np.max(w)))
150 ycenter = center(pupil.illuminated, 0)
151 xcenter = center(pupil.illuminated, 1)
152 ytarget = pupil.illuminated.shape[0]//2
153 xtarget = pupil.illuminated.shape[1]//2
154 pupil.illuminated = np.roll(np.roll(pupil.illuminated,
def __init__(self, visitInfo, pupilSize, npix)
Construct a PupilFactory.
Pupil obscuration function.
def getPupil(self, point)
Calculate a Pupil at a given point in the focal plane.
Pupil obscuration function factory for use with Fourier optics.
def __init__(self, illuminated, size, scale)
Construct a Pupil.