22 __all__ = [
"SimpleMatch",
"ReferenceMatch",
"SourceMatch",
"clone",
"matchCls",
"packMatches"]
28 from ._base
import BaseCatalog
29 from ._schema
import Schema
30 from ._table
import SimpleMatch, ReferenceMatch, SourceMatch, matchXy, matchRaDec
34 return "Match(%s,\n %s,\n %g)" % \
35 (repr(self.first), repr(self.second), self.distance)
40 if hasattr(s,
"getRa")
and hasattr(s,
"getDec"):
41 return " RA,Dec=(%g,%g) deg" % (s.getRa().asDegrees(), s.getDec().asDegrees())
45 if hasattr(s,
"getX")
and hasattr(s,
"getY"):
46 return " x,y=(%g,%g)" % (s.getX(), s.getY())
50 return s.__class__.__name__ + (
"(id %d" % s.getId()) + sourceRaDec(s) + sourceXy(s) +
")"
52 return "Match(%s, %s, dist %g)" % (sourceStr(self.first), sourceStr(self.second), self.distance,)
55 def __getitem__(self, i):
56 """Treat a Match as a tuple of length 3: (first, second, distance)"""
69 def __setitem__(self, i, val):
70 """Treat a Match as a tuple of length 3: (first, second, distance)"""
88 return self.__class__(self.first, self.second, self.distance)
100 for matchCls
in (SimpleMatch, ReferenceMatch, SourceMatch):
101 matchCls.__repr__ = __repr__
102 matchCls.__str__ = __str__
103 matchCls.__getitem__ = __getitem__
104 matchCls.__setitem__ = __setitem__
105 matchCls.__len__ = __len__
106 matchCls.clone = clone
112 """Make a catalog of matches from a sequence of matches.
114 The catalog contains three fields:
115 - first: the ID of the first source record in each match
116 - second: the ID of the second source record in each match
117 - distance: the distance of each match
122 Sequence of matches, typically of type SimpleMatch,
123 ReferenceMatch or SourceMatch. Each element must support:
124 `.first.getId()`->int, `.second.getId()->int` and
130 The catalog of matches.
134 This pure python implementation exists as a historical artifact
135 related to SWIG limitations. It might be practical to wrap the
136 overloaded C++ functions with pybind11, but there didn't seem much
140 outKey1 = schema.addField(
"first", type=np.int64,
141 doc=
"ID for first source record in match.")
142 outKey2 = schema.addField(
"second", type=np.int64,
143 doc=
"ID for second source record in match.")
144 keyD = schema.addField(
"distance", type=np.float64,
145 doc=
"Distance between matches sources.")
147 result.table.preallocate(len(matches))
148 for match
in matches:
149 record = result.addNew()
150 record.set(outKey1, match.first.getId())
151 record.set(outKey2, match.second.getId())
152 record.set(keyD, match.distance)
158 reason=
"Overloads that don't use `MatchControl` are deprecated. To be removed after 20.0.0.")
161 reason=
"Overloads that don't use `MatchControl` are deprecated. To be removed after 20.0.0.")