Coverage for python/lsst/faro/measurement/DetectorMeasurement.py : 32%

Hot-keys 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
1import lsst.pipe.base as pipeBase
2from lsst.verify.tasks import MetricConnections
3import lsst.pex.config as pexConfig
5from lsst.faro.base.CatalogMeasurementBase import CatalogMeasurementBaseTaskConfig, CatalogMeasurementBaseTask
7__all__ = ("DetectorMeasurementTaskConfig", "DetectorMeasurementTask")
10class DetectorMeasurementTaskConnections(MetricConnections,
11 dimensions=("instrument", "visit", "detector", "band"),
12 defaultTemplates={"photoCalibName": "calexp.photoCalib",
13 "externalPhotoCalibName": "fgcm",
14 "wcsName": "calexp.wcs",
15 "externalWcsName": "jointcal"}):
17 catalog = pipeBase.connectionTypes.Input(
18 doc="Source catalog.",
19 dimensions=("instrument", "visit", "detector", "band"),
20 storageClass="SourceCatalog",
21 name="src"
22 )
23 skyWcs = pipeBase.connectionTypes.Input(
24 doc="WCS for the catalog.",
25 dimensions=("instrument", "visit", "detector", "band"),
26 storageClass="Wcs",
27 name="{wcsName}"
28 )
29 photoCalib = pipeBase.connectionTypes.Input(
30 doc="Photometric calibration object.",
31 dimensions=("instrument", "visit", "detector", "band"),
32 storageClass="PhotoCalib",
33 name="{photoCalibName}"
34 )
35 externalSkyWcsTractCatalog = pipeBase.connectionTypes.Input(
36 doc=("Per-tract, per-visit wcs calibrations. These catalogs use the detector "
37 "id for the catalog id, sorted on id for fast lookup."),
38 name="{externalWcsName}SkyWcsCatalog",
39 storageClass="ExposureCatalog",
40 dimensions=("instrument", "visit", "tract"),
41 )
42 externalSkyWcsGlobalCatalog = pipeBase.connectionTypes.Input(
43 doc=("Per-visit wcs calibrations computed globally (with no tract information). "
44 "These catalogs use the detector id for the catalog id, sorted on id for "
45 "fast lookup."),
46 name="{externalWcsName}SkyWcsCatalog",
47 storageClass="ExposureCatalog",
48 dimensions=("instrument", "visit"),
49 )
50 externalPhotoCalibTractCatalog = pipeBase.connectionTypes.Input(
51 doc=("Per-tract, per-visit photometric calibrations. These catalogs use the "
52 "detector id for the catalog id, sorted on id for fast lookup."),
53 name="{externalPhotoCalibName}PhotoCalibCatalog",
54 storageClass="ExposureCatalog",
55 dimensions=("instrument", "visit", "tract"),
56 )
57 externalPhotoCalibGlobalCatalog = pipeBase.connectionTypes.Input(
58 doc=("Per-visit photometric calibrations computed globally (with no tract "
59 "information). These catalogs use the detector id for the catalog id, "
60 "sorted on id for fast lookup."),
61 name="{externalPhotoCalibName}PhotoCalibCatalog",
62 storageClass="ExposureCatalog",
63 dimensions=("instrument", "visit"),
64 )
65 measurement = pipeBase.connectionTypes.Output(
66 doc="Per-detector measurement.",
67 dimensions=("instrument", "visit", "detector", "band"),
68 storageClass="MetricValue",
69 name="metricvalue_{package}_{metric}"
70 )
72 def __init__(self, *, config=None):
73 super().__init__(config=config)
74 if config.doApplyExternalSkyWcs:
75 if config.useGlobalExternalSkyWcs:
76 self.inputs.remove("externalSkyWcsTractCatalog")
77 else:
78 self.inputs.remove("externalSkyWcsGlobalCatalog")
79 else:
80 self.inputs.remove("externalSkyWcsTractCatalog")
81 self.inputs.remove("externalSkyWcsGlobalCatalog")
82 if config.doApplyExternalPhotoCalib:
83 if config.useGlobalExternalPhotoCalib:
84 self.inputs.remove("externalPhotoCalibTractCatalog")
85 else:
86 self.inputs.remove("externalPhotoCalibGlobalCatalog")
87 else:
88 self.inputs.remove("externalPhotoCalibTractCatalog")
89 self.inputs.remove("externalPhotoCalibGlobalCatalog")
92class DetectorMeasurementTaskConfig(CatalogMeasurementBaseTaskConfig,
93 pipelineConnections=DetectorMeasurementTaskConnections):
94 doApplyExternalSkyWcs = pexConfig.Field(doc="Whether or not to use the external wcs.",
95 dtype=bool, default=False)
96 useGlobalExternalSkyWcs = pexConfig.Field(doc="Whether or not to use the global external wcs.",
97 dtype=bool, default=False)
98 doApplyExternalPhotoCalib = pexConfig.Field(doc="Whether or not to use the external photoCalib.",
99 dtype=bool, default=False)
100 useGlobalExternalPhotoCalib = pexConfig.Field(doc="Whether or not to use the global external photoCalib.",
101 dtype=bool, default=False)
104class DetectorMeasurementTask(CatalogMeasurementBaseTask):
105 ConfigClass = DetectorMeasurementTaskConfig
106 _DefaultName = "detectorMeasurementTask"
108 def run(self, catalog, photoCalib, skyWcs):
109 return self.measure.run(catalog, self.config.connections.metric)
111 def runQuantum(self, butlerQC, inputRefs, outputRefs):
112 inputs = butlerQC.get(inputRefs)
113 if self.config.doApplyExternalPhotoCalib:
114 detector = inputRefs.catalog.dataId['detector']
115 if self.config.useGlobalExternalPhotoCalib:
116 externalPhotoCalibCatalog = inputs.pop('externalPhotoCalibGlobalCatalog')
117 else:
118 externalPhotoCalibCatalog = inputs.pop('externalPhotoCalibTractCatalog')
119 row = externalPhotoCalibCatalog.find(detector)
120 externalPhotoCalib = row.getPhotoCalib()
121 inputs['photoCalib'] = externalPhotoCalib
122 if self.config.doApplyExternalSkyWcs:
123 detector = inputRefs.catalog.dataId['detector']
124 if self.config.useGlobalExternalSkyWcs:
125 externalSkyWcsCatalog = inputs.pop('externalSkyWcsGlobalCatalog')
126 else:
127 externalSkyWcsCatalog = inputs.pop('externalSkyWcsTractCatalog')
128 row = externalSkyWcsCatalog.find(detector)
129 externalSkyWcs = row.getWcs()
130 inputs['skyWcs'] = externalSkyWcs
132 outputs = self.run(**inputs)
133 if outputs.measurement is not None:
134 butlerQC.put(outputs, outputRefs)
135 else:
136 self.log.debug("Skipping measurement of {!r} on {} "
137 "as not applicable.", self, inputRefs)