Coverage for tests/test_validPolygon.py: 34%

54 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-09-02 02:18 -0700

1# This file is part of afw. 

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""" 

23Tests for ValidPolygon 

24 

25Run with: 

26 python test_validPolygon.py 

27or 

28 pytest test_validPolygon.py 

29""" 

30import os 

31import unittest 

32 

33import lsst.utils.tests 

34import lsst.geom 

35import lsst.afw.geom as afwGeom 

36import lsst.afw.image as afwImage 

37import lsst.afw.table as afwTable 

38 

39 

40class ValidPolygonTestCase(lsst.utils.tests.TestCase): 

41 

42 def setUp(self): 

43 self.bbox = lsst.geom.Box2I( 

44 lsst.geom.Point2I(0, 0), lsst.geom.Point2I(20, 20)) 

45 x = [0, 0, 10, 10] 

46 y = [0, 10, 10, 0] 

47 self.polygon = afwGeom.Polygon([lsst.geom.Point2D(xc, yc) 

48 for xc, yc in zip(x, y)]) 

49 

50 def testPersistence(self): 

51 """Test that we can round-trip an ValidPolygon through FITS persistence.""" 

52 with lsst.utils.tests.getTempFilePath(".fits") as filename: 

53 self.polygon.writeFits(filename) 

54 polygon2 = afwGeom.Polygon.readFits(filename) 

55 self.assertEqual(self.polygon, polygon2) 

56 

57 def testExposurePersistence(self): 

58 """Test that the ValidPolygon is saved with an Exposure""" 

59 with lsst.utils.tests.getTempFilePath(".fits") as filename: 

60 exposure1 = afwImage.ExposureF(self.bbox) 

61 exposure1.getInfo().setValidPolygon(self.polygon) 

62 exposure1.writeFits(filename) 

63 exposure2 = afwImage.ExposureF(filename) 

64 polygon2 = exposure2.getInfo().getValidPolygon() 

65 self.assertEqual(self.polygon, polygon2) 

66 

67 def testExposureRecordPersistence(self): 

68 """Test that the ValidPolygon is saved with an ExposureRecord""" 

69 with lsst.utils.tests.getTempFilePath(".fits") as filename: 

70 cat1 = afwTable.ExposureCatalog( 

71 afwTable.ExposureTable.makeMinimalSchema()) 

72 record1 = cat1.addNew() 

73 record1.setValidPolygon(self.polygon) 

74 cat1.writeFits(filename) 

75 cat2 = afwTable.ExposureCatalog.readFits(filename) 

76 record2 = cat2[0] 

77 polygon2 = record2.getValidPolygon() 

78 self.assertEqual(self.polygon, polygon2) 

79 

80 def testExposureCatalogBackwardsCompatibility(self): 

81 """Test that we can read an ExposureCatalog written with an old version of the code.""" 

82 testPath = os.path.abspath(os.path.dirname(__file__)) 

83 filename = os.path.join(testPath, "data", "version-0-ExposureCatalog.fits") 

84 cat = afwTable.ExposureCatalog.readFits(filename) 

85 record = cat[0] 

86 self.assertIsNone(record.getValidPolygon()) 

87 

88 filename2 = os.path.join(testPath, "data", "version-1-ExposureCatalog.fits") 

89 cat2 = afwTable.ExposureCatalog.readFits(filename2) 

90 record2 = cat2[0] 

91 self.assertIsNone(record2.getValidPolygon()) 

92 

93 

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

95 pass 

96 

97 

98def setup_module(module): 

99 lsst.utils.tests.init() 

100 

101 

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

103 lsst.utils.tests.init() 

104 unittest.main()