LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
transforms.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 """Measurement transformations.
24 
25 When a measurement plugin is run, it provides raw, uncalibrated outputs such
26 as pixel positions. A transformation may be run as a post-processing step to
27 convert those outputs to calibrated quantities, such as celestial coordinates.
28 
29 At construction, the transformation is passed the configuration and name of
30 the plugin whose outputs it will be transformaing (all fields in the input
31 table produced by that plugin will have their field names prefixed by the
32 plugin name) and a `SchemaMapper` which holds the schemata for the input and
33 output catalogs and which may be used to directly map fields between the
34 catalogs.
35 
36 When a transformer is called, it is handed a `SourceCatalog` containing the
37 measurements to be transformed, a `BaseCatalog` in which to store results, and
38 information about the WCS and calibration of the data. It may be safely
39 assumed that both are contiguous in memory, thus a ColumnView may be used for
40 efficient processing. If the transformation is not possible, it should be
41 aborted by throwing an exception; if this happens, the caller should
42 assume that the contents of the output catalog are inconsistent.
43 
44 Transformations can be defined in Python or in C++. Python code should inherit
45 from `MeasurementTransform`, following its interface.
46 """
47 
48 from lsst.afw.table import CoordKey
49 from lsst.pex.exceptions import LengthError
50 from .baseLib import CentroidResultKey
51 
52 __all__ = ("NullTransform", "PassThroughTransform", "SimpleCentroidTransform")
53 
54 class MeasurementTransform(object):
55  """!
56  Base class for measurement transformations.
57 
58  Create transformations by deriving from this class, implementing
59  `__call__()` and (optionally) augmenting `__init__()`.
60  """
61  def __init__(self, config, name, mapper):
62  self.name = name
63  self.config = config
64 
65  def __call__(self, inputCatalog, outputCatalog, wcs, calib):
66  raise NotImplementedError()
67 
68  @staticmethod
69  def _checkCatalogSize(cat1, cat2):
70  if len(cat1) != len(cat2):
71  raise LengthError("Catalog size mismatch")
72 
73 
75  """!
76  The null transform transfers no data from input to output.
77 
78  This is intended as the default for measurements for which no other
79  transformation is specified.
80  """
81  def __call__(self, inputCatalog, outputCatalog, wcs, calib):
82  self._checkCatalogSize(inputCatalog, outputCatalog)
83 
84 
86  """!
87  Copy all fields named after the measurement plugin from input to output, without transformation.
88  """
89  def __init__(self, config, name, mapper):
90  MeasurementTransform.__init__(self, config, name, mapper)
91  for key, field in mapper.getInputSchema().extract(name + "*").itervalues():
92  mapper.addMapping(key)
93 
94  def __call__(self, inputCatalog, outputCatalog, wcs, calib):
95  self._checkCatalogSize(inputCatalog, outputCatalog)
96 
97 
99  """!
100  Transform a pixel centroid, excluding uncertainties, to celestial coordinates.
101  """
102  def __init__(self, config, name, mapper):
103  MeasurementTransform.__init__(self, config, name, mapper)
104  self.coordKey = CoordKey.addFields(mapper.editOutputSchema(), name, "Position from " + name)
105 
106  def __call__(self, inputCatalog, outputCatalog, wcs, calib):
107  self._checkCatalogSize(inputCatalog, outputCatalog)
108  centroidResultKey = CentroidResultKey(inputCatalog.schema[self.name])
109  for inSrc, outSrc in zip(inputCatalog, outputCatalog):
110  self.coordKey.set(outSrc, wcs.pixelToSky(centroidResultKey.get(inSrc).getCentroid()))
Copy all fields named after the measurement plugin from input to output, without transformation.
Definition: transforms.py:85
The null transform transfers no data from input to output.
Definition: transforms.py:74
Base class for measurement transformations.
Definition: transforms.py:54
Transform a pixel centroid, excluding uncertainties, to celestial coordinates.
Definition: transforms.py:98