LSSTApplications  18.1.0
LSSTDataManagementBasePackage
source.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2016 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include "pybind11/pybind11.h"
24 #include "pybind11/eigen.h"
25 
26 #include <memory>
27 
28 #include "ndarray/pybind11.h"
29 
32 #include "lsst/afw/table/Simple.h"
33 #include "lsst/afw/table/Schema.h"
34 #include "lsst/afw/table/slots.h"
35 #include "lsst/afw/table/Source.h"
39 
40 namespace py = pybind11;
41 using namespace pybind11::literals;
42 
43 namespace lsst {
44 namespace afw {
45 namespace table {
46 namespace {
47 
48 using PySourceRecord = py::class_<SourceRecord, std::shared_ptr<SourceRecord>, SimpleRecord>;
49 using PySourceTable = py::class_<SourceTable, std::shared_ptr<SourceTable>, SimpleTable>;
50 using PySourceColumnView =
51  py::class_<SourceColumnViewT<SourceRecord>, std::shared_ptr<SourceColumnViewT<SourceRecord>>,
52  ColumnViewT<SourceRecord>>;
53 
54 /*
55 Declare member and static functions for a pybind11 wrapper of SourceRecord
56 */
57 PySourceRecord declareSourceRecord(py::module &mod) {
58  PySourceRecord cls(mod, "SourceRecord");
59  cls.def("getFootprint", &SourceRecord::getFootprint);
60  cls.def("setFootprint", &SourceRecord::setFootprint);
61  cls.def("getTable", &SourceRecord::getTable);
62  cls.def_property_readonly("table", &SourceRecord::getTable);
63 
64  cls.def("getParent", &SourceRecord::getParent);
65  cls.def("setParent", &SourceRecord::setParent, "id"_a);
66 
67  cls.def("getPsfInstFlux", &SourceRecord::getPsfInstFlux);
68  cls.def("getPsfInstFluxErr", &SourceRecord::getPsfInstFluxErr);
69  cls.def("getPsfFluxFlag", &SourceRecord::getPsfFluxFlag);
70 
71  cls.def("getModelInstFlux", &SourceRecord::getModelInstFlux);
72  cls.def("getModelInstFluxErr", &SourceRecord::getModelInstFluxErr);
73  cls.def("getModelFluxFlag", &SourceRecord::getModelFluxFlag);
74 
75  cls.def("getApInstFlux", &SourceRecord::getApInstFlux);
76  cls.def("getApInstFluxErr", &SourceRecord::getApInstFluxErr);
77  cls.def("getApFluxFlag", &SourceRecord::getApFluxFlag);
78 
79  cls.def("getGaussianInstFlux", &SourceRecord::getGaussianInstFlux);
80  cls.def("getGaussianInstFluxErr", &SourceRecord::getGaussianInstFluxErr);
81  cls.def("getGaussianFluxFlag", &SourceRecord::getGaussianFluxFlag);
82 
83  cls.def("getCalibInstFlux", &SourceRecord::getCalibInstFlux);
84  cls.def("getCalibInstFluxErr", &SourceRecord::getCalibInstFluxErr);
85  cls.def("getCalibFluxFlag", &SourceRecord::getCalibFluxFlag);
86 
87  cls.def("getCentroid", &SourceRecord::getCentroid);
88  cls.def("getCentroidErr", &SourceRecord::getCentroidErr);
89  cls.def("getCentroidFlag", &SourceRecord::getCentroidFlag);
90 
91  cls.def("getShape", &SourceRecord::getShape);
92  cls.def("getShapeErr", &SourceRecord::getShapeErr);
93  cls.def("getShapeFlag", &SourceRecord::getShapeFlag);
94 
95  cls.def("getX", &SourceRecord::getX);
96  cls.def("getY", &SourceRecord::getY);
97  cls.def("getIxx", &SourceRecord::getIxx);
98  cls.def("getIyy", &SourceRecord::getIyy);
99  cls.def("getIxy", &SourceRecord::getIxy);
100  cls.def("updateCoord", (void (SourceRecord::*)(geom::SkyWcs const &)) & SourceRecord::updateCoord,
101  "wcs"_a);
102  cls.def("updateCoord",
103  (void (SourceRecord::*)(geom::SkyWcs const &, PointKey<double> const &)) &
104  SourceRecord::updateCoord,
105  "wcs"_a, "key"_a);
106  return cls;
107 }
108 
109 /*
110 Declare member and static functions for a pybind11 wrapper of SourceTable
111 */
112 PySourceTable declareSourceTable(py::module &mod) {
113  PySourceTable cls(mod, "SourceTable");
114  cls.def("clone", &SourceTable::clone);
115  cls.def_static("make",
116  (std::shared_ptr<SourceTable>(*)(Schema const &, std::shared_ptr<IdFactory> const &)) &
117  SourceTable::make);
118  cls.def_static("make", (std::shared_ptr<SourceTable>(*)(Schema const &)) & SourceTable::make);
119  cls.def_static("makeMinimalSchema", &SourceTable::makeMinimalSchema);
120  cls.def_static("getParentKey", &SourceTable::getParentKey);
121  cls.def("copyRecord",
122  (std::shared_ptr<SourceRecord>(SourceTable::*)(BaseRecord const &)) & SourceTable::copyRecord);
123  cls.def("copyRecord",
124  (std::shared_ptr<SourceRecord>(SourceTable::*)(BaseRecord const &, SchemaMapper const &)) &
125  SourceTable::copyRecord);
126  cls.def("makeRecord", &SourceTable::makeRecord);
127 
128  cls.def("getPsfFluxSlot", &SourceTable::getPsfFluxSlot);
129  cls.def("definePsfFlux", &SourceTable::definePsfFlux, "name"_a);
130 
131  cls.def("getModelFluxSlot", &SourceTable::getModelFluxSlot);
132  cls.def("defineModelFlux", &SourceTable::defineModelFlux, "name"_a);
133 
134  cls.def("getApFluxSlot", &SourceTable::getApFluxSlot);
135  cls.def("defineApFlux", &SourceTable::defineApFlux, "name"_a);
136 
137  cls.def("getGaussianFluxSlot", &SourceTable::getGaussianFluxSlot);
138  cls.def("defineGaussianFlux", &SourceTable::defineGaussianFlux, "name"_a);
139 
140  cls.def("getCalibFluxSlot", &SourceTable::getCalibFluxSlot);
141  cls.def("defineCalibFlux", &SourceTable::defineCalibFlux, "name"_a);
142 
143  cls.def("getCentroidSlot", &SourceTable::getCentroidSlot);
144  cls.def("defineCentroid", &SourceTable::defineCentroid, "name"_a);
145  cls.def("getCentroidDefinition", &SourceTable::getCentroidDefinition);
146  cls.def("hasCentroidSlot", &SourceTable::hasCentroidSlot);
147  cls.def("getCentroidKey", &SourceTable::getCentroidKey);
148  cls.def("getCentroidErrKey", &SourceTable::getCentroidErrKey);
149  cls.def("getCentroidFlagKey", &SourceTable::getCentroidFlagKey);
150 
151  cls.def("getShapeSlot", &SourceTable::getShapeSlot);
152  cls.def("defineShape", &SourceTable::defineShape, "name"_a);
153  cls.def("getShapeDefinition", &SourceTable::getShapeDefinition);
154  cls.def("hasShapeSlot", &SourceTable::hasShapeSlot);
155  cls.def("getShapeKey", &SourceTable::getShapeKey);
156  cls.def("getShapeErrKey", &SourceTable::getShapeErrKey);
157  cls.def("getShapeFlagKey", &SourceTable::getShapeFlagKey);
158 
159  return cls;
160 }
161 
162 PySourceColumnView declareSourceColumnView(py::module &mod) {
163  table::python::declareColumnView<SourceRecord>(mod, "Source", true);
164  PySourceColumnView cls(mod, "SourceColumnView");
165  using SourceColumnView = SourceColumnViewT<SourceRecord>;
166  cls.def("getPsfInstFlux", &SourceColumnView::getPsfInstFlux);
167  cls.def("getPsfInstFluxErr", &SourceColumnView::getPsfInstFluxErr);
168  cls.def("getApInstFlux", &SourceColumnView::getApInstFlux);
169  cls.def("getApInstFluxErr", &SourceColumnView::getApInstFluxErr);
170  cls.def("getModelInstFlux", &SourceColumnView::getModelInstFlux);
171  cls.def("getModelInstFluxErr", &SourceColumnView::getModelInstFluxErr);
172  cls.def("getGaussianInstFlux", &SourceColumnView::getGaussianInstFlux);
173  cls.def("getGaussianInstFluxErr", &SourceColumnView::getGaussianInstFluxErr);
174  cls.def("getCalibInstFlux", &SourceColumnView::getCalibInstFlux);
175  cls.def("getCalibInstFluxErr", &SourceColumnView::getCalibInstFluxErr);
176  cls.def("getX", &SourceColumnView::getX);
177  cls.def("getY", &SourceColumnView::getY);
178  cls.def("getIxx", &SourceColumnView::getIxx);
179  cls.def("getIyy", &SourceColumnView::getIyy);
180  cls.def("getIxy", &SourceColumnView::getIxy);
181  return cls;
182 };
183 
184 PYBIND11_MODULE(source, mod) {
185  py::module::import("lsst.afw.geom.ellipses");
186  py::module::import("lsst.afw.table.simple");
187  py::module::import("lsst.afw.table.aggregates");
188  py::module::import("lsst.afw.table.slots");
189 
190  // SourceFitsFlags enum values are used as integer masks, so wrap as attributes instead of an enum
191  // static_cast is required to avoid an import error (py::cast and py::int_ do not work by themselves
192  // and are not required with the static_cast)
193  mod.attr("SOURCE_IO_NO_FOOTPRINTS") = static_cast<int>(SourceFitsFlags::SOURCE_IO_NO_FOOTPRINTS);
194  mod.attr("SOURCE_IO_NO_HEAVY_FOOTPRINTS") =
196 
197  auto clsSourceRecord = declareSourceRecord(mod);
198  auto clsSourceTable = declareSourceTable(mod);
199  auto clsSourceColumnView = declareSourceColumnView(mod);
200  auto clsSourceCatalog = table::python::declareSortedCatalog<SourceRecord>(mod, "Source");
201 
202  clsSourceRecord.attr("Table") = clsSourceTable;
203  clsSourceRecord.attr("ColumnView") = clsSourceColumnView;
204  clsSourceRecord.attr("Catalog") = clsSourceCatalog;
205  clsSourceTable.attr("Record") = clsSourceRecord;
206  clsSourceTable.attr("ColumnView") = clsSourceColumnView;
207  clsSourceTable.attr("Catalog") = clsSourceCatalog;
208  clsSourceCatalog.attr("Record") = clsSourceRecord;
209  clsSourceCatalog.attr("Table") = clsSourceTable;
210  clsSourceCatalog.attr("ColumnView") = clsSourceColumnView;
211 }
212 } // namespace
213 } // namespace table
214 } // namespace afw
215 } // namespace lsst
PYBIND11_MODULE(camera, mod)
Definition: camera.cc:34
A base class for image defects.
SourceColumnViewT< SourceRecord > SourceColumnView
Definition: fwd.h:83
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
Read/write heavy footprints as non-heavy footprints.
Definition: Source.h:58
Do not read/write footprints at all.
Definition: Source.h:57