LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
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.
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
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)
def getChildren(self, parent, *args)
Definition: _source.py:35
def _getPsfShapeComponent(self, suffix)
Definition: _source.py:124
Record class that contains measurements made on a single exposure.
Definition: Source.h:78
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
daf::base::PropertySet * set
Definition: fits.cc:927