23 """Measurement transformations.
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.
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
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.
44 Transformations can be defined in Python or in C++. Python code should inherit
45 from `MeasurementTransform`, following its interface.
50 from .baseLib
import CentroidResultKey
52 __all__ = (
"NullTransform",
"PassThroughTransform",
"SimpleCentroidTransform")
56 Base class for measurement transformations.
58 Create transformations by deriving from this class, implementing
59 `__call__()` and (optionally) augmenting `__init__()`.
65 def __call__(self, inputCatalog, outputCatalog, wcs, calib):
66 raise NotImplementedError()
70 if len(cat1) != len(cat2):
71 raise LengthError(
"Catalog size mismatch")
76 The null transform transfers no data from input to output.
78 This is intended as the default for measurements for which no other
79 transformation is specified.
81 def __call__(self, inputCatalog, outputCatalog, wcs, calib):
87 Copy all fields named after the measurement plugin from input to output, without transformation.
90 MeasurementTransform.__init__(self, config, name, mapper)
91 for key, field
in mapper.getInputSchema().extract(name +
"*").itervalues():
92 mapper.addMapping(key)
94 def __call__(self, inputCatalog, outputCatalog, wcs, calib):
100 Transform a pixel centroid, excluding uncertainties, to celestial coordinates.
103 MeasurementTransform.__init__(self, config, name, mapper)
104 self.
coordKey = CoordKey.addFields(mapper.editOutputSchema(), name,
"Position from " + name)
106 def __call__(self, inputCatalog, outputCatalog, wcs, calib):
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()))