Coverage for python/lsst/analysis/tools/tasks/calexpSummaryAnalysis.py: 47%

30 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-14 19:45 +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 "CalexpSummaryAnalysisConfig", 

25 "CalexpSummaryAnalysisTask", 

26) 

27 

28import dataclasses 

29 

30import lsst.pex.config as pexConfig 

31from lsst.pipe.base import ( 

32 InputQuantizedConnection, 

33 OutputQuantizedConnection, 

34 QuantumContext, 

35 UpstreamFailureNoWorkFound, 

36) 

37from lsst.pipe.base import connectionTypes as cT 

38 

39from ..interfaces import AnalysisBaseConfig, AnalysisBaseConnections, AnalysisPipelineTask 

40 

41 

42class CalexpSummaryAnalysisConnections( 

43 AnalysisBaseConnections, 

44 dimensions=("visit", "band", "detector"), 

45 defaultTemplates={"inputName": "calexp.summaryStats", "outputName": "calexpSummary"}, 

46): 

47 data = cT.Input( 

48 doc="Summary statistics of a visit image, which is a legacy Exposure or an " 

49 "lsst.images.VisitImage depending on input_image_type. Only the parent dataset type is " 

50 "taken from connections.data; input_image_type sets the component that is read from it.", 

51 name="calexp.summaryStats", 

52 storageClass="ExposureSummaryStats", 

53 dimensions=("visit", "band", "detector"), 

54 deferLoad=False, 

55 ) 

56 

57 def __init__(self, *, config=None): 

58 super().__init__(config=config) 

59 

60 parent = self.data.name.split(".")[0] 

61 if config.input_image_type == "future": 

62 name = f"{parent}.summary_stats" 

63 storage_class = "ObservationSummaryStats" 

64 else: 

65 name = f"{parent}.summaryStats" 

66 storage_class = "ExposureSummaryStats" 

67 self.data = dataclasses.replace(self.data, name=name, storageClass=storage_class) 

68 

69 

70class CalexpSummaryAnalysisConfig(AnalysisBaseConfig, pipelineConnections=CalexpSummaryAnalysisConnections): 

71 input_image_type = pexConfig.ChoiceField[str]( 

72 "Which image type to read the summary statistics from.", 

73 allowed={ 

74 "legacy": "Read ``summaryStats`` from an `lsst.afw.image.Exposure`.", 

75 "future": "Read ``summary_stats`` from an `lsst.images.VisitImage`.", 

76 }, 

77 optional=False, 

78 default="legacy", 

79 ) 

80 

81 

82class CalexpSummaryAnalysisTask(AnalysisPipelineTask): 

83 ConfigClass = CalexpSummaryAnalysisConfig 

84 _DefaultName = "calexpSummary" 

85 

86 def runQuantum( 

87 self, 

88 butlerQC: QuantumContext, 

89 inputRefs: InputQuantizedConnection, 

90 outputRefs: OutputQuantizedConnection, 

91 ) -> None: 

92 # Docstring inherited. 

93 

94 inputs = butlerQC.get(inputRefs) 

95 

96 summary = inputs["data"] 

97 if summary is None: 

98 raise UpstreamFailureNoWorkFound("No summary stats attached to the input image.") 

99 outputs = self.run(data=summary.__dict__) 

100 butlerQC.put(outputs, outputRefs)