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

41 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-24 08:53 +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 

29 

30from lsst.pipe.base import Struct 

31from lsst.pipe.base import connectionTypes as cT 

32from lsst.skymap import BaseSkyMap 

33 

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

35 

36 

37class CoaddDepthSummaryPlotConnections( 

38 AnalysisBaseConnections, 

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

40 defaultTemplates={ 

41 "coaddName": "", 

42 }, 

43): 

44 skymap = cT.Input( 

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

46 name=BaseSkyMap.SKYMAP_DATASET_TYPE_NAME, 

47 storageClass="SkyMap", 

48 dimensions=("skymap",), 

49 ) 

50 

51 n_image_data = cT.Input( 

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

53 name="{coaddName}_coadd_n_image", 

54 storageClass="ImageU", 

55 multiple=True, 

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

57 deferLoad=True, 

58 ) 

59 

60 

61class CoaddDepthSummaryPlotConfig(AnalysisBaseConfig, pipelineConnections=CoaddDepthSummaryPlotConnections): 

62 pass 

63 

64 

65class CoaddDepthSummaryPlotTask(AnalysisPipelineTask): 

66 ConfigClass = CoaddDepthSummaryPlotConfig 

67 _DefaultName = "coaddDepthSummaryPlot" 

68 

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

70 inputs = butlerQC.get(inputRefs) 

71 skymap = inputs["skymap"] 

72 dataId = butlerQC.quantum.dataId 

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

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

75 butlerQC.put(outputs, outputRefs) 

76 

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

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

79 bands = [] 

80 patches = [] 

81 

82 depths = [] 

83 pixels = [] 

84 

85 for n_image_handle in data["n_image_data"]: 

86 n_image = n_image_handle.get() 

87 data_id = n_image_handle.dataId 

88 band = str(data_id.band.name) 

89 patch = int(data_id.patch.id) 

90 

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

92 

93 depths.extend(depth) 

94 pixels.extend(pixel) 

95 

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

97 bands.append(band) 

98 patches.append(patch) 

99 

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

101 

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

103 

104 return outputs