36 """Return the subset of self for which the parent field equals the
39 In order for this method to return the correct result, it must be
40 sorted by parent (i.e. self.isSorted(SourceTable.getParentKey()) must
41 be True). This is naturally the case with SourceCatalogs produced by
42 the detection and deblending tasks, but it may not be true when
43 concatenating multiple such catalogs.
45 Additional Catalogs or sequences whose elements correspond in order to
46 the records of self (i.e. ``zip(self, *args)`` is valid) will be
47 subset using the same slice object used on self, and these subsets
48 will be returned along with the subset of self.
52 parent : `int` or `iterable` of `int`
53 ID(s) of the parent(s) to get children for.
54 args : `~lsst.afw.table.Catalog`
55 Additional catalogs to subset for the children to return.
59 children : a single iterable of `~lsst.afw.table.SourceRecord`
60 Children sources if ``parent`` is of type `int`, or a generator
61 yielding a `~lsst.afw.table.SourceRecord`s Children sources for
62 each parent if ``parent`` is an `iterable`.
67 Raised if the catalog is not sorted by the parent key.
71 Each call to this function checks if the catalog is sorted, which is
72 of O(n) complexity, while fetching the children is of O(log n). To
73 minimize the computational overhead, it is preferable to prepare an
74 iterable of parent ids for which the children need to be fetched and
75 pass the iterable as ``parent``.
77 if not self.isSorted(SourceTable.getParentKey()):
79 "The table is not sorted by parent, so cannot getChildren")
81 def _getChildrenWithoutChecking(parent):
82 """Return the subset of self for which the parent field equals the
85 This function works as desired only if `self` is sorted by the
86 parent key, but does not check if it is sorted. This function must
87 be used only after ensuring outside of the function that
88 self.isSorted(SourceTable.getParentKey() evaluates to True.
93 ID of the parent to get children for.
97 children : iterable of `~lsst.afw.table.SourceRecord`
100 s = self.equal_range(parent, SourceTable.getParentKey())
102 return (self[s],) + tuple(arg[s]
for arg
in args)
107 return (_getChildrenWithoutChecking(p)
for p
in parent)
109 return _getChildrenWithoutChecking(parent)