LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
transformMeasurement.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # LSST Data Management System
4 # Copyright 2008-2015 AURA/LSST.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
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 LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 """
24 Tasks for transforming raw measurement outputs to calibrated quantities.
25 """
26 import lsst.afw.table as afwTable
27 import lsst.meas.base as measBase
28 import lsst.pex.config as pexConfig
29 import lsst.pipe.base as pipeBase
30 
31 def 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 
39 class 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')
45  )
46 
47 ## \addtogroup LSST_task_documentation
48 ## \{
49 ## \page pipeTasks_TransformTask
50 ## \ref TransformTask "TransformTask"
51 ## Task for transforming raw measurement outputs to calibrated quantities.
52 ## \}
53 
54 class TransformTask(pipeBase.Task):
55  """!Transform a SourceCatalog containing raw measurements to calibrated form.
56 
57  Given a set of measurement algorithms with their associated configuration,
58  the table of source measurements they have produced, and information about
59  an associated WCS and calibration, transform the raw measurement output to
60  a calibrated form.
61 
62  Transformations are defined on a per-measurement-plugin basis. In
63  addition, a configurable set of fields may be simply copied from the input
64  to the output catalog.
65  """
66  ConfigClass = TransformConfig
67  _DefaultName = "transform"
68 
69  def __init__(self, measConfig, pluginRegistry, inputSchema, *args, **kwargs):
70  """!Initialize TransformTask.
71 
72  @param[in] measConfig Configuration for the measurement task which
73  produced the measurments being transformed.
74  @param[in] pluginRegistry A PluginRegistry which maps plugin names to measurement algorithms.
75  @param[in] inputSchema The schema of the input catalog.
76  @param[in] *args Passed through to pipeBase.Task.__init__()
77  @param[in] *kwargs Passed through to pipeBase.Task.__init__()
78  """
79  pipeBase.Task.__init__(self, *args, **kwargs)
80 
81  # Define a mapper and add the basic fields to be copied.
82  self.mapper = afwTable.SchemaMapper(inputSchema)
83  for field in self.config.copyFields:
84  self.mapper.addMapping(inputSchema.find(field).key)
85 
86  # Build a list of all transforms that will be applied to the input. We
87  # will iterate over this in run().
88 
89  self.transforms = []
90  for name in measConfig.plugins.names:
91  config = measConfig.plugins.get(name)
92  transformClass = pluginRegistry.get(name).PluginClass.getTransformClass()
93  self.transforms.append(transformClass(config, name, self.mapper))
94 
95  def getSchemaCatalogs(self):
96  """!Return a dict containing an empty catalog representative of this task's output."""
97  transformedSrc = afwTable.BaseCatalog(self.mapper.getOutputSchema())
98  return {'transformedSrc': transformedSrc}
99 
100  def run(self, inputCat, wcs, calib):
101  """!Transform raw source measurements to calibrated quantities.
102 
103  @param[in] inputCat SourceCatalog of sources to transform.
104  @param[in] wcs The world coordinate system under which transformations will take place.
105  @param[in] calib The calibration under which transformations will take place.
106 
107  @return A BaseCatalog containing the transformed measurements.
108  """
109  outputCat = afwTable.BaseCatalog(self.mapper.getOutputSchema())
110  outputCat.extend(inputCat, mapper=self.mapper)
111 
112  # Transforms may use a ColumnView on the input and output catalogs,
113  # which requires that the data be contiguous in memory.
114  inputCat = makeContiguous(inputCat)
115  outputCat = makeContiguous(outputCat)
116 
117  for transform in self.transforms:
118  transform(inputCat, outputCat, wcs, calib)
119  return outputCat
120 
121 
122 class RunTransformConfig(pexConfig.Config):
123  """!Configuration for RunTransformTask."""
124  transform = pexConfig.ConfigurableField(
125  doc="Subtask which performs transformations",
126  target=TransformTask
127  )
128  measConfig = pexConfig.Field(
129  dtype=str,
130  doc="Dataset type of measurement operation configuration",
131  default="processCcd_config"
132  )
133  measType = pexConfig.ChoiceField(
134  dtype=str,
135  doc="Type of measurement operation performed",
136  default="SingleFrame",
137  allowed={
138  "SingleFrame": "Single frame measurement",
139  "Forced": "Forced measurement"
140  }
141  )
142 
143 
144 class RunTransformTask(pipeBase.CmdLineTask):
145  """!Basic interface for TransformTask.
146 
147  Provide a command-line task which can be used to run TransformTask.
148 
149  - Loads a plugin registry based on configuration;
150  - Loads configuration for the measurement task which was applied from a repository;
151  - Loads the SourceCatalog input schema from a repository;
152  - For each input dataRef, reads the SourceCatalog, WCS and calibration from the
153  repository and executes TransformTask.
154 
155  This can be sub-tasked to support whatever dataset types or sources for
156  the WCS and calibration information are required.
157  """
158  ConfigClass = RunTransformConfig
159  RunnerClass = pipeBase.ButlerInitializedTaskRunner
160  _DefaultName = "transformMeasurement"
161 
162  def __init__(self, *args, **kwargs):
163  pipeBase.CmdLineTask.__init__(self, *args, config=kwargs['config'], log=kwargs['log'])
164  if self.config.measType == "SingleFrame":
165  pluginRegistry = measBase.sfm.SingleFramePlugin.registry
166  elif self.config.measType == "Forced":
167  pluginRegistry = measBase.forcedMeasurement.ForcedPlugin.registry
168  self.makeSubtask('transform', pluginRegistry=pluginRegistry,
169  measConfig=kwargs['butler'].get(self.config.measConfig).measurement.value,
170  inputSchema=kwargs['butler'].get("src_schema").schema)
171 
172  @pipeBase.timeMethod
173  def run(self, dataRef):
174  """!Transform the source catalog referred to by dataRef.
175 
176  The result is both returned and written as dataset type "transformedSrc"
177  to the provided dataRef.
178 
179  @param[in] dataRef Data reference for source catalog (src) &
180  calibrated exposure (calexp).
181 
182  @returns A BaseCatalog containing the transformed measurements.
183  """
184  inputCat = dataRef.get('src')
185  wcs = dataRef.get('calexp').getWcs()
186  calib = dataRef.get('calexp').getCalib()
187  outputCat = self.transform.run(inputCat, wcs, calib)
188  dataRef.put(outputCat, "transformedSrc")
189  return outputCat
Transform a SourceCatalog containing raw measurements to calibrated form.
A custom container class for records, based on std::vector.
Definition: Catalog.h:94
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:19
def makeContiguous
Return a version of the input catalog which is contiguous in memory.
def getSchemaCatalogs
Return a dict containing an empty catalog representative of this task&#39;s output.
def run
Transform raw source measurements to calibrated quantities.
def run
Transform the source catalog referred to by dataRef.