LSSTApplications  18.1.0
LSSTDataManagementBasePackage
simple.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 "ndarray/pybind11.h"
25 
28 #include "lsst/afw/table/Simple.h"
32 
33 namespace py = pybind11;
34 using namespace py::literals;
35 
36 namespace lsst {
37 namespace afw {
38 namespace table {
39 namespace {
40 
41 using PySimpleTable = py::class_<SimpleTable, std::shared_ptr<SimpleTable>, BaseTable>;
42 using PySimpleRecord = py::class_<SimpleRecord, std::shared_ptr<SimpleRecord>, BaseRecord>;
43 
44 PySimpleRecord declareSimpleRecord(py::module &mod) {
45  PySimpleRecord cls(mod, "SimpleRecord");
46  cls.def("getId", &SimpleRecord::getId);
47  cls.def("setId", &SimpleRecord::setId);
48  cls.def("getTable", &SimpleRecord::getTable);
49  cls.def_property_readonly("table", &SimpleRecord::getTable);
50  cls.def("getCoord", &SimpleRecord::getCoord);
51  cls.def("setCoord", &SimpleRecord::setCoord);
52  cls.def("getRa", &SimpleRecord::getRa);
53  cls.def("setRa", &SimpleRecord::setRa);
54  cls.def("getDec", &SimpleRecord::getDec);
55  cls.def("setDec", &SimpleRecord::setDec);
56  return cls;
57 }
58 
59 PySimpleTable declareSimpleTable(py::module &mod) {
60  PySimpleTable cls(mod, "SimpleTable");
61  cls.def_static("make",
62  (std::shared_ptr<SimpleTable>(*)(Schema const &, std::shared_ptr<IdFactory> const &)) &
63  SimpleTable::make);
64  cls.def_static("make", (std::shared_ptr<SimpleTable>(*)(Schema const &)) & SimpleTable::make);
65  cls.def_static("makeMinimalSchema", &SimpleTable::makeMinimalSchema);
66  cls.def_static("checkSchema", &SimpleTable::checkSchema, "schema"_a);
67  cls.def_static("getIdKey", &SimpleTable::getIdKey);
68  cls.def_static("getCoordKey", &SimpleTable::getCoordKey);
69 
70  cls.def("getIdFactory", (std::shared_ptr<IdFactory> (SimpleTable::*)()) & SimpleTable::getIdFactory);
71  cls.def("setIdFactory", &SimpleTable::setIdFactory, "idFactory"_a);
72  cls.def("clone", &SimpleTable::clone);
73  cls.def("makeRecord", &SimpleTable::makeRecord);
74  cls.def("copyRecord",
75  (std::shared_ptr<SimpleRecord> (SimpleTable::*)(BaseRecord const &)) & SimpleTable::copyRecord,
76  "other"_a);
77  cls.def("copyRecord",
78  (std::shared_ptr<SimpleRecord> (SimpleTable::*)(BaseRecord const &, SchemaMapper const &)) &
79  SimpleTable::copyRecord,
80  "other"_a, "mapper"_a);
81  return cls;
82 }
83 
84 } // namespace lsst::afw::table::<anonymous>
85 
86 PYBIND11_MODULE(simple, mod) {
87  py::module::import("lsst.afw.coord"); // needed, but why? Perhaps can be removed after RFC-460
88  py::module::import("lsst.afw.table.base");
89  py::module::import("lsst.afw.table.idFactory");
90 
91  auto clsSimpleRecord = declareSimpleRecord(mod);
92  auto clsSimpleTable = declareSimpleTable(mod);
93  auto clsSimpleColumnView = table::python::declareColumnView<SimpleRecord>(mod, "Simple");
94  auto clsSimpleCatalog = table::python::declareSortedCatalog<SimpleRecord>(mod, "Simple");
95 
96  clsSimpleRecord.attr("Table") = clsSimpleTable;
97  clsSimpleRecord.attr("ColumnView") = clsSimpleColumnView;
98  clsSimpleRecord.attr("Catalog") = clsSimpleCatalog;
99  clsSimpleTable.attr("Record") = clsSimpleRecord;
100  clsSimpleTable.attr("ColumnView") = clsSimpleColumnView;
101  clsSimpleTable.attr("Catalog") = clsSimpleCatalog;
102  clsSimpleCatalog.attr("Record") = clsSimpleRecord;
103  clsSimpleCatalog.attr("Table") = clsSimpleTable;
104  clsSimpleCatalog.attr("ColumnView") = clsSimpleColumnView;
105 }
106 }
107 }
108 } // namespace lsst::afw::table
A base class for image defects.
PYBIND11_MODULE(simple, mod)
Definition: simple.cc:86