22 from __future__
import absolute_import, division, print_function
26 from ..base
import BaseCatalog
27 from ..schema
import Schema
28 from .match
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 117 @param[in] matches Sequence of matches, typically of type SimpleMatch, ReferenceMatch or SourceMatch. 118 Each element must support: `.first.getId()`->int, `.second.getId()->int` and `.distance->float`. 119 @return a catalog of matches. 121 @note this pure python implementation exists because SWIG could not easily be used to wrap 122 the overloaded C++ functions, so this was written and tested. It might be practical 123 to wrap the overloaded C++ functions with pybind11, but there didn't seem much point. 126 outKey1 = schema.addField(
"first", type=np.int64,
127 doc=
"ID for first source record in match.")
128 outKey2 = schema.addField(
"second", type=np.int64,
129 doc=
"ID for second source record in match.")
130 keyD = schema.addField(
"distance", type=np.float64,
131 doc=
"Distance between matches sources.")
133 result.table.preallocate(len(matches))
134 for match
in matches:
135 record = result.addNew()
136 record.set(outKey1, match.first.getId())
137 record.set(outKey2, match.second.getId())
138 record.set(keyD, match.distance)
CatalogT< BaseRecord > BaseCatalog