Coverage for python/lsst/analysis/tools/tasks/objectTableSurveyAnalysis.py: 43%
36 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-13 11:45 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-13 11:45 +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/>.
20from __future__ import annotations
22__all__ = ("ObjectTableSurveyAnalysisTask",)
25from typing import TYPE_CHECKING, Any, Iterable, Mapping
27if TYPE_CHECKING: 27 ↛ 28line 27 didn't jump to line 28, because the condition on line 27 was never true
28 from lsst.daf.butler import DataCoordinate, DeferredDatasetHandle
30from astropy.table import vstack
31from lsst.pipe.base import connectionTypes as ct
32from lsst.skymap import BaseSkyMap
34from ..actions.plot.plotUtils import shorten_list
35from ..interfaces import AnalysisBaseConfig, AnalysisBaseConnections, AnalysisPipelineTask, KeyedData
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=BaseSkyMap.SKYMAP_DATASET_TYPE_NAME,
46 storageClass="SkyMap",
47 dimensions=("skymap",),
48 )
50 data = ct.Input(
51 doc="Input catalog of objects",
52 name="objectTable_tract",
53 storageClass="ArrowAstropy",
54 deferLoad=True,
55 dimensions=("tract", "skymap"),
56 multiple=True,
57 )
60class ObjectTableSurveyAnalysisConfig(
61 AnalysisBaseConfig, pipelineConnections=ObjectTableSurveyAnalysisConnections
62):
63 pass
66class ObjectTableSurveyAnalysisTask(AnalysisPipelineTask):
67 """A specialized ``AnalysisPipelineTask`` for multiple tracts."""
69 ConfigClass = ObjectTableSurveyAnalysisConfig
70 _DefaultName = "objectTableSurveyAnalysis"
72 def parsePlotInfo(
73 self, inputs: Mapping[str, Any] | None, dataId: DataCoordinate | None, connectionName: str = "data"
74 ) -> Mapping[str, str]:
75 # Docstring inherited
77 if inputs is None:
78 tableName = ""
79 run = ""
80 tracts = []
81 else:
82 tableName = inputs[connectionName][0].ref.datasetType.name
83 run = inputs[connectionName][0].ref.run
84 tracts = [data.ref.dataId["tract"] for data in list(inputs[connectionName])]
86 # Initialize the plot info dictionary
87 plotInfo = {
88 "tableName": tableName,
89 "run": run,
90 "tract": shorten_list(tracts),
91 }
93 self._populatePlotInfoWithDataId(plotInfo, dataId)
94 return plotInfo
96 def loadData( # type: ignore[override]
97 self,
98 handle: Iterable[DeferredDatasetHandle],
99 names: Iterable[str] | None = None,
100 ) -> KeyedData:
101 """Load the minimal set of keyed data from the input dataset.
103 Parameters
104 ----------
105 handle : `Iterable` of `DeferredDatasetHandle`
106 Handle to load the dataset with only the specified columns.
107 names : `Iterable` of `str`
108 The names of keys to extract from the dataset.
109 If `names` is `None` then the `collectInputNames` method
110 is called to generate the names.
111 For most purposes these are the names of columns to load from
112 a catalog or data frame.
114 Returns
115 -------
116 result: `KeyedData`
117 The dataset with only the specified keys loaded.
118 """
119 # Except associatedSourceTractAnalysis, all other tasks trivially
120 # subclass this, so names don't get utilized.
121 if names is None:
122 names = self.collectInputNames()
124 cats = []
125 for h in handle:
126 cats.append(h.get(parameters={"columns": names}))
127 return vstack(cats)