LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Public Attributes | List of all members
lsst.afw.table.multiMatch.MultiMatch Class Reference

Public Member Functions

def __init__ (self, schema, dataIdFormat, coordField="coord", idField="id", radius=None, RecordClass=SourceRecord)
 
def makeRecord (self, inputRecord, dataId, objId)
 
def add (self, catalog, dataId)
 
def finish (self, removeAmbiguous=True)
 

Public Attributes

 radius
 
 mapper
 
 coordKey
 
 idKey
 
 dataIdKeys
 
 objectKey
 
 result
 
 reference
 
 ambiguous
 
 table
 
 nextObjId
 

Detailed Description

Initialize a multi-catalog match.

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

Definition at line 30 of file multiMatch.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 52 of file multiMatch.py.

53  RecordClass=SourceRecord):
54  if radius is None:
55  radius = 0.5*lsst.geom.arcseconds
56  elif not isinstance(radius, lsst.geom.Angle):
57  raise ValueError("'radius' argument must be an Angle")
58  self.radius = radius
59  self.mapper = SchemaMapper(schema)
60  self.mapper.addMinimalSchema(schema, True)
61  self.coordKey = CoordKey(schema[coordField])
62  self.idKey = schema.find(idField).key
63  self.dataIdKeys = {}
64  outSchema = self.mapper.editOutputSchema()
65  outSchema.setAliasMap(self.mapper.getInputSchema().getAliasMap())
66  self.objectKey = outSchema.addField(
67  "object", type=numpy.int64, doc="Unique ID for joined sources")
68  for name, dataType in dataIdFormat.items():
69  self.dataIdKeys[name] = outSchema.addField(
70  name, type=dataType, doc="'%s' data ID component")
71  # self.result will be a catalog containing the union of all matched records, with an 'object' ID
72  # column that can be used to group matches. Sources that have ambiguous matches may appear
73  # multiple times.
74  self.result = None
75  # self.reference will be a subset of self.result, with exactly one record for each group of matches
76  # (we'll use the one from the first catalog matched into this group)
77  # We'll use this to match against each subsequent catalog.
78  self.reference = None
79  # A set of ambiguous objects that we may want to ultimately remove from
80  # the final merged catalog.
81  self.ambiguous = set()
82  # Table used to allocate new records for the ouput catalog.
83  self.table = RecordClass.Table.make(self.mapper.getOutputSchema())
84  # Counter used to assign the next object ID
85  self.nextObjId = 1
86 
A class representing an angle.
Definition: Angle.h:127
daf::base::PropertySet * set
Definition: fits.cc:912
def getInputSchema(task, butler=None, schema=None)
Obtain the input schema either directly or froma butler reference.

Member Function Documentation

◆ add()

def lsst.afw.table.multiMatch.MultiMatch.add (   self,
  catalog,
  dataId 
)
Add a new catalog to the match, corresponding to the given data ID.
The new catalog is appended to the `self.result` and
`self.reference` catalogs.

Parameters
----------
catalog : `lsst.afw.table.base.Catalog`
    Catalog to be added to the match result.
dataId : `DataId` or `dict`
    Data id for the catalog to be added.

Definition at line 111 of file multiMatch.py.

111  def add(self, catalog, dataId):
112  """Add a new catalog to the match, corresponding to the given data ID.
113  The new catalog is appended to the `self.result` and
114  `self.reference` catalogs.
115 
116  Parameters
117  ----------
118  catalog : `lsst.afw.table.base.Catalog`
119  Catalog to be added to the match result.
120  dataId : `DataId` or `dict`
121  Data id for the catalog to be added.
122  """
123  if self.result is None:
124  self.result = self.table.Catalog(self.table)
125  for record in catalog:
126  self.result.append(self.makeRecord(
127  record, dataId, objId=self.nextObjId))
128  self.nextObjId += 1
129  self.reference = self.result.copy(deep=False)
130  return
131  catalog.sort(self.idKey) # pre-sort for speedy by-id access later.
132  # Will remove from this set as objects are matched.
133  unmatchedIds = {record.get(self.idKey) for record in catalog}
134  # Temporary dict mapping new source ID to a set of associated objects.
135  newToObj = {}
136  matches = lsst.afw.table.matchRaDec(self.reference, catalog, self.radius)
137  matchedRefIds = set()
138  matchedCatIds = set()
139  for refRecord, newRecord, distance in matches:
140  objId = refRecord.get(self.objectKey)
141  if objId in matchedRefIds:
142  # We've already matched this object against another new source,
143  # mark it as ambiguous.
144  self.ambiguous.add(objId)
145  matchedRefIds.add(objId)
146  if newRecord.get(self.idKey) in matchedCatIds:
147  # We've already matched this new source to one or more other objects
148  # Mark all involved objects as ambiguous
149  self.ambiguous.add(objId)
150  self.ambiguous |= newToObj.get(newRecord.get(self.idKey), set())
151  matchedCatIds.add(newRecord.get(self.idKey))
152  unmatchedIds.discard(newRecord.get(self.idKey))
153  # Populate the newToObj dict (setdefault trick is an idiom for
154  # appending to a dict-of-sets)
155  newToObj.setdefault(newRecord.get(self.idKey), set()).add(objId)
156  # Add a new result record for this match.
157  self.result.append(self.makeRecord(newRecord, dataId, objId))
158  # Add any unmatched sources from the new catalog as new objects to both
159  # the joined result catalog and the reference catalog.
160  for objId in unmatchedIds:
161  newRecord = catalog.find(objId, self.idKey)
162  resultRecord = self.makeRecord(newRecord, dataId, self.nextObjId)
163  self.nextObjId += 1
164  self.result.append(resultRecord)
165  self.reference.append(resultRecord)
166 
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33
std::vector< Match< typename Cat1::Record, typename Cat2::Record > > matchRaDec(Cat1 const &cat1, Cat2 const &cat2, lsst::geom::Angle radius, MatchControl const &mc=MatchControl())
Compute all tuples (s1,s2,d) where s1 belings to cat1, s2 belongs to cat2 and d, the distance between...
Definition: Match.cc:158

