lsst.meas.astrom  16.0-13-g5f6c0b1
denormalizeMatches.py
Go to the documentation of this file.
1 
2 __all__ = ["denormalizeMatches"]
3 
4 import lsst.afw.table
5 
6 
7 def denormalizeMatches(matches, matchMeta=None):
8  """Generate a denormalized Catalog of matches
9 
10  This is intended for writing matches in a convenient way.
11  Normally we write matches in a 'normalized' form: recording only the join
12  table (reference ID, source ID) to minimise space (the reference and source
13  catalogs should both be available separately, so the only extra information
14  we need is how to join them). However, using that can be a pain, since it
15  requires reading each catalog and doing the join.
16 
17  This function generates a Catalog containing all the information in the
18  matches. The reference catalog entries are in columns with "ref_"
19  prepended, while the source catalog entries are in columns with "src_"
20  prepended. The distance between the matches is in a column named
21  "distance".
22 
23  Parameters
24  ----------
25  matches : `list` of `lsst.afw.table.ReferenceMatch`
26  List of matches between reference catalog and source catalog.
27  matchMeta : `lsst.daf.base.PropertyList`
28  Matching metadata to write in catalog.
29 
30  Returns
31  -------
32  catalog : `lsst.afw.table.BaseCatalog`
33  Catalog containing matchlist entries.
34 
35  See also
36  --------
37  `lsst.afw.table.packMatches`
38  """
39  if len(matches) == 0:
40  raise RuntimeError("No matches provided.")
41 
42  refSchema = matches[0].first.getSchema()
43  srcSchema = matches[0].second.getSchema()
44 
45  refMapper, srcMapper = lsst.afw.table.SchemaMapper.join([refSchema, srcSchema], ["ref_", "src_"])
46  schema = refMapper.editOutputSchema()
47  distKey = schema.addField("distance", type=float, doc="Distance between ref and src")
48 
49  catalog = lsst.afw.table.BaseCatalog(schema)
50  catalog.reserve(len(matches))
51  for mm in matches:
52  row = catalog.addNew()
53  row.assign(mm.first, refMapper)
54  row.assign(mm.second, srcMapper)
55  row.set(distKey, mm.distance)
56 
57  if matchMeta is not None:
58  catalog.getTable().setMetadata(matchMeta)
59 
60  return catalog
def denormalizeMatches(matches, matchMeta=None)
static std::vector< SchemaMapper > join(std::vector< Schema > const &inputs, std::vector< std::string > const &prefixes=std::vector< std::string >())