Coverage for python / lsst / analysis / tools / tasks / coaddDepthSummaryPlot.py: 38%
41 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 18:53 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 18: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
23__all__ = (
24 "CoaddDepthSummaryPlotConfig",
25 "CoaddDepthSummaryPlotTask",
26)
28import numpy as np
29from lsst.pipe.base import Struct
30from lsst.pipe.base import connectionTypes as cT
31from lsst.skymap import BaseSkyMap
33from ..interfaces import AnalysisBaseConfig, AnalysisBaseConnections, AnalysisPipelineTask, KeyedData
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 )
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 )
60class CoaddDepthSummaryPlotConfig(AnalysisBaseConfig, pipelineConnections=CoaddDepthSummaryPlotConnections):
61 pass
64class CoaddDepthSummaryPlotTask(AnalysisPipelineTask):
65 ConfigClass = CoaddDepthSummaryPlotConfig
66 _DefaultName = "coaddDepthSummaryPlot"
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)
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 = []
81 depths = []
82 pixels = []
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)
90 depth, pixel = np.unique(n_image.array, return_counts=True)
92 depths.extend(depth)
93 pixels.extend(pixel)
95 for i in range(len(depth)):
96 bands.append(band)
97 patches.append(patch)
99 pixel_data = {"patch": patches, "band": bands, "depth": depths, "pixels": pixels}
101 outputs = super().run(data=pixel_data, **kwargs) # this creates a struct for the output
103 return outputs