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

33 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-08-06 04: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 typing import TYPE_CHECKING, Any, Iterable, Mapping, cast 

26 

27import pandas as pd 

28 

29if TYPE_CHECKING: 29 ↛ 30line 29 didn't jump to line 30, because the condition on line 29 was never true

30 from lsst.daf.butler import DataCoordinate, DeferredDatasetHandle 

31 

32from lsst.pipe.base import connectionTypes as ct 

33from lsst.skymap import BaseSkyMap 

34 

35from ..actions.plot.plotUtils import shorten_list 

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

37 

38 

39class ObjectTableSurveyAnalysisConnections( 

40 AnalysisBaseConnections, 

41 dimensions=("skymap",), 

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

43): 

44 skymap = ct.Input( 

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

46 name=BaseSkyMap.SKYMAP_DATASET_TYPE_NAME, 

47 storageClass="SkyMap", 

48 dimensions=("skymap",), 

49 ) 

50 

51 data = ct.Input( 

52 doc="Input catalog of objects", 

53 name="objectTable_tract", 

54 storageClass="DataFrame", 

55 deferLoad=True, 

56 multiple=True, 

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

58 ) 

59 

60 

61class ObjectTableSurveyAnalysisConfig( 

62 AnalysisBaseConfig, pipelineConnections=ObjectTableSurveyAnalysisConnections 

63): 

64 pass 

65 

66 

67class ObjectTableSurveyAnalysisTask(AnalysisPipelineTask): 

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

69 

70 ConfigClass = ObjectTableSurveyAnalysisConfig 

71 _DefaultName = "objectTableSurveyAnalysis" 

72 

73 def parsePlotInfo( 

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

75 ) -> Mapping[str, str]: 

76 # Docstring inherited 

77 

78 if inputs is None: 

79 tableName = "" 

80 run = "" 

81 tracts = [] 

82 else: 

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

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

85 tracts = [data.ref.dataId["tract"] for data in inputs[connectionName]] 

86 

87 # Initialize the plot info dictionary 

88 plotInfo = { 

89 "tableName": tableName, 

90 "run": run, 

91 "tract": shorten_list(tracts), 

92 } 

93 

94 self._populatePlotInfoWithDataId(plotInfo, dataId) 

95 return plotInfo 

96 

97 def loadData( # type: ignore[override] 

98 self, 

99 handle: Iterable[DeferredDatasetHandle], 

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

101 ) -> KeyedData: 

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

103 

104 Parameters 

105 ---------- 

106 handle : `Iterable` of `DeferredDatasetHandle` 

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

108 names : `Iterable` of `str` 

109 The names of keys to extract from the dataset. 

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

111 is called to generate the names. 

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

113 a catalog or data frame. 

114 

115 Returns 

116 ------- 

117 result: `KeyedData` 

118 The dataset with only the specified keys loaded. 

119 """ 

120 # Except associatedSourceTractAnalysis, all other tasks trivially 

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

122 if names is None: 

123 names = self.collectInputNames() 

124 

125 return cast(KeyedData, pd.concat(h.get(parameters={"columns": names}) for h in handle))