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