25from ._base
import Catalog
26from ._table
import SourceCatalog, SourceTable
28Catalog.register(
"Source", SourceCatalog)
35 """Return the subset of self for which the parent field equals the
38 In order for this method to
return the correct result, it must be
39 sorted by parent (i.e. self.isSorted(SourceTable.getParentKey()) must
40 be
True). This
is naturally the case
with SourceCatalogs produced by
41 the detection
and deblending tasks, but it may
not be true when
42 concatenating multiple such catalogs.
44 Additional Catalogs
or sequences whose elements correspond
in order to
45 the records of self (i.e. ``zip(self, *args)``
is valid) will be
46 subset using the same slice object used on self,
and these subsets
47 will be returned along
with the subset of self.
51 parent : `int`
or `iterable` of `int`
52 ID(s) of the parent(s) to get children
for.
54 Additional catalogs to subset
for the children to
return.
59 Children sources
if ``parent``
is of type `int`,
or a generator
61 each parent
if ``parent``
is an `iterable`.
66 Raised
if the catalog
is not sorted by the parent key.
70 Each call to this function checks
if the catalog
is sorted, which
is
71 of O(n) complexity,
while fetching the children
is of O(log n). To
72 minimize the computational overhead, it
is preferable to prepare an
73 iterable of parent ids
for which the children need to be fetched
and
74 pass the iterable
as ``parent``.
76 if not self.isSorted(SourceTable.getParentKey()):
78 "The table is not sorted by parent, so cannot getChildren")
80 def _getChildrenWithoutChecking(parent):
81 """Return the subset of self for which the parent field equals the
84 This function works as desired only
if `self`
is sorted by the
85 parent key, but does
not check
if it
is sorted. This function must
86 be used only after ensuring outside of the function that
87 self.isSorted(SourceTable.getParentKey() evaluates to
True.
92 ID of the parent to get children
for.
99 s = self.equal_range(parent, SourceTable.getParentKey())
101 return (self[s],) + tuple(arg[s]
for arg
in args)
106 return (_getChildrenWithoutChecking(p)
for p
in parent)
108 return _getChildrenWithoutChecking(parent)
def getChildren(self, parent, *args)
Record class that contains measurements made on a single exposure.