Coverage for python / lsst / cp / pipe / cpFringe.py: 51%

37 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-21 10:54 +0000

1# This file is part of cp_pipe. 

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 <http://www.gnu.org/licenses/>. 

21import lsst.pex.config as pexConfig 

22import lsst.pipe.base as pipeBase 

23import lsst.pipe.base.connectionTypes as cT 

24import lsst.cp.pipe.cpCombine as cpCombine 

25import lsst.meas.algorithms as measAlg 

26import lsst.afw.detection as afwDet 

27 

28 

29__all__ = ["CpFringeTask", "CpFringeTaskConfig"] 

30 

31 

32class CpFringeConnections(pipeBase.PipelineTaskConnections, 

33 dimensions=("instrument", "exposure", "detector")): 

34 inputExp = cT.Input( 

35 name="cpFringeISR", 

36 doc="Input pre-processed exposures to combine.", 

37 storageClass="Exposure", 

38 dimensions=("instrument", "exposure", "detector"), 

39 ) 

40 

41 outputExp = cT.Output( 

42 name="cpFringeProc", 

43 doc="Output combined proposed calibration.", 

44 storageClass="Exposure", 

45 dimensions=("instrument", "exposure", "detector"), 

46 ) 

47 

48 

49class CpFringeTaskConfig(pipeBase.PipelineTaskConfig, 

50 pipelineConnections=CpFringeConnections): 

51 stats = pexConfig.ConfigurableField( 

52 target=cpCombine.CalibStatsTask, 

53 doc="Statistics task to use.", 

54 ) 

55 subtractBackground = pexConfig.ConfigurableField( 

56 target=measAlg.SubtractBackgroundTask, 

57 doc="Background configuration", 

58 ) 

59 detection = pexConfig.ConfigurableField( 

60 target=measAlg.SourceDetectionTask, 

61 doc="Detection configuration", 

62 ) 

63 detectSigma = pexConfig.Field( 

64 dtype=float, 

65 default=1.0, 

66 doc="Detection psf gaussian sigma.", 

67 ) 

68 

69 def setDefaults(self): 

70 self.detection.reEstimateBackground = False 

71 

72 

73class CpFringeTask(pipeBase.PipelineTask): 

74 """Combine pre-processed fringe frames into a proposed master calibration. 

75 """ 

76 

77 ConfigClass = CpFringeTaskConfig 

78 _DefaultName = "cpFringe" 

79 

80 def __init__(self, **kwargs): 

81 super().__init__(**kwargs) 

82 self.makeSubtask("stats") 

83 self.makeSubtask("subtractBackground") 

84 self.makeSubtask("detection") 

85 

86 def run(self, inputExp): 

87 """Preprocess input exposures prior to FRINGE combination. 

88 

89 This task scales and renormalizes the input frame based on the 

90 image background, and then masks all pixels above the 

91 detection threshold. 

92 

93 Parameters 

94 ---------- 

95 inputExp : `lsst.afw.image.Exposure` 

96 Pre-processed fringe frame data to combine. 

97 

98 Returns 

99 ------- 

100 results : `lsst.pipe.base.Struct` 

101 The results struct containing: 

102 

103 ``outputExp`` 

104 Fringe pre-processed frame (`lsst.afw.image.Exposure`). 

105 """ 

106 bg = self.stats.run(inputExp) 

107 self.subtractBackground.run(inputExp) 

108 mi = inputExp.getMaskedImage() 

109 mi /= bg 

110 

111 fpSets = self.detection.detectFootprints(inputExp, sigma=self.config.detectSigma) 

112 mask = mi.getMask() 

113 detected = 1 << mask.addMaskPlane("DETECTED") 

114 for fpSet in (fpSets.positive, fpSets.negative): 

115 if fpSet is not None: 

116 afwDet.setMaskFromFootprintList(mask, fpSet.getFootprints(), detected) 

117 

118 return pipeBase.Struct( 

119 outputExp=inputExp, 

120 )