25 from ..base
import BaseCatalog
26 from ..schema
import Schema
27 from .match
import SimpleMatch, ReferenceMatch, SourceMatch
31 return "Match(%s,\n %s,\n %g)" % \
32 (repr(self.first), repr(self.second), self.distance)
37 if hasattr(s,
"getRa")
and hasattr(s,
"getDec"):
38 return " RA,Dec=(%g,%g) deg" % (s.getRa().asDegrees(), s.getDec().asDegrees())
42 if hasattr(s,
"getX")
and hasattr(s,
"getY"):
43 return " x,y=(%g,%g)" % (s.getX(), s.getY())
47 return s.__class__.__name__ + (
"(id %d" % s.getId()) + sourceRaDec(s) + sourceXy(s) +
")" 49 return "Match(%s, %s, dist %g)" % (sourceStr(self.first), sourceStr(self.second), self.distance,)
52 def __getitem__(self, i):
53 """Treat a Match as a tuple of length 3: (first, second, distance)""" 66 def __setitem__(self, i, val):
67 """Treat a Match as a tuple of length 3: (first, second, distance)""" 85 return self.__class__(self.first, self.second, self.distance)
97 for matchCls
in (SimpleMatch, ReferenceMatch, SourceMatch):
98 matchCls.__repr__ = __repr__
99 matchCls.__str__ = __str__
100 matchCls.__getitem__ = __getitem__
101 matchCls.__setitem__ = __setitem__
102 matchCls.__len__ = __len__
103 matchCls.clone = clone
109 """Make a catalog of matches from a sequence of matches. 111 The catalog contains three fields: 112 - first: the ID of the first source record in each match 113 - second: the ID of the second source record in each match 114 - distance: the distance of each match 116 @param[in] matches Sequence of matches, typically of type SimpleMatch, ReferenceMatch or SourceMatch. 117 Each element must support: `.first.getId()`->int, `.second.getId()->int` and `.distance->float`. 118 @return a catalog of matches. 120 @note this pure python implementation exists because SWIG could not easily be used to wrap 121 the overloaded C++ functions, so this was written and tested. It might be practical 122 to wrap the overloaded C++ functions with pybind11, but there didn't seem much point. 125 outKey1 = schema.addField(
"first", type=np.int64,
126 doc=
"ID for first source record in match.")
127 outKey2 = schema.addField(
"second", type=np.int64,
128 doc=
"ID for second source record in match.")
129 keyD = schema.addField(
"distance", type=np.float64,
130 doc=
"Distance between matches sources.")
132 result.table.preallocate(len(matches))
133 for match
in matches:
134 record = result.addNew()
135 record.set(outKey1, match.first.getId())
136 record.set(outKey2, match.second.getId())
137 record.set(keyD, match.distance)
CatalogT< BaseRecord > BaseCatalog