27 #include "pybind11/pybind11.h"
30 #include "pybind11/stl.h"
32 #include "ndarray/pybind11.h"
44 using namespace py::literals;
48 namespace cameraGeom {
52 using PyDetectorBase = py::class_<DetectorBase, std::shared_ptr<DetectorBase>>;
53 using PyDetector = py::class_<Detector, DetectorBase, std::shared_ptr<Detector>, typehandling::Storable>;
54 using PyDetectorBuilder = py::class_<Detector::Builder, DetectorBase, std::shared_ptr<Detector::Builder>>;
55 using PyDetectorPartialRebuilder = py::class_<Detector::PartialRebuilder, Detector::Builder,
57 using PyDetectorInCameraBuilder =
58 py::class_<Detector::InCameraBuilder, Detector::Builder, std::shared_ptr<Detector::InCameraBuilder>>;
61 template <
typename SysT,
typename PyClass>
62 void declare1SysMethods(
PyClass &cls) {
66 cls.def(
"getCenter", (
lsst::geom::Point2D(Detector::*)(SysT
const &)
const) & Detector::getCenter,
68 cls.def(
"hasTransform", (
bool (Detector::*)(SysT
const &)
const) & Detector::hasTransform,
"cameraSys"_a);
72 template <
typename FromSysT,
typename ToSysT,
typename PyClass>
73 void declare2SysMethods(
PyClass &cls) {
74 cls.def(
"getTransform",
77 Detector::getTransform,
78 "fromSys"_a,
"toSys"_a);
83 "point"_a,
"fromSys"_a,
"toSys"_a);
86 FromSysT
const &, ToSysT
const &)
const) &
88 "points"_a,
"fromSys"_a,
"toSys"_a);
92 wrappers.
wrapType(PyDetectorBase(wrappers.
module,
"DetectorBase"), [](
auto &mod,
auto &cls) {
93 cls.def(
"getName", &DetectorBase::getName);
94 cls.def(
"getId", &DetectorBase::getId);
95 cls.def(
"getType", &DetectorBase::getType);
96 cls.def(
"getPhysicalType", &DetectorBase::getPhysicalType);
97 cls.def(
"getSerial", &DetectorBase::getSerial);
98 cls.def(
"getBBox", &DetectorBase::getBBox);
99 cls.def(
"getOrientation", &DetectorBase::getOrientation);
100 cls.def(
"getPixelSize", &DetectorBase::getPixelSize);
101 cls.def(
"hasCrosstalk", &DetectorBase::hasCrosstalk);
102 cls.def(
"getCrosstalk", &DetectorBase::getCrosstalk);
103 cls.def(
"getNativeCoordSys", &DetectorBase::getNativeCoordSys);
104 cls.def(
"makeCameraSys",
105 py::overload_cast<CameraSys const &>(&DetectorBase::makeCameraSys, py::const_),
107 cls.def(
"makeCameraSys",
108 py::overload_cast<CameraSysPrefix const &>(&DetectorBase::makeCameraSys, py::const_),
109 "cameraSysPrefix"_a);
113 void declareDetectorBuilder(PyDetector &parent);
114 void declareDetectorPartialRebuilder(PyDetector &parent);
115 void declareDetectorInCameraBuilder(PyDetector &parent);
118 wrappers.
wrapType(PyDetector(wrappers.
module,
"Detector"), [](
auto &mod,
auto &cls) {
119 declareDetectorBuilder(cls);
120 declareDetectorPartialRebuilder(cls);
121 declareDetectorInCameraBuilder(cls);
122 cls.def(
"rebuild", &Detector::rebuild);
123 declare1SysMethods<CameraSys>(cls);
124 declare1SysMethods<CameraSysPrefix>(cls);
125 declare2SysMethods<CameraSys, CameraSys>(cls);
126 declare2SysMethods<CameraSys, CameraSysPrefix>(cls);
127 declare2SysMethods<CameraSysPrefix, CameraSys>(cls);
128 declare2SysMethods<CameraSysPrefix, CameraSysPrefix>(cls);
129 cls.def(
"getTransformMap", &Detector::getTransformMap);
130 cls.def(
"getAmplifiers", &Detector::getAmplifiers);
134 [](Detector const &self, std::ptrdiff_t i) {
135 return self[utils::python::cppIndex(self.size(), i)];
138 cls.def(
"__getitem__", py::overload_cast<std::string const &>(&Detector::operator[], py::const_),
140 cls.def(
"__len__", &Detector::size);
145 void declareDetectorBuilder(PyDetector &parent) {
146 PyDetectorBuilder cls(parent,
"Builder");
147 cls.def(
"setBBox", &Detector::Builder::setBBox);
148 cls.def(
"setType", &Detector::Builder::setType);
149 cls.def(
"setSerial", &Detector::Builder::setSerial);
150 cls.def(
"setPhysicalType", &Detector::Builder::setPhysicalType);
151 cls.def(
"setCrosstalk", &Detector::Builder::setCrosstalk);
152 cls.def(
"unsetCrosstalk", &Detector::Builder::unsetCrosstalk);
153 cls.def(
"getAmplifiers", &Detector::Builder::getAmplifiers);
160 cls.def(
"__getitem__", py::overload_cast<std::string const &>(&Detector::Builder::operator[], py::const_),
163 cls.def(
"clear", &Detector::Builder::clear);
164 cls.def(
"__len__", &Detector::Builder::size);
167 void declareDetectorPartialRebuilder(PyDetector &parent) {
168 PyDetectorPartialRebuilder cls(parent,
"PartialRebuilder");
169 cls.def(py::init<Detector const &>(),
"detector"_a);
170 cls.def(
"finish", &Detector::PartialRebuilder::finish);
173 void declareDetectorInCameraBuilder(PyDetector &parent) {
174 PyDetectorInCameraBuilder cls(parent,
"InCameraBuilder");
175 cls.def(
"setOrientation", &Detector::InCameraBuilder::setOrientation);
176 cls.def(
"setPixelSize", &Detector::InCameraBuilder::setPixelSize);
177 cls.def(
"setTransformFromPixelsTo",
178 py::overload_cast<CameraSysPrefix
const &,
180 &Detector::InCameraBuilder::setTransformFromPixelsTo),
181 "toSys"_a,
"transform"_a);
182 cls.def(
"setTransformFromPixelsTo",
184 &Detector::InCameraBuilder::setTransformFromPixelsTo),
185 "toSys"_a,
"transform"_a);
186 cls.def(
"discardTransformFromPixelsTo",
187 py::overload_cast<CameraSysPrefix const &>(
188 &Detector::InCameraBuilder::discardTransformFromPixelsTo),
190 cls.def(
"discardTransformFromPixelsTo",
191 py::overload_cast<CameraSys const &>(&Detector::InCameraBuilder::discardTransformFromPixelsTo),
197 wrappers.
wrapType(py::enum_<DetectorType>(wrappers.
module,
"DetectorType"), [](
auto &mod,
auto &enm) {
198 enm.value(
"SCIENCE", DetectorType::SCIENCE);
199 enm.value(
"FOCUS", DetectorType::FOCUS);
200 enm.value(
"GUIDER", DetectorType::GUIDER);
201 enm.value(
"WAVEFRONT", DetectorType::WAVEFRONT);
203 declareDetectorBase(wrappers);
204 declareDetector(wrappers);
A helper class for subdividing pybind11 module across multiple translation units (i....
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
void addInheritanceDependency(std::string const &name)
Indicate an external module that provides a base class for a subsequent addType call.
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
void wrapDetector(lsst::utils::python::WrapperCollection &)
py::class_< PixelAreaBoundedField, std::shared_ptr< PixelAreaBoundedField >, BoundedField > PyClass
void addPersistableMethods(pybind11::class_< Class, Args... > &cls)
Add table::io::Persistable and PersistableFacade methods to the pybind11 wrapper for a class.
std::size_t cppIndex(std::ptrdiff_t size, std::ptrdiff_t i)
Compute a C++ index from a Python index (negative values count from the end) and range-check.
A base class for image defects.