LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+1b3060144d,g18429d2f64+f642bf4753,g199a45376c+0ba108daf9,g1fd858c14a+2dcf163641,g262e1987ae+7b8c96d2ca,g29ae962dfc+3bd6ecb08a,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+53e1a9e7c5,g4595892280+fef73a337f,g47891489e3+2efcf17695,g4d44eb3520+642b70b07e,g53246c7159+8c5ae1fdc5,g67b6fd64d1+2efcf17695,g67fd3c3899+b70e05ef52,g74acd417e5+317eb4c7d4,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+2efcf17695,g8d7436a09f+3be3c13596,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+a4e7b16d9b,g97be763408+ad77d7208f,g9dd6db0277+b70e05ef52,ga681d05dcb+a3f46e7fff,gabf8522325+735880ea63,gac2eed3f23+2efcf17695,gb89ab40317+2efcf17695,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+b70e05ef52,gdab6d2f7ff+317eb4c7d4,gdc713202bf+b70e05ef52,gdfd2d52018+b10e285e0f,ge365c994fd+310e8507c4,ge410e46f29+2efcf17695,geaed405ab2+562b3308c0,gffca2db377+8c5ae1fdc5,w.2025.35
LSST Data Management Base Package
Loading...
Searching...
No Matches
_source.cc
Go to the documentation of this file.
1/*
2 * This file is part of afw.
3 *
4 * Developed for the LSST Data Management System.
5 * This product includes software developed by the LSST Project
6 * (https://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#include "pybind11/pybind11.h"
25#include "pybind11/eigen.h"
26
27#include <memory>
28
29#include "ndarray/pybind11.h"
30
32
42
43namespace py = pybind11;
44using namespace pybind11::literals;
45
46namespace lsst {
47namespace afw {
48namespace table {
49
50using cpputils::python::WrapperCollection;
51
52namespace {
53
54using PySourceRecord = py::classh<SourceRecord, SimpleRecord>;
55using PySourceTable = py::classh<SourceTable, SimpleTable>;
56using PySourceColumnView = py::classh<SourceColumnViewT<SourceRecord>, ColumnViewT<SourceRecord>>;
57
58/*
59Declare member and static functions for a pybind11 wrapper of SourceRecord
60*/
61PySourceRecord declareSourceRecord(WrapperCollection &wrappers) {
62 return wrappers.wrapType(PySourceRecord(wrappers.module, "SourceRecord"), [](auto &mod, auto &cls) {
63 cls.def("getFootprint", &SourceRecord::getFootprint);
64 cls.def("setFootprint", &SourceRecord::setFootprint);
65 cls.def("getTable", &SourceRecord::getTable);
66 cls.def_property_readonly("table", &SourceRecord::getTable);
67
68 cls.def("getParent", &SourceRecord::getParent);
69 cls.def("setParent", &SourceRecord::setParent, "id"_a);
70
71 cls.def("getPsfInstFlux", &SourceRecord::getPsfInstFlux);
72 cls.def("getPsfInstFluxErr", &SourceRecord::getPsfInstFluxErr);
73 cls.def("getPsfFluxFlag", &SourceRecord::getPsfFluxFlag);
74
75 cls.def("getModelInstFlux", &SourceRecord::getModelInstFlux);
76 cls.def("getModelInstFluxErr", &SourceRecord::getModelInstFluxErr);
77 cls.def("getModelFluxFlag", &SourceRecord::getModelFluxFlag);
78
79 cls.def("getApInstFlux", &SourceRecord::getApInstFlux);
80 cls.def("getApInstFluxErr", &SourceRecord::getApInstFluxErr);
81 cls.def("getApFluxFlag", &SourceRecord::getApFluxFlag);
82
83 cls.def("getGaussianInstFlux", &SourceRecord::getGaussianInstFlux);
84 cls.def("getGaussianInstFluxErr", &SourceRecord::getGaussianInstFluxErr);
85 cls.def("getGaussianFluxFlag", &SourceRecord::getGaussianFluxFlag);
86
87 cls.def("getCalibInstFlux", &SourceRecord::getCalibInstFlux);
88 cls.def("getCalibInstFluxErr", &SourceRecord::getCalibInstFluxErr);
89 cls.def("getCalibFluxFlag", &SourceRecord::getCalibFluxFlag);
90
91 cls.def("getCentroid", &SourceRecord::getCentroid);
92 cls.def("getCentroidErr", &SourceRecord::getCentroidErr);
93 cls.def("getCentroidFlag", &SourceRecord::getCentroidFlag);
94
95 cls.def("getShape", &SourceRecord::getShape);
96 cls.def("getShapeErr", &SourceRecord::getShapeErr);
97 cls.def("getShapeFlag", &SourceRecord::getShapeFlag);
98
99 cls.def("getX", &SourceRecord::getX);
100 cls.def("getY", &SourceRecord::getY);
101 cls.def("getIxx", &SourceRecord::getIxx);
102 cls.def("getIyy", &SourceRecord::getIyy);
103 cls.def("getIxy", &SourceRecord::getIxy);
104 cls.def("updateCoord", (void (SourceRecord::*)(geom::SkyWcs const &, bool)) & SourceRecord::updateCoord,
105 "wcs"_a, "include_covariance"_a=true);
106 cls.def("updateCoord",
107 (void (SourceRecord::*)(geom::SkyWcs const &, PointKey<double> const &, bool)) &
108 SourceRecord::updateCoord,
109 "wcs"_a, "key"_a, "include_covariance"_a=true);
110 });
111}
112
113/*
114Declare member and static functions for a pybind11 wrapper of SourceTable
115*/
116PySourceTable declareSourceTable(WrapperCollection &wrappers) {
117 return wrappers.wrapType(PySourceTable(wrappers.module, "SourceTable"), [](auto &mod, auto &cls) {
118 cls.def("clone", &SourceTable::clone);
119 cls.def_static("make",
120 (std::shared_ptr<SourceTable>(*)(Schema const &, std::shared_ptr<IdFactory> const &)) &
121 SourceTable::make);
122 cls.def_static("make", (std::shared_ptr<SourceTable>(*)(Schema const &)) & SourceTable::make);
123 cls.def_static("makeMinimalSchema", &SourceTable::makeMinimalSchema);
124 cls.def_static("getParentKey", &SourceTable::getParentKey);
125 cls.def("copyRecord", (std::shared_ptr<SourceRecord>(SourceTable::*)(BaseRecord const &)) &
126 SourceTable::copyRecord);
127 cls.def("copyRecord",
128 (std::shared_ptr<SourceRecord>(SourceTable::*)(BaseRecord const &, SchemaMapper const &)) &
129 SourceTable::copyRecord);
130 cls.def("makeRecord", &SourceTable::makeRecord);
131
132 cls.def("getPsfFluxSlot", &SourceTable::getPsfFluxSlot);
133 cls.def("definePsfFlux", &SourceTable::definePsfFlux, "name"_a);
134
135 cls.def("getModelFluxSlot", &SourceTable::getModelFluxSlot);
136 cls.def("defineModelFlux", &SourceTable::defineModelFlux, "name"_a);
137
138 cls.def("getApFluxSlot", &SourceTable::getApFluxSlot);
139 cls.def("defineApFlux", &SourceTable::defineApFlux, "name"_a);
140
141 cls.def("getGaussianFluxSlot", &SourceTable::getGaussianFluxSlot);
142 cls.def("defineGaussianFlux", &SourceTable::defineGaussianFlux, "name"_a);
143
144 cls.def("getCalibFluxSlot", &SourceTable::getCalibFluxSlot);
145 cls.def("defineCalibFlux", &SourceTable::defineCalibFlux, "name"_a);
146
147 cls.def("getCentroidSlot", &SourceTable::getCentroidSlot);
148 cls.def("defineCentroid", &SourceTable::defineCentroid, "name"_a);
149
150 cls.def("getShapeSlot", &SourceTable::getShapeSlot);
151 cls.def("defineShape", &SourceTable::defineShape, "name"_a);
152 });
153}
154
155PySourceColumnView declareSourceColumnView(WrapperCollection &wrappers) {
156 table::python::declareColumnView<SourceRecord>(wrappers, "Source", true);
157 return wrappers.wrapType(PySourceColumnView(wrappers.module, "SourceColumnView"),
158 [](auto &mod, auto &cls) {
159 using Class = SourceColumnViewT<SourceRecord>;
160 cls.def("getPsfInstFlux", &Class::getPsfInstFlux);
161 cls.def("getPsfInstFluxErr", &Class::getPsfInstFluxErr);
162 cls.def("getApInstFlux", &Class::getApInstFlux);
163 cls.def("getApInstFluxErr", &Class::getApInstFluxErr);
164 cls.def("getModelInstFlux", &Class::getModelInstFlux);
165 cls.def("getModelInstFluxErr", &Class::getModelInstFluxErr);
166 cls.def("getGaussianInstFlux", &Class::getGaussianInstFlux);
167 cls.def("getGaussianInstFluxErr", &Class::getGaussianInstFluxErr);
168 cls.def("getCalibInstFlux", &Class::getCalibInstFlux);
169 cls.def("getCalibInstFluxErr", &Class::getCalibInstFluxErr);
170 cls.def("getX", &Class::getX);
171 cls.def("getY", &Class::getY);
172 cls.def("getIxx", &Class::getIxx);
173 cls.def("getIyy", &Class::getIyy);
174 cls.def("getIxy", &Class::getIxy);
175 });
176}
177
178} // namespace
179
181 // TODO: uncomment once afw.geom uses WrapperCollection
182 // wrappers.addSignatureDependency("lsst.afw.geom.ellipses");
183
184 // SourceFitsFlags enum values are used as integer masks, so wrap as attributes instead of an enum
185 // static_cast is required to avoid an import error (py::cast and py::int_ do not work by themselves
186 // and are not required with the static_cast)
187 auto &mod = wrappers.module;
188 mod.attr("SOURCE_IO_NO_FOOTPRINTS") = static_cast<int>(SourceFitsFlags::SOURCE_IO_NO_FOOTPRINTS);
189 mod.attr("SOURCE_IO_NO_HEAVY_FOOTPRINTS") =
191
192 auto clsSourceRecord = declareSourceRecord(wrappers);
193 auto clsSourceTable = declareSourceTable(wrappers);
194 auto clsSourceColumnView = declareSourceColumnView(wrappers);
195 auto clsSourceCatalog = table::python::declareSortedCatalog<SourceRecord>(wrappers, "Source");
196
197 clsSourceRecord.attr("Table") = clsSourceTable;
198 clsSourceRecord.attr("ColumnView") = clsSourceColumnView;
199 clsSourceRecord.attr("Catalog") = clsSourceCatalog;
200 clsSourceTable.attr("Record") = clsSourceRecord;
201 clsSourceTable.attr("ColumnView") = clsSourceColumnView;
202 clsSourceTable.attr("Catalog") = clsSourceCatalog;
203 clsSourceCatalog.attr("Record") = clsSourceRecord;
204 clsSourceCatalog.attr("Table") = clsSourceTable;
205 clsSourceCatalog.attr("ColumnView") = clsSourceColumnView;
206}
207
208} // namespace table
209} // namespace afw
210} // namespace lsst
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
Definition python.h:391
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition python.h:448
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition python.h:242
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition python.h:448
PySortedCatalog< Record > declareSortedCatalog(cpputils::python::WrapperCollection &wrappers, std::string const &name, bool isBase=false)
Wrap an instantiation of lsst::afw::table::SortedCatalogT<Record>.
PyColumnView< Record > declareColumnView(cpputils::python::WrapperCollection &wrappers, std::string const &name, bool isBase=false)
Declare member and static functions for a given instantiation of lsst::afw::table::ColumnViewT<Record...
Definition columnView.h:52
void wrapSource(WrapperCollection &wrappers)
Definition _source.cc:180
@ SOURCE_IO_NO_FOOTPRINTS
Do not read/write footprints at all.
Definition Source.h:53
@ SOURCE_IO_NO_HEAVY_FOOTPRINTS
Read/write heavy footprints as non-heavy footprints.
Definition Source.h:54