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

32 statements  

« prev     ^ index     » next       coverage.py v7.2.4, created at 2023-04-30 03:04 -0700

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 

33 

34from ..actions.plot.plotUtils import shorten_list 

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

36 

37 

38class ObjectTableSurveyAnalysisConnections( 

39 AnalysisBaseConnections, 

40 dimensions=("skymap",), 

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

42): 

43 skymap = ct.Input( 

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

45 name="skyMap", 

46 storageClass="SkyMap", 

47 dimensions=("skymap",), 

48 ) 

49 

50 data = ct.Input( 

51 doc="Input catalog of objects", 

52 name="objectTable_tract", 

53 storageClass="DataFrame", 

54 deferLoad=True, 

55 multiple=True, 

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

57 ) 

58 

59 

60class ObjectTableSurveyAnalysisConfig( 

61 AnalysisBaseConfig, pipelineConnections=ObjectTableSurveyAnalysisConnections 

62): 

63 pass 

64 

65 

66class ObjectTableSurveyAnalysisTask(AnalysisPipelineTask): 

67 ConfigClass = ObjectTableSurveyAnalysisConfig 

68 _DefaultName = "objectTableSurveyAnalysis" 

69 

70 def parsePlotInfo( 

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

72 ) -> Mapping[str, str]: 

73 # Docstring inherited 

74 

75 if inputs is None: 

76 tableName = "" 

77 run = "" 

78 tracts = [] 

79 else: 

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

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

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

83 

84 # Initialize the plot info dictionary 

85 plotInfo = { 

86 "tableName": tableName, 

87 "run": run, 

88 "tract": shorten_list(tracts), 

89 } 

90 

91 self._populatePlotInfoWithDataId(plotInfo, dataId) 

92 return plotInfo 

93 

94 def loadData( # type: ignore[override] 

95 self, 

96 handle: Iterable[DeferredDatasetHandle], 

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

98 ) -> KeyedData: 

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

100 

101 Parameters 

102 ---------- 

103 handle : `Iterable` of `DeferredDatasetHandle` 

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

105 names : `Iterable` of `str` 

106 The names of keys to extract from the dataset. 

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

108 is called to generate the names. 

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

110 a catalog or data frame. 

111 

112 Returns 

113 ------- 

114 result: `KeyedData` 

115 The dataset with only the specified keys loaded. 

116 """ 

117 # Except associatedSourceTractAnalysis, all other tasks trivially 

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

119 if names is None: 

120 names = self.collectInputNames() 

121 

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