LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+0dd8ce4237,g1470d8bcf6+3ea6592b6f,g2079a07aa2+86d27d4dc4,g2305ad1205+5ca4c0b359,g295015adf3+d10818ec9d,g2a9a014e59+6f9be1b9cd,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+703ba97ebf,g487adcacf7+4fa16da234,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+ffa42b374e,g5a732f18d5+53520f316c,g64a986408d+0dd8ce4237,g858d7b2824+0dd8ce4237,g8a8a8dda67+585e252eca,g99cad8db69+d39438377f,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+f1d96605c8,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e5339d463f,gc120e1dc64+da31e9920e,gc28159a63d+0e5473021a,gcf0d15dbbd+703ba97ebf,gdaeeff99f8+f9a426f77a,ge6526c86ff+889fc9d533,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf18bd8381d+7268b93478,gff1a9f87cc+0dd8ce4237,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | List of all members
lsst.afw.table._source.SourceCatalog Class Reference
Inheritance diagram for lsst.afw.table._source.SourceCatalog:
lsst.meas.base.forcedPhotCcd.may lsst.meas.base.forcedPhotCcd.may

Public Member Functions

 getChildren (self, parent, *args)
 

Detailed Description

Definition at line 33 of file _source.py.

Member Function Documentation

◆ getChildren()

lsst.afw.table._source.SourceCatalog.getChildren ( self,
parent,
* args )
Return the subset of self for which the parent field equals the
given value.

In order for this method to return the correct result, it must be
sorted by parent (i.e. self.isSorted(SourceTable.getParentKey()) must
be True).  This is naturally the case with SourceCatalogs produced by
the detection and deblending tasks, but it may not be true when
concatenating multiple such catalogs.

Additional Catalogs or sequences whose elements correspond in order to
the records of self (i.e. ``zip(self, *args)`` is valid) will be
subset using the same slice object used on self, and these subsets
will be returned along with the subset of self.

Parameters
----------
parent : `int` or `iterable` of `int`
    ID(s) of the parent(s) to get children for.
args : `~lsst.afw.table.Catalog`
    Additional catalogs to subset for the children to return.

Returns
-------
children : a single iterable of `~lsst.afw.table.SourceRecord`
    Children sources if ``parent`` is of type `int`, or a generator
    yielding a `~lsst.afw.table.SourceRecord`s Children sources for
    each parent if ``parent`` is an `iterable`.

Raises
------
AssertionError
    Raised if the catalog is not sorted by the parent key.

Notes
-----
Each call to this function checks if the catalog is sorted, which is
of O(n) complexity, while fetching the children is of O(log n). To
minimize the computational overhead, it is preferable to prepare an
iterable of parent ids for which the children need to be fetched and
pass the iterable as ``parent``.

Definition at line 35 of file _source.py.

35 def getChildren(self, parent, *args):
36 """Return the subset of self for which the parent field equals the
37 given value.
38
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.
44
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.
49
50 Parameters
51 ----------
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.
56
57 Returns
58 -------
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`.
63
64 Raises
65 ------
66 AssertionError
67 Raised if the catalog is not sorted by the parent key.
68
69 Notes
70 -----
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``.
76 """
77 if not self.isSorted(SourceTable.getParentKey()):
78 raise AssertionError(
79 "The table is not sorted by parent, so cannot getChildren")
80
81 def _getChildrenWithoutChecking(parent):
82 """Return the subset of self for which the parent field equals the
83 given value.
84
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.
89
90 Parameter
91 ---------
92 parent : `int`
93 ID of the parent to get children for.
94
95 Returns
96 -------
97 children : iterable of `~lsst.afw.table.SourceRecord`
98 Children sources.
99 """
100 s = self.equal_range(parent, SourceTable.getParentKey())
101 if args:
102 return (self[s],) + tuple(arg[s] for arg in args)
103 else:
104 return self[s]
105
106 try:
107 return (_getChildrenWithoutChecking(p) for p in parent)
108 except TypeError:
109 return _getChildrenWithoutChecking(parent)
110
111
112@continueClass

The documentation for this class was generated from the following file: