Coverage for tests/test_fitTanSipWcsHighOrder.py: 25%

63 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-05-03 10:36 +0000

1# 

2# LSST Data Management System 

3# Copyright 2008-2017 LSST Corporation. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

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

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

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

11# (at your option) any later version. 

12# 

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

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

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

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22import unittest 

23 

24import numpy as np 

25 

26import lsst.utils.tests 

27import lsst.geom 

28import lsst.afw.geom as afwGeom 

29from lsst.meas.astrom import approximateWcs 

30 

31 

32class ApproximateWcsTestCase(lsst.utils.tests.TestCase): 

33 

34 """A test case for CreateWcsWithSip 

35 

36 Use involves setting one class attribute: 

37 * MatchClass: match class, e.g. ReferenceMatch or SourceMatch 

38 """ 

39 

40 def setUp(self): 

41 self.crPix = lsst.geom.Point2D(15000, 4000) 

42 dimd = lsst.geom.Extent2D(4000, 4000) 

43 bboxd = lsst.geom.Box2D(self.crPix - dimd/2, dimd) 

44 self.bbox = lsst.geom.Box2I(bboxd) 

45 self.tanWcs = afwGeom.makeSkyWcs(crpix=self.crPix, 

46 crval=lsst.geom.SpherePoint(215.5, 53.0, lsst.geom.degrees), 

47 cdMatrix=np.array([[5.10808596133527E-05, 1.85579539217196E-07], 

48 [-8.27440751733828E-07, -5.10281493481982E-05]])) 

49 

50 def tearDown(self): 

51 del self.tanWcs 

52 

53 def testTrivial(self): 

54 """Add no distortion""" 

55 for order in (3, 4, 5, 6): 

56 self.doTest("testTrivial", afwGeom.makeIdentityTransform(), order=order, doPlot=False) 

57 

58 def testRadial(self): 

59 """Add a radial transform""" 

60 for order in (4, 5, 6): 

61 self.doTest("testRadial", afwGeom.makeRadialTransform([0, 1.001, 0.000003]), order=order, 

62 doPlot=False) 

63 

64 def testWarnings(self): 

65 """Test that approximateWcs raises a UserWarning when it cannot achieve desired tolerance""" 

66 radialTransform = afwGeom.makeRadialTransform([0, 2.0, 3.0]) 

67 wcs = afwGeom.makeModifiedWcs(pixelTransform=radialTransform, wcs=self.tanWcs, 

68 modifyActualPixels=False) 

69 with self.assertRaises(UserWarning): 

70 approximateWcs(wcs=wcs, bbox=self.bbox, order=2) 

71 

72 def doTest(self, name, transform, order=3, doPlot=False): 

73 """Add the specified distorting transform to a TAN WCS and fit it 

74 

75 The resulting WCS pixelToSky method acts as follows: 

76 pixelToSky(transform.applyForward(pixels)) 

77 """ 

78 wcs = afwGeom.makeModifiedWcs(pixelTransform=transform, 

79 wcs=self.tanWcs, 

80 modifyActualPixels=False) 

81 

82 fitWcs = approximateWcs( 

83 wcs=wcs, 

84 bbox=self.bbox, 

85 order=order, 

86 ) 

87 

88 if doPlot: 

89 self.plotWcs(wcs, fitWcs, self.bbox, transform) 

90 

91 msg = "ERROR: %s failed with order %s" % (name, order) 

92 self.assertWcsAlmostEqualOverBBox(wcs, fitWcs, self.bbox, 

93 maxDiffSky=0.001*lsst.geom.arcseconds, maxDiffPix=0.02, msg=msg) 

94 

95 def plotWcs(self, wcs0, wcs1, bbox, transform): 

96 import matplotlib.pyplot as plt 

97 bboxd = lsst.geom.Box2D(bbox) 

98 x0Arr = [] 

99 y0Arr = [] 

100 x1Arr = [] 

101 y1Arr = [] 

102 x2Arr = [] 

103 y2Arr = [] 

104 for x in np.linspace(bboxd.getMinX(), bboxd.getMaxX(), 10): 

105 for y in np.linspace(bboxd.getMinY(), bboxd.getMaxY(), 10): 

106 pixelPos0 = lsst.geom.Point2D(x, y) 

107 skyCoord = wcs0.pixelToSky(pixelPos0) 

108 pixelPos1 = wcs1.skyToPixel(skyCoord) 

109 distortedPos = transform.applyForward(pixelPos0) 

110 x0Arr.append(pixelPos0[0]) 

111 y0Arr.append(pixelPos0[1]) 

112 x1Arr.append(pixelPos1[0]) 

113 y1Arr.append(pixelPos1[1]) 

114 x2Arr.append(distortedPos[0]) 

115 y2Arr.append(distortedPos[1]) 

116 plt.plot(x0Arr, y0Arr, 'b+', x1Arr, y1Arr, 'rx', x2Arr, y2Arr, 'g.') 

117 

118 plt.show() 

119 

120 

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

122 pass 

123 

124 

125def setup_module(module): 

126 lsst.utils.tests.init() 

127 

128 

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

130 lsst.utils.tests.init() 

131 unittest.main()