Coverage for tests/test_plotting.py: 43%
57 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-22 12:15 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-22 12:15 +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/>.
22import unittest
23import tempfile
24import os
25import numpy as np
27import lsst.utils.tests
28import lsst.utils
29from lsst.summit.utils.plotting import plot
30from lsst.summit.utils.utils import detectObjectsInExp
31import lsst.afw.image as afwImage
32from lsst.afw.geom import SpanSet
33from lsst.afw.detection import Footprint
36class PlottingTestCase(lsst.utils.tests.TestCase):
37 try:
38 afwDataDir = lsst.utils.getPackageDir('afwdata')
39 except Exception:
40 afwDataDir = None
41 filename = 'postISRCCD_2020021800224-EMPTY~EMPTY-det000.fits.fz'
43 @classmethod
44 def setUpClass(cls):
45 cls.outputDir = tempfile.mkdtemp()
47 @unittest.skipUnless(afwDataDir, "afwdata not available")
48 def test_plot(self):
49 """Test that the the plot is made and saved
50 """
51 fullName = os.path.join(self.afwDataDir, "LATISS/postISRCCD", self.filename)
52 exp = afwImage.ExposureF(fullName)
53 centroids = [(567, 746), (576, 599), (678, 989)]
55 foot1 = Footprint(SpanSet.fromShape(5, offset=(690, 710)))
56 foot2 = Footprint(SpanSet.fromShape(6, offset=(159, 216)))
57 fpset = detectObjectsInExp(exp)
59 # Input is an exposure
60 outputFilename = os.path.join(self.outputDir, 'testPlotting_exp.jpg')
61 plot(exp,
62 centroids=centroids,
63 footprints=fpset,
64 addLegend=True,
65 savePlotAs=outputFilename)
66 self.assertTrue(os.path.isfile(outputFilename))
67 self.assertTrue(os.path.getsize(outputFilename) > 10000)
69 # Input is an image
70 outputFilename = os.path.join(self.outputDir, 'testPlotting_image.jpg')
71 im = exp.image
72 plot(im,
73 footprints=[foot1, foot2],
74 savePlotAs=outputFilename)
75 self.assertTrue(os.path.isfile(outputFilename))
76 self.assertTrue(os.path.getsize(outputFilename) > 10000)
78 # Input is a masked image
79 outputFilename = os.path.join(self.outputDir, 'testPloting_mask.jpg')
80 masked = exp.maskedImage
81 plot(masked,
82 savePlotAs=outputFilename)
83 self.assertTrue(os.path.isfile(outputFilename))
84 self.assertTrue(os.path.getsize(outputFilename) > 10000)
86 # Input is a numpy array
87 outputFilename = os.path.join(self.outputDir, 'testPlotting_nparr.jpg')
88 nparr = exp.image.array
89 plot(nparr,
90 footprints=foot1,
91 savePlotAs=outputFilename)
92 self.assertTrue(os.path.isfile(outputFilename))
93 self.assertTrue(os.path.getsize(outputFilename) > 10000)
95 # Nans in the image
96 nparr[1200:1250, 1300:1345] = np.nan
97 for stretch in ['ccs', 'asinh', 'power', 'log', 'linear', 'sqrt']:
98 plot(nparr,
99 showCompass=False,
100 stretch=stretch)
102 # Image consists of nans
103 nparr[:, :] = np.nan
104 plot(nparr)
107def setup_module(module):
108 lsst.utils.tests.init()
111if __name__ == "__main__": 111 ↛ 112line 111 didn't jump to line 112, because the condition on line 111 was never true
112 lsst.utils.tests.init()
113 unittest.main()