LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
_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 
31 #include "lsst/utils/python.h"
32 
35 #include "lsst/afw/table/Simple.h"
36 #include "lsst/afw/table/Schema.h"
37 #include "lsst/afw/table/slots.h"
38 #include "lsst/afw/table/Source.h"
42 
43 namespace py = pybind11;
44 using namespace pybind11::literals;
45 
46 namespace lsst {
47 namespace afw {
48 namespace table {
49 
50 using utils::python::WrapperCollection;
51 
52 namespace {
53 
54 using PySourceRecord = py::class_<SourceRecord, std::shared_ptr<SourceRecord>, SimpleRecord>;
55 using PySourceTable = py::class_<SourceTable, std::shared_ptr<SourceTable>, SimpleTable>;
56 using PySourceColumnView =
57  py::class_<SourceColumnViewT<SourceRecord>, std::shared_ptr<SourceColumnViewT<SourceRecord>>,
58  ColumnViewT<SourceRecord>>;
59 
60 /*
61 Declare member and static functions for a pybind11 wrapper of SourceRecord
62 */
63 PySourceRecord declareSourceRecord(WrapperCollection &wrappers) {
64  return wrappers.wrapType(PySourceRecord(wrappers.module, "SourceRecord"), [](auto &mod, auto &cls) {
65  cls.def("getFootprint", &SourceRecord::getFootprint);
66  cls.def("setFootprint", &SourceRecord::setFootprint);
67  cls.def("getTable", &SourceRecord::getTable);
68  cls.def_property_readonly("table", &SourceRecord::getTable);
69 
70  cls.def("getParent", &SourceRecord::getParent);
71  cls.def("setParent", &SourceRecord::setParent, "id"_a);
72 
73  cls.def("getPsfInstFlux", &SourceRecord::getPsfInstFlux);
74  cls.def("getPsfInstFluxErr", &SourceRecord::getPsfInstFluxErr);
75  cls.def("getPsfFluxFlag", &SourceRecord::getPsfFluxFlag);
76 
77  cls.def("getModelInstFlux", &SourceRecord::getModelInstFlux);
78  cls.def("getModelInstFluxErr", &SourceRecord::getModelInstFluxErr);
79  cls.def("getModelFluxFlag", &SourceRecord::getModelFluxFlag);
80 
81  cls.def("getApInstFlux", &SourceRecord::getApInstFlux);
82  cls.def("getApInstFluxErr", &SourceRecord::getApInstFluxErr);
83  cls.def("getApFluxFlag", &SourceRecord::getApFluxFlag);
84 
85  cls.def("getGaussianInstFlux", &SourceRecord::getGaussianInstFlux);
86  cls.def("getGaussianInstFluxErr", &SourceRecord::getGaussianInstFluxErr);
87  cls.def("getGaussianFluxFlag", &SourceRecord::getGaussianFluxFlag);
88 
89  cls.def("getCalibInstFlux", &SourceRecord::getCalibInstFlux);
90  cls.def("getCalibInstFluxErr", &SourceRecord::getCalibInstFluxErr);
91  cls.def("getCalibFluxFlag", &SourceRecord::getCalibFluxFlag);
92 
93  cls.def("getCentroid", &SourceRecord::getCentroid);
94  cls.def("getCentroidErr", &SourceRecord::getCentroidErr);
95  cls.def("getCentroidFlag", &SourceRecord::getCentroidFlag);
96 
97  cls.def("getShape", &SourceRecord::getShape);
98  cls.def("getShapeErr", &SourceRecord::getShapeErr);
99  cls.def("getShapeFlag", &SourceRecord::getShapeFlag);
100 
101  cls.def("getX", &SourceRecord::getX);
102  cls.def("getY", &SourceRecord::getY);
103  cls.def("getIxx", &SourceRecord::getIxx);
104  cls.def("getIyy", &SourceRecord::getIyy);
105  cls.def("getIxy", &SourceRecord::getIxy);
106  cls.def("updateCoord", (void (SourceRecord::*)(geom::SkyWcs const &)) & SourceRecord::updateCoord,
107  "wcs"_a);
108  cls.def("updateCoord",
109  (void (SourceRecord::*)(geom::SkyWcs const &, PointKey<double> const &)) &
110  SourceRecord::updateCoord,
111  "wcs"_a, "key"_a);
112  });
113 }
114 
115 /*
116 Declare member and static functions for a pybind11 wrapper of SourceTable
117 */
118 PySourceTable declareSourceTable(WrapperCollection &wrappers) {
119  return wrappers.wrapType(PySourceTable(wrappers.module, "SourceTable"), [](auto &mod, auto &cls) {
120  cls.def("clone", &SourceTable::clone);
121  cls.def_static("make",
122  (std::shared_ptr<SourceTable>(*)(Schema const &, std::shared_ptr<IdFactory> const &)) &
123  SourceTable::make);
124  cls.def_static("make", (std::shared_ptr<SourceTable>(*)(Schema const &)) & SourceTable::make);
125  cls.def_static("makeMinimalSchema", &SourceTable::makeMinimalSchema);
126  cls.def_static("getParentKey", &SourceTable::getParentKey);
127  cls.def("copyRecord", (std::shared_ptr<SourceRecord>(SourceTable::*)(BaseRecord const &)) &
128  SourceTable::copyRecord);
129  cls.def("copyRecord",
130  (std::shared_ptr<SourceRecord>(SourceTable::*)(BaseRecord const &, SchemaMapper const &)) &
131  SourceTable::copyRecord);
132  cls.def("makeRecord", &SourceTable::makeRecord);
133 
134  cls.def("getPsfFluxSlot", &SourceTable::getPsfFluxSlot);
135  cls.def("definePsfFlux", &SourceTable::definePsfFlux, "name"_a);
136 
137  cls.def("getModelFluxSlot", &SourceTable::getModelFluxSlot);
138  cls.def("defineModelFlux", &SourceTable::defineModelFlux, "name"_a);
139 
140  cls.def("getApFluxSlot", &SourceTable::getApFluxSlot);
141  cls.def("defineApFlux", &SourceTable::defineApFlux, "name"_a);
142 
143  cls.def("getGaussianFluxSlot", &SourceTable::getGaussianFluxSlot);
144  cls.def("defineGaussianFlux", &SourceTable::defineGaussianFlux, "name"_a);
145 
146  cls.def("getCalibFluxSlot", &SourceTable::getCalibFluxSlot);
147  cls.def("defineCalibFlux", &SourceTable::defineCalibFlux, "name"_a);
148 
149  cls.def("getCentroidSlot", &SourceTable::getCentroidSlot);
150  cls.def("defineCentroid", &SourceTable::defineCentroid, "name"_a);
151 
152  cls.def("getShapeSlot", &SourceTable::getShapeSlot);
153  cls.def("defineShape", &SourceTable::defineShape, "name"_a);
154  });
155 }
156 
157 PySourceColumnView declareSourceColumnView(WrapperCollection &wrappers) {
158  table::python::declareColumnView<SourceRecord>(wrappers, "Source", true);
159  return wrappers.wrapType(PySourceColumnView(wrappers.module, "SourceColumnView"),
160  [](auto &mod, auto &cls) {
161  using Class = SourceColumnViewT<SourceRecord>;
162  cls.def("getPsfInstFlux", &Class::getPsfInstFlux);
163  cls.def("getPsfInstFluxErr", &Class::getPsfInstFluxErr);
164  cls.def("getApInstFlux", &Class::getApInstFlux);
165  cls.def("getApInstFluxErr", &Class::getApInstFluxErr);
166  cls.def("getModelInstFlux", &Class::getModelInstFlux);
167  cls.def("getModelInstFluxErr", &Class::getModelInstFluxErr);
168  cls.def("getGaussianInstFlux", &Class::getGaussianInstFlux);
169  cls.def("getGaussianInstFluxErr", &Class::getGaussianInstFluxErr);
170  cls.def("getCalibInstFlux", &Class::getCalibInstFlux);
171  cls.def("getCalibInstFluxErr", &Class::getCalibInstFluxErr);
172  cls.def("getX", &Class::getX);
173  cls.def("getY", &Class::getY);
174  cls.def("getIxx", &Class::getIxx);
175  cls.def("getIyy", &Class::getIyy);
176  cls.def("getIxy", &Class::getIxy);
177  });
178 }
179 
180 } // namespace
181 
182 void wrapSource(WrapperCollection &wrappers) {
183  // TODO: uncomment once afw.geom uses WrapperCollection
184  // wrappers.addSignatureDependency("lsst.afw.geom.ellipses");
185 
186  // SourceFitsFlags enum values are used as integer masks, so wrap as attributes instead of an enum
187  // static_cast is required to avoid an import error (py::cast and py::int_ do not work by themselves
188  // and are not required with the static_cast)
189  auto &mod = wrappers.module;
190  mod.attr("SOURCE_IO_NO_FOOTPRINTS") = static_cast<int>(SourceFitsFlags::SOURCE_IO_NO_FOOTPRINTS);
191  mod.attr("SOURCE_IO_NO_HEAVY_FOOTPRINTS") =
193 
194  auto clsSourceRecord = declareSourceRecord(wrappers);
195  auto clsSourceTable = declareSourceTable(wrappers);
196  auto clsSourceColumnView = declareSourceColumnView(wrappers);
197  auto clsSourceCatalog = table::python::declareSortedCatalog<SourceRecord>(wrappers, "Source");
198 
199  clsSourceRecord.attr("Table") = clsSourceTable;
200  clsSourceRecord.attr("ColumnView") = clsSourceColumnView;
201  clsSourceRecord.attr("Catalog") = clsSourceCatalog;
202  clsSourceTable.attr("Record") = clsSourceRecord;
203  clsSourceTable.attr("ColumnView") = clsSourceColumnView;
204  clsSourceTable.attr("Catalog") = clsSourceCatalog;
205  clsSourceCatalog.attr("Record") = clsSourceRecord;
206  clsSourceCatalog.attr("Table") = clsSourceTable;
207  clsSourceCatalog.attr("ColumnView") = clsSourceColumnView;
208 }
209 
210 } // namespace table
211 } // namespace afw
212 } // namespace lsst
Simple.h
std::shared_ptr
STL class.
python.h
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::geom.transform.transformContinued.cls
cls
Definition: transformContinued.py:33
BaseRecord.h
slots.h
lsst::afw::table::SOURCE_IO_NO_FOOTPRINTS
@ SOURCE_IO_NO_FOOTPRINTS
Do not read/write footprints at all.
Definition: Source.h:55
columnView.h
lsst::utils::python::WrapperCollection
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition: python.h:242
catalog.h
Source.h
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::afw::table::wrapSource
void wrapSource(WrapperCollection &wrappers)
Definition: _source.cc:182
lsst::afw::table::SOURCE_IO_NO_HEAVY_FOOTPRINTS
@ SOURCE_IO_NO_HEAVY_FOOTPRINTS
Read/write heavy footprints as non-heavy footprints.
Definition: Source.h:56
sortedCatalog.h
BaseTable.h
pybind11
Definition: _GenericMap.cc:40
Schema.h
lsst::utils::python::WrapperCollection::module
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition: python.h:448