22 __all__ = [
"SimpleMatch",
"ReferenceMatch",
"SourceMatch",
"clone",
"matchCls",
"packMatches"]
26 from ._base
import BaseCatalog
27 from ._schema
import Schema
28 from ._table
import SimpleMatch, ReferenceMatch, SourceMatch
32 return "Match(%s,\n %s,\n %g)" % \
33 (repr(self.first), repr(self.second), self.distance)
38 if hasattr(s,
"getRa")
and hasattr(s,
"getDec"):
39 return " RA,Dec=(%g,%g) deg" % (s.getRa().asDegrees(), s.getDec().asDegrees())
43 if hasattr(s,
"getX")
and hasattr(s,
"getY"):
44 return " x,y=(%g,%g)" % (s.getX(), s.getY())
48 return s.__class__.__name__ + (
"(id %d" % s.getId()) + sourceRaDec(s) + sourceXy(s) +
")"
50 return "Match(%s, %s, dist %g)" % (sourceStr(self.first), sourceStr(self.second), self.distance,)
53 def __getitem__(self, i):
54 """Treat a Match as a tuple of length 3: (first, second, distance)"""
67 def __setitem__(self, i, val):
68 """Treat a Match as a tuple of length 3: (first, second, distance)"""
86 return self.__class__(self.first, self.second, self.distance)
98 for matchCls
in (SimpleMatch, ReferenceMatch, SourceMatch):
99 matchCls.__repr__ = __repr__
100 matchCls.__str__ = __str__
101 matchCls.__getitem__ = __getitem__
102 matchCls.__setitem__ = __setitem__
103 matchCls.__len__ = __len__
104 matchCls.clone = clone
110 """Make a catalog of matches from a sequence of matches.
112 The catalog contains three fields:
113 - first: the ID of the first source record in each match
114 - second: the ID of the second source record in each match
115 - distance: the distance of each match
120 Sequence of matches, typically of type SimpleMatch,
121 ReferenceMatch or SourceMatch. Each element must support:
122 `.first.getId()`->int, `.second.getId()->int` and
128 The catalog of matches.
132 This pure python implementation exists as a historical artifact
133 related to SWIG limitations. It might be practical to wrap the
134 overloaded C++ functions with pybind11, but there didn't seem much
138 outKey1 = schema.addField(
"first", type=np.int64,
139 doc=
"ID for first source record in match.")
140 outKey2 = schema.addField(
"second", type=np.int64,
141 doc=
"ID for second source record in match.")
142 keyD = schema.addField(
"distance", type=np.float64,
143 doc=
"Distance between matches sources.")
145 result.table.preallocate(len(matches))
146 for match
in matches:
147 record = result.addNew()
148 record.set(outKey1, match.first.getId())
149 record.set(outKey2, match.second.getId())
150 record.set(keyD, match.distance)