Hide keyboard shortcuts

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

# 

# 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/>. 

# 

 

__all__ = ['PupilFactory', 'Pupil'] 

 

import numpy as np 

 

 

class Pupil: 

"""!Pupil obscuration function. 

""" 

 

def __init__(self, illuminated, size, scale): 

"""!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 

 

 

class PupilFactory: 

"""!Pupil obscuration function factory for use with Fourier optics. 

""" 

 

def __init__(self, visitInfo, pupilSize, npix): 

"""!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) 

 

def getPupil(self, point): 

"""!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") 

 

@staticmethod 

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) 

 

def _fullPupil(self): 

"""Make a fully-illuminated Pupil. 

 

@returns Pupil 

""" 

illuminated = np.ones(self.u.shape, dtype=np.bool) 

return Pupil(illuminated, self.pupilSize, self.pupilScale) 

 

def _cutCircleInterior(self, pupil, p0, r): 

"""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 

 

def _cutCircleExterior(self, pupil, p0, r): 

"""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 

 

def _cutRay(self, pupil, p0, angle, thickness): 

"""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 

 

def _centerPupil(self, pupil): 

"""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)