LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
Public Member Functions | List of all members
lsst.afw.table._source.SourceCatalog Class Reference

Public Member Functions

def getChildren (self, parent, *args)
 

Detailed Description

Definition at line 32 of file _source.py.

Member Function Documentation

◆ getChildren()

def 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 34 of file _source.py.

34  def getChildren(self, parent, *args):
35  """Return the subset of self for which the parent field equals the
36  given value.
37 
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.
43 
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.
48 
49  Parameters
50  ----------
51  parent : `int` or `iterable` of `int`
52  ID(s) of the parent(s) to get children for.
53  args : `~lsst.afw.table.Catalog`
54  Additional catalogs to subset for the children to return.
55 
56  Returns
57  -------
58  children : a single iterable of `~lsst.afw.table.SourceRecord`
59  Children sources if ``parent`` is of type `int`, or a generator
60  yielding a `~lsst.afw.table.SourceRecord`s Children sources for
61  each parent if ``parent`` is an `iterable`.
62 
63  Raises
64  ------
65  AssertionError
66  Raised if the catalog is not sorted by the parent key.
67 
68  Notes
69  -----
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``.
75  """
76  if not self.isSorted(SourceTable.getParentKey()):
77  raise AssertionError(
78  "The table is not sorted by parent, so cannot getChildren")
79 
80  def _getChildrenWithoutChecking(parent):
81  """Return the subset of self for which the parent field equals the
82  given value.
83 
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.
88 
89  Parameter
90  ---------
91  parent : `int`
92  ID of the parent to get children for.
93 
94  Returns
95  -------
96  children : iterable of `~lsst.afw.table.SourceRecord`
97  Children sources.
98  """
99  s = self.equal_range(parent, SourceTable.getParentKey())
100  if args:
101  return (self[s],) + tuple(arg[s] for arg in args)
102  else:
103  return self[s]
104 
105  try:
106  return (_getChildrenWithoutChecking(p) for p in parent)
107  except TypeError:
108  return _getChildrenWithoutChecking(parent)

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