Coverage for python/lsst/faro/measurement/ForcedSourceTableMeasurement.py: 50%
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/>.
23import lsst.pipe.base as pipeBase
24import lsst.pex.config as pexConfig
26from lsst.faro.base.CatalogMeasurementBase import (
27 CatalogMeasurementBaseConnections,
28 CatalogMeasurementBaseConfig,
29 CatalogMeasurementBaseTask,
30)
32__all__ = (
33 "ForcedSourceTableMeasurementConnections",
34 "ForcedSourceTableMeasurementConfig",
35 "ForcedSourceTableMeasurementTask",
36 "ForcedSourceMultiBandTableMeasurementConnections",
37 "ForcedSourceMultiBandTableMeasurementConfig",
38 "ForcedSourceMultiBandTableMeasurementTask",
39)
42class ForcedSourceTableMeasurementConnections(
43 CatalogMeasurementBaseConnections,
44 dimensions=("tract", "skymap", "band"),
45):
47 catalog = pipeBase.connectionTypes.Input(
48 doc="Forced source table in parquet format, per tract",
49 dimensions=("tract", "skymap"),
50 storageClass="DataFrame",
51 name="forcedSourceTable_tract",
52 deferLoad=True,
53 )
55 measurement = pipeBase.connectionTypes.Output(
56 doc="Per-tract measurement.",
57 dimensions=("tract", "skymap", "band"),
58 storageClass="MetricValue",
59 name="metricvalue_{package}_{metric}",
60 )
63class ForcedSourceTableMeasurementConfig(
64 CatalogMeasurementBaseConfig, pipelineConnections=ForcedSourceTableMeasurementConnections
65):
66 """Configuration for ForcedSourceTableMeasurementTask."""
68 columns = pexConfig.ListField(
69 doc="Band-independent columns from forcedSourceTable_tract to load.",
70 dtype=str,
71 default=["coord_ra", "coord_dec", "band", "detect_isPrimary", "psfFlux", "psfFluxErr"],
72 )
75class ForcedSourceTableMeasurementTask(CatalogMeasurementBaseTask):
76 """Base class for per-band science performance metrics measured on multi-visit forced source catalogs."""
78 ConfigClass = ForcedSourceTableMeasurementConfig
79 _DefaultName = "forcedSourceTableMeasurementTask"
81 def runQuantum(self, butlerQC, inputRefs, outputRefs):
82 inputs = butlerQC.get(inputRefs)
83 kwargs = {"band": butlerQC.quantum.dataId['band']}
85 columns = self.config.columns.list()
86 tmp_catalog = inputs["catalog"].get(parameters={"columns": columns})
87 # Extract only the entries from the band of interest:
88 kwargs["catalog"] = tmp_catalog[tmp_catalog.band == kwargs["band"]]
90 outputs = self.run(**kwargs)
91 if outputs.measurement is not None:
92 butlerQC.put(outputs, outputRefs)
93 else:
94 self.log.debugf(
95 "Skipping measurement of {!r} on {} " "as not applicable.",
96 self,
97 inputRefs,
98 )
101class ForcedSourceMultiBandTableMeasurementConnections(
102 CatalogMeasurementBaseConnections,
103 dimensions=("tract", "skymap"),
104):
106 catalog = pipeBase.connectionTypes.Input(
107 doc="Forced source table in parquet format, per tract",
108 dimensions=("tract", "skymap"),
109 storageClass="DataFrame",
110 name="forcedSourceTable_tract",
111 deferLoad=True,
112 )
114 measurement = pipeBase.connectionTypes.Output(
115 doc="Per-tract measurement.",
116 dimensions=("tract", "skymap"),
117 storageClass="MetricValue",
118 name="metricvalue_{package}_{metric}",
119 )
122class ForcedSourceMultiBandTableMeasurementConfig(
123 ForcedSourceTableMeasurementConfig,
124 pipelineConnections=ForcedSourceMultiBandTableMeasurementConnections
125):
126 """Configuration for ForcedSourceMultiBandTableMeasurementTask."""
128 bands = pexConfig.ListField(
129 doc="Bands for band-specific column loading from ForcedSourceTable_tract.",
130 dtype=str,
131 default=["g", "r", "i", "z", "y"],
132 )
135class ForcedSourceMultiBandTableMeasurementTask(CatalogMeasurementBaseTask):
136 """Base class for multi-band science performance metrics measured on
137 multi-visit forced source catalogs."""
139 ConfigClass = ForcedSourceMultiBandTableMeasurementConfig
140 _DefaultName = "forcedSourceMultiBandTableMeasurementTask"
142 def runQuantum(self, butlerQC, inputRefs, outputRefs):
143 inputs = butlerQC.get(inputRefs)
144 kwargs = {"bands": self.config.bands.list()}
146 columns = self.config.columns.list()
147 tmp_catalog = inputs["catalog"].get(parameters={"columns": columns})
148 # Extract only the entries from the band of interest:
149 kwargs["catalog"] = tmp_catalog[tmp_catalog.band.isin(kwargs["bands"])]
151 outputs = self.run(**kwargs)
152 if outputs.measurement is not None:
153 butlerQC.put(outputs, outputRefs)
154 else:
155 self.log.debugf(
156 "Skipping measurement of {!r} on {} " "as not applicable.",
157 self,
158 inputRefs,
159 )