LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
_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_getPsfShapeComponent("xx")
135
136 def getPsfIyy(self):
137 return self._getPsfShapeComponent_getPsfShapeComponent("yy")
138
139 def getPsfIxy(self):
140 return self._getPsfShapeComponent_getPsfShapeComponent("xy")
141
143 return self._getPsfShapeComponent_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_getPsfShapeComponent("xx")
160
161 def getPsfIyy(self):
162 return self._getPsfShapeComponent_getPsfShapeComponent("yy")
163
164 def getPsfIxy(self):
165 return self._getPsfShapeComponent_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:912