LSSTApplications  18.1.0
LSSTDataManagementBasePackage
peak.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 
25 #include <memory>
26 #include <sstream>
27 
28 //#include <pybind11/stl.h>
29 
30 #include "lsst/utils/python.h"
31 
37 
38 namespace py = pybind11;
39 using namespace py::literals;
40 
41 namespace lsst {
42 namespace afw {
43 namespace detection {
44 
45 namespace {
46 
47 using PyPeakRecord = py::class_<PeakRecord, std::shared_ptr<PeakRecord>, table::BaseRecord>;
48 using PyPeakTable = py::class_<PeakTable, std::shared_ptr<PeakTable>, table::BaseTable>;
49 
53 void declarePeakRecord(PyPeakRecord &cls) {
54  cls.def("getTable", &PeakRecord::getTable);
55  cls.def_property_readonly("table", &PeakRecord::getTable);
56  cls.def("getId", &PeakRecord::getId);
57  cls.def("setId", &PeakRecord::setId);
58  cls.def("getIx", &PeakRecord::getIx);
59  cls.def("getIy", &PeakRecord::getIy);
60  cls.def("setIx", &PeakRecord::setIx);
61  cls.def("setIy", &PeakRecord::setIy);
62  cls.def("getI", &PeakRecord::getI);
63  cls.def("getCentroid", (lsst::geom::Point2I (PeakRecord::*)(bool) const) & PeakRecord::getCentroid);
64  cls.def("getCentroid", (lsst::geom::Point2D (PeakRecord::*)() const) & PeakRecord::getCentroid);
65  cls.def("getFx", &PeakRecord::getFx);
66  cls.def("getFy", &PeakRecord::getFy);
67  cls.def("setFx", &PeakRecord::setFx);
68  cls.def("setFy", &PeakRecord::setFy);
69  cls.def("getF", &PeakRecord::getF);
70  cls.def("getPeakValue", &PeakRecord::getPeakValue);
71  cls.def("setPeakValue", &PeakRecord::setPeakValue);
72  utils::python::addOutputOp(cls, "__str__");
73  utils::python::addOutputOp(cls, "__repr__");
74 }
75 
79 void declarePeakTable(PyPeakTable &cls) {
80  cls.def_static("make", &PeakTable::make, "schema"_a, "forceNew"_a = false);
81  cls.def_static("makeMinimalSchema", &PeakTable::makeMinimalSchema);
82  cls.def_static("checkSchema", &PeakTable::checkSchema, "schema"_a);
83  cls.def("getIdFactory", (std::shared_ptr<table::IdFactory> (PeakTable::*)()) & PeakTable::getIdFactory);
84  cls.def("setIdFactory", &PeakTable::setIdFactory, "factory"_a);
85  cls.def_static("getIdKey", &PeakTable::getIdKey);
86  cls.def_static("getIxKey", &PeakTable::getIxKey);
87  cls.def_static("getIyKey", &PeakTable::getIyKey);
88  cls.def_static("getFxKey", &PeakTable::getFxKey);
89  cls.def_static("getFyKey", &PeakTable::getFyKey);
90  cls.def_static("getPeakValueKey", &PeakTable::getPeakValueKey);
91  cls.def("clone", &PeakTable::clone);
92  cls.def("makeRecord", &PeakTable::makeRecord);
93  cls.def("copyRecord", (std::shared_ptr<PeakRecord> (PeakTable::*)(afw::table::BaseRecord const &)) &
94  PeakTable::copyRecord);
95  cls.def("copyRecord", (std::shared_ptr<PeakRecord> (PeakTable::*)(afw::table::BaseRecord const &,
96  afw::table::SchemaMapper const &)) &
97  PeakTable::copyRecord);
98 }
99 
100 } // lsst::afw::detection::<anonymous>
101 
102 PYBIND11_MODULE(peak, mod) {
103  /* Module level */
104  PyPeakRecord clsPeakRecord(mod, "PeakRecord");
105  PyPeakTable clsPeakTable(mod, "PeakTable");
106 
107  /* Members */
108  declarePeakRecord(clsPeakRecord);
109  declarePeakTable(clsPeakTable);
110  auto clsPeakColumnView = table::python::declareColumnView<PeakRecord>(mod, "Peak");
111  auto clsPeakCatalog = table::python::declareCatalog<PeakRecord>(mod, "Peak");
112 
113  clsPeakRecord.attr("Table") = clsPeakTable;
114  clsPeakRecord.attr("ColumnView") = clsPeakColumnView;
115  clsPeakRecord.attr("Catalog") = clsPeakCatalog;
116  clsPeakTable.attr("Record") = clsPeakRecord;
117  clsPeakTable.attr("ColumnView") = clsPeakColumnView;
118  clsPeakTable.attr("Catalog") = clsPeakCatalog;
119  clsPeakCatalog.attr("Record") = clsPeakRecord;
120  clsPeakCatalog.attr("Table") = clsPeakTable;
121  clsPeakCatalog.attr("ColumnView") = clsPeakColumnView;
122 }
123 }
124 }
125 } // lsst::afw::detection
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
Definition: python.h:87
A base class for image defects.
PYBIND11_MODULE(peak, mod)
Definition: peak.cc:102