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

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

# 

# LSST Data Management System 

# Copyright 2008-2015 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 <http://www.lsstcorp.org/LegalNotices/>. 

# 

""" 

Tasks for transforming raw measurement outputs to calibrated quantities. 

""" 

import lsst.afw.table as afwTable 

import lsst.pex.config as pexConfig 

import lsst.pipe.base as pipeBase 

 

 

def makeContiguous(catalog): 

"""!Return a version of the input catalog which is contiguous in memory.""" 

if not catalog.isContiguous(): 

return catalog.copy(deep=True) 

else: 

return catalog 

 

 

class TransformConfig(pexConfig.Config): 

"""!Configuration for TransformTask.""" 

copyFields = pexConfig.ListField( 

dtype=str, 

doc="Fields to copy from input to output catalog without transformation", 

default=('id', 'coord_ra', 'coord_dec') 

) 

 

## \addtogroup LSST_task_documentation 

## \{ 

## \page TransformTask 

## \ref TransformTask_ "TransformTask" 

## \copybrief TransformTask 

## \} 

 

 

class TransformTask(pipeBase.Task): 

r"""! 

\anchor TransformTask_ 

 

\brief Transform a SourceCatalog containing raw measurements to calibrated form. 

 

\section pipe_tasks_transform_Contents Contents 

 

- \ref pipe_tasks_transform_purpose 

- \ref pipe_tasks_transform_initialize 

- \ref pipe_tasks_transform_invoke 

 

\section pipe_tasks_transform_purpose Description 

 

Given a set of measurement algorithms with their associated configuration, 

the table of source measurements they have produced, and information about 

an associated WCS and calibration, transform the raw measurement output to 

a calibrated form. 

 

Transformations are defined on a per-measurement-plugin basis. In 

addition, a configurable set of fields may be simply copied from the input 

to the output catalog. 

 

This task operates on an input SourceCatalog and returns a BaseCatalog 

containing the transformed results. It requires that the caller supply 

information on the configuration of the measurement task which produced 

the input data as well as the world coordinate system and calibration 

under which the transformation will take place. It provides no 

functionality for reading or writing data from a Butler: rather, 

per-dataset-type command line tasks are provided to obtain the appropriate 

information from a Butler (or elsewhere) and then delegate to this task. 

 

\section pipe_tasks_transform_initialize Task initialization 

 

\copydoc \_\_init\_\_ 

 

\section pipe_tasks_transform_invoke Task invocation 

 

\copydoc run 

""" 

ConfigClass = TransformConfig 

_DefaultName = "transform" 

 

def __init__(self, measConfig, inputSchema, outputDataset, *args, **kwargs): 

"""!Initialize TransformTask. 

 

@param[in] measConfig Configuration for the measurement task which 

produced the measurments being transformed. 

@param[in] inputSchema The schema of the input catalog. 

@param[in] outputDataset The butler dataset type of the output catalog. 

@param[in] *args Passed through to pipeBase.Task.__init__() 

@param[in] *kwargs Passed through to pipeBase.Task.__init__() 

""" 

pipeBase.Task.__init__(self, *args, **kwargs) 

 

# This task can be used to generate multiple different output dataset types. We 

# need to be able to specify the output type together with its schema. 

self.outputDataset = outputDataset 

 

# Define a mapper and add the basic fields to be copied. 

self.mapper = afwTable.SchemaMapper(inputSchema) 

for field in self.config.copyFields: 

self.mapper.addMapping(inputSchema.find(field).key) 

 

# Build a list of all transforms that will be applied to the input. We 

# will iterate over this in run(). 

self.transforms = [] 

for name in measConfig.plugins.names: 

config = measConfig.plugins.get(name) 

transformClass = measConfig.plugins.registry.get(name).PluginClass.getTransformClass() 

self.transforms.append(transformClass(config, name, self.mapper)) 

 

def getSchemaCatalogs(self): 

"""!Return a dict containing an empty catalog representative of this task's output.""" 

transformedSrc = afwTable.BaseCatalog(self.mapper.getOutputSchema()) 

return {self.outputDataset: transformedSrc} 

 

def run(self, inputCat, wcs, photoCalib): 

"""!Transform raw source measurements to calibrated quantities. 

 

@param[in] inputCat SourceCatalog of sources to transform. 

@param[in] wcs The world coordinate system under which transformations will take place. 

@param[in] photoCalib The calibration under which transformations will take place. 

 

@return A BaseCatalog containing the transformed measurements. 

""" 

outputCat = afwTable.BaseCatalog(self.mapper.getOutputSchema()) 

outputCat.extend(inputCat, mapper=self.mapper) 

 

# Transforms may use a ColumnView on the input and output catalogs, 

# which requires that the data be contiguous in memory. 

inputCat = makeContiguous(inputCat) 

outputCat = makeContiguous(outputCat) 

 

for transform in self.transforms: 

transform(inputCat, outputCat, wcs, photoCalib) 

return outputCat 

 

 

class RunTransformConfig(pexConfig.Config): 

"""!Configuration for RunTransformTaskBase derivatives.""" 

transform = pexConfig.ConfigurableField( 

doc="Subtask which performs transformations", 

target=TransformTask 

) 

inputConfigType = pexConfig.Field( 

dtype=str, 

doc="Dataset type of measurement operation configuration", 

) 

 

 

class RunTransformTaskBase(pipeBase.CmdLineTask): 

