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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

# 

# LSST Data Management System 

# Copyright 2008-2016 AURA/LSST. 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <https://www.lsstcorp.org/LegalNotices/>. 

# 

 

"""PipelineTask for associating DiaSources with previous DiaObjects. 

 

Additionally performs forced photometry on the calibrated and difference 

images at the updated locations of DiaObjects. 

 

Currently loads directly from the Apdb rather than pre-loading. 

""" 

 

import os 

 

import lsst.dax.apdb as daxApdb 

import lsst.pex.config as pexConfig 

import lsst.pipe.base as pipeBase 

import lsst.pipe.base.connectionTypes as connTypes 

from lsst.utils import getPackageDir 

 

from lsst.ap.association import ( 

AssociationTask, 

DiaForcedSourceTask, 

LoadDiaCatalogsTask, 

MapDiaSourceTask, 

make_dia_object_schema, 

make_dia_source_schema) 

 

__all__ = ("DiaPipelineConfig", 

"DiaPipelineTask", 

"DiaPipelineConnections") 

 

 

class DiaPipelineConnections(pipeBase.PipelineTaskConnections, 

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

defaultTemplates={"coaddName": "deep"}): 

"""Butler connections for DiaPipelineTask. 

""" 

diaSourceSchema = connTypes.InitInput( 

doc="Schema of the DiaSource catalog produced during image " 

"differencing", 

name="{coaddName}Diff_diaSrc_schema", 

storageClass="SourceCatalog", 

multiple=True 

) 

diaSourceCat = connTypes.Input( 

doc="Catalog of DiaSources produced during image differencing.", 

name="{coaddName}Diff_diaSrc", 

storageClass="SourceCatalog", 

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

) 

diffIm = connTypes.Input( 

doc="Difference image on which the DiaSources were detected.", 

name="{coaddName}Diff_differenceExp", 

storageClass="ExposureF", 

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

) 

exposure = connTypes.Input( 

doc="Calibrated exposure differenced with a template image during " 

"image differencing.", 

name="calexp", 

storageClass="ExposureF", 

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

) 

apdbMarker = connTypes.Output( 

doc="Marker dataset storing the configuration of the Apdb for each " 

"visit/detector. Used to signal the completion of the pipeline.", 

name="apdb_marker", 

storageClass="", 

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

) 

 

 

class DiaPipelineConfig(pipeBase.PipelineTaskConfig, 

pipelineConnections=DiaPipelineConnections): 

"""Config for DiaPipelineTask. 

""" 

apdb = pexConfig.ConfigurableField( 

target=daxApdb.Apdb, 

ConfigClass=daxApdb.ApdbConfig, 

doc="Database connection for storing associated DiaSources and " 

"DiaObjects. Must already be initialized.", 

) 

diaSourceDpddifier = pexConfig.ConfigurableField( 

target=MapDiaSourceTask, 

doc="Task for assigning columns from the raw output of ip_diffim into " 

"a schema that more closely resembles the DPDD.", 

) 

diaCatalogLoader = pexConfig.ConfigurableField( 

target=LoadDiaCatalogsTask, 

doc="Task to load DiaObjects and DiaSources from the Apdb.", 

) 

associator = pexConfig.ConfigurableField( 

target=AssociationTask, 

doc="Task used to associate DiaSources with DiaObjects.", 

) 

diaForcedSource = pexConfig.ConfigurableField( 

target=DiaForcedSourceTask, 

doc="Task used for force photometer DiaObject locations in direct and " 

"difference images.", 

) 

 

def setDefaults(self): 

self.apdb.dia_object_index = "baseline" 

self.apdb.dia_object_columns = [] 

self.apdb.extra_schema_file = os.path.join( 

getPackageDir("ap_association"), 

"data", 

"apdb-ap-pipe-schema-extra.yaml") 

 

def validate(self): 

pexConfig.Config.validate(self) 

if self.diaCatalogLoader.htmLevel != \ 

