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 

24from lsst.verify.tasks import MetricTask, MetricConfig, MetricConnections 

25from lsst.pipe.tasks.loadReferenceCatalog import LoadReferenceCatalogTask 

26import lsst.geom 

27 

28from .BaseSubTasks import NumSourcesTask 

29 

30__all__ = ('CatalogMeasurementBaseConnections', 'CatalogMeasurementBaseConfig', 

31 'CatalogMeasurementBaseTask') 

32 

33 

34class CatalogMeasurementBaseConnections(MetricConnections, 

35 defaultTemplates={'refDataset': ''}): 

36 

37 refCat = pipeBase.connectionTypes.PrerequisiteInput( 

38 doc='Reference catalog', 

39 name='{refDataset}', 

40 storageClass='SimpleCatalog', 

41 dimensions=('skypix',), 

42 deferLoad=True, 

43 multiple=True 

44 ) 

45 

46 def __init__(self, *, config=None): 

47 super().__init__(config=config) 

48 if config.connections.refDataset == '': 

49 self.prerequisiteInputs.remove('refCat') 

50 

51 

52class CatalogMeasurementBaseConfig(MetricConfig, 

53 pipelineConnections=CatalogMeasurementBaseConnections): 

54 """Configuration for CatalogMeasurementBaseTask.""" 

55 

56 measure = pexConfig.ConfigurableField( 

57 # This task is meant to make measurements of various types. 

58 # The default task is, therefore, a bit of a place holder. 

59 # It is expected that this will be overridden in the pipeline 

60 # definition in most cases. 

61 target=NumSourcesTask, 

62 doc="Measure task") 

63 

64 referenceCatalogLoader = pexConfig.ConfigurableField( 

65 target=LoadReferenceCatalogTask, 

66 doc="Reference catalog loader", 

67 ) 

68 

69 def setDefaults(self): 

70 self.referenceCatalogLoader.refObjLoader.ref_dataset_name = '' 

71 self.referenceCatalogLoader.doApplyColorTerms = False 

72 

73 def validate(self): 

74 super().validate() 

75 if self.connections.refDataset != self.referenceCatalogLoader.refObjLoader.ref_dataset_name: 

76 msg = "The reference datasets specified in connections and reference catalog loader must match." 

77 raise pexConfig.FieldValidationError( 

78 CatalogMeasurementBaseConfig.referenceCatalogLoader, self, msg) 

79 

80 

81class CatalogMeasurementBaseTask(MetricTask): 

82 """Base class for science performance metrics measured from source/object catalogs.""" 

83 

84 ConfigClass = CatalogMeasurementBaseConfig 

85 _DefaultName = "catalogMeasurementBaseTask" 

86 

87 def __init__(self, config, *args, **kwargs): 

88 super().__init__(*args, config=config, **kwargs) 

89 self.makeSubtask('measure') 

90 

91 def run(self, catalog, **kwargs): 

92 return self.measure.run(self.config.connections.metric, catalog, **kwargs) 

93 

94 def _getReferenceCatalog(self, butlerQC, dataIds, refCats, filterList, epoch=None): 

95 """Load reference catalog in sky region of interest. 

96 

97 Parameters 

98 ---------- 

99 butlerQC : `lsst.pipe.base.butlerQuantumContext.ButlerQuantumContext` 

100 Butler quantum context for a Gen3 repository. 

101 dataIds: interable of `lsst.daf.butler.dataId` 

102 An iterable object of dataIds that point to reference catalogs 

103 in a Gen3 repository. 

104 refCats : iterable of `lsst.daf.butler.DeferredDatasetHandle` 

105 An iterable object of dataset refs for reference catalogs in 

106 a Gen3 repository. 

107 filterList : `list` [`str`] 

108 List of camera physicalFilter names to apply color terms. 

109 epoch : `astropy.time.Time`, optional 

110 Epoch to which to correct proper motion and parallax 

111 (if available), or `None` to not apply such corrections. 

112 

113 Returns 

114 ------- 

115 refCat : `lsst.afw.table.SimpleCatalog` 

116 Catalog of reference objects from region. 

117 refCatCorrected : `numpy.ndarray` 

118 Catalog of reference objects with proper motions and color terms 

119 (optionally) applied. 

120 """ 

121 center = lsst.geom.SpherePoint(butlerQC.quantum.dataId.region.getBoundingCircle().getCenter()) 

122 radius = butlerQC.quantum.dataId.region.getBoundingCircle().getOpeningAngle() 

123 

124 loaderTask = LoadReferenceCatalogTask( 

125 config=self.config.referenceCatalogLoader, 

126 dataIds=dataIds, 

127 refCats=refCats) 

128 

129 # Get catalog with proper motion and color terms applied 

130 refCatCorrected = loaderTask.getSkyCircleCatalog(center, radius, 

131 filterList, 

132 epoch=epoch) 

133 

134 # Get unformatted catalog w/ all columns 

135 skyCircle = loaderTask.refObjLoader.loadSkyCircle(center, radius, 

136 loaderTask._referenceFilter, 

137 epoch=epoch) 

138 refCat = skyCircle.refCat 

139 

140 return refCat, refCatCorrected