r"""! 

\anchor RunTransformTaskBase_ 

 

\brief Command line interface for TransformTask. 

 

\section pipe_tasks_transform_Contents Contents 

 

- \ref pipe_tasks_runtransform_purpose 

- \ref pipe_tasks_runtransform_invoke 

 

\section pipe_tasks_runtransform_purpose Description 

 

Provides a command-line task which can be used to run TransformTask. 

 

- Loads a plugin registry based on configuration; 

- Loads configuration for the measurement task which was applied from a repository; 

- Loads the SourceCatalog input schema from a repository; 

- For each input dataRef, reads the SourceCatalog, WCS and calibration from the 

repository and executes TransformTask. 

 

This is not a fully-fledged command line task: it requires specialization to a particular 

source type by defining the variables indicated below. 

 

\section pipe_tasks_runtransform_invoke Task invocation 

 

\copydoc run 

""" 

RunnerClass = pipeBase.ButlerInitializedTaskRunner 

ConfigClass = RunTransformConfig 

 

# Subclasses should provide definitions for the attributes named below. 

# Properties can be used if appropriate. 

# 

# Standard CmdLineTask attributes: 

_DefaultName = None 

 

# Butler dataset type of the source type to be transformed ("src", "forced_src", etc): 

sourceType = None 

 

# Butler dataset type of the calibration exposure to use when transforming ("calexp", etc): 

calexpType = None 

 

@property 

def inputSchemaType(self): 

"""! 

The Butler dataset type for the schema of the input source catalog. 

 

By default, we append `_schema` to the input source type. Subclasses may customize 

if required. 

""" 

return self.sourceType + "_schema" 

 

@property 

def outputDataset(self): 

"""! 

The Butler dataset type for the schema of the output catalog. 

 

By default, we prepend `transformed_` to the input source type. Subclasses may 

customize if required. 

""" 

return 'transformed_' + self.sourceType 

 

@property 

def measurementConfig(self): 

"""! 

The configuration of the measurement operation used to generate the input catalog. 

 

By default we look for `measurement` under the root configuration of the 

generating task. Subclasses may customize this (e.g. to `calibrate.measurement`) 

if required. 

""" 

return self.butler.get(self.config.inputConfigType).measurement.value 

 

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

pipeBase.CmdLineTask.__init__(self, *args, config=kwargs['config'], log=kwargs['log']) 

self.butler = kwargs['butler'] 

self.makeSubtask('transform', measConfig=self.measurementConfig, 

inputSchema=self.butler.get(self.inputSchemaType).schema, 

outputDataset=self.outputDataset) 

 

@pipeBase.timeMethod 

def runDataRef(self, dataRef): 

"""!Transform the source catalog referred to by dataRef. 

 

The result is both returned and written as dataset type "transformed_" + the input 

source dataset type to the provided dataRef. 

 

@param[in] dataRef Data reference for source catalog & calibrated exposure. 

 

@returns A BaseCatalog containing the transformed measurements. 

""" 

inputCat = dataRef.get(self.sourceType) 

wcs = dataRef.get(self.calexpType).getWcs() 

photoCalib = dataRef.get(self.calexpType).getPhotoCalib() 

outputCat = self.transform.run(inputCat, wcs, photoCalib) 

dataRef.put(outputCat, self.outputDataset) 

return outputCat 

 

 

## \addtogroup LSST_task_documentation 

## \{ 

## \page SrcTransformTask 

## \ref SrcTransformTask_ "SrcTransformTask" 

## \copybrief SrcTransformTask 

## \} 

 

class SrcTransformTask(RunTransformTaskBase): 

"""! 

\anchor SrcTransformTask_ 

 

\brief Transform ``src`` measuremenents to calibrated form. 

 

This is a specialization of \ref RunTransformTaskBase_ "RunTransformTaskBase" which 

operates on ``src`` measurements. Refer to the parent documentation for details. 

""" 

_DefaultName = "transformSrcMeasurement" 

sourceType = 'src' 

calexpType = 'calexp' 

 

@property 

def measurementConfig(self): 

return self.butler.get(self.config.inputConfigType).calibrate.measurement.value 

 

 

## \addtogroup LSST_task_documentation 

## \{ 

## \page ForcedSrcTransformTask 

## \ref ForcedSrcTransformTask_ "ForcedSrcTransformTask" 

## \copybrief ForcedSrcTransformTask 

## \} 

 

class ForcedSrcTransformTask(RunTransformTaskBase): 

"""! 

\anchor ForcedSrcTransformTask_ 

 

\brief Transform ``forced_src`` measuremenents to calibrated form. 

 

This is a specialization of \ref RunTransformTaskBase_ "RunTransformTaskBase" which 

operates on ``forced_src`` measurements. Refer to the parent documentation for details. 

""" 

_DefaultName = "transformForcedSrcMeasurement" 

sourceType = 'forced_src' 

calexpType = 'calexp' 

 

 

## \addtogroup LSST_task_documentation 

## \{ 

## \page CoaddSrcTransformTask 

## \ref CoaddSrcTransformTask_ "CoaddSrcTransformTask" 

## \copybrief CoaddSrcTransformTask 

## \} 

 

class CoaddSrcTransformTask(RunTransformTaskBase): 

"""! 

\anchor CoaddSrcTransformTask_ 

 

\brief Transform measuremenents made on coadds to calibrated form. 

 

This is a specialization of \ref RunTransformTaskBase_ "RunTransformTaskBase" which 

operates on measurements made on coadds. Refer to the parent documentation for details. 

""" 

_DefaultName = "transformCoaddSrcMeasurement" 

 

@property 

def coaddName(self): 

return self.butler.get(self.config.inputConfigType).coaddName 

 

@property 

def sourceType(self): 

return self.coaddName + "Coadd_meas" 

 

@property 

def calexpType(self): 

return self.coaddName + "Coadd_calexp" 

 

def _getConfigName(self): 

return "%s_transformCoaddSrcMeasurement_config" % (self.coaddName,) 

 

def _getMetaDataName(self): 

return "%s_transformCoaddSrcMeasurement_metadata" % (self.coaddName,)