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

31 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__ = ("DiffimDetectorVisitMetricsAnalysisConfig", "DiffimDetectorVisitMetricsAnalysisTask") 

24 

25import lsst.pex.config 

26import pandas as pd 

27from deprecated.sphinx import deprecated 

28from lsst.pipe.base import NoWorkFound, connectionTypes 

29 

30from ..interfaces import AnalysisBaseConfig, AnalysisBaseConnections, AnalysisPipelineTask 

31 

32 

33class DiffimDetectorVisitMetricsAnalysisConnections( 

34 AnalysisBaseConnections, 

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

36): 

37 metadataSubtract = connectionTypes.Input( 

38 doc="Task metadata from image differencing", 

39 name="subtractImages_metadata", 

40 storageClass="TaskMetadata", 

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

42 ) 

43 metadataDetect = connectionTypes.Input( 

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

45 name="detectAndMeasure_metadata", 

46 storageClass="TaskMetadata", 

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

48 ) 

49 

50 

51class DiffimDetectorVisitMetricsAnalysisConfig( 

52 AnalysisBaseConfig, pipelineConnections=DiffimDetectorVisitMetricsAnalysisConnections 

53): 

54 kernelSubtaskName = lsst.pex.config.Field( 

55 dtype=str, 

56 default="makeKernel", 

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

58 ) 

59 

60 

61@deprecated( 

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

63 version="v29.0", 

64 category=FutureWarning, 

65) 

66class DiffimDetectorVisitMetricsAnalysisTask(AnalysisPipelineTask): 

67 ConfigClass = DiffimDetectorVisitMetricsAnalysisConfig 

68 _DefaultName = "DiffimDetectorVisitMetricsAnalysis" 

69 

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

71 inputs = butlerQC.get(inputRefs) 

72 detectTaskName = inputRefs.metadataDetect.datasetType.name 

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

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

75 if not metadata: 

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

77 inputs.pop("metadataDetect") 

78 

79 subtractTaskName = inputRefs.metadataSubtract.datasetType.name 

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

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

82 inputs.pop("metadataSubtract") 

83 self.taskName = subtractTaskName 

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

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

86 # dataframe. 

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

88 butlerQC.put(outputs, outputRefs)