LSSTApplications  18.1.0
LSSTDataManagementBasePackage
schemaMapper.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2017 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/stl.h"
25 
26 #include "lsst/afw/table/Field.h"
27 #include "lsst/afw/table/Key.h"
28 #include "lsst/afw/table/Schema.h"
31 
32 namespace py = pybind11;
33 using namespace pybind11::literals;
34 
35 namespace lsst {
36 namespace afw {
37 namespace table {
38 namespace {
39 
40 using PySchemaMapper = py::class_<SchemaMapper, std::shared_ptr<SchemaMapper>>;
41 
42 template <typename T>
43 void declareSchemaMapperOverloads(PySchemaMapper &cls, std::string const &suffix) {
44  cls.def("getMapping", (Key<T>(SchemaMapper::*)(Key<T> const &) const) & SchemaMapper::getMapping);
45  cls.def("isMapped", (bool (SchemaMapper::*)(Key<T> const &) const) & SchemaMapper::isMapped);
46 };
47 
48 PYBIND11_MODULE(schemaMapper, mod) {
49  py::module::import("lsst.afw.table.schema");
50 
51  PySchemaMapper cls(mod, "SchemaMapper");
52 
53  cls.def(py::init<>());
54  cls.def(py::init<Schema const &, Schema const &>());
55  cls.def(py::init<Schema const &, bool>(), "input"_a, "shareAliasMap"_a = false);
56 
57  cls.def("getInputSchema", &SchemaMapper::getInputSchema);
58  cls.def("getOutputSchema", &SchemaMapper::getOutputSchema);
59  cls.def("editOutputSchema", &SchemaMapper::editOutputSchema, py::return_value_policy::reference_internal);
60  cls.def("addMinimalSchema", &SchemaMapper::addMinimalSchema, "minimal"_a, "doMap"_a = true);
61  cls.def_static("removeMinimalSchema", &SchemaMapper::removeMinimalSchema);
62  cls.def_static("join", &SchemaMapper::join, "inputs"_a, "prefixes"_a = std::vector<std::string>());
63 
64  declareSchemaMapperOverloads<std::uint8_t>(cls, "B");
65  declareSchemaMapperOverloads<std::uint16_t>(cls, "U");
66  declareSchemaMapperOverloads<std::int32_t>(cls, "I");
67  declareSchemaMapperOverloads<std::int64_t>(cls, "L");
68  declareSchemaMapperOverloads<float>(cls, "F");
69  declareSchemaMapperOverloads<double>(cls, "D");
70  declareSchemaMapperOverloads<std::string>(cls, "String");
71  declareSchemaMapperOverloads<lsst::geom::Angle>(cls, "Angle");
72  declareSchemaMapperOverloads<lsst::afw::table::Flag>(cls, "Flag");
73  declareSchemaMapperOverloads<lsst::afw::table::Array<std::uint8_t>>(cls, "ArrayB");
74  declareSchemaMapperOverloads<lsst::afw::table::Array<std::uint16_t>>(cls, "ArrayU");
75  declareSchemaMapperOverloads<lsst::afw::table::Array<int>>(cls, "ArrayI");
76  declareSchemaMapperOverloads<lsst::afw::table::Array<float>>(cls, "ArrayF");
77  declareSchemaMapperOverloads<lsst::afw::table::Array<double>>(cls, "ArrayD");
78 }
79 } // namespace
80 } // namespace table
81 } // namespace afw
82 } // namespace lsst
def getInputSchema(task, butler=None, schema=None)
Obtain the input schema either directly or froma butler reference.
PYBIND11_MODULE(camera, mod)
Definition: camera.cc:34
STL class.
A base class for image defects.