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 ( 

26 CatalogMeasurementBaseConnections, 

27 CatalogMeasurementBaseConfig, 

28 CatalogMeasurementBaseTask, 

29) 

30 

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

32 

33 

34class DetectorTableMeasurementConnections( 

35 CatalogMeasurementBaseConnections, 

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

37 defaultTemplates={"refDataset": ""}, 

38): 

39 

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 ) 

47 

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 ) 

54 

55 

56class DetectorTableMeasurementConfig( 

57 CatalogMeasurementBaseConfig, 

58 pipelineConnections=DetectorTableMeasurementConnections, 

59): 

60 """Configuration for DetectorTableMeasurementTask.""" 

61 

62 columns = pexConfig.ListField( 

63 doc="Columns from sourceTable_visit to load.", 

64 dtype=str, 

65 default=["coord_ra", "coord_dec", "detector"], 

66 ) 

67 

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 ) 

75 

76 

77class DetectorTableMeasurementTask(CatalogMeasurementBaseTask): 

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

79 

80 ConfigClass = DetectorTableMeasurementConfig 

81 _DefaultName = "detectorTableMeasurementTask" 

82 

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] 

88 

89 kwargs = {} 

90 if self.config.connections.refDataset != "": 

91 refCats = inputs.pop("refCat") 

92 filterList = [butlerQC.quantum.dataId.records["physical_filter"].name] 

93 # Time at the start of the visit 

94 epoch = butlerQC.quantum.dataId.records["visit"].timespan.begin 

95 refCat, refCatCorrected = self._getReferenceCatalog( 

96 butlerQC, 

97 [ref.datasetRef.dataId for ref in inputRefs.refCat], 

98 refCats, 

99 filterList, 

100 epoch, 

101 ) 

102 kwargs["refCat"] = refCat 

103 kwargs["refCatCorrected"] = refCatCorrected 

104 

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

106 if outputs.measurement is not None: 

107 butlerQC.put(outputs, outputRefs) 

108 else: 

109 self.log.debug( 

110 "Skipping measurement of {!r} on {} " "as not applicable.", 

111 self, 

112 inputRefs, 

113 )