Coverage for python/lsst/afw/cameraGeom/pupil.py : 27%
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
|
# # LSST Data Management System # Copyright 2017 LSST Corporation. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. #
"""!Pupil obscuration function. """
"""!Construct a Pupil
@param[in] illuminated 2D numpy array indicating which parts of the pupil plane are illuminated. @param[in] size Size of pupil plane array in meters. Note that this may be larger than the actual diameter of the illuminated pupil to accommodate zero-padding. @param[in] scale Sampling interval of pupil plane array in meters. """ self.illuminated = illuminated self.size = size self.scale = scale
"""!Pupil obscuration function factory for use with Fourier optics. """
"""!Construct a PupilFactory.
@param[in] visitInfo VisitInfo object for a particular exposure. @param[in] pupilSize Size in meters of constructed Pupil array. Note that this may be larger than the actual diameter of the illuminated pupil to accommodate zero-padding. @param[in] npix Constructed Pupils will be npix x npix. """ self.visitInfo = visitInfo self.pupilSize = pupilSize self.npix = npix self.pupilScale = pupilSize/npix u = (np.arange(npix, dtype=np.float64) - (npix - 1)/2) * self.pupilScale self.u, self.v = np.meshgrid(u, u)
"""!Calculate a Pupil at a given point in the focal plane.
@param point Point2D indicating focal plane coordinates. @returns Pupil """ raise NotImplementedError( "PupilFactory not implemented for this camera")
def _pointLineDistance(p0, p1, p2): """Compute the right-angle distance between the points given by `p0` and the line that passes through `p1` and `p2`.
@param[in] p0 2-tuple of numpy arrays (x,y coords) @param[in] p1 2-tuple of scalars (x,y coords) @param[in] p2 2-tuple of scalars (x,y coords) @returns numpy array of distances; shape congruent to p0[0] """ x0, y0 = p0 x1, y1 = p1 x2, y2 = p2 dy21 = y2 - y1 dx21 = x2 - x1 return np.abs(dy21*x0 - dx21*y0 + x2*y1 - y2*x1)/np.hypot(dy21, dx21)
"""Make a fully-illuminated Pupil.
@returns Pupil """ illuminated = np.ones(self.u.shape, dtype=np.bool) return Pupil(illuminated, self.pupilSize, self.pupilScale)
"""Cut out the interior of a circular region from a Pupil.
@param[in,out] pupil Pupil to modify in place @param[in] p0 2-tuple indicating region center @param[in] r Circular region radius """ r2 = (self.u - p0[0])**2 + (self.v - p0[1])**2 pupil.illuminated[r2 < r**2] = False
"""Cut out the exterior of a circular region from a Pupil.
@param[in,out] pupil Pupil to modify in place @param[in] p0 2-tuple indicating region center @param[in] r Circular region radius """ r2 = (self.u - p0[0])**2 + (self.v - p0[1])**2 pupil.illuminated[r2 > r**2] = False
"""Cut out a ray from a Pupil.
@param[in,out] pupil Pupil to modify in place @param[in] p0 2-tuple indicating ray starting point @param[in] angle Ray angle measured CCW from +x. @param[in] thickness Thickness of cutout """ angleRad = angle.asRadians() # the 1 is arbitrary, just need something to define another point on # the line p1 = (p0[0] + 1, p0[1] + np.tan(angleRad)) d = PupilFactory._pointLineDistance((self.u, self.v), p0, p1) pupil.illuminated[(d < 0.5*thickness) & ((self.u - p0[0])*np.cos(angleRad) + (self.v - p0[1])*np.sin(angleRad) >= 0)] = False
"""Center the illuminated portion of the pupil in array.
@param[in,out] pupil Pupil to modify in place """ def center(arr, axis): smash = np.sum(arr, axis=axis) w = np.where(smash)[0] return int(0.5*(np.min(w)+np.max(w))) ycenter = center(pupil.illuminated, 0) xcenter = center(pupil.illuminated, 1) ytarget = pupil.illuminated.shape[0]//2 xtarget = pupil.illuminated.shape[1]//2 pupil.illuminated = np.roll(np.roll(pupil.illuminated, xtarget-xcenter, axis=0), ytarget-ycenter, axis=1) |