Hide keyboard shortcuts

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

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/>. 

21 

22import lsst.pipe.base as pipeBase 

23import lsst.pex.config as pexConfig 

24 

25from lsst.faro.base.CatalogMeasurementBase import (CatalogMeasurementBaseConnections, 

26 CatalogMeasurementBaseConfig, 

27 CatalogMeasurementBaseTask) 

28 

29__all__ = ("DetectorTableMeasurementConfig", "DetectorTableMeasurementTask") 

30 

31 

32class DetectorTableMeasurementConnections(CatalogMeasurementBaseConnections, 

33 dimensions=("instrument", "visit", "detector", "band"), 

34 defaultTemplates={"refDataset": ""}): 

35 

36 catalog = pipeBase.connectionTypes.Input( 

37 doc="Source table in parquet format, per visit", 

38 dimensions=("instrument", "visit", "band"), 

39 storageClass="DataFrame", 

40 name="sourceTable_visit", 

41 deferLoad=True 

42 ) 

43 

44 measurement = pipeBase.connectionTypes.Output( 

45 doc="Per-detector measurement", 

46 dimensions=("instrument", "visit", "detector", "band"), 

47 storageClass="MetricValue", 

48 name="metricvalue_{package}_{metric}" 

49 ) 

50 

51 

52class DetectorTableMeasurementConfig(CatalogMeasurementBaseConfig, 

53 pipelineConnections=DetectorTableMeasurementConnections): 

54 """Configuration for DetectorTableMeasurementTask.""" 

55 

56 columns = pexConfig.ListField(doc="Columns from sourceTable_visit to load.", 

57 dtype=str, default=['coord_ra', 'coord_dec', 'detector']) 

58 

59 def validate(self): 

60 super().validate() 

61 if 'detector' not in self.columns: 

62 msg = "The column `detector` must be appear in the list of columns." 

63 raise pexConfig.FieldValidationError(DetectorTableMeasurementConfig.columns, self, msg) 

64 

65 

66class DetectorTableMeasurementTask(CatalogMeasurementBaseTask): 

67 """Base class for science performance metrics measured on single-detector source catalogs.""" 

68 

69 ConfigClass = DetectorTableMeasurementConfig 

70 _DefaultName = "detectorTableMeasurementTask" 

71 

72 def runQuantum(self, butlerQC, inputRefs, outputRefs): 

73 inputs = butlerQC.get(inputRefs) 

74 catalog = inputs['catalog'].get(parameters={'columns': self.config.columns}) 

75 selection = (catalog['detector'] == butlerQC.quantum.dataId['detector']) 

76 catalog = catalog[selection] 

77 

78 kwargs = {} 

79 if self.config.connections.refDataset != '': 

80 refCats = inputs.pop('refCat') 

81 filterList = [butlerQC.quantum.dataId.records['physical_filter'].name] 

82 # Time at the start of the visit 

83 epoch = butlerQC.quantum.dataId.records['visit'].timespan.begin 

84 refCat, refCatCorrected = self._getReferenceCatalog(butlerQC, 

85 [ref.datasetRef.dataId 

86 for ref in inputRefs.refCat], 

87 refCats, 

88 filterList, 

89 epoch) 

90 kwargs['refCat'] = refCat 

91 kwargs['refCatCorrected'] = refCatCorrected 

92 

93 outputs = self.run(catalog, **kwargs) 

94 if outputs.measurement is not None: 

95 butlerQC.put(outputs, outputRefs) 

96 else: 

97 self.log.debug("Skipping measurement of {!r} on {} " 

98 "as not applicable.", self, inputRefs)