LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
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