Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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 

25 

26import lsst.utils.tests 

27import lsst.afw.image as afwImage 

28from lsst.meas.algorithms import SourceDetectionTask 

29from lsst.meas.extensions.scarlet import ScarletDeblendTask 

30from lsst.afw.table import SourceCatalog 

31 

32 

33from utils import initData 

34 

35 

36class TestDeblend(lsst.utils.tests.TestCase): 

37 def test_deblend_task(self): 

38 # Set the random seed so that the noise field is unaffected 

39 np.random.seed(0) 

40 # Test that executing the deblend task works 

41 # In the future we can have more detailed tests, 

42 # but for now this at least ensures that the task isn't broken 

43 shape = (5, 31, 55) 

44 coords = [(15, 25), (10, 30), (17, 38)] 

45 amplitudes = [80, 60, 90] 

46 result = initData(shape, coords, amplitudes) 

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

48 B, Ny, Nx = shape 

49 

50 # Add some noise, otherwise the task will blow up due to 

51 # zero variance 

52 noise = 10*(np.random.rand(*images.shape).astype(np.float32)-.5) 

53 images += noise 

54 

55 filters = "grizy" 

56 _images = afwImage.MultibandMaskedImage.fromArrays(filters, images.astype(np.float32), None, noise) 

57 coadds = [afwImage.Exposure(img, dtype=img.image.array.dtype) for img in _images] 

58 coadds = afwImage.MultibandExposure.fromExposures(filters, coadds) 

59 for b, coadd in enumerate(coadds): 

60 coadd.setPsf(psfs[b]) 

61 

62 schema = SourceCatalog.Table.makeMinimalSchema() 

63 

64 detectionTask = SourceDetectionTask(schema=schema) 

65 config = ScarletDeblendTask.ConfigClass() 

66 config.maxIter = 300 

67 deblendTask = ScarletDeblendTask(schema=schema, config=config) 

68 

69 table = SourceCatalog.Table.make(schema) 

70 detectionResult = detectionTask.run(table, coadds["r"]) 

71 catalog = detectionResult.sources 

72 self.assertEqual(len(catalog), 1) 

73 _, result = deblendTask.run(coadds, catalog) 

74 

75 

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

77 pass 

78 

79 

80def setup_module(module): 

81 lsst.utils.tests.init() 

82 

83 

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

85 lsst.utils.tests.init() 

86 unittest.main()