Coverage for python/lsst/faro/measurement/DetectorTableMeasurement.py: 30%
36 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-06 02:50 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-06 02:50 -0800
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 def validate(self):
63 super().validate()
64 if "detector" not in self.measure.columns:
65 msg = "The column `detector` must be appear in the list of columns."
66 raise pexConfig.FieldValidationError(
67 self.measure.ConfigClass.columns, self, msg
68 )
71class DetectorTableMeasurementTask(CatalogMeasurementBaseTask):
72 """Base class for science performance metrics measured on single-detector source catalogs."""
74 ConfigClass = DetectorTableMeasurementConfig
75 _DefaultName = "detectorTableMeasurementTask"
77 def runQuantum(self, butlerQC, inputRefs, outputRefs):
78 """currentBands is set to None in sourceTable contexts, because currentBands is used to
79 provide the correct parquet column names."""
80 inputs = butlerQC.get(inputRefs)
81 kwargs = {}
82 kwargs["currentBands"] = None
84 columns = list(self.config.measure.columns.values())
85 columnsWithSelectors = self._getTableColumnsSelectors(columns, currentBands=kwargs["currentBands"])
86 catalog = inputs["catalog"].get(parameters={"columns": columnsWithSelectors})
88 selection = catalog["detector"] == butlerQC.quantum.dataId["detector"]
89 catalog = catalog[selection]
90 kwargs["catalog"] = catalog
92 if self.config.connections.refDataset != "":
93 refCats = inputs.pop("refCat")
94 filterList = [butlerQC.quantum.dataId.records["physical_filter"].name]
95 # Time at the start of the visit
96 epoch = butlerQC.quantum.dataId.records["visit"].timespan.begin
97 refCat = self._getReferenceCatalog(
98 butlerQC,
99 [ref.datasetRef.dataId for ref in inputRefs.refCat],
100 refCats,
101 filterList,
102 epoch,
103 )
104 kwargs["refCat"] = refCat
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 )