Coverage for python / lsst / analysis / tools / tasks / diffimTaskDetectorVisitMetricsAnalysis.py: 52%

31 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-04 17:41 +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__ = ("DiffimDetectorVisitMetricsAnalysisConfig", "DiffimDetectorVisitMetricsAnalysisTask") 

24 

25import pandas as pd 

26from deprecated.sphinx import deprecated 

27 

28import lsst.pex.config 

29from lsst.pipe.base import NoWorkFound, connectionTypes 

30 

31from ..interfaces import AnalysisBaseConfig, AnalysisBaseConnections, AnalysisPipelineTask 

32 

33 

34class DiffimDetectorVisitMetricsAnalysisConnections( 

35 AnalysisBaseConnections, 

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

37): 

38 metadataSubtract = connectionTypes.Input( 

39 doc="Task metadata from image differencing", 

40 name="subtractImages_metadata", 

41 storageClass="TaskMetadata", 

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

43 ) 

44 metadataDetect = connectionTypes.Input( 

45 doc="Task metadata from DIA detection and measurement", 

46 name="detectAndMeasure_metadata", 

47 storageClass="TaskMetadata", 

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

49 ) 

50 

51 

52class DiffimDetectorVisitMetricsAnalysisConfig( 

53 AnalysisBaseConfig, pipelineConnections=DiffimDetectorVisitMetricsAnalysisConnections 

54): 

55 kernelSubtaskName = lsst.pex.config.Field( 

56 dtype=str, 

57 default="makeKernel", 

58 doc="Perform diffim decorrelation to undo pixel correlation due to A&L ", 

59 ) 

60 

61 

62@deprecated( 

63 reason=("TaskMetadataAnalysisTask should be used instead."), 

64 version="v29.0", 

65 category=FutureWarning, 

66) 

67class DiffimDetectorVisitMetricsAnalysisTask(AnalysisPipelineTask): 

68 ConfigClass = DiffimDetectorVisitMetricsAnalysisConfig 

69 _DefaultName = "DiffimDetectorVisitMetricsAnalysis" 

70 

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

72 inputs = butlerQC.get(inputRefs) 

73 detectTaskName = inputRefs.metadataDetect.datasetType.name 

74 detectTaskName = detectTaskName[: detectTaskName.find("_")] 

75 metadata = inputs["metadataDetect"].metadata[detectTaskName].to_dict() 

76 if not metadata: 

77 raise NoWorkFound("No metadata entries for detectAndMeasure.") 

78 inputs.pop("metadataDetect") 

79 

80 subtractTaskName = inputRefs.metadataSubtract.datasetType.name 

81 subtractTaskName = subtractTaskName[: subtractTaskName.find("_")] 

82 metadata |= inputs["metadataSubtract"].metadata[subtractTaskName].to_dict() 

83 inputs.pop("metadataSubtract") 

84 self.taskName = subtractTaskName 

85 # Some metadata entries might have different lengths or simply floats. 

86 # Pass the dict in a list to tell Pandas that this is one row in the 

87 # dataframe. 

88 outputs = self.run(data=pd.DataFrame([metadata])) 

89 butlerQC.put(outputs, outputRefs)