Coverage for tests/test_plotting.py: 43%

57 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-03-28 14:27 +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 

22import os 

23import tempfile 

24import unittest 

25 

26import numpy as np 

27 

28import lsst.afw.image as afwImage 

29import lsst.utils 

30import lsst.utils.tests 

31from lsst.afw.detection import Footprint 

32from lsst.afw.geom import SpanSet 

33from lsst.summit.utils.plotting import plot 

34from lsst.summit.utils.utils import detectObjectsInExp 

35 

36 

37class PlottingTestCase(lsst.utils.tests.TestCase): 

38 try: 

39 afwDataDir = lsst.utils.getPackageDir("afwdata") 

40 except Exception: 

41 afwDataDir = None 

42 filename = "postISRCCD_2020021800224-EMPTY~EMPTY-det000.fits.fz" 

43 

44 @classmethod 

45 def setUpClass(cls): 

46 cls.outputDir = tempfile.mkdtemp() 

47 

48 @unittest.skipUnless(afwDataDir, "afwdata not available") 

49 def test_plot(self): 

50 """Test that the the plot is made and saved""" 

51 fullName = os.path.join(self.afwDataDir, "LATISS/postISRCCD", self.filename) 

52 exp = afwImage.ExposureF(fullName) 

53 centroids = [(567, 746), (576, 599), (678, 989)] 

54 

55 foot1 = Footprint(SpanSet.fromShape(5, offset=(690, 710))) 

56 foot2 = Footprint(SpanSet.fromShape(6, offset=(159, 216))) 

57 fpset = detectObjectsInExp(exp) 

58 

59 # Input is an exposure 

60 outputFilename = os.path.join(self.outputDir, "testPlotting_exp.jpg") 

61 plot(exp, centroids=centroids, footprints=fpset, addLegend=True, savePlotAs=outputFilename) 

62 self.assertTrue(os.path.isfile(outputFilename)) 

63 self.assertTrue(os.path.getsize(outputFilename) > 10000) 

64 

65 # Input is an image 

66 outputFilename = os.path.join(self.outputDir, "testPlotting_image.jpg") 

67 im = exp.image 

68 plot(im, footprints=[foot1, foot2], savePlotAs=outputFilename) 

69 self.assertTrue(os.path.isfile(outputFilename)) 

70 self.assertTrue(os.path.getsize(outputFilename) > 10000) 

71 

72 # Input is a masked image 

73 outputFilename = os.path.join(self.outputDir, "testPloting_mask.jpg") 

74 masked = exp.maskedImage 

75 plot(masked, savePlotAs=outputFilename) 

76 self.assertTrue(os.path.isfile(outputFilename)) 

77 self.assertTrue(os.path.getsize(outputFilename) > 10000) 

78 

79 # Input is a numpy array 

80 outputFilename = os.path.join(self.outputDir, "testPlotting_nparr.jpg") 

81 nparr = exp.image.array 

82 plot(nparr, footprints=foot1, savePlotAs=outputFilename) 

83 self.assertTrue(os.path.isfile(outputFilename)) 

84 self.assertTrue(os.path.getsize(outputFilename) > 10000) 

85 

86 # Nans in the image 

87 nparr[1200:1250, 1300:1345] = np.nan 

88 for stretch in ["ccs", "asinh", "power", "log", "linear", "sqrt"]: 

89 plot(nparr, showCompass=False, stretch=stretch) 

90 

91 # Image consists of nans 

92 nparr[:, :] = np.nan 

93 plot(nparr) 

94 

95 

96def setup_module(module): 

97 lsst.utils.tests.init() 

98 

99 

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

101 lsst.utils.tests.init() 

102 unittest.main()