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

import numpy as np 

import unittest 

import lsst.utils.tests 

from lsst.sims.seeingModel import SeeingModel, SeeingModelConfig 

 

 

class TestSeeingModel(unittest.TestCase): 

def setUp(self): 

# Set config to known values. 

config = SeeingModelConfig() 

config.telescope_seeing = 0.25 

config.optical_design_seeing = 0.08 

config.camera_seeing = 0.30 

config.raw_seeing_wavelength = 500 

# Define a non-default set of effective wavelengths for testing. 

filterlist = ['u', 'g', 'r', 'i', 'z'] 

effwavelens = [ 367.06988658, 482.68517118, 

622.32403587, 754.59752265, 

869.09018708] 

config.filter_list = filterlist 

config.filter_effwavelens = effwavelens 

config.efd_columns = ['raw_seeing'] 

config.efd_delta_time = 0 

config.target_columns = ['airmass'] 

self.config = config 

 

def test_configure(self): 

# Configure with defaults. 

seeingModel = SeeingModel() 

conf = SeeingModelConfig() 

self.assertEqual(seeingModel._config, conf) 

# Test specifying the config. 

seeingModel = SeeingModel(self.config) 

self.assertEqual(seeingModel._config.filter_list, self.config.filter_list) 

# Test specifying an incorrect config. 

self.assertRaises(RuntimeError, SeeingModel, 0.8) 

 

def test_status(self): 

seeingModel = SeeingModel() 

confDict = seeingModel.config_info() 

expected_keys = ['SeeingModel_version', 'SeeingModel_sha', 'efd_columns', 'efd_delta_time', 

'filter_list', 'filter_effwavelens', 'raw_seeing_wavelength', 

'telescope_seeing', 'camera_seeing', 'optical_design_seeing', 

'target_columns'] 

for k in expected_keys: 

self.assertTrue(k in confDict.keys()) 

 

def test_efd_requirements(self): 

seeingModel = SeeingModel(self.config) 

cols = seeingModel.efd_requirements[0] 

deltaT = seeingModel.efd_requirements[1] 

self.assertEqual(self.config.efd_columns, cols) 

self.assertEqual(self.config.efd_delta_time, deltaT) 

 

def test_targetmap_requirements(self): 

seeingModel = SeeingModel(self.config) 

self.assertEqual(seeingModel.target_requirements, self.config.target_columns) 

 

def test_fwhm_system_zenith(self): 

# Check calculation is being done as expected. 

seeingModel = SeeingModel(self.config) 

self.assertEqual(seeingModel.fwhm_system_zenith, 0.39862262855989494) 

 

def test_fwhmGeomEff(self): 

# Check that the translation between FWHM effective and geometric is done as expected. 

# (note that fwhmEff_tofwhmGeom & fwhmGeom_to_fwhmEff are static methods) 

# Document-20160 for reference. 

fwhm_eff = 1.23 

fwhm_geom = 0.822 * fwhm_eff + 0.052 

self.assertEqual(fwhm_geom, SeeingModel.fwhmEff_to_fwhmGeom(fwhm_eff)) 

self.assertEqual(fwhm_eff, SeeingModel.fwhmGeom_to_fwhmEff(fwhm_geom)) 

 

def test_call(self): 

# Check the calculation from fwhm_500 to fwhm_eff/fwhm_geom. 

# Use simple effective wavelengths and airmass values. 

config = SeeingModelConfig() 

config.filter_list = ['500', '1000'] 

config.filter_effwavelens = [500.0, 1000.0] 

wavelens = np.array(config.filter_effwavelens) 

seeingModel = SeeingModel(config) 

# Simple fwhm_500 input. 

fwhm_500 = 1.0 

# Single airmass. 

airmass = 1.0 

efdData = {config.efd_columns[0]: fwhm_500} 

targetDict = {'airmass': airmass} 

seeing = seeingModel(efdData, targetDict) 

fwhm_eff = seeing['fwhmEff'] 

fwhm_geom = seeing['fwhmGeom'] 

# Check shape of returned values. 

self.assertEqual(fwhm_eff.shape, (len(seeingModel.eff_wavelens),)) 

# Check actual value of seeing in @ wavelen[0] @ zenith after addition of system. 

fwhm_system = seeingModel.fwhm_system_zenith 

expected_fwhm_eff = 1.16 * np.sqrt(fwhm_system ** 2 + 1.04 * fwhm_500 ** 2) 

self.assertAlmostEqual(fwhm_eff[0], expected_fwhm_eff, 15) 

# Check expected value if we remove the system component. 

seeingModel.fwhm_system_zenith = 0 

seeing = seeingModel(efdData, targetDict) 

expected_fwhm_eff = 1.16 * np.sqrt(1.04) * fwhm_500 

self.assertAlmostEqual(seeing['fwhmEff'][0], expected_fwhm_eff, 15) 

# Check scaling with wavelength (remove system component). 

expected_fwhm_eff = 1.16 * np.sqrt(1.04) * fwhm_500 * np.power(500./wavelens[1], 0.3) 

self.assertAlmostEqual(seeing['fwhmEff'][1], expected_fwhm_eff, places=15) 

# Multiple airmasses. 

airmass = np.array([1.0, 1.5]) 

targetDict = {'airmass': airmass} 

seeing = seeingModel(efdData, targetDict) 

self.assertEqual(seeing['fwhmEff'].shape, (len(seeingModel.eff_wavelens), len(airmass))) 

expected_fwhm_eff = fwhm_500 * 1.16 * np.sqrt(1.04) 

self.assertEqual(seeing['fwhmEff'][0][0], expected_fwhm_eff) 

# Check scaling with airmass. 

expected_fwhm_eff = expected_fwhm_eff * np.power(airmass[1], 0.6) 

self.assertAlmostEqual(seeing['fwhmEff'][0][1], expected_fwhm_eff, places=15) 

 

 

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

pass 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

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

lsst.utils.tests.init() 

unittest.main()