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

# 

# LSST Data Management System 

# See COPYRIGHT file at the top of the source tree. 

# 

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

# 

 

 

from astropy import units 

import numpy as np 

import unittest 

 

from lsst.afw.geom import Angle 

from lsst.afw.coord import Observatory, Weather 

from lsst.afw.coord.refraction import refraction, differentialRefraction 

from lsst.afw.geom import degrees 

import lsst.utils.tests 

 

 

class RefractionTestSuite(lsst.utils.tests.TestCase): 

"""Test the refraction calculations.""" 

 

def setUp(self): 

"""Define parameters used by every test.""" 

lsstLat = -30.244639*degrees 

lsstLon = -70.749417*degrees 

lsstAlt = 2663. 

lsstTemperature = 20.*units.Celsius # in degrees Celsius 

lsstHumidity = 10. # in percent 

lsstPressure = 73892.*units.pascal # 1 atmosphere. 

np.random.seed(5) 

 

self.weather = Weather(lsstTemperature/units.Celsius, lsstPressure/units.pascal, lsstHumidity) 

self.observatory = Observatory(lsstLon, lsstLat, lsstAlt) 

 

def testWavelengthRangeError(self): 

"""Refraction should raise an error if the wavelength is out of range.""" 

elevation = Angle(np.random.random()*np.pi/2.) 

wl_low = 230. 

wl_high = 2059. 

self.assertRaises(ValueError, refraction, wl_low, elevation, self.observatory, weather=self.weather) 

self.assertRaises(ValueError, refraction, wl_high, elevation, self.observatory, weather=self.weather) 

 

def testZenithZero(self): 

"""There should be no refraction exactly at zenith.""" 

elevation = Angle(np.pi/2.) 

wl = 505. # in nm 

refractZen = refraction(wl, elevation, self.observatory, weather=self.weather) 

self.assertAlmostEqual(refractZen.asDegrees(), 0.) 

 

def testNoDifferential(self): 

"""There should be no differential refraction if the wavelength is the same as the reference.""" 

wl = 470. # in nm 

wl_ref = wl 

elevation = Angle(np.random.random()*np.pi/2.) 

diffRefraction = differentialRefraction(wl, wl_ref, elevation, self.observatory, weather=self.weather) 

self.assertFloatsAlmostEqual(diffRefraction.asDegrees(), 0.) 

 

def testRefractHighAirmass(self): 

"""Compare the refraction calculation to precomputed values.""" 

elevation = Angle(np.pi/6.) # Airmass 2.0 

wls = [370., 480., 620., 860., 960., 1025.] # in nm 

refVals = [73.04868430514726, 

71.74884360909664, 

71.02058121935002, 

70.51172189207065, 

70.40446894800584, 

70.35113687114644, 

] 

for wl, refVal in zip(wls, refVals): 

refract = refraction(wl, elevation, self.observatory, weather=self.weather) 

self.assertFloatsAlmostEqual(refract.asArcseconds(), refVal, rtol=1e-3) 

 

def testRefractWeatherNan(self): 

"""Test the values of refraction when no weather is supplied.""" 

elevation = Angle(np.random.random()*np.pi/2.) 

elevation = Angle(np.pi/6.) # Airmass 2.0 

wls = [370., 480., 620., 860., 960., 1025.] # in nm 

refVals = [76.7339313496466, 

75.36869048516252, 

74.60378630142982, 

74.06932963258161, 

73.95668242959853, 

73.9006681751504, 

] 

for wl, refVal in zip(wls, refVals): 

refract = refraction(wl, elevation, self.observatory) 

self.assertFloatsAlmostEqual(refract.asArcseconds(), refVal, rtol=1e-3) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()