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

28 statements  

« prev     ^ index     » next       coverage.py v7.2.5, created at 2023-05-03 03:49 -0700

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 

23 

24from lsst.faro.base.CatalogMeasurementBase import ( 

25 CatalogMeasurementBaseConnections, 

26 CatalogMeasurementBaseConfig, 

27 CatalogMeasurementBaseTask, 

28) 

29 

30__all__ = ("VisitTableMeasurementConfig", "VisitTableMeasurementTask") 

31 

32 

33class VisitTableMeasurementConnections( 

34 CatalogMeasurementBaseConnections, dimensions=("instrument", "visit", "band") 

35): 

36 

37 catalog = pipeBase.connectionTypes.Input( 

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

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

40 storageClass="DataFrame", 

41 name="sourceTable_visit", 

42 deferLoad=True, 

43 ) 

44 

45 measurement = pipeBase.connectionTypes.Output( 

46 doc="Per-visit measurement", 

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

48 storageClass="MetricValue", 

49 name="metricvalue_{package}_{metric}", 

50 ) 

51 

52 

53class VisitTableMeasurementConfig( 

54 CatalogMeasurementBaseConfig, pipelineConnections=VisitTableMeasurementConnections 

55): 

56 """Configuration for VisitTableMeasurementTask.""" 

57 

58 

59class VisitTableMeasurementTask(CatalogMeasurementBaseTask): 

60 """Base class for science performance metrics measured on single-visit source catalogs.""" 

61 

62 ConfigClass = VisitTableMeasurementConfig 

63 _DefaultName = "visitTableMeasurementTask" 

64 

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

66 """currentBands is set to None in SourceTable contexts, because currentBands is used to 

67 provide the correct parquet column names.""" 

68 inputs = butlerQC.get(inputRefs) 

69 

70 kwargs = {} 

71 kwargs["currentBands"] = None 

72 

73 columns = list(self.config.measure.columns.values()) 

74 columnsWithSelectors = self._getTableColumnsSelectors(columns, currentBands=kwargs["currentBands"]) 

75 catalog = inputs["catalog"].get(parameters={"columns": columnsWithSelectors}) 

76 kwargs["catalog"] = catalog 

77 

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

79 refCats = inputs.pop("refCat") 

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

81 # Time at the start of the visit 

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

83 refCat = self._getReferenceCatalog( 

84 butlerQC, 

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

86 refCats, 

87 filterList, 

88 epoch, 

89 ) 

90 kwargs["refCat"] = refCat 

91 

92 outputs = self.run(**kwargs) 

93 if outputs.measurement is not None: 

94 butlerQC.put(outputs, outputRefs) 

95 else: 

96 self.log.debug( 

97 "Skipping measurement of %r on %s as not applicable.", 

98 self, 

99 inputRefs, 

100 )