lsst.afw  13.0-73-gb2a4e38
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
35 
36 namespace py = pybind11;
37 using namespace py::literals;
38 
39 namespace lsst {
40 namespace afw {
41 namespace detection {
42 
43 namespace {
44 
45 using PyPeakRecord = py::class_<PeakRecord, std::shared_ptr<PeakRecord>, table::BaseRecord>;
46 using PyPeakTable = py::class_<PeakTable, std::shared_ptr<PeakTable>, table::BaseTable>;
47 
51 void declarePeakRecord(PyPeakRecord &cls) {
52  cls.def("getTable", &PeakRecord::getTable);
53  cls.def_property_readonly("table", &PeakRecord::getTable);
54  cls.def("getId", &PeakRecord::getId);
55  cls.def("setId", &PeakRecord::setId);
56  cls.def("getIx", &PeakRecord::getIx);
57  cls.def("getIy", &PeakRecord::getIy);
58  cls.def("setIx", &PeakRecord::setIx);
59  cls.def("setIy", &PeakRecord::setIy);
60  cls.def("getI", &PeakRecord::getI);
61  cls.def("getCentroid", (afw::geom::Point2I (PeakRecord::*)(bool) const) & PeakRecord::getCentroid);
62  cls.def("getCentroid", (afw::geom::Point2D (PeakRecord::*)() const) & PeakRecord::getCentroid);
63  cls.def("getFx", &PeakRecord::getFx);
64  cls.def("getFy", &PeakRecord::getFy);
65  cls.def("setFx", &PeakRecord::setFx);
66  cls.def("setFy", &PeakRecord::setFy);
67  cls.def("getF", &PeakRecord::getF);
68  cls.def("getPeakValue", &PeakRecord::getPeakValue);
69  cls.def("setPeakValue", &PeakRecord::setPeakValue);
70  auto streamStr = [](PeakRecord const &self) {
71  std::stringstream buffer;
72  buffer << self;
73  return buffer.str();
74  };
75  cls.def("__str__", streamStr);
76  cls.def("__repr__", streamStr);
77 }
78 
82 void declarePeakTable(PyPeakTable &cls) {
83  cls.def_static("make", &PeakTable::make, "schema"_a, "forceNew"_a = false);
84  cls.def_static("makeMinimalSchema", &PeakTable::makeMinimalSchema);
85  cls.def_static("checkSchema", &PeakTable::checkSchema, "schema"_a);
86  cls.def("getIdFactory", (std::shared_ptr<table::IdFactory> (PeakTable::*)()) & PeakTable::getIdFactory);
87  cls.def("setIdFactory", &PeakTable::setIdFactory, "factory"_a);
88  cls.def_static("getIdKey", &PeakTable::getIdKey);
89  cls.def_static("getIxKey", &PeakTable::getIxKey);
90  cls.def_static("getIyKey", &PeakTable::getIyKey);
91  cls.def_static("getFxKey", &PeakTable::getFxKey);
92  cls.def_static("getFyKey", &PeakTable::getFyKey);
93  cls.def_static("getPeakValueKey", &PeakTable::getPeakValueKey);
94  cls.def("clone", &PeakTable::clone);
95  cls.def("makeRecord", &PeakTable::makeRecord);
96  cls.def("copyRecord", (std::shared_ptr<PeakRecord> (PeakTable::*)(afw::table::BaseRecord const &)) &
97  PeakTable::copyRecord);
98  cls.def("copyRecord", (std::shared_ptr<PeakRecord> (PeakTable::*)(afw::table::BaseRecord const &,
99  afw::table::SchemaMapper const &)) &
100  PeakTable::copyRecord);
101 }
102 
103 } // lsst::afw::detection::<anonymous>
104 
106  py::module mod("_peak", "Python wrapper for afw _peak library");
107 
108  /* Module level */
109  PyPeakRecord clsPeakRecord(mod, "PeakRecord");
110  PyPeakTable clsPeakTable(mod, "PeakTable");
111 
112  /* Members */
113  declarePeakRecord(clsPeakRecord);
114  declarePeakTable(clsPeakTable);
115  auto clsPeakColumnView = table::python::declareColumnView<PeakRecord>(mod, "Peak");
116  auto clsPeakCatalog = table::python::declareCatalog<PeakRecord>(mod, "Peak");
117 
118  clsPeakRecord.attr("Table") = clsPeakTable;
119  clsPeakRecord.attr("ColumnView") = clsPeakColumnView;
120  clsPeakRecord.attr("Catalog") = clsPeakCatalog;
121  clsPeakTable.attr("Record") = clsPeakRecord;
122  clsPeakTable.attr("ColumnView") = clsPeakColumnView;
123  clsPeakTable.attr("Catalog") = clsPeakCatalog;
124  clsPeakCatalog.attr("Record") = clsPeakRecord;
125  clsPeakCatalog.attr("Table") = clsPeakTable;
126  clsPeakCatalog.attr("ColumnView") = clsPeakColumnView;
127 
128  return mod.ptr();
129 }
130 }
131 }
132 } // lsst::afw::detection
PYBIND11_PLUGIN(_cameraPoint)
Definition: cameraPoint.cc:35
Point< double, 2 > Point2D
Definition: Point.h:273
double const _a
Definition: RandomImage.cc:77
Point< int, 2 > Point2I
Definition: Point.h:270