LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+0dd8ce4237,g1470d8bcf6+3ea6592b6f,g2079a07aa2+86d27d4dc4,g2305ad1205+5ca4c0b359,g295015adf3+d10818ec9d,g2a9a014e59+6f9be1b9cd,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+703ba97ebf,g487adcacf7+4fa16da234,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+ffa42b374e,g5a732f18d5+53520f316c,g64a986408d+0dd8ce4237,g858d7b2824+0dd8ce4237,g8a8a8dda67+585e252eca,g99cad8db69+d39438377f,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+f1d96605c8,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e5339d463f,gc120e1dc64+da31e9920e,gc28159a63d+0e5473021a,gcf0d15dbbd+703ba97ebf,gdaeeff99f8+f9a426f77a,ge6526c86ff+889fc9d533,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf18bd8381d+7268b93478,gff1a9f87cc+0dd8ce4237,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
lsst.afw.table.multiMatch.MultiMatch Class Reference

Public Member Functions

 __init__ (self, schema, dataIdFormat, coordField="coord", idField="id", radius=None, RecordClass=SourceRecord)
 
 makeRecord (self, inputRecord, dataId, objId)
 
 add (self, catalog, dataId)
 
 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__()

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:128
daf::base::PropertySet * set
Definition fits.cc:931

Member Function Documentation

◆ add()

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::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()

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

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: