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

from builtins import zip 

import unittest 

import os 

import numpy as np 

from lsst.utils import getPackageDir 

import lsst.utils.tests 

 

from lsst.sims.utils.CodeUtilities import sims_clean_up 

from lsst.sims.utils import ObservationMetaData 

from lsst.sims.photUtils import PhotometricParameters 

from lsst.sims.coordUtils.utils import ReturnCamera 

from lsst.sims.coordUtils import _raDecFromPixelCoords, pupilCoordsFromPixelCoords 

from lsst.sims.GalSimInterface import GalSimDetector, GalSimCameraWrapper 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class GalSimDetectorTest(unittest.TestCase): 

 

@classmethod 

def tearDownClass(cls): 

sims_clean_up() 

 

def setUp(self): 

baseDir = os.path.join(getPackageDir('sims_GalSimInterface'), 

'tests', 'cameraData') 

 

self.camera = ReturnCamera(baseDir) 

 

ra = 145.0 

dec = -73.0 

self.epoch = 2000.0 

mjd = 49250.0 

rotSkyPos = 45.0 

self.obs = ObservationMetaData(pointingRA=ra, 

pointingDec=dec, 

boundType='circle', 

boundLength=1.0, 

mjd=mjd, 

rotSkyPos=rotSkyPos) 

 

def tearDown(self): 

del self.camera 

 

def testContainsRaDec(self): 

""" 

Test whether or not the method containsRaDec correctly identifies 

RA and Dec that fall inside and outside the detector 

""" 

 

photParams = PhotometricParameters() 

gsdet = GalSimDetector(self.camera[0].getName(), 

GalSimCameraWrapper(self.camera), 

self.obs, self.epoch, 

photParams=photParams) 

 

xxList = [gsdet.xMinPix, gsdet.xMaxPix] 

yyList = [gsdet.yMinPix, gsdet.yMaxPix] 

dxList = [-1.0, 1.0] 

dyList = [-1.0, 1.0] 

 

xPixList = [] 

yPixList = [] 

correctAnswer = [] 

 

for xx, yy, dx, dy in zip(xxList, yyList, dxList, dyList): 

xPixList.append(xx) 

yPixList.append(yy) 

correctAnswer.append(True) 

 

xPixList.append(xx+dx) 

yPixList.append(yy) 

correctAnswer.append(False) 

 

xPixList.append(xx) 

yPixList.append(yy+dy) 

correctAnswer.append(False) 

 

nameList = [gsdet.name]*len(xPixList) 

xPixList = np.array(xPixList) 

yPixList = np.array(yPixList) 

 

raList, decList = _raDecFromPixelCoords(xPixList, yPixList, 

nameList, 

camera=self.camera, 

obs_metadata=self.obs, 

epoch=self.epoch) 

 

testAnswer = gsdet.containsRaDec(raList, decList) 

 

for c, t in zip(correctAnswer, testAnswer): 

self.assertIs(c, t) 

 

def testContainsPupilCoordinates(self): 

""" 

Test whether or not the method containsRaDec correctly identifies 

RA and Dec that fall inside and outside the detector 

""" 

 

photParams = PhotometricParameters() 

gsdet = GalSimDetector(self.camera[0].getName(), 

GalSimCameraWrapper(self.camera), 

self.obs, self.epoch, 

photParams=photParams) 

 

xxList = [gsdet.xMinPix, gsdet.xMaxPix] 

yyList = [gsdet.yMinPix, gsdet.yMaxPix] 

dxList = [-1.0, 1.0] 

dyList = [-1.0, 1.0] 

 

xPixList = [] 

yPixList = [] 

correctAnswer = [] 

 

for xx, yy, dx, dy in zip(xxList, yyList, dxList, dyList): 

xPixList.append(xx) 

yPixList.append(yy) 

correctAnswer.append(True) 

 

xPixList.append(xx+dx) 

yPixList.append(yy) 

correctAnswer.append(False) 

 

xPixList.append(xx) 

yPixList.append(yy+dy) 

correctAnswer.append(False) 

 

nameList = [gsdet.name]*len(xPixList) 

xPixList = np.array(xPixList) 

yPixList = np.array(yPixList) 

 

xPupilList, yPupilList = \ 

pupilCoordsFromPixelCoords(xPixList, yPixList, 

nameList, camera=self.camera) 

 

testAnswer = gsdet.containsPupilCoordinates(xPupilList, yPupilList) 

 

for c, t in zip(correctAnswer, testAnswer): 

self.assertIs(c, t) 

 

 

class MemoryTestClass(lsst.utils.tests.MemoryTestCase): 

pass 

 

147 ↛ 148line 147 didn't jump to line 148, because the condition on line 147 was never trueif __name__ == "__main__": 

lsst.utils.tests.init() 

unittest.main()