Coverage for tests/test_utils.py: 29%

75 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-12 11:07 +0000

1# This file is part of summit_utils. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21 

22"""Test cases for utils.""" 

23 

24import copy 

25import itertools 

26import unittest 

27 

28import astropy.time 

29import astropy.units as u 

30import lsst.afw.image as afwImage 

31import lsst.geom as geom 

32import lsst.utils.tests 

33import numpy as np 

34from astro_metadata_translator import makeObservationInfo 

35from lsst.obs.base import createInitialSkyWcsFromBoresight 

36from lsst.obs.base.makeRawVisitInfoViaObsInfo import MakeRawVisitInfoViaObsInfo 

37from lsst.obs.lsst import Latiss 

38from lsst.summit.utils.utils import getExpPositionOffset 

39from lsst.obs.lsst.translators.latiss import AUXTEL_LOCATION 

40 

41 

42class ExpSkyPositionOffsetTestCase(lsst.utils.tests.TestCase): 

43 """A test case for testing sky position offsets for exposures.""" 

44 

45 def setUp(self): 

46 camera = Latiss.getCamera() 

47 self.assertTrue(len(camera) == 1) 

48 self.detector = camera[0] 

49 

50 self.viMaker = MakeRawVisitInfoViaObsInfo() 

51 self.mi = afwImage.maskedImage.MaskedImageF(0, 0) 

52 self.baseHeader = dict(boresight_airmass=1.5, 

53 temperature=15*u.deg_C, 

54 observation_type="science", 

55 exposure_time=5*u.ks, 

56 detector_num=32, 

57 location=AUXTEL_LOCATION, 

58 ) 

59 

60 def test_getExpPositionOffset(self): 

61 epsilon = 0.0001 

62 ra1s = [0, 45, 90] 

63 ra2s = copy.copy(ra1s) 

64 ra2s.extend([r + epsilon for r in ra1s]) 

65 ra1s = np.deg2rad(ra1s) 

66 ra2s = np.deg2rad(ra2s) 

67 

68 epsilon = 0.0001 

69 dec1s = [0, 45, 90] 

70 dec2s = copy.copy(dec1s) 

71 dec2s.extend([d + epsilon for d in dec1s[:-1]]) # skip last point as >90 not allowed for dec 

72 

73 rotAngle1 = geom.Angle(43.2, geom.degrees) # arbitrary non-zero 

74 rotAngle2 = geom.Angle(56.7, geom.degrees) 

75 

76 t1 = astropy.time.Time("2021-09-15T12:00:00", format="isot", scale="utc") 

77 t2 = astropy.time.Time("2021-09-15T12:01:00", format="isot", scale="utc") 

78 expTime = astropy.time.TimeDelta(20, format='sec') 

79 

80 header1 = copy.copy(self.baseHeader) 

81 header2 = copy.copy(self.baseHeader) 

82 header1['datetime_begin'] = astropy.time.Time(t1, format="isot", scale="utc") 

83 header2['datetime_begin'] = astropy.time.Time(t2, format="isot", scale="utc") 

84 

85 header1['datetime_end'] = astropy.time.Time(t1+expTime, format="isot", scale="utc") 

86 header2['datetime_end'] = astropy.time.Time(t2+expTime, format="isot", scale="utc") 

87 

88 obsInfo1 = makeObservationInfo(**header1) 

89 obsInfo2 = makeObservationInfo(**header2) 

90 

91 vi1 = self.viMaker.observationInfo2visitInfo(obsInfo1) 

92 vi2 = self.viMaker.observationInfo2visitInfo(obsInfo2) 

93 expInfo1 = afwImage.ExposureInfo() 

94 expInfo1.setVisitInfo(vi1) 

95 expInfo2 = afwImage.ExposureInfo() 

96 expInfo2.setVisitInfo(vi2) 

97 

98 for ra1, dec1, ra2, dec2 in itertools.product(ra1s, dec1s, ra2s, dec2s): 

99 pos1 = geom.SpherePoint(ra1, dec1, geom.degrees) 

100 pos2 = geom.SpherePoint(ra2, dec2, geom.degrees) 

101 

102 wcs1 = createInitialSkyWcsFromBoresight(pos1, rotAngle1, self.detector, flipX=True) 

103 wcs2 = createInitialSkyWcsFromBoresight(pos2, rotAngle2, self.detector, flipX=True) 

104 

105 exp1 = afwImage.ExposureF(self.mi, expInfo1) 

106 exp2 = afwImage.ExposureF(self.mi, expInfo2) 

107 

108 exp1.setWcs(wcs1) 

109 exp2.setWcs(wcs2) 

110 

111 result = getExpPositionOffset(exp1, exp2) 

112 

113 deltaRa = ra1 - ra2 

114 deltaDec = dec1 - dec2 

115 

116 self.assertAlmostEqual(result.deltaRa.asDegrees(), deltaRa, 6) 

117 self.assertAlmostEqual(result.deltaDec.asDegrees(), deltaDec, 6) 

118 

119 

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

121 pass 

122 

123 

124def setup_module(module): 

125 lsst.utils.tests.init() 

126 

127 

128if __name__ == "__main__": 128 ↛ 129line 128 didn't jump to line 129, because the condition on line 128 was never true

129 lsst.utils.tests.init() 

130 unittest.main()