LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
transformMeasurement.py
Go to the documentation of this file.
2# LSST Data Management System
3# Copyright 2008-2015 AURA/LSST.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
22"""
23Tasks for transforming raw measurement outputs to calibrated quantities.
24"""
25import lsst.afw.table as afwTable
26import lsst.pex.config as pexConfig
27import lsst.pipe.base as pipeBase
28from lsst.utils.timer import timeMethod
29
30
31def makeContiguous(catalog):
32 """!Return a version of the input catalog which is contiguous in memory."""
33 if not catalog.isContiguous():
34 return catalog.copy(deep=True)
35 else:
36 return catalog
37
38
39class TransformConfig(pexConfig.Config):
40 """!Configuration for TransformTask."""
41 copyFields = pexConfig.ListField(
42 dtype=str,
43 doc="Fields to copy from input to output catalog without transformation",
44 default=('id', 'coord_ra', 'coord_dec')
45 )
46
47
53
54
55class TransformTask(pipeBase.Task):
56 r"""!
57 \anchor TransformTask_
58
59 \brief Transform a SourceCatalog containing raw measurements to calibrated form.
60
61 \section pipe_tasks_transform_Contents Contents
62
63 - \ref pipe_tasks_transform_purpose
64 - \ref pipe_tasks_transform_initialize
65 - \ref pipe_tasks_transform_invoke
66
67 \section pipe_tasks_transform_purpose Description
68
69 Given a set of measurement algorithms with their associated configuration,
70 the table of source measurements they have produced, and information about
71 an associated WCS and calibration, transform the raw measurement output to
72 a calibrated form.
73
74 Transformations are defined on a per-measurement-plugin basis. In
75 addition, a configurable set of fields may be simply copied from the input
76 to the output catalog.
77
78 This task operates on an input SourceCatalog and returns a BaseCatalog
79 containing the transformed results. It requires that the caller supply
80 information on the configuration of the measurement task which produced
81 the input data as well as the world coordinate system and calibration
82 under which the transformation will take place. It provides no
83 functionality for reading or writing data from a Butler: rather,
84 per-dataset-type command line tasks are provided to obtain the appropriate
85 information from a Butler (or elsewhere) and then delegate to this task.
86
87 \section pipe_tasks_transform_initialize Task initialization
88
89 \copydoc \_\_init\_\_
90
91 \section pipe_tasks_transform_invoke Task invocation
92
93 \copydoc run
94 """
95 ConfigClass = TransformConfig
96 _DefaultName = "transform"
97
98 def __init__(self, measConfig, inputSchema, outputDataset, *args, **kwargs):
99 """!Initialize TransformTask.
100
101 @param[in] measConfig Configuration for the measurement task which
102 produced the measurments being transformed.
103 @param[in] inputSchema The schema of the input catalog.
104 @param[in] outputDataset The butler dataset type of the output catalog.
105 @param[in] *args Passed through to pipeBase.Task.__init__()
106 @param[in] *kwargs Passed through to pipeBase.Task.__init__()
107 """
108 pipeBase.Task.__init__(self, *args, **kwargs)
109
110 # This task can be used to generate multiple different output dataset types. We
111 # need to be able to specify the output type together with its schema.
112 self.outputDatasetoutputDataset = outputDataset
113
114 # Define a mapper and add the basic fields to be copied.
115 self.mappermapper = afwTable.SchemaMapper(inputSchema)
116 for field in self.config.copyFields:
117 self.mappermapper.addMapping(inputSchema.find(field).key)
118
119 # Build a list of all transforms that will be applied to the input. We
120 # will iterate over this in run().
121 self.transformstransforms = []
122 for name in measConfig.plugins.names:
123 config = measConfig.plugins.get(name)
124 transformClass = measConfig.plugins.registry.get(name).PluginClass.getTransformClass()
125 self.transformstransforms.append(transformClass(config, name, self.mappermapper))
126
128 """!Return a dict containing an empty catalog representative of this task's output."""
129 transformedSrc = afwTable.BaseCatalog(self.mappermapper.getOutputSchema())
130 return {self.outputDatasetoutputDataset: transformedSrc}
131
132 @timeMethod
133 def run(self, inputCat, wcs, photoCalib):
134 """!Transform raw source measurements to calibrated quantities.
135
136 @param[in] inputCat SourceCatalog of sources to transform.
137 @param[in] wcs The world coordinate system under which transformations will take place.
138 @param[in] photoCalib The calibration under which transformations will take place.
139
140 @return A BaseCatalog containing the transformed measurements.
141 """
142 outputCat = afwTable.BaseCatalog(self.mappermapper.getOutputSchema())
143 outputCat.extend(inputCat, mapper=self.mappermapper)
144
145 # Transforms may use a ColumnView on the input and output catalogs,
146 # which requires that the data be contiguous in memory.
147 inputCat = makeContiguous(inputCat)
148 outputCat = makeContiguous(outputCat)
149
150 for transform in self.transformstransforms:
151 transform(inputCat, outputCat, wcs, photoCalib)
152 return outputCat
153
154
155class RunTransformConfig(pexConfig.Config):
156 """!Configuration for RunTransformTaskBase derivatives."""
157 transform = pexConfig.ConfigurableField(
158 doc="Subtask which performs transformations",
159 target=TransformTask
160 )
161 inputConfigType = pexConfig.Field(
162 dtype=str,
163 doc="Dataset type of measurement operation configuration",
164 )
165
166
167class RunTransformTaskBase(pipeBase.CmdLineTask):
168 r"""!
169 \anchor RunTransformTaskBase_
170
171 \brief Command line interface for TransformTask.
172
173 \section pipe_tasks_runtransform_Contents Contents
174
175 - \ref pipe_tasks_runtransform_purpose
176 - \ref pipe_tasks_runtransform_invoke
177
178 \section pipe_tasks_runtransform_purpose Description
179
180 Provides a command-line task which can be used to run TransformTask.
181
182 - Loads a plugin registry based on configuration;
183 - Loads configuration for the measurement task which was applied from a repository;
184 - Loads the SourceCatalog input schema from a repository;
185 - For each input dataRef, reads the SourceCatalog, WCS and calibration from the
186 repository and executes TransformTask.
187
188 This is not a fully-fledged command line task: it requires specialization to a particular
189 source type by defining the variables indicated below.
190
191 \section pipe_tasks_runtransform_invoke Task invocation
192
193 \copydoc run
194 """
195 RunnerClass = pipeBase.ButlerInitializedTaskRunner
196 ConfigClass = RunTransformConfig
197
198 # Subclasses should provide definitions for the attributes named below.
199 # Properties can be used if appropriate.
200 #
201 # Standard CmdLineTask attributes:
202 _DefaultName = None
203
204 # Butler dataset type of the source type to be transformed ("src", "forced_src", etc):
205 sourceType = None
206
207 # Butler dataset type of the calibration exposure to use when transforming ("calexp", etc):
208 calexpType = None
209
210 @property
212 """!
213 The Butler dataset type for the schema of the input source catalog.
214
215 By default, we append `_schema` to the input source type. Subclasses may customize
216 if required.
217 """
218 return self.sourceTypesourceType + "_schema"
219
220 @property
221 def outputDataset(self):
222 """!
223 The Butler dataset type for the schema of the output catalog.
224
225 By default, we prepend `transformed_` to the input source type. Subclasses may
226 customize if required.
227 """
228 return 'transformed_' + self.sourceTypesourceType
229
230 @property
232 """!
233 The configuration of the measurement operation used to generate the input catalog.
234
235 By default we look for `measurement` under the root configuration of the
236 generating task. Subclasses may customize this (e.g. to `calibrate.measurement`)
237 if required.
238 """
239 return self.butlerbutler.get(self.config.inputConfigType).measurement.value
240
241 def __init__(self, *args, **kwargs):
242 pipeBase.CmdLineTask.__init__(self, *args, config=kwargs['config'], log=kwargs['log'])
243 self.butlerbutler = kwargs['butler']
244 self.makeSubtask('transform', measConfig=self.measurementConfigmeasurementConfig,
245 inputSchema=self.butlerbutler.get(self.inputSchemaTypeinputSchemaType).schema,
246 outputDataset=self.outputDatasetoutputDataset)
247
248 @timeMethod
249 def runDataRef(self, dataRef):
250 """!Transform the source catalog referred to by dataRef.
251
252 The result is both returned and written as dataset type "transformed_" + the input
253 source dataset type to the provided dataRef.
254
255 @param[in] dataRef Data reference for source catalog & calibrated exposure.
256
257 @returns A BaseCatalog containing the transformed measurements.
258 """
259 inputCat = dataRef.get(self.sourceTypesourceType)
260 wcs = dataRef.get(self.calexpTypecalexpType).getWcs()
261 photoCalib = dataRef.get(self.calexpTypecalexpType).getPhotoCalib()
262 outputCat = self.transform.run(inputCat, wcs, photoCalib)
263 dataRef.put(outputCat, self.outputDatasetoutputDataset)
264 return outputCat
265
266
267
273
275 """!
276 \anchor SrcTransformTask_
277
278 \brief Transform ``src`` measuremenents to calibrated form.
279
280 This is a specialization of \ref RunTransformTaskBase_ "RunTransformTaskBase" which
281 operates on ``src`` measurements. Refer to the parent documentation for details.
282 """
283 _DefaultName = "transformSrcMeasurement"
284 sourceType = 'src'
285 calexpType = 'calexp'
286
287 @property
289 return self.butlerbutler.get(self.config.inputConfigType).calibrate.measurement.value
290
291
292
298
300 """!
301 \anchor ForcedSrcTransformTask_
302
303 \brief Transform ``forced_src`` measuremenents to calibrated form.
304
305 This is a specialization of \ref RunTransformTaskBase_ "RunTransformTaskBase" which
306 operates on ``forced_src`` measurements. Refer to the parent documentation for details.
307 """
308 _DefaultName = "transformForcedSrcMeasurement"
309 sourceType = 'forced_src'
310 calexpType = 'calexp'
311
312
313
319
321 """!
322 \anchor CoaddSrcTransformTask_
323
324 \brief Transform measuremenents made on coadds to calibrated form.
325
326 This is a specialization of \ref RunTransformTaskBase_ "RunTransformTaskBase" which
327 operates on measurements made on coadds. Refer to the parent documentation for details.
328 """
329 _DefaultName = "transformCoaddSrcMeasurement"
330
331 @property
332 def coaddName(self):
333 return self.butlerbutler.get(self.config.inputConfigType).coaddName
334
335 @property
336 def sourceType(self):
337 return self.coaddNamecoaddName + "Coadd_meas"
338
339 @property
340 def calexpType(self):
341 return self.coaddNamecoaddName + "Coadd_calexp"
342
343 def _getConfigName(self):
344 return "%s_transformCoaddSrcMeasurement_config" % (self.coaddNamecoaddName,)
345
346 def _getMetaDataName(self):
347 return "%s_transformCoaddSrcMeasurement_metadata" % (self.coaddNamecoaddName,)
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
Configuration for RunTransformTaskBase derivatives.
def inputSchemaType(self)
The Butler dataset type for the schema of the input source catalog.
def measurementConfig(self)
The configuration of the measurement operation used to generate the input catalog.
def outputDataset(self)
The Butler dataset type for the schema of the output catalog.
def runDataRef(self, dataRef)
Transform the source catalog referred to by dataRef.
def measurementConfig(self)
The configuration of the measurement operation used to generate the input catalog.
def run(self, inputCat, wcs, photoCalib)
Transform raw source measurements to calibrated quantities.
def __init__(self, measConfig, inputSchema, outputDataset, *args, **kwargs)
Initialize TransformTask.
def getSchemaCatalogs(self)
Return a dict containing an empty catalog representative of this task's output.
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33
def run(self, coaddExposures, bbox, wcs, dataIds, **kwargs)
Definition: getTemplate.py:596
def makeContiguous(catalog)
Return a version of the input catalog which is contiguous in memory.