LSST Applications g180d380827+0f66a164bb,g2079a07aa2+86d27d4dc4,g2305ad1205+7d304bc7a0,g29320951ab+500695df56,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+e42ea45bea,g48712c4677+36a86eeaa5,g487adcacf7+2dd8f347ac,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+c70619cc9d,g5a732f18d5+53520f316c,g5ea96fc03c+341ea1ce94,g64a986408d+f7cd9c7162,g858d7b2824+f7cd9c7162,g8a8a8dda67+585e252eca,g99cad8db69+469ab8c039,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+c92fc63c7e,gbd866b1f37+f7cd9c7162,gc120e1dc64+02c66aa596,gc28159a63d+0e5473021a,gc3e9b769f7+b0068a2d9f,gcf0d15dbbd+e42ea45bea,gdaeeff99f8+f9a426f77a,ge6526c86ff+84383d05b3,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+f7cd9c7162,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
_source.py
Go to the documentation of this file.
1# This file is part of afw.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
21
22__all__ = []
23
24from lsst.utils import continueClass
25from lsst.pex.exceptions import LogicError
26from ._base import Catalog
27from ._table import QuadrupoleKey, SourceCatalog, SourceColumnView, SourceRecord, SourceTable
28
29Catalog.register("Source", SourceCatalog)
30
31
32@continueClass
34
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
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
113class SourceRecord: # noqa: F811
114
115 def getPsfShape(self):
116 # Catch the KeyError and raise LogicError from `pex.exception` for
117 # consistent behavior with similar C++ methods (getIxx, getIyy, etc.)
118 try:
119 return QuadrupoleKey(self.schema["slot_PsfShape"]).get(self)
120 except KeyError:
121 raise LogicError("Key is not valid (if this is a SourceRecord, make sure slot aliases have been "
122 "set up)") from None
123
124 def _getPsfShapeComponent(self, suffix):
125 # Catch the KeyError and raise LogicError from `pex.exception` for
126 # consistent behavior with similar C++ methods (getIxx, getIyy, etc.)
127 try:
128 return self["slot_PsfShape_" + suffix]
129 except KeyError:
130 raise LogicError("Key is not valid (if this is a SourceRecord, make sure slot aliases have been "
131 "set up)") from None
132
133 def getPsfIxx(self):
134 return self._getPsfShapeComponent("xx")
135
136 def getPsfIyy(self):
137 return self._getPsfShapeComponent("yy")
138
139 def getPsfIxy(self):
140 return self._getPsfShapeComponent("xy")
141
143 return self._getPsfShapeComponent("flag")
144
145
146@continueClass
147class SourceColumnView: # noqa: F811
148
149 def _getPsfShapeComponent(self, suffix):
150 # Catch the KeyError and raise LogicError from `pex.exception` for
151 # consistent behavior with similar C++ methods (getIxx, getIyy, etc.)
152 try:
153 return self["slot_PsfShape_" + suffix]
154 except KeyError:
155 raise LogicError("Key is not valid (if this is a SourceCatalog, make sure slot aliases have been "
156 "set up)") from None
157
158 def getPsfIxx(self):
159 return self._getPsfShapeComponent("xx")
160
161 def getPsfIyy(self):
162 return self._getPsfShapeComponent("yy")
163
164 def getPsfIxy(self):
165 return self._getPsfShapeComponent("xy")
166
167
168@continueClass
169class SourceTable: # noqa: F811
170
171 def definePsfShape(self, name):
172 self.schema.getAliasMap().set("slot_PsfShape", name)
getChildren(self, parent, *args)
Definition _source.py:35
Tag types used to declare specialized field types.
Definition misc.h:31
Reports errors in the logical structure of the program.
Definition Runtime.h:46
daf::base::PropertySet * set
Definition fits.cc:931