Coverage for python / lsst / analysis / tools / tasks / objectTableSurveyAnalysis.py: 46%

35 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-23 09:00 +0000

1# Developed for the LSST Data Management System. 

2# This product includes software developed by the LSST Project 

3# (https://www.lsst.org). 

4# See the COPYRIGHT file at the top-level directory of this distribution 

5# for details of code ownership. 

6# 

7# This program is free software: you can redistribute it and/or modify 

8# it under the terms of the GNU General Public License as published by 

9# the Free Software Foundation, either version 3 of the License, or 

10# (at your option) any later version. 

11# 

12# This program is distributed in the hope that it will be useful, 

13# but WITHOUT ANY WARRANTY; without even the implied warranty of 

14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

15# GNU General Public License for more details. 

16# 

17# You should have received a copy of the GNU General Public License 

18# along with this program. If not, see <https://www.gnu.org/licenses/>. 

19 

20from __future__ import annotations 

21 

22__all__ = ("ObjectTableSurveyAnalysisTask",) 

23 

24 

25from collections.abc import Iterable, Mapping 

26from typing import TYPE_CHECKING, Any 

27 

28if TYPE_CHECKING: 

29 from lsst.daf.butler import DataCoordinate, DeferredDatasetHandle 

30 

31from astropy.table import vstack 

32 

33from lsst.pipe.base import connectionTypes as ct 

34from lsst.skymap import BaseSkyMap 

35 

36from ..actions.plot.plotUtils import shorten_list 

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

38 

39 

40class ObjectTableSurveyAnalysisConnections( 

41 AnalysisBaseConnections, 

42 dimensions=("skymap",), 

43 defaultTemplates={"input": "deepCoadd"}, 

44): 

45 skymap = ct.Input( 

46 doc="Input definition of geometry/bbox and projection/wcs for warped exposures", 

47 name=BaseSkyMap.SKYMAP_DATASET_TYPE_NAME, 

48 storageClass="SkyMap", 

49 dimensions=("skymap",), 

50 ) 

51 

52 data = ct.Input( 

53 doc="Input catalog of objects", 

54 name="objectTable_tract", 

55 storageClass="ArrowAstropy", 

56 deferLoad=True, 

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

58 multiple=True, 

59 ) 

60 

61 

62class ObjectTableSurveyAnalysisConfig( 

63 AnalysisBaseConfig, pipelineConnections=ObjectTableSurveyAnalysisConnections 

64): 

65 pass 

66 

67 

68class ObjectTableSurveyAnalysisTask(AnalysisPipelineTask): 

69 """A specialized ``AnalysisPipelineTask`` for multiple tracts.""" 

70 

71 ConfigClass = ObjectTableSurveyAnalysisConfig 

72 _DefaultName = "objectTableSurveyAnalysis" 

73 

74 def parsePlotInfo( 

75 self, inputs: Mapping[str, Any] | None, dataId: DataCoordinate | None, connectionName: str = "data" 

76 ) -> Mapping[str, str]: 

77 # Docstring inherited 

78 

79 if inputs is None: 

80 tableName = "" 

81 run = "" 

82 tracts = [] 

83 else: 

84 tableName = inputs[connectionName][0].ref.datasetType.name 

85 run = inputs[connectionName][0].ref.run 

86 tracts = [data.ref.dataId["tract"] for data in list(inputs[connectionName])] 

87 

88 # Initialize the plot info dictionary 

89 plotInfo = { 

90 "tableName": tableName, 

91 "run": run, 

92 "tract": shorten_list(tracts), 

93 } 

94 

95 self._populatePlotInfoWithDataId(plotInfo, dataId) 

96 return plotInfo 

97 

98 def loadData( # type: ignore[override] 

99 self, 

100 handle: Iterable[DeferredDatasetHandle], 

101 names: Iterable[str] | None = None, 

102 ) -> KeyedData: 

103 """Load the minimal set of keyed data from the input dataset. 

104 

105 Parameters 

106 ---------- 

107 handle : `Iterable` of `DeferredDatasetHandle` 

108 Handle to load the dataset with only the specified columns. 

109 names : `Iterable` of `str` 

110 The names of keys to extract from the dataset. 

111 If `names` is `None` then the `collectInputNames` method 

112 is called to generate the names. 

113 For most purposes these are the names of columns to load from 

114 a catalog or data frame. 

115 

116 Returns 

117 ------- 

118 result: `KeyedData` 

119 The dataset with only the specified keys loaded. 

120 """ 

121 # Except associatedSourceTractAnalysis, all other tasks trivially 

122 # subclass this, so names don't get utilized. 

123 if names is None: 

124 names = self.collectInputNames() 

125 

126 cats = [] 

127 for h in handle: 

128 cats.append(h.get(parameters={"columns": names})) 

129 return vstack(cats)