self.associator.diaCalculation.plugins["ap_HTMIndex"].htmLevel: 

raise ValueError("HTM index level in LoadDiaCatalogsTask must be " 

"equal to HTMIndexDiaCalculationPlugin index " 

"level.") 

 

 

class DiaPipelineTask(pipeBase.PipelineTask): 

"""Task for loading, associating and storing Difference Image Analysis 

(DIA) Objects and Sources. 

""" 

ConfigClass = DiaPipelineConfig 

_DefaultName = "diaPipe" 

RunnerClass = pipeBase.ButlerInitializedTaskRunner 

 

def __init__(self, initInputs=None, **kwargs): 

super().__init__(**kwargs) 

self.apdb = self.config.apdb.apply( 

afw_schemas=dict(DiaObject=make_dia_object_schema(), 

DiaSource=make_dia_source_schema())) 

self.makeSubtask("diaSourceDpddifier", 

inputSchema=initInputs["diaSourceSchema"]) 

self.makeSubtask("diaCatalogLoader") 

self.makeSubtask("associator") 

self.makeSubtask("diaForcedSource") 

 

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

inputs = butlerQC.get(inputRefs) 

expId, expBits = butlerQC.quantum.dataId.pack("visit_detector", 

returnMaxBits=True) 

inputs["ccdExposureIdBits"] = expBits 

 

outputs = self.run(**inputs) 

 

butlerQC.put(outputs, outputRefs) 

 

@pipeBase.timeMethod 

def run(self, diaSourceCat, diffIm, exposure, ccdExposureIdBits): 

"""Process DiaSources and DiaObjects. 

 

Load previous DiaObjects and their DiaSource history. Calibrate the 

values in the diaSourceCat. Associate new DiaSources with previous 

DiaObjects. Run forced photometry at the updated DiaObject locations. 

Store the results in the Alert Production Database (Apdb). 

 

Parameters 

---------- 

diaSourceCat : `lsst.afw.table.SourceCatalog` 

Newly detected DiaSources. 

diffIm : `lsst.afw.image.Exposure` 

Difference image exposure in which the sources in ``diaSourceCat`` 

were detected. 

exposure : `lsst.afw.image.Exposure` 

Calibrated exposure differenced with a template to create 

``diffIm``. 

ccdExposureIdBits : `int` 

Number of bits used for a unique ``ccdVisitId``. 

 

Returns 

------- 

results : `lsst.pipe.base.Struct` 

Results struct with components. 

 

- ``apdb_maker`` : Marker dataset to store in the Butler indicating 

that this ccdVisit has completed successfully. 

(`lsst.dax.apdb.ApdbConfig`) 

""" 

self.log.info("Running DiaPipeline...") 

# Put the SciencePipelines through a SDMification step and return 

# calibrated columns with the expect output database names. 

diaSources = self.diaSourceDpddifier.run(diaSourceCat, 

diffIm, 

return_pandas=True) 

 

# Load the DiaObjects and DiaSource history. 

loaderResult = self.diaCatalogLoader.run(diffIm, self.apdb) 

 

# Associate new DiaSources with existing DiaObjects and update 

# DiaObject summary statistics using the full DiaSource history. 

assocResults = self.associator.run(diaSources, 

loaderResult.diaObjects, 

loaderResult.diaSources) 

 

# Force photometer on the Difference and Calibrated exposures using 

# the new and updated DiaObject locations. 

diaForcedSources = self.diaForcedSource.run( 

assocResults.diaObjects, 

ccdExposureIdBits, 

exposure, 

diffIm) 

 

# Store DiaSources and updated DiaObjects in the Apdb. 

self.apdb.storeDiaSources(assocResults.diaSources) 

self.apdb.storeDiaObjects( 

assocResults.updatedDiaObjects, 

exposure.getInfo().getVisitInfo().getDate().toPython()) 

self.apdb.storeDiaForcedSources(diaForcedSources) 

 

return pipeBase.Struct(apdb_maker=self.config.apdb.value)