Coverage for python / lsst / analysis / tools / tasks / coaddDepthSummaryPlot.py: 38%

41 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-22 09:08 +0000

1# This file is part of analysis_tools. 

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/>. 

21from __future__ import annotations 

22 

23__all__ = ( 

24 "CoaddDepthSummaryPlotConfig", 

25 "CoaddDepthSummaryPlotTask", 

26) 

27 

28import numpy as np 

29from lsst.pipe.base import Struct 

30from lsst.pipe.base import connectionTypes as cT 

31from lsst.skymap import BaseSkyMap 

32 

33from ..interfaces import AnalysisBaseConfig, AnalysisBaseConnections, AnalysisPipelineTask, KeyedData 

34 

35 

36class CoaddDepthSummaryPlotConnections( 

37 AnalysisBaseConnections, 

38 dimensions=("tract", "skymap"), 

39 defaultTemplates={ 

40 "coaddName": "", 

41 }, 

42): 

43 skymap = cT.Input( 

44 doc="The skymap that covers the tract that the data is from.", 

45 name=BaseSkyMap.SKYMAP_DATASET_TYPE_NAME, 

46 storageClass="SkyMap", 

47 dimensions=("skymap",), 

48 ) 

49 

50 n_image_data = cT.Input( 

51 doc="Coadd n_image to load from the butler (pixel values are the number of input images).", 

52 name="{coaddName}_coadd_n_image", 

53 storageClass="ImageU", 

54 multiple=True, 

55 dimensions=("tract", "patch", "band", "skymap"), 

56 deferLoad=True, 

57 ) 

58 

59 

60class CoaddDepthSummaryPlotConfig(AnalysisBaseConfig, pipelineConnections=CoaddDepthSummaryPlotConnections): 

61 pass 

62 

63 

64class CoaddDepthSummaryPlotTask(AnalysisPipelineTask): 

65 ConfigClass = CoaddDepthSummaryPlotConfig 

66 _DefaultName = "coaddDepthSummaryPlot" 

67 

68 def runQuantum(self, butlerQC, inputRefs, outputRefs): 

69 inputs = butlerQC.get(inputRefs) 

70 skymap = inputs["skymap"] 

71 dataId = butlerQC.quantum.dataId 

72 tractInfo = skymap[dataId["tract"]] 

73 outputs = self.run(data={"n_image_data": inputs["n_image_data"]}, tractInfo=tractInfo) 

74 butlerQC.put(outputs, outputRefs) 

75 

76 def run(self, *, data: KeyedData | None = None, **kwargs) -> Struct: 

77 """Use n_images to make a plot illustrating coadd depth.""" 

78 bands = [] 

79 patches = [] 

80 

81 depths = [] 

82 pixels = [] 

83 

84 for n_image_handle in data["n_image_data"]: 

85 n_image = n_image_handle.get() 

86 data_id = n_image_handle.dataId 

87 band = str(data_id.band.name) 

88 patch = int(data_id.patch.id) 

89 

90 depth, pixel = np.unique(n_image.array, return_counts=True) 

91 

92 depths.extend(depth) 

93 pixels.extend(pixel) 

94 

95 for i in range(len(depth)): 

96 bands.append(band) 

97 patches.append(patch) 

98 

99 pixel_data = {"patch": patches, "band": bands, "depth": depths, "pixels": pixels} 

100 

101 outputs = super().run(data=pixel_data, **kwargs) # this creates a struct for the output 

102 

103 return outputs