Coverage for python/lsst/faro/measurement/DetectorTableMeasurement.py: 33%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of faro.
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/>.
22import lsst.pipe.base as pipeBase
23import lsst.pex.config as pexConfig
25from lsst.faro.base.CatalogMeasurementBase import (
26 CatalogMeasurementBaseConnections,
27 CatalogMeasurementBaseConfig,
28 CatalogMeasurementBaseTask,
29)
31__all__ = ("DetectorTableMeasurementConfig", "DetectorTableMeasurementTask")
34class DetectorTableMeasurementConnections(
35 CatalogMeasurementBaseConnections,
36 dimensions=("instrument", "visit", "detector", "band"),
37 defaultTemplates={"refDataset": ""},
38):
40 catalog = pipeBase.connectionTypes.Input(
41 doc="Source table in parquet format, per visit",
42 dimensions=("instrument", "visit", "band"),
43 storageClass="DataFrame",
44 name="sourceTable_visit",
45 deferLoad=True,
46 )
48 measurement = pipeBase.connectionTypes.Output(
49 doc="Per-detector measurement",
50 dimensions=("instrument", "visit", "detector", "band"),
51 storageClass="MetricValue",
52 name="metricvalue_{package}_{metric}",
53 )
56class DetectorTableMeasurementConfig(
57 CatalogMeasurementBaseConfig,
58 pipelineConnections=DetectorTableMeasurementConnections,
59):
60 """Configuration for DetectorTableMeasurementTask."""
62 columns = pexConfig.ListField(
63 doc="Columns from sourceTable_visit to load.",
64 dtype=str,
65 default=["coord_ra", "coord_dec", "detector"],
66 )
68 def validate(self):
69 super().validate()
70 if "detector" not in self.columns:
71 msg = "The column `detector` must be appear in the list of columns."
72 raise pexConfig.FieldValidationError(
73 DetectorTableMeasurementConfig.columns, self, msg
74 )
77class DetectorTableMeasurementTask(CatalogMeasurementBaseTask):
78 """Base class for science performance metrics measured on single-detector source catalogs."""
80 ConfigClass = DetectorTableMeasurementConfig
81 _DefaultName = "detectorTableMeasurementTask"
83 def runQuantum(self, butlerQC, inputRefs, outputRefs):
84 inputs = butlerQC.get(inputRefs)
85 catalog = inputs["catalog"].get(parameters={"columns": self.config.columns})
86 selection = catalog["detector"] == butlerQC.quantum.dataId["detector"]
87 catalog = catalog[selection]
89 kwargs = {}
90 kwargs['catalog'] = catalog
91 if self.config.connections.refDataset != "":
92 refCats = inputs.pop("refCat")
93 filterList = [butlerQC.quantum.dataId.records["physical_filter"].name]
94 # Time at the start of the visit
95 epoch = butlerQC.quantum.dataId.records["visit"].timespan.begin
96 refCat, refCatCorrected = self._getReferenceCatalog(
97 butlerQC,
98 [ref.datasetRef.dataId for ref in inputRefs.refCat],
99 refCats,
100 filterList,
101 epoch,
102 )
103 kwargs["refCat"] = refCat
104 kwargs["refCatCorrected"] = refCatCorrected
106 outputs = self.run(**kwargs)
107 if outputs.measurement is not None:
108 butlerQC.put(outputs, outputRefs)
109 else:
110 self.log.debug(
111 "Skipping measurement of {!r} on {} " "as not applicable.",
112 self,
113 inputRefs,
114 )