Coverage for tests/test_scarlet.py: 30%

41 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2023-02-05 18:26 -0800

1# This file is part of meas_extensions_scarlet. 

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 unittest 

23 

24import numpy as np 

25import scarlet 

26from scarlet.initialization import init_source 

27 

28import lsst.meas.extensions.scarlet as mes 

29import lsst.utils.tests 

30 

31from utils import numpyToStack, initData 

32 

33 

34class TestLsstSource(lsst.utils.tests.TestCase): 

35 def test_to_heavy(self): 

36 shape = (5, 31, 55) 

37 B, Ny, Nx = shape 

38 coords = [(20, 10), (10, 30), (17, 42)] 

39 result = initData(shape, coords, [3, 2, 1]) 

40 targetPsfImage, psfImages, images, channels, seds, morphs, targetPsf, psfs = result 

41 images = images.astype(np.float32) 

42 seds = seds.astype(np.float32) 

43 

44 frame = scarlet.Frame(shape, psf=targetPsf, channels=np.arange(B)) 

45 observation = scarlet.Observation(images, psf=psfImages, channels=np.arange(B)).match(frame) 

46 foot, peak, bbox = numpyToStack(images, coords[0], (15, 3)) 

47 xmin = bbox.getMinX() 

48 ymin = bbox.getMinY() 

49 center = np.array([peak.getIy()-ymin, peak.getIx()-xmin], dtype=int) 

50 src = init_source(frame=frame, center=center, observations=[observation], thresh=0) 

51 

52 # Convolve the model with the observed PSF 

53 model = src.get_model(frame=src.frame) 

54 model = observation.render(model) 

55 

56 # Test Model to Heavy 

57 filters = [f for f in "grizy"] 

58 src.detectedPeak = peak 

59 hFoot = mes.source.modelToHeavy(src, filters, bbox.getMin(), observation) 

60 

61 # Test the peak in each band 

62 for single in hFoot: 

63 peaks = single.getPeaks() 

64 self.assertEqual(len(peaks), 1) 

65 hPeak = peaks[0] 

66 self.assertEqual(hPeak.getIx()-xmin, coords[0][1]) 

67 self.assertEqual(hPeak.getIy()-ymin, coords[0][0]) 

68 

69 

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

71 pass 

72 

73 

74def setup_module(module): 

75 lsst.utils.tests.init() 

76 

77 

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

79 lsst.utils.tests.init() 

80 unittest.main()