◆ finish()

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).

Parameters
----------
removeAmbiguous : `bool`, optional
    Should ambiguous matches be removed from the match
    catalog?  Defaults to True.

Returns
-------
result : `lsst.afw.table.base.Catalog`
    Final match catalog, sorted by object.

Definition at line 167 of file multiMatch.py.

167  def finish(self, removeAmbiguous=True):
168  """Return the final match catalog, after sorting it by object, copying
169  it to ensure contiguousness, and optionally removing ambiguous
170  matches.
171 
172  After calling finish(), the in-progress state of the matcher
173  is returned to the state it was just after construction, with
174  the exception of the object ID counter (which is not reset).
175 
176  Parameters
177  ----------
178  removeAmbiguous : `bool`, optional
179  Should ambiguous matches be removed from the match
180  catalog? Defaults to True.
181 
182  Returns
183  -------
184  result : `lsst.afw.table.base.Catalog`
185  Final match catalog, sorted by object.
186  """
187  if removeAmbiguous:
188  result = self.table.Catalog(self.table)
189  for record in self.result:
190  if record.get(self.objectKey) not in self.ambiguous:
191  result.append(record)
192  else:
193  result = self.result
194  result.sort(self.objectKey)
195  result = result.copy(deep=True)
196  self.result = None
197  self.reference = None
198  self.ambiguous = set()
199  return result
200 
201 

◆ makeRecord()

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.

Parameters
----------
inputRecord : `lsst.afw.table.source.sourceRecord`
    Record to use as the reference for the new result.
dataId : `DataId` or `dict`
    Data id describing the data.
objId : `int`
    Object id of the object to be added.

Returns
-------
outputRecord : `lsst.afw.table.source.sourceRecord`
    Newly generated record.

Definition at line 87 of file multiMatch.py.

87  def makeRecord(self, inputRecord, dataId, objId):
88  """Create a new result record from the given input record, using the
89  given data ID and object ID to fill in additional columns.
90 
91  Parameters
92  ----------
93  inputRecord : `lsst.afw.table.source.sourceRecord`
94  Record to use as the reference for the new result.
95  dataId : `DataId` or `dict`
96  Data id describing the data.
97  objId : `int`
98  Object id of the object to be added.
99 
100  Returns
101  -------
102  outputRecord : `lsst.afw.table.source.sourceRecord`
103  Newly generated record.
104  """
105  outputRecord = self.table.copyRecord(inputRecord, self.mapper)
106  for name, key in self.dataIdKeys.items():
107  outputRecord.set(key, dataId[name])
108  outputRecord.set(self.objectKey, objId)
109  return outputRecord
110 
std::vector< SchemaItem< Flag > > * items

Member Data Documentation

◆ ambiguous

lsst.afw.table.multiMatch.MultiMatch.ambiguous

Definition at line 81 of file multiMatch.py.

◆ coordKey

lsst.afw.table.multiMatch.MultiMatch.coordKey

Definition at line 61 of file multiMatch.py.

◆ dataIdKeys

lsst.afw.table.multiMatch.MultiMatch.dataIdKeys

Definition at line 63 of file multiMatch.py.

◆ idKey

lsst.afw.table.multiMatch.MultiMatch.idKey

Definition at line 62 of file multiMatch.py.

◆ mapper

lsst.afw.table.multiMatch.MultiMatch.mapper

Definition at line 59 of file multiMatch.py.

◆ nextObjId

lsst.afw.table.multiMatch.MultiMatch.nextObjId

Definition at line 85 of file multiMatch.py.

◆ objectKey

lsst.afw.table.multiMatch.MultiMatch.objectKey

Definition at line 66 of file multiMatch.py.

◆ radius

lsst.afw.table.multiMatch.MultiMatch.radius

Definition at line 58 of file multiMatch.py.

◆ reference

lsst.afw.table.multiMatch.MultiMatch.reference

Definition at line 78 of file multiMatch.py.

◆ result

lsst.afw.table.multiMatch.MultiMatch.result

Definition at line 74 of file multiMatch.py.

◆ table

lsst.afw.table.multiMatch.MultiMatch.table

Definition at line 83 of file multiMatch.py.


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