LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | List of all members
lsst.afw.table.multiMatch.MultiMatch Class Reference
Inheritance diagram for lsst.afw.table.multiMatch.MultiMatch:

Public Member Functions

def __init__
 
def makeRecord
 
def add
 
def finish
 

Public Attributes

 radius
 
 mapper
 
 coordKey
 
 idKey
 
 dataIdKeys
 
 objectKey
 
 result
 
 reference
 
 ambiguous
 
 table
 
 nextObjId
 

Detailed Description

Definition at line 6 of file multiMatch.py.

Constructor & Destructor Documentation

def lsst.afw.table.multiMatch.MultiMatch.__init__ (   self,
  schema,
  dataIdFormat,
  coordField = "coord",
  idField = "id",
  radius = None,
  RecordClass = SourceRecord 
)
Initialize a multi-catalog match.

Arguments:
  schema -------- schema shared by all catalogs to be included in the match.
  dataIdFormat -- dict of name: type for all data ID keys (e.g. {"visit":int, "ccd":int}).
  coordField ---- prefix for _ra and _dec fields that contain the coordinates to use for the match.
  idField ------- name of the field in schema that contains unique object IDs.
  radius -------- lsst.afw.geom.Angle; maximum separation for a match.  Defaults to 0.5 arcseconds.
  RecordClass --- type of record (a subclass of lsst.afw.table.BaseRecord) to expect in catalogs
          to be matched.

Definition at line 9 of file multiMatch.py.

9 
10  RecordClass=SourceRecord):
11  """Initialize a multi-catalog match.
12 
13  Arguments:
14  schema -------- schema shared by all catalogs to be included in the match.
15  dataIdFormat -- dict of name: type for all data ID keys (e.g. {"visit":int, "ccd":int}).
16  coordField ---- prefix for _ra and _dec fields that contain the coordinates to use for the match.
17  idField ------- name of the field in schema that contains unique object IDs.
18  radius -------- lsst.afw.geom.Angle; maximum separation for a match. Defaults to 0.5 arcseconds.
19  RecordClass --- type of record (a subclass of lsst.afw.table.BaseRecord) to expect in catalogs
20  to be matched.
21  """
22  if radius is None:
23  radius = 0.5*lsst.afw.geom.arcseconds
24  elif not isinstance(radius, lsst.afw.geom.Angle):
25  raise ValueError("'radius' argument must be an Angle")
26  self.radius = radius
27  self.mapper = SchemaMapper(schema)
28  self.mapper.addMinimalSchema(schema, True)
29  self.coordKey = CoordKey(schema[coordField])
30  self.idKey = schema.find(idField).key
31  self.dataIdKeys = {}
32  outSchema = self.mapper.editOutputSchema()
33  self.objectKey = outSchema.addField("object", type=numpy.int64, doc="Unique ID for joined sources")
34  for name, dataType in dataIdFormat.iteritems():
35  self.dataIdKeys[name] = outSchema.addField(name, type=dataType, doc="'%s' data ID component")
36  # self.result will be a catalog containing the union of all matched records, with an 'object' ID
37  # column that can be used to group matches. Sources that have ambiguous matches may appear
38  # multiple times.
39  self.result = None
40  # self.reference will be a subset of self.result, with exactly one record for each group of matches
41  # (we'll use the one from the first catalog matched into this group)
42  # We'll use this to match against each subsequent catalog.
43  self.reference = None
44  # A set of ambiguous objects that we may want to ultimately remove from the final merged catalog.
45  self.ambiguous = set()
46  # Table used to allocate new records for the ouput catalog.
47  self.table = RecordClass.Table.make(self.mapper.getOutputSchema())
48  # Counter used to assign the next object ID
49  self.nextObjId = 1
A FunctorKey used to get or set celestial coordiantes from a pair of Angle keys.
Definition: aggregates.h:119

Member Function Documentation

def lsst.afw.table.multiMatch.MultiMatch.add (   self,
  catalog,
  dataId 
)
Add a new catalog to the match, corresponding to the given data ID.

Definition at line 59 of file multiMatch.py.

59 
60  def add(self, catalog, dataId):
61  """Add a new catalog to the match, corresponding to the given data ID.
62  """
63  if self.result is None:
64  self.result = self.table.Catalog(self.table)
65  for record in catalog:
66  self.result.append(self.makeRecord(record, dataId, objId=self.nextObjId))
67  self.nextObjId += 1
68  self.reference = self.result.copy(deep=False)
69  return
70  # Temporary dict mapping object ID to reference record
71  # Will remove from this dict as objects are matched.
72  objById = {record.get(self.objectKey): record for record in self.reference}
73  # Temporary dict mapping source ID to new catalog record.
74  # Will remove from this dict as objects are matched.
75  newById = {record.get(self.idKey): record for record in catalog}
76  # Temporary dict mapping new source ID to a set of associated objects.
77  newToObj = {}
78  matches = lsst.afw.table.matchRaDec(self.reference, catalog, self.radius)
79  for refRecord, newRecord, distance in matches:
80  objId = refRecord.get(self.objectKey)
81  if objById.pop(objId, None) is None:
82  # We've already matched this object against another new source,
83  # mark it as ambiguous.
84  self.ambiguous.add(objId)
85  if newById.pop(newRecord.get(self.idKey), None) is None:
86  # We've already matched this new source to one or more other objects
87  # Mark all involved objects as ambiguous
88  self.ambiguous.add(objId)
89  self.ambiguous |= newToObj.get(newRecord.get(self.idKey), set())
90  # Populate the newToObj dict (setdefault trick is an idiom for appending to a dict-of-sets)
91  newToObj.setdefault(newRecord.get(self.idKey), set()).add(objId)
92  # Add a new result record for this match.
93  self.result.append(self.makeRecord(newRecord, dataId, objId))
94  # Add any unmatched sources from the new catalog as new objects to both the joined result catalog
95  # and the reference catalog.
96  for newRecord in newById.itervalues():
97  resultRecord = self.makeRecord(newRecord, dataId, self.nextObjId)
98  self.nextObjId += 1
99  self.result.append(resultRecord)
100  self.reference.append(resultRecord)
std::vector< Match< typename Cat::Record, typename Cat::Record > > matchRaDec(Cat const &cat, Angle radius, bool symmetric=true)
def lsst.afw.table.multiMatch.MultiMatch.finish (   self,
  removeAmbiguous = True 
)
Return the final match catalog, after sorting it by object, copying it to ensure contiguousness,
and optionally removing ambiguous matches.

After calling finish(), the in-progress state of the matcher is returned to the state it was
just after construction, with the exception of the object ID counter (which is not reset).

Definition at line 101 of file multiMatch.py.

102  def finish(self, removeAmbiguous=True):
103  """Return the final match catalog, after sorting it by object, copying it to ensure contiguousness,
104  and optionally removing ambiguous matches.
105 
106  After calling finish(), the in-progress state of the matcher is returned to the state it was
107  just after construction, with the exception of the object ID counter (which is not reset).
108  """
109  if removeAmbiguous:
110  result = self.table.Catalog(self.table)
111  for record in self.result:
112  if record.get(self.objectKey) not in self.ambiguous:
113  result.append(record)
114  else:
115  result = self.result
116  result.sort(self.objectKey)
117  result = result.copy(deep=True)
118  self.result = None
119  self.reference = None
120  self.ambiguous = set()
121  return result
122 
def lsst.afw.table.multiMatch.MultiMatch.makeRecord (   self,
  inputRecord,
  dataId,
  objId 
)
Create a new result record from the given input record, using the given data ID and object ID
to fill in additional columns.

Definition at line 50 of file multiMatch.py.

50 
51  def makeRecord(self, inputRecord, dataId, objId):
52  """Create a new result record from the given input record, using the given data ID and object ID
53  to fill in additional columns."""
54  outputRecord = self.table.copyRecord(inputRecord, self.mapper)
55  for name, key in self.dataIdKeys.iteritems():
56  outputRecord.set(key, dataId[name])
57  outputRecord.set(self.objectKey, objId)
58  return outputRecord

Member Data Documentation

lsst.afw.table.multiMatch.MultiMatch.ambiguous

Definition at line 44 of file multiMatch.py.

lsst.afw.table.multiMatch.MultiMatch.coordKey

Definition at line 28 of file multiMatch.py.

lsst.afw.table.multiMatch.MultiMatch.dataIdKeys

Definition at line 30 of file multiMatch.py.

lsst.afw.table.multiMatch.MultiMatch.idKey

Definition at line 29 of file multiMatch.py.

lsst.afw.table.multiMatch.MultiMatch.mapper

Definition at line 26 of file multiMatch.py.

lsst.afw.table.multiMatch.MultiMatch.nextObjId

Definition at line 48 of file multiMatch.py.

lsst.afw.table.multiMatch.MultiMatch.objectKey

Definition at line 32 of file multiMatch.py.

lsst.afw.table.multiMatch.MultiMatch.radius

Definition at line 25 of file multiMatch.py.

lsst.afw.table.multiMatch.MultiMatch.reference

Definition at line 42 of file multiMatch.py.

lsst.afw.table.multiMatch.MultiMatch.result

Definition at line 38 of file multiMatch.py.

lsst.afw.table.multiMatch.MultiMatch.table

Definition at line 46 of file multiMatch.py.


The documentation for this class was generated from the following file: