27#include "pybind11/pybind11.h"
30#include "pybind11/stl.h"
32#include "ndarray/pybind11.h"
43using namespace py::literals;
51using PyDetectorBase = py::class_<DetectorBase, std::shared_ptr<DetectorBase>>;
52using PyDetector = py::class_<Detector, DetectorBase, std::shared_ptr<Detector>, typehandling::Storable>;
53using PyDetectorBuilder = py::class_<Detector::Builder, DetectorBase, std::shared_ptr<Detector::Builder>>;
54using PyDetectorPartialRebuilder = py::class_<Detector::PartialRebuilder, Detector::Builder,
56using PyDetectorInCameraBuilder =
57 py::class_<Detector::InCameraBuilder, Detector::Builder, std::shared_ptr<Detector::InCameraBuilder>>;
60template <
typename SysT,
typename PyClass>
61void declare1SysMethods(PyClass &cls) {
65 cls.def(
"getCenter", (
lsst::geom::Point2D(Detector::*)(SysT const &) const) & Detector::getCenter,
67 cls.def(
"hasTransform", (
bool (Detector::*)(SysT const &) const) & Detector::hasTransform,
"cameraSys"_a);
71template <
typename FromSysT,
typename ToSysT,
typename PyClass>
72void declare2SysMethods(PyClass &cls) {
73 cls.def(
"getTransform",
76 Detector::getTransform,
77 "fromSys"_a,
"toSys"_a);
82 "point"_a,
"fromSys"_a,
"toSys"_a);
85 FromSysT const &, ToSysT const &) const) &
87 "points"_a,
"fromSys"_a,
"toSys"_a);
91 wrappers.
wrapType(PyDetectorBase(wrappers.module,
"DetectorBase"), [](
auto &mod,
auto &cls) {
92 cls.def(
"getName", &DetectorBase::getName);
93 cls.def(
"getId", &DetectorBase::getId);
94 cls.def(
"getType", &DetectorBase::getType);
95 cls.def(
"getPhysicalType", &DetectorBase::getPhysicalType);
96 cls.def(
"getSerial", &DetectorBase::getSerial);
97 cls.def(
"getBBox", &DetectorBase::getBBox);
98 cls.def(
"getOrientation", &DetectorBase::getOrientation);
99 cls.def(
"getPixelSize", &DetectorBase::getPixelSize);
100 cls.def(
"hasCrosstalk", &DetectorBase::hasCrosstalk);
101 cls.def(
"getCrosstalk", &DetectorBase::getCrosstalk);
102 cls.def(
"getNativeCoordSys", &DetectorBase::getNativeCoordSys);
103 cls.def(
"makeCameraSys",
104 py::overload_cast<CameraSys const &>(&DetectorBase::makeCameraSys, py::const_),
106 cls.def(
"makeCameraSys",
107 py::overload_cast<CameraSysPrefix const &>(&DetectorBase::makeCameraSys, py::const_),
108 "cameraSysPrefix"_a);
112void declareDetectorBuilder(PyDetector &parent);
113void declareDetectorPartialRebuilder(PyDetector &parent);
114void declareDetectorInCameraBuilder(PyDetector &parent);
117 wrappers.
wrapType(PyDetector(wrappers.module,
"Detector"), [](
auto &mod,
auto &cls) {
118 declareDetectorBuilder(cls);
119 declareDetectorPartialRebuilder(cls);
120 declareDetectorInCameraBuilder(cls);
121 cls.def(
"rebuild", &Detector::rebuild);
122 declare1SysMethods<CameraSys>(cls);
123 declare1SysMethods<CameraSysPrefix>(cls);
124 declare2SysMethods<CameraSys, CameraSys>(cls);
125 declare2SysMethods<CameraSys, CameraSysPrefix>(cls);
126 declare2SysMethods<CameraSysPrefix, CameraSys>(cls);
127 declare2SysMethods<CameraSysPrefix, CameraSysPrefix>(cls);
128 cls.def(
"getTransformMap", &Detector::getTransformMap);
129 cls.def(
"getAmplifiers", &Detector::getAmplifiers);
133 [](Detector const &self, std::ptrdiff_t i) {
134 return self[cpputils::python::cppIndex(self.size(), i)];
137 cls.def(
"__getitem__", py::overload_cast<std::string const &>(&Detector::operator[], py::const_),
144void declareDetectorBuilder(PyDetector &parent) {
145 PyDetectorBuilder cls(parent,
"Builder");
159 cls.def(
"__getitem__", py::overload_cast<std::string const &>(&Detector::Builder::operator[], py::const_),
166void declareDetectorPartialRebuilder(PyDetector &parent) {
167 PyDetectorPartialRebuilder cls(parent,
"PartialRebuilder");
168 cls.def(py::init<Detector const &>(),
"detector"_a);
172void declareDetectorInCameraBuilder(PyDetector &parent) {
173 PyDetectorInCameraBuilder cls(parent,
"InCameraBuilder");
176 cls.def(
"setTransformFromPixelsTo",
177 py::overload_cast<CameraSysPrefix
const &,
180 "toSys"_a,
"transform"_a);
181 cls.def(
"setTransformFromPixelsTo",
184 "toSys"_a,
"transform"_a);
185 cls.def(
"discardTransformFromPixelsTo",
186 py::overload_cast<CameraSysPrefix const &>(
189 cls.def(
"discardTransformFromPixelsTo",
196 wrappers.
wrapType(py::enum_<DetectorType>(wrappers.module,
"DetectorType"), [](
auto &mod,
auto &enm) {
197 enm.value(
"SCIENCE", DetectorType::SCIENCE);
198 enm.value(
"FOCUS", DetectorType::FOCUS);
199 enm.value(
"GUIDER", DetectorType::GUIDER);
200 enm.value(
"WAVEFRONT", DetectorType::WAVEFRONT);
202 declareDetectorBase(wrappers);
203 declareDetector(wrappers);
void setSerial(std::string const &serial)
Set the detector serial "number".
void setBBox(lsst::geom::Box2I const &bbox)
Set the bounding box.
void setPhysicalType(std::string const &physicalType)
Set the detector's physical type.
void setCrosstalk(CrosstalkMatrix const &crosstalk)
Set the crosstalk coefficients.
std::vector< std::shared_ptr< Amplifier::Builder > > const & getAmplifiers() const
Return the sequence of Amplifier::Builders directly.
void setType(DetectorType type)
Set the purpose of this detector.
void unsetCrosstalk()
Remove the crosstalk coefficient matrix.
void append(std::shared_ptr< Amplifier::Builder > builder)
Append a new amplifier.
std::size_t size() const
Return the number of amplifiers (renamed to len in Python).
void clear()
Remove all amplifiers.
void setOrientation(Orientation const &orientation)
Set the orientation of the detector in the focal plane.
void setTransformFromPixelsTo(CameraSysPrefix const &toSys, std::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > transform)
Set the transformation from PIXELS to the given coordinate system.
bool discardTransformFromPixelsTo(CameraSysPrefix const &toSys)
Remove any transformation from PIXELS to the given coordinate system.
void setPixelSize(lsst::geom::Extent2D const &pixelSize)
Set the pixel size (in mm).
std::shared_ptr< Detector const > finish() const
Construct a new Detector from the current state of the Builder.
std::size_t size() const
Get the number of amplifiers.
A helper class for subdividing pybind11 module across multiple translation units (i....
void addInheritanceDependency(std::string const &name)
Indicate an external module that provides a base class for a subsequent addType call.
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 wrapDetector(lsst::cpputils::python::WrapperCollection &)
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.
Point< double, 2 > Point2D