Coverage for tests/test_utils.py: 46%

40 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-23 12:34 +0000

1#!/usr/bin/env python 

2 

3# 

4# LSST Data Management System 

5# 

6# Copyright 2008-2017 AURA/LSST. 

7# 

8# This product includes software developed by the 

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

10# 

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

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

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

14# (at your option) any later version. 

15# 

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

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

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

19# GNU General Public License for more details. 

20# 

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

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

23# see <https://www.lsstcorp.org/LegalNotices/>. 

24# 

25"""Test cases for lsst.cp.pipe.utils""" 

26 

27from __future__ import absolute_import, division, print_function 

28import unittest 

29import numpy as np 

30 

31import lsst.utils 

32import lsst.utils.tests 

33 

34from lsst.geom import Box2I, Point2I, Extent2I 

35from lsst.ip.isr import isrMock 

36 

37import lsst.cp.pipe.utils as cpUtils 

38 

39 

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

41 """A test case for the utility functions for cp_pipe.""" 

42 

43 def setUp(self): 

44 

45 mockImageConfig = isrMock.IsrMock.ConfigClass() 

46 

47 # flatDrop is not really relevant as we replace the data 

48 # but good to note it in case we change how this image is made 

49 mockImageConfig.flatDrop = 0.99999 

50 mockImageConfig.isTrimmed = True 

51 

52 self.flatExp = isrMock.FlatMock(config=mockImageConfig).run() 

53 (shapeY, shapeX) = self.flatExp.getDimensions() 

54 

55 self.rng = np.random.RandomState(0) 

56 self.flatMean = 1000 

57 self.flatWidth = np.sqrt(self.flatMean) 

58 flatData = self.rng.normal(self.flatMean, self.flatWidth, (shapeX, shapeY)) 

59 self.flatExp.image.array[:] = flatData 

60 

61 def test_countMaskedPixels(self): 

62 exp = self.flatExp.clone() 

63 mi = exp.maskedImage 

64 self.assertEqual(cpUtils.countMaskedPixels(mi, 'NO_DATA'), 0) 

65 self.assertEqual(cpUtils.countMaskedPixels(mi, 'BAD'), 0) 

66 

67 NODATABIT = mi.mask.getPlaneBitMask("NO_DATA") 

68 noDataBox = Box2I(Point2I(31, 49), Extent2I(3, 6)) 

69 mi.mask[noDataBox] |= NODATABIT 

70 

71 self.assertEqual(cpUtils.countMaskedPixels(mi, 'NO_DATA'), noDataBox.getArea()) 

72 self.assertEqual(cpUtils.countMaskedPixels(mi, 'BAD'), 0) 

73 

74 mi.mask[noDataBox] ^= NODATABIT # XOR to reset what we did 

75 self.assertEqual(cpUtils.countMaskedPixels(mi, 'NO_DATA'), 0) 

76 

77 

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

79 pass 

80 

81 

82def setup_module(module): 

83 lsst.utils.tests.init() 

84 

85 

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

87 lsst.utils.tests.init() 

88 unittest